Skip to content

Commit 7dc9ee8

Browse files
committed
fix: O3 optimizer crash with PEEK
1 parent a4f8525 commit 7dc9ee8

File tree

3 files changed

+66
-5
lines changed

3 files changed

+66
-5
lines changed

src/arch/z80/optimizer/cpustate.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __init__(self):
3333

3434
def _get_hl_addr(self, addr: str) -> Tuple[str, str]:
3535
if is_number(addr):
36-
return addr, str(int(addr) + 1)
36+
return addr, str(valnum(addr) + 1)
3737

3838
ptr = RE_OFFSET.match(addr)
3939
if ptr is None:
@@ -54,7 +54,7 @@ def read_16_bit_value(self, addr: str) -> str:
5454
hi = self.mem[addr_hi]
5555
lo = self.mem[addr_lo]
5656
if is_number(hi) and is_number(lo):
57-
return str(int(lo) + 256 * int(hi))
57+
return str(valnum(lo) + 256 * valnum(hi))
5858

5959
result = f"{hi}|{lo}"
6060
if (label_ := get_orig_label_from_unknown16("")) is not None:
@@ -64,8 +64,9 @@ def read_16_bit_value(self, addr: str) -> str:
6464

6565
def write_16_bit_value(self, addr: str, value: str) -> None:
6666
if is_number(value):
67-
v_hi = str((int(value) >> 8) & 0xFF)
68-
v_lo = str(int(value) & 0xFF)
67+
value_ = valnum(value)
68+
v_hi = str((value_ >> 8) & 0xFF)
69+
v_lo = str(value_ & 0xFF)
6970
else:
7071
if is_unknown16(value):
7172
v_ = value
@@ -88,7 +89,7 @@ def read_8_bit_value(self, addr: str) -> str:
8889

8990
def write_8_bit_value(self, addr: str, value: str) -> None:
9091
if is_number(value):
91-
value = str(int(value) & 0xFF)
92+
value = str(valnum(value) & 0xFF)
9293
elif is_unknown16(value):
9394
value = get_L_from_unknown_value(value)
9495
elif is_label(value):

tests/functional/zx48k/opt3_peek.asm

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
org 32768
2+
.core.__START_PROGRAM:
3+
di
4+
push ix
5+
push iy
6+
exx
7+
push hl
8+
exx
9+
ld hl, 0
10+
add hl, sp
11+
ld (.core.__CALL_BACK__), hl
12+
ei
13+
jp .core.__MAIN_PROGRAM__
14+
.core.__CALL_BACK__:
15+
DEFW 0
16+
.core.ZXBASIC_USER_DATA:
17+
; Defines USER DATA Length in bytes
18+
.core.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_END - .core.ZXBASIC_USER_DATA
19+
.core.__LABEL__.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_LEN
20+
.core.__LABEL__.ZXBASIC_USER_DATA EQU .core.ZXBASIC_USER_DATA
21+
_dataSprite:
22+
DEFB 00, 00
23+
.core.ZXBASIC_USER_DATA_END:
24+
.core.__MAIN_PROGRAM__:
25+
ld hl, (_dataSprite)
26+
ld de, 26
27+
add hl, de
28+
push hl
29+
ld hl, (_dataSprite)
30+
add hl, de
31+
ld a, (hl)
32+
ld hl, (24328 - 1)
33+
add a, h
34+
pop hl
35+
ld (hl), a
36+
ld bc, 0
37+
.core.__END_PROGRAM:
38+
di
39+
ld hl, (.core.__CALL_BACK__)
40+
ld sp, hl
41+
exx
42+
pop hl
43+
pop iy
44+
pop ix
45+
exx
46+
ei
47+
ret
48+
;; --- end of user code ---
49+
END

tests/functional/zx48k/opt3_peek.bas

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#define spriteStatus (dataSprite)
2+
#define spriteTimer (dataSprite+26)
3+
4+
dim d1 as ubyte
5+
dim dataSprite as Uinteger
6+
7+
const variablesGlobales as UInteger= 24326
8+
const tictac as UInteger= (variablesGlobales+2)
9+
10+
poke spriteTimer,peek(spriteTimer)+peek(tictac)
11+
d1=peek(spriteTimer)+peek (tictac)

0 commit comments

Comments
 (0)