shithub: rgbds

Download patch

ref: 47442941b6a9480b14d784336fbb79c80b3000d8
parent: b16d2d069511ebf58de303861d5ae783f0b7b8d8
author: Rangi <35663410+Rangi42@users.noreply.github.com>
date: Mon Nov 1 15:16:52 EDT 2021

Support ! operator for condition codes (#720)

Fixes #719

--- a/src/asm/parser.y
+++ b/src/asm/parser.y
@@ -653,6 +653,7 @@
 %type	<constValue>	reg_ss
 %type	<constValue>	reg_rr
 %type	<constValue>	reg_tt
+%type	<constValue>	ccode_expr
 %type	<constValue>	ccode
 %type	<expr>		op_a_n
 %type	<constValue>	op_a_r
@@ -1775,7 +1776,7 @@
 			sect_AbsByte(0xCD);
 			sect_RelWord(&$2, 1);
 		}
-		| T_Z80_CALL ccode T_COMMA reloc_16bit {
+		| T_Z80_CALL ccode_expr T_COMMA reloc_16bit {
 			sect_AbsByte(0xC4 | ($2 << 3));
 			sect_RelWord(&$4, 1);
 		}
@@ -1822,7 +1823,7 @@
 			sect_AbsByte(0xC3);
 			sect_RelWord(&$2, 1);
 		}
-		| T_Z80_JP ccode T_COMMA reloc_16bit {
+		| T_Z80_JP ccode_expr T_COMMA reloc_16bit {
 			sect_AbsByte(0xC2 | ($2 << 3));
 			sect_RelWord(&$4, 1);
 		}
@@ -1835,7 +1836,7 @@
 			sect_AbsByte(0x18);
 			sect_PCRelByte(&$2, 1);
 		}
-		| T_Z80_JR ccode T_COMMA reloc_16bit {
+		| T_Z80_JR ccode_expr T_COMMA reloc_16bit {
 			sect_AbsByte(0x20 | ($2 << 3));
 			sect_PCRelByte(&$4, 1);
 		}
@@ -2017,7 +2018,7 @@
 ;
 
 z80_ret		: T_Z80_RET { sect_AbsByte(0xC9); }
-		| T_Z80_RET ccode { sect_AbsByte(0xC0 | ($2 << 3)); }
+		| T_Z80_RET ccode_expr { sect_AbsByte(0xC0 | ($2 << 3)); }
 ;
 
 z80_reti	: T_Z80_RETI { sect_AbsByte(0xD9); }
@@ -2170,6 +2171,12 @@
 
 T_MODE_L	: T_TOKEN_L
 		| T_OP_LOW T_LPAREN T_MODE_HL T_RPAREN
+;
+
+ccode_expr	: ccode
+		| T_OP_LOGICNOT ccode_expr {
+			$$ = $2 ^ 1;
+		}
 ;
 
 ccode		: T_CC_NZ { $$ = CC_NZ; }
--- a/src/gbz80.7
+++ b/src/gbz80.7
@@ -62,6 +62,8 @@
 Execute if C is set.
 .It Sy NC
 Execute if C is not set.
+.It Sy ! cc
+Negates a condition code.
 .El
 .It Ar vec
 One of the
--- /dev/null
+++ b/test/asm/ccode.asm
@@ -1,0 +1,21 @@
+SECTION "ccode test", ROM0[0]
+
+Label:
+
+.local1
+	jp z, Label
+	jr nz, .local1
+	call c, Label
+	call nc, Label
+
+.local2
+	jp !nz, Label
+	jr !z, .local2
+	call !nc, Label
+	call !c, Label
+
+.local3
+	jp !!z, Label
+	jr !!nz, .local3
+	call !!c, Label
+	call !!nc, Label
binary files /dev/null b/test/asm/ccode.out.bin differ