From c1c5b10082166c7a091132989ceb8f6e72c9ee9e Mon Sep 17 00:00:00 2001 From: Sylvie <35663410+Rangi42@users.noreply.github.com> Date: Tue, 10 Dec 2024 21:27:37 -0500 Subject: [PATCH] Deprecate `LDH` with $00-$FF (#1575) --- include/asm/rpn.hpp | 2 +- man/rgbasm-old.5 | 17 +++++++++++++++++ src/asm/parser.y | 14 ++++++++++++-- src/asm/rpn.cpp | 8 ++++++-- src/link/patch.cpp | 6 ++++++ test/asm/deprecated-ldio.err | 8 ++++++++ 6 files changed, 50 insertions(+), 5 deletions(-) diff --git a/include/asm/rpn.hpp b/include/asm/rpn.hpp index b5b95ba83..69d7700c3 100644 --- a/include/asm/rpn.hpp +++ b/include/asm/rpn.hpp @@ -53,7 +53,7 @@ struct Expression { void makeUnaryOp(RPNCommand op, Expression &&src); void makeBinaryOp(RPNCommand op, Expression &&src1, Expression const &src2); - void makeCheckHRAM(); + bool makeCheckHRAM(); void makeCheckRST(); void checkNBit(uint8_t n) const; diff --git a/man/rgbasm-old.5 b/man/rgbasm-old.5 index 29217ff37..767e51523 100644 --- a/man/rgbasm-old.5 +++ b/man/rgbasm-old.5 @@ -267,6 +267,23 @@ Instead, use .Ql LDH [C], A and .Ql LDH A, [C] . +.Ss LDH [n8], A and LDH A, [n8] +Deprecated in 0.9.0. +.Pp +.Ql LDH +used to treat "addresses" from +.Ad $00 +to +.Ad $FF +as if they were the low byte of an address from +.Ad $FF00 +to +.Ad $FFFF . +.Pp +Instead, use +.Ql LDH [n16], A +and +.Ql LDH A, [n16] . .Ss rgbasm -i Deprecated in 0.6.0, removed in 0.8.0. .Pp diff --git a/src/asm/parser.y b/src/asm/parser.y index cb4069093..7a74d7bb1 100644 --- a/src/asm/parser.y +++ b/src/asm/parser.y @@ -1949,13 +1949,23 @@ z80_ldd: z80_ldh: Z80_LDH MODE_A COMMA op_mem_ind { - $4.makeCheckHRAM(); + if ($4.makeCheckHRAM()) { + warning( + WARNING_OBSOLETE, + "LDH is deprecated with values from $00 to $FF; use $FF00 to $FFFF\n" + ); + } sect_ConstByte(0xF0); sect_RelByte($4, 1); } | Z80_LDH op_mem_ind COMMA MODE_A { - $2.makeCheckHRAM(); + if ($2.makeCheckHRAM()) { + warning( + WARNING_OBSOLETE, + "LDH is deprecated with values from $00 to $FF; use $FF00 to $FFFF\n" + ); + } sect_ConstByte(0xE0); sect_RelByte($2, 1); diff --git a/src/asm/rpn.cpp b/src/asm/rpn.cpp index 126c02483..129922722 100644 --- a/src/asm/rpn.cpp +++ b/src/asm/rpn.cpp @@ -568,16 +568,20 @@ void Expression::makeBinaryOp(RPNCommand op, Expression &&src1, Expression const } } -void Expression::makeCheckHRAM() { +bool Expression::makeCheckHRAM() { isSymbol = false; if (!isKnown()) { *reserveSpace(1) = RPN_HRAM; } else if (int32_t val = value(); val >= 0xFF00 && val <= 0xFFFF) { // That range is valid, but only keep the lower byte data = val & 0xFF; - } else if (val < 0 || val > 0xFF) { + } else if (val >= 0 && val <= 0xFF) { + // That range is valid, but deprecated + return true; + } else { error("Source address $%" PRIx32 " not between $FF00 to $FFFF\n", val); } + return false; } void Expression::makeCheckRST() { diff --git a/src/link/patch.cpp b/src/link/patch.cpp index a64f1df19..9270782be 100644 --- a/src/link/patch.cpp +++ b/src/link/patch.cpp @@ -356,6 +356,12 @@ static int32_t computeRPNExpr(Patch const &patch, std::vector const &fil isError = true; } value = 0; + } else if (value >= 0 && value <= 0xFF) { + warning( + patch.src, + patch.lineNo, + "LDH is deprecated with values from $00 to $FF; use $FF00 to $FFFF" + ); } value &= 0xFF; break; diff --git a/test/asm/deprecated-ldio.err b/test/asm/deprecated-ldio.err index a1abbe3b8..d9b04081b 100644 --- a/test/asm/deprecated-ldio.err +++ b/test/asm/deprecated-ldio.err @@ -1,3 +1,7 @@ +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] @@ -10,6 +14,10 @@ warning: deprecated-ldio.asm(15): [-Wobsolete] LDIO is deprecated; use LDH warning: deprecated-ldio.asm(16): [-Wobsolete] LDIO is deprecated; use LDH +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]