shithub: scc

Download patch

ref: 2f51459d358787bb85dfbb87b004920aeaf625a1
parent: d9814fd84bcabdda378b83e3d7c97d350e5eb16a
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Dec 29 04:12:42 EST 2017

[as-z80] Add indirect jumps

--- a/as/target/x80/ins.c
+++ b/as/target/x80/ins.c
@@ -485,7 +485,7 @@
 }
 
 void
-cc(Op *op, Node **args)
+branch(Op *op, Node **args)
 {
 	unsigned char buf[4];
 	Node *flag, *imm;
@@ -492,8 +492,13 @@
 	int n = op->size, i = n;
 	unsigned val;
 
-	flag = args[0];
-	imm = args[1];
+	flag = imm = NULL;
+	if (args[0]->addr == AREG) {
+		flag = args[0];
+		imm = args[1];
+	} else if (args[0]->addr == AIMM) {
+		imm = args[0];
+	}
 	memcpy(buf, op->bytes, n);
 
 	if (imm) {
@@ -501,16 +506,10 @@
 		buf[--i] = val >> 8;
 		buf[--i] = val;
 	}
-	buf[--i] |= flag2int(flag->sym->argtype) << 3;
+	if (flag)
+		buf[--i] |= flag2int(flag->sym->argtype) << 3;
 
 	emit(buf, n);
-}
-
-void
-jr(Op *op, Node **args)
-{
-	/* TODO */
-	abort();
 }
 
 void
--- a/as/target/x80/proc.h
+++ b/as/target/x80/proc.h
@@ -55,6 +55,8 @@
 	AINDER_BC,    /* (BC) */
 	AINDER_SP,    /* (SP) */
 	AINDER_C,     /* (C) */
+	AINDER_IX,    /* (IX) */
+	AINDER_IY,    /* (IY) */
 
 	AIMM3,         /* 3 bit immediate */
 	AZERO,         /* a literal 0 */
--- a/as/target/x80/rules.dat
+++ b/as/target/x80/rules.dat
@@ -21,6 +21,8 @@
 \(HL\)	AINDER_HL
 \(SP\)	AINDER_SP
 \(C\)	AINDER_C
+\(IX\)	AINDER_IX
+\(IY\)	AINDER_IY
 SP	AREG_SP
 HL	AREG_HL
 DE	AREG_DE
--- a/as/target/x80/x80.dat
+++ b/as/target/x80/x80.dat
@@ -332,18 +332,20 @@
 OTDR	none	2	0xed,0xbb	noargs	Z80,R800
 
 # Jump group
-JP	imm16	3	0xc3	imm16	Z80,R800,GB80
-JP	cc,imm16	3	0xc2	cc	Z80,R800,GB80
-JR	imm8	2	0x18	jr	Z80,R800,GB80
-JR	ss,imm8	2	0x00	jr	Z80,R800,GB80
-JP	IY	2	0xfd,0xe9	noargs	Z80,R800
-DJNZ	imm8	2	0x10	jr	Z80,R800,GB80
+JP	imm16	3	0xc3	branch	Z80,R800,GB80
+JP	cc,imm16	3	0xc2	branch	Z80,R800,GB80
+JR	imm8	2	0x18	branch	Z80,R800,GB80
+JR	ss,imm8	2	0x00	branch	Z80,R800,GB80
+JP	(HL)	1	0xe9	branch	Z80,R800,GB80
+JP	(IX)	2	0xdd,0xe9	branch	Z80,R800
+JP	(IY)	2	0xfd,0xe9	branch	Z80,R800
+DJNZ	imm8	2	0x10	branch	Z80,R800,GB80
 
 # Call and return group
-CALL	imm16	3	0xcd	imm16	Z80,R800,GB80
-CALL	cc,imm16	3	0xc4	cc	Z80,R800
+CALL	imm16	3	0xcd	branch	Z80,R800,GB80
+CALL	cc,imm16	3	0xc4	branch	Z80,R800
 RET	none	1	0xc9	noargs	Z80,R800,GB80
-RET	cc	1	0xc0	cc	Z80,R800
+RET	cc	1	0xc0	branch	Z80,R800
 RETI	none	2	0xed,0x4d	noargs	Z80,R800
 RETN	none	2	0xed,0x45	noargs	Z80,R800
 RST	rst	1	0xc7	rst	Z80,R800,GB80
--- a/as/target/z80/proc.c
+++ b/as/target/z80/proc.c
@@ -91,6 +91,12 @@
 		case AINDER_BC:
 			arg = AREG_BC;
 			goto indirect;
+		case AINDER_IX:
+			arg = AREG_IX;
+			goto indirect;
+		case AINDER_IY:
+			arg = AREG_IY;
+			goto indirect;
 		case AINDER_SP:
 			arg = AREG_SP;
 		indirect:
--- a/as/target/z80/test.s
+++ b/as/target/z80/test.s
@@ -757,7 +757,7 @@
 	POP	%IX	/ DD E1
 	EX	(%SP),%IX	/ DD E3
 	PUSH	%IX	/ DD E5
-/	JP	(%IX)	/ DD E9
+	JP	(%IX)	/ DD E9
 	LD	%SP,%IX	/ DD F9
 	SBC	%A,64	/ DE 40
 	RST	24	/ DF
@@ -770,7 +770,7 @@
 	AND	%A,16	/ E6 10
 	RST	32	/ E7
 	RET	%PE	/ E8
-/E9	JP (HL)
+	JP	(%HL)	/ E9
 	JP	%PE,16384	/ EA 00 40
 	EX	%DE,%HL	/ EB
 	CALL	%PE,16384	/ EC 00 40
@@ -1130,7 +1130,7 @@
 	POP	%IY	/ FD E1
 	EX	(%SP),%IY	/ FD E3
 	PUSH	%IY	/ FD E5
-/FDE9	JP (IY)
+	JP	(%IY)	/ FD E9
 	LD	%SP,%IY	/ FD F9
 	CP	%A,32	/ FE 20
 	RST	56	/ FF