Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request boriel-basic#612 from boriel/bugfix/O3_optimizer_a…
Browse files Browse the repository at this point in the history
…nd_peek

Bugfix/o3 optimizer and peek
  • Loading branch information
boriel committed May 23, 2022
2 parents a4f8525 + 7dc9ee8 commit 9333410
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/arch/z80/optimizer/cpustate.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(self):

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

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

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

def write_16_bit_value(self, addr: str, value: str) -> None:
if is_number(value):
v_hi = str((int(value) >> 8) & 0xFF)
v_lo = str(int(value) & 0xFF)
value_ = valnum(value)
v_hi = str((value_ >> 8) & 0xFF)
v_lo = str(value_ & 0xFF)
else:
if is_unknown16(value):
v_ = value
Expand All @@ -88,7 +89,7 @@ def read_8_bit_value(self, addr: str) -> str:

def write_8_bit_value(self, addr: str, value: str) -> None:
if is_number(value):
value = str(int(value) & 0xFF)
value = str(valnum(value) & 0xFF)
elif is_unknown16(value):
value = get_L_from_unknown_value(value)
elif is_label(value):
Expand Down
49 changes: 49 additions & 0 deletions tests/functional/zx48k/opt3_peek.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
org 32768
.core.__START_PROGRAM:
di
push ix
push iy
exx
push hl
exx
ld hl, 0
add hl, sp
ld (.core.__CALL_BACK__), hl
ei
jp .core.__MAIN_PROGRAM__
.core.__CALL_BACK__:
DEFW 0
.core.ZXBASIC_USER_DATA:
; Defines USER DATA Length in bytes
.core.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_END - .core.ZXBASIC_USER_DATA
.core.__LABEL__.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_LEN
.core.__LABEL__.ZXBASIC_USER_DATA EQU .core.ZXBASIC_USER_DATA
_dataSprite:
DEFB 00, 00
.core.ZXBASIC_USER_DATA_END:
.core.__MAIN_PROGRAM__:
ld hl, (_dataSprite)
ld de, 26
add hl, de
push hl
ld hl, (_dataSprite)
add hl, de
ld a, (hl)
ld hl, (24328 - 1)
add a, h
pop hl
ld (hl), a
ld bc, 0
.core.__END_PROGRAM:
di
ld hl, (.core.__CALL_BACK__)
ld sp, hl
exx
pop hl
pop iy
pop ix
exx
ei
ret
;; --- end of user code ---
END
11 changes: 11 additions & 0 deletions tests/functional/zx48k/opt3_peek.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#define spriteStatus (dataSprite)
#define spriteTimer (dataSprite+26)

dim d1 as ubyte
dim dataSprite as Uinteger

const variablesGlobales as UInteger= 24326
const tictac as UInteger= (variablesGlobales+2)

poke spriteTimer,peek(spriteTimer)+peek(tictac)
d1=peek(spriteTimer)+peek (tictac)

0 comments on commit 9333410

Please sign in to comment.