Skip to content

Commit d7121f5

Browse files
authored
Merge pull request #685 from boriel/bugfix/peek_ulong
fix: fixes PEEK(ULong, ...)
2 parents 6ba50a0 + ed5c4a2 commit d7121f5

8 files changed

Lines changed: 202 additions & 2 deletions

File tree

src/arch/z80/backend/_32bit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def _32bit_oper(op1, op2=None, *, reversed: bool = False, preserveHL: bool = Fal
6363
if immediate:
6464
op = op[1:]
6565

66-
hl = "hl" if not preserveHL and not indirect else "bc"
66+
hl = "hl" if not preserveHL else "bc"
6767

6868
if is_int(op):
6969
int1 = True

src/arch/z80/visitor/builtin_translator.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ def visit_RND(self, node): # A special "ZEROARY" function with no parameters
5757
self.runtime_call(RuntimeLabel.RND, Type.float_.size)
5858

5959
def visit_PEEK(self, node):
60-
self.ic_load(node.type_, node.t, "*" + str(node.children[0].t))
60+
if node.operand.token == "NUMBER":
61+
self.ic_load(node.type_, node.t, "*#" + str(node.operand.t))
62+
else:
63+
self.ic_load(node.type_, node.t, "*" + str(node.operand.t))
6164

6265
# region MATH Functions
6366
def visit_SIN(self, node):
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
_x:
22+
DEFB 00, 00
23+
_y:
24+
DEFB 00
25+
.core.ZXBASIC_USER_DATA_END:
26+
.core.__MAIN_PROGRAM__:
27+
ld a, (16384)
28+
ld (_y), a
29+
ld hl, (_x)
30+
ld a, (hl)
31+
ld (_y), a
32+
ld hl, (_x)
33+
ld a, (hl)
34+
ld (_y), a
35+
ld hl, 0
36+
ld b, h
37+
ld c, l
38+
.core.__END_PROGRAM:
39+
di
40+
ld hl, (.core.__CALL_BACK__)
41+
ld sp, hl
42+
exx
43+
pop hl
44+
exx
45+
pop iy
46+
pop ix
47+
ei
48+
ret
49+
;; --- end of user code ---
50+
END
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
DIM x as UInteger
2+
3+
DIM y as UByte
4+
y = PEEK(UByte, 16384)
5+
y = PEEK(UByte, x)
6+
y = PEEK(UByte, x + 0)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
_x:
22+
DEFB 00, 00
23+
_y:
24+
DEFB 00, 00
25+
.core.ZXBASIC_USER_DATA_END:
26+
.core.__MAIN_PROGRAM__:
27+
ld hl, (16384)
28+
ld (_y), hl
29+
ld hl, (_x)
30+
ld a, (hl)
31+
inc hl
32+
ld h, (hl)
33+
ld l, a
34+
ld (_y), hl
35+
ld hl, (_x)
36+
ld a, (hl)
37+
inc hl
38+
ld h, (hl)
39+
ld l, a
40+
ld (_y), hl
41+
ld hl, 0
42+
ld b, h
43+
ld c, l
44+
.core.__END_PROGRAM:
45+
di
46+
ld hl, (.core.__CALL_BACK__)
47+
ld sp, hl
48+
exx
49+
pop hl
50+
exx
51+
pop iy
52+
pop ix
53+
ei
54+
ret
55+
;; --- end of user code ---
56+
END
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
DIM x as UInteger
2+
3+
DIM y as UInteger
4+
y = PEEK(UInteger, 16384)
5+
y = PEEK(UInteger, x)
6+
y = PEEK(UInteger, x + 0)
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
_x:
22+
DEFB 00, 00
23+
_y:
24+
DEFB 00, 00, 00, 00
25+
.core.ZXBASIC_USER_DATA_END:
26+
.core.__MAIN_PROGRAM__:
27+
ld hl, 16384
28+
call .core.__ILOAD32
29+
ld (_y), hl
30+
ld (_y + 2), de
31+
ld hl, (_x)
32+
call .core.__ILOAD32
33+
ld (_y), hl
34+
ld (_y + 2), de
35+
ld hl, (_x)
36+
call .core.__ILOAD32
37+
ld (_y), hl
38+
ld (_y + 2), de
39+
ld hl, 0
40+
ld b, h
41+
ld c, l
42+
.core.__END_PROGRAM:
43+
di
44+
ld hl, (.core.__CALL_BACK__)
45+
ld sp, hl
46+
exx
47+
pop hl
48+
exx
49+
pop iy
50+
pop ix
51+
ei
52+
ret
53+
;; --- end of user code ---
54+
#line 1 "/zxbasic/src/arch/zx48k/library-asm/iload32.asm"
55+
; __FASTCALL__ routine which
56+
; loads a 32 bits integer into DE,HL
57+
; stored at position pointed by POINTER HL
58+
; DE,HL <-- (HL)
59+
push namespace core
60+
__ILOAD32:
61+
ld e, (hl)
62+
inc hl
63+
ld d, (hl)
64+
inc hl
65+
ld a, (hl)
66+
inc hl
67+
ld h, (hl)
68+
ld l, a
69+
ex de, hl
70+
ret
71+
pop namespace
72+
#line 29 "peek_ulong.bas"
73+
END
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
DIM x as UInteger
2+
3+
DIM y as ULong
4+
y = PEEK(ULong, 16384)
5+
y = PEEK(ULong, x)
6+
y = PEEK(ULong, x + 0)

0 commit comments

Comments
 (0)