Skip to content

Commit c1c5b10

Browse files
authored
Deprecate LDH with $00-$FF (#1575)
1 parent f44de0c commit c1c5b10

File tree

6 files changed

+50
-5
lines changed

6 files changed

+50
-5
lines changed

include/asm/rpn.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ struct Expression {
5353
void makeUnaryOp(RPNCommand op, Expression &&src);
5454
void makeBinaryOp(RPNCommand op, Expression &&src1, Expression const &src2);
5555

56-
void makeCheckHRAM();
56+
bool makeCheckHRAM();
5757
void makeCheckRST();
5858

5959
void checkNBit(uint8_t n) const;

man/rgbasm-old.5

+17
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,23 @@ Instead, use
267267
.Ql LDH [C], A
268268
and
269269
.Ql LDH A, [C] .
270+
.Ss LDH [n8], A and LDH A, [n8]
271+
Deprecated in 0.9.0.
272+
.Pp
273+
.Ql LDH
274+
used to treat "addresses" from
275+
.Ad $00
276+
to
277+
.Ad $FF
278+
as if they were the low byte of an address from
279+
.Ad $FF00
280+
to
281+
.Ad $FFFF .
282+
.Pp
283+
Instead, use
284+
.Ql LDH [n16], A
285+
and
286+
.Ql LDH A, [n16] .
270287
.Ss rgbasm -i
271288
Deprecated in 0.6.0, removed in 0.8.0.
272289
.Pp

src/asm/parser.y

+12-2
Original file line numberDiff line numberDiff line change
@@ -1949,13 +1949,23 @@ z80_ldd:
19491949

19501950
z80_ldh:
19511951
Z80_LDH MODE_A COMMA op_mem_ind {
1952-
$4.makeCheckHRAM();
1952+
if ($4.makeCheckHRAM()) {
1953+
warning(
1954+
WARNING_OBSOLETE,
1955+
"LDH is deprecated with values from $00 to $FF; use $FF00 to $FFFF\n"
1956+
);
1957+
}
19531958

19541959
sect_ConstByte(0xF0);
19551960
sect_RelByte($4, 1);
19561961
}
19571962
| Z80_LDH op_mem_ind COMMA MODE_A {
1958-
$2.makeCheckHRAM();
1963+
if ($2.makeCheckHRAM()) {
1964+
warning(
1965+
WARNING_OBSOLETE,
1966+
"LDH is deprecated with values from $00 to $FF; use $FF00 to $FFFF\n"
1967+
);
1968+
}
19591969

19601970
sect_ConstByte(0xE0);
19611971
sect_RelByte($2, 1);

src/asm/rpn.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -568,16 +568,20 @@ void Expression::makeBinaryOp(RPNCommand op, Expression &&src1, Expression const
568568
}
569569
}
570570

571-
void Expression::makeCheckHRAM() {
571+
bool Expression::makeCheckHRAM() {
572572
isSymbol = false;
573573
if (!isKnown()) {
574574
*reserveSpace(1) = RPN_HRAM;
575575
} else if (int32_t val = value(); val >= 0xFF00 && val <= 0xFFFF) {
576576
// That range is valid, but only keep the lower byte
577577
data = val & 0xFF;
578-
} else if (val < 0 || val > 0xFF) {
578+
} else if (val >= 0 && val <= 0xFF) {
579+
// That range is valid, but deprecated
580+
return true;
581+
} else {
579582
error("Source address $%" PRIx32 " not between $FF00 to $FFFF\n", val);
580583
}
584+
return false;
581585
}
582586

583587
void Expression::makeCheckRST() {

src/link/patch.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,12 @@ static int32_t computeRPNExpr(Patch const &patch, std::vector<Symbol> const &fil
356356
isError = true;
357357
}
358358
value = 0;
359+
} else if (value >= 0 && value <= 0xFF) {
360+
warning(
361+
patch.src,
362+
patch.lineNo,
363+
"LDH is deprecated with values from $00 to $FF; use $FF00 to $FFFF"
364+
);
359365
}
360366
value &= 0xFF;
361367
break;

test/asm/deprecated-ldio.err

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
warning: deprecated-ldio.asm(5): [-Wobsolete]
2+
LDH is deprecated with values from $00 to $FF; use $FF00 to $FFFF
3+
warning: deprecated-ldio.asm(6): [-Wobsolete]
4+
LDH is deprecated with values from $00 to $FF; use $FF00 to $FFFF
15
warning: deprecated-ldio.asm(8): [-Wobsolete]
26
LD [C], A is deprecated; use LDH [C], A
37
warning: deprecated-ldio.asm(9): [-Wobsolete]
@@ -10,6 +14,10 @@ warning: deprecated-ldio.asm(15): [-Wobsolete]
1014
LDIO is deprecated; use LDH
1115
warning: deprecated-ldio.asm(16): [-Wobsolete]
1216
LDIO is deprecated; use LDH
17+
warning: deprecated-ldio.asm(20): [-Wobsolete]
18+
LDH is deprecated with values from $00 to $FF; use $FF00 to $FFFF
19+
warning: deprecated-ldio.asm(21): [-Wobsolete]
20+
LDH is deprecated with values from $00 to $FF; use $FF00 to $FFFF
1321
warning: deprecated-ldio.asm(23): [-Wobsolete]
1422
LD [C], A is deprecated; use LDH [C], A
1523
warning: deprecated-ldio.asm(24): [-Wobsolete]

0 commit comments

Comments
 (0)