Skip to content

Commit 951f53e

Browse files
authored
Merge pull request #1045 from boriel-basic/fix/cast_fix_to_long
Fix/cast fix to long
2 parents 8fb788e + 4f362f4 commit 951f53e

9 files changed

Lines changed: 217 additions & 10 deletions

File tree

src/arch/z80/backend/common.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -385,19 +385,24 @@ def to_long(stype: DataType) -> list[str]:
385385
)
386386
return output
387387

388-
if stype in {I8_t, U8_t, F16_t}: # Byte to word
388+
if stype in (I8_t, U8_t): # Byte to word
389389
output = to_word(stype)
390+
output.append("ld e, h")
391+
output.append("ld d, h")
390392

391-
if stype != F16_t: # If it's a byte, just copy H to D,E
392-
output.append("ld e, h")
393-
output.append("ld d, h")
393+
elif stype == I16_t: # Signed byte or fixed to word
394+
output.extend(
395+
[
396+
"ld a, h",
397+
"add a, a",
398+
"sbc a, a",
399+
"ld e, a",
400+
"ld d, a",
401+
]
402+
)
394403

395-
elif stype in (I16_t, F16_t): # Signed byte or fixed to word
396-
output.append("ld a, h")
397-
output.append("add a, a")
398-
output.append("sbc a, a")
399-
output.append("ld e, a")
400-
output.append("ld d, a")
404+
elif stype == F16_t:
405+
output.extend(["ex de, hl", "ld de, 0"])
401406

402407
elif stype in (U32_t, I32_t):
403408
return []
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 (.core.__CALL_BACK__), sp
10+
ei
11+
jp .core.__MAIN_PROGRAM__
12+
.core.__CALL_BACK__:
13+
DEFW 0
14+
.core.ZXBASIC_USER_DATA:
15+
; Defines USER DATA Length in bytes
16+
.core.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_END - .core.ZXBASIC_USER_DATA
17+
.core.__LABEL__.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_LEN
18+
.core.__LABEL__.ZXBASIC_USER_DATA EQU .core.ZXBASIC_USER_DATA
19+
_v1:
20+
DEFB 00h
21+
DEFB 80h
22+
DEFB 01h
23+
DEFB 00h
24+
_v2:
25+
DEFB 00, 00, 00, 00
26+
.core.ZXBASIC_USER_DATA_END:
27+
.core.__MAIN_PROGRAM__:
28+
ld hl, (_v1)
29+
ld de, (_v1 + 2)
30+
ex de, hl
31+
ld de, 0
32+
ld (_v2), hl
33+
ld (_v2 + 2), de
34+
ld hl, 0
35+
ld b, h
36+
ld c, l
37+
.core.__END_PROGRAM:
38+
di
39+
ld hl, (.core.__CALL_BACK__)
40+
ld sp, hl
41+
exx
42+
pop hl
43+
exx
44+
pop iy
45+
pop ix
46+
ei
47+
ret
48+
;; --- end of user code ---
49+
END
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
DIM v1 As Fixed = 1.5
2+
DIM v2 As Long
3+
4+
v2 = v1
5+
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 (.core.__CALL_BACK__), sp
10+
ei
11+
jp .core.__MAIN_PROGRAM__
12+
.core.__CALL_BACK__:
13+
DEFW 0
14+
.core.ZXBASIC_USER_DATA:
15+
; Defines USER DATA Length in bytes
16+
.core.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_END - .core.ZXBASIC_USER_DATA
17+
.core.__LABEL__.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_LEN
18+
.core.__LABEL__.ZXBASIC_USER_DATA EQU .core.ZXBASIC_USER_DATA
19+
_v1:
20+
DEFB 00h
21+
DEFB 80h
22+
DEFB 01h
23+
DEFB 00h
24+
_v2:
25+
DEFB 00, 00, 00, 00
26+
.core.ZXBASIC_USER_DATA_END:
27+
.core.__MAIN_PROGRAM__:
28+
ld hl, (_v1)
29+
ld de, (_v1 + 2)
30+
ex de, hl
31+
ld de, 0
32+
ld (_v2), hl
33+
ld (_v2 + 2), de
34+
ld hl, 0
35+
ld b, h
36+
ld c, l
37+
.core.__END_PROGRAM:
38+
di
39+
ld hl, (.core.__CALL_BACK__)
40+
ld sp, hl
41+
exx
42+
pop hl
43+
exx
44+
pop iy
45+
pop ix
46+
ei
47+
ret
48+
;; --- end of user code ---
49+
END
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
DIM v1 As Fixed = 1.5
2+
DIM v2 As ULong
3+
4+
v2 = v1
5+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
org 32768
2+
.core.__START_PROGRAM:
3+
di
4+
push iy
5+
ld iy, 0x5C3A ; ZX Spectrum ROM variables address
6+
ld (.core.__CALL_BACK__), sp
7+
ei
8+
jp .core.__MAIN_PROGRAM__
9+
.core.__CALL_BACK__:
10+
DEFW 0
11+
.core.ZXBASIC_USER_DATA:
12+
; Defines USER DATA Length in bytes
13+
.core.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_END - .core.ZXBASIC_USER_DATA
14+
.core.__LABEL__.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_LEN
15+
.core.__LABEL__.ZXBASIC_USER_DATA EQU .core.ZXBASIC_USER_DATA
16+
_v1:
17+
DEFB 00h
18+
DEFB 80h
19+
DEFB 01h
20+
DEFB 00h
21+
_v2:
22+
DEFB 00, 00, 00, 00
23+
.core.ZXBASIC_USER_DATA_END:
24+
.core.__MAIN_PROGRAM__:
25+
ld hl, (_v1)
26+
ld de, (_v1 + 2)
27+
ex de, hl
28+
ld de, 0
29+
ld (_v2), hl
30+
ld (_v2 + 2), de
31+
ld hl, 0
32+
ld b, h
33+
ld c, l
34+
.core.__END_PROGRAM:
35+
di
36+
ld hl, (.core.__CALL_BACK__)
37+
ld sp, hl
38+
pop iy
39+
ei
40+
ret
41+
;; --- end of user code ---
42+
END
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
DIM v1 As Fixed = 1.5
2+
DIM v2 As Long
3+
4+
v2 = v1
5+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
org 32768
2+
.core.__START_PROGRAM:
3+
di
4+
push iy
5+
ld iy, 0x5C3A ; ZX Spectrum ROM variables address
6+
ld (.core.__CALL_BACK__), sp
7+
ei
8+
jp .core.__MAIN_PROGRAM__
9+
.core.__CALL_BACK__:
10+
DEFW 0
11+
.core.ZXBASIC_USER_DATA:
12+
; Defines USER DATA Length in bytes
13+
.core.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_END - .core.ZXBASIC_USER_DATA
14+
.core.__LABEL__.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_LEN
15+
.core.__LABEL__.ZXBASIC_USER_DATA EQU .core.ZXBASIC_USER_DATA
16+
_v1:
17+
DEFB 00h
18+
DEFB 80h
19+
DEFB 01h
20+
DEFB 00h
21+
_v2:
22+
DEFB 00, 00, 00, 00
23+
.core.ZXBASIC_USER_DATA_END:
24+
.core.__MAIN_PROGRAM__:
25+
ld hl, (_v1)
26+
ld de, (_v1 + 2)
27+
ex de, hl
28+
ld de, 0
29+
ld (_v2), hl
30+
ld (_v2 + 2), de
31+
ld hl, 0
32+
ld b, h
33+
ld c, l
34+
.core.__END_PROGRAM:
35+
di
36+
ld hl, (.core.__CALL_BACK__)
37+
ld sp, hl
38+
pop iy
39+
ei
40+
ret
41+
;; --- end of user code ---
42+
END
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
DIM v1 As Fixed = 1.5
2+
DIM v2 As ULong
3+
4+
v2 = v1
5+

0 commit comments

Comments
 (0)