shithub: scc

Download patch

ref: 4b78a1bebc78fa724444f23265e7c2d90e098024
parent: fa5537937b3c5ab2f10bff43b9a1dc56b540176d
author: Roberto E. Vargas Caballero <[email protected]>
date: Fri Sep 29 05:55:23 EDT 2017

[as] Add r8_imm format instruction in z80

This instruction format is used in that instruction that
uses a register from A, B, C, D, E, H, L and a 8 bit
inmediate.

--- a/as/expr.c
+++ b/as/expr.c
@@ -260,6 +260,8 @@
 	int c;
 	char *p;
 
+	if (*textp == '%')
+		++textp, ++endp;
 	while (isalnum(c = *endp))
 		++endp;
 	tok2str();
--- a/as/main.c
+++ b/as/main.c
@@ -105,6 +105,7 @@
 	if (argc != 2)
 		usage();
 
+	iarch();
 	filename = argv[1];
 	for (pass = 1; pass <= 2; pass++) {
 		if (!dopass(filename))
--- a/as/target/gen.awk
+++ b/as/target/gen.awk
@@ -74,6 +74,8 @@
 			out = out "AIMM32"
 		} else if (match(a, /^imm64/)) {
 			out = "AIMM64"
+		} else if (match(a, /^reg_8/)) {
+			out = out "AREG_8"
 		} else {
 			print "wrong arg", a
 			exit 1
--- /dev/null
+++ b/as/target/x80/ins.c
@@ -1,0 +1,33 @@
+static char sccsid[] = "@(#) ./as/target/z80/ins.c";
+
+#include "../../../inc/scc.h"
+#include "../../as.h"
+#include "proc.h"
+
+int
+r8(int reg)
+{
+	switch (reg) {
+	case AREG_B:  return 0;
+	case AREG_C:  return 1;
+	case AREG_D:  return 2;
+	case AREG_E:  return 3;
+	case AREG_H:  return 4;
+	case AREG_L:  return 5;
+	case AREG_A:  return 7;
+	default:      return -1;
+	}
+}
+
+void
+r8_imm(Op *op, Node **args)
+{
+	Node *par1, *par2;
+	unsigned char buf[2];
+
+	par1 = *args++;
+	par2 = *args;
+	buf[0] = *op->bytes | r8(par1->sym->argtype) << 3;
+	buf[1] = par2->sym->value;
+	emit(cursec, buf, 2);
+}
--- a/as/target/x80/proc.h
+++ b/as/target/x80/proc.h
@@ -27,4 +27,8 @@
 	AREG_R,
 	AREG_I,
 	AREG_AF_,
+
+	AREG_8,		/* class register for B, C, D, E, H, L and A */
 };
+
+extern int r8(int reg);
\ No newline at end of file
--- a/as/target/x80/x80.dat
+++ b/as/target/x80/x80.dat
@@ -51,3 +51,4 @@
 OTIR	none	2	0xed,0xb3	noargs	Z80,R800
 OUTD	none	2	0xed,0xab	noargs	Z80,R800
 OTDR	none	2	0xed,0xbb	noargs	Z80,R800
+LD	reg_8,imm8	2	0x06	r8_imm	Z80,R800,GB80
--- a/as/target/z80/ins.c
+++ b/as/target/z80/ins.c
@@ -1,4 +1,4 @@
-static char sccsid[] = "@(#) ./as/target/i386/ins.c";
+static char sccsid[] = "@(#) ./as/target/z80/ins.c";
 
 #include "../../../inc/scc.h"
 #include "../../as.h"
--- a/as/target/z80/proc.c
+++ b/as/target/z80/proc.c
@@ -64,6 +64,12 @@
 		if (arg & AREP)
 			--p;
 		switch (arg & ~AREP) {
+		case AREG_8:
+			if (np->op != AREG)
+				return 0;
+			if (r8(np->sym->argtype) == -1)
+				return 0;
+			break;
 		case AIMM8:
 		case AIMM16:
 		case AIMM32:
@@ -78,5 +84,6 @@
 			abort();
 		}
 	}
-	return 1;
+
+	return (!arg || arg & AREP) && !*args;
 }
--- a/as/target/z80/target.mk
+++ b/as/target/z80/target.mk
@@ -1,5 +1,5 @@
 
-Z80_LST = target/z80/instbl.o target/z80/ins.o target/z80/proc.o
+Z80_LST = target/z80/instbl.o target/z80/ins.o target/z80/proc.o target/x80/ins.o
 
 $(Z80_LST): target/x80/proc.h