Skip to content

Commit

Permalink
Undeprecate ld [$ff00+c]
Browse files Browse the repository at this point in the history
  • Loading branch information
Rangi42 committed Jan 18, 2025
1 parent 6ae3f04 commit c01b402
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 22 deletions.
21 changes: 17 additions & 4 deletions src/asm/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -1973,14 +1973,21 @@ z80_ldh:
| Z80_LDH MODE_A COMMA c_ind {
sect_ConstByte(0xF2);
}
| Z80_LDH MODE_A COMMA ff00_c_ind {
sect_ConstByte(0xF2);
}
| Z80_LDH c_ind COMMA MODE_A {
sect_ConstByte(0xE2);
}
| Z80_LDH ff00_c_ind COMMA MODE_A {
sect_ConstByte(0xE2);
}
;

c_ind:
LBRACK MODE_C RBRACK
| LBRACK relocexpr OP_ADD MODE_C RBRACK {
c_ind: LBRACK MODE_C RBRACK;

ff00_c_ind:
LBRACK relocexpr OP_ADD MODE_C RBRACK {
// This has to use `relocexpr`, not `iconst`, to avoid a shift/reduce conflict
if ($2.getConstVal() != 0xFF00)
::error("Base value must be equal to $FF00 for $FF00+C\n");
Expand Down Expand Up @@ -2031,7 +2038,10 @@ z80_ld_mem:
;

z80_ld_c_ind:
Z80_LD c_ind COMMA MODE_A {
Z80_LD ff00_c_ind COMMA MODE_A {
sect_ConstByte(0xE2);
}
| Z80_LD c_ind COMMA MODE_A {
warning(WARNING_OBSOLETE, "LD [C], A is deprecated; use LDH [C], A\n");
sect_ConstByte(0xE2);
}
Expand Down Expand Up @@ -2064,6 +2074,9 @@ z80_ld_a:
| Z80_LD reg_a COMMA reg_r {
sect_ConstByte(0x40 | ($2 << 3) | $4);
}
| Z80_LD reg_a COMMA ff00_c_ind {
sect_ConstByte(0xF2);
}
| Z80_LD reg_a COMMA c_ind {
warning(WARNING_OBSOLETE, "LD A, [C] is deprecated; use LDH A, [C]\n");
sect_ConstByte(0xF2);
Expand Down
8 changes: 0 additions & 8 deletions test/asm/deprecated-ldio.err
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ warning: deprecated-ldio.asm(5): [-Wobsolete]
LDH is deprecated with values from $00 to $FF; use $FF00 to $FFFF
warning: deprecated-ldio.asm(6): [-Wobsolete]
LDH is deprecated with values from $00 to $FF; use $FF00 to $FFFF
warning: deprecated-ldio.asm(8): [-Wobsolete]
LD [C], A is deprecated; use LDH [C], A
warning: deprecated-ldio.asm(9): [-Wobsolete]
LD A, [C] is deprecated; use LDH A, [C]
warning: deprecated-ldio.asm(13): [-Wobsolete]
LDIO is deprecated; use LDH
warning: deprecated-ldio.asm(14): [-Wobsolete]
Expand All @@ -18,10 +14,6 @@ warning: deprecated-ldio.asm(20): [-Wobsolete]
LDH is deprecated with values from $00 to $FF; use $FF00 to $FFFF
warning: deprecated-ldio.asm(21): [-Wobsolete]
LDH is deprecated with values from $00 to $FF; use $FF00 to $FFFF
warning: deprecated-ldio.asm(23): [-Wobsolete]
LD [C], A is deprecated; use LDH [C], A
warning: deprecated-ldio.asm(24): [-Wobsolete]
LD A, [C] is deprecated; use LDH A, [C]
warning: deprecated-ldio.asm(28): [-Wobsolete]
LDIO is deprecated; use LDH
warning: deprecated-ldio.asm(29): [-Wobsolete]
Expand Down
8 changes: 4 additions & 4 deletions test/asm/ff00+c-bad.asm
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

SECTION "ff00+c or not to ff00+c", ROMX

ldh a, [$ff00 + c]
ldh [65280 + c], a
ld a, [$ff00 + c]
ld [65280 + c], a

; Not ok
ldh a, [$ff01 + c]
ldh [xyz + c], a
ld a, [$ff01 + c]
ld [xyz + c], a
6 changes: 3 additions & 3 deletions test/asm/ff00+c.asm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SECTION "test", ROM0[0]
ldh [ $ff00 + c ], a
ld [ $ff00 + c ], a
; 257 spaces exceeds both LEXER_BUF_SIZE (64) and uint8_t limit (255)
ldh [ $ff00 + c ], a
ldh [ $ff00 + c ], a
ld [ $ff00 + c ], a
ld [ $ff00 + c ], a
2 changes: 1 addition & 1 deletion test/asm/invalid-instructions.asm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
SECTION "invalid", ROM0[$10000]
ld [hl], [hl]
ldh a, [$00ff+c]
ld a, [$00ff+c]
ld b, [c]
ld b, [bc]
ld b, [$4000]
Expand Down
4 changes: 2 additions & 2 deletions test/link/all-instructions.asm
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ ENDM
ld [hl],a
ld [$ABCD],a
ldh [$ff00+$DB],a
ldh [$ff00+c],a
ld [$ff00+c],a
ldh [$ff00 + c],a
ldh [c],a

Expand All @@ -164,7 +164,7 @@ ENDM
ld a,[$ABCD]
ldh a,[$ff00+$DB]
ldh a,[$ff00+c]
ldh a,[$ff00 + c]
ld a,[$ff00 + c]
ldh a,[c]

ld [hl+],a
Expand Down

0 comments on commit c01b402

Please sign in to comment.