Skip to content

Commit

Permalink
Deprecate LDH with $00-$FF (#1575)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rangi42 authored Dec 11, 2024
1 parent f44de0c commit c1c5b10
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 5 deletions.
2 changes: 1 addition & 1 deletion include/asm/rpn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 17 additions & 0 deletions man/rgbasm-old.5
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions src/asm/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions src/asm/rpn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 6 additions & 0 deletions src/link/patch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,12 @@ static int32_t computeRPNExpr(Patch const &patch, std::vector<Symbol> 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;
Expand Down
8 changes: 8 additions & 0 deletions test/asm/deprecated-ldio.err
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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]
Expand Down

0 comments on commit c1c5b10

Please sign in to comment.