Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions src/arch/z80/backend/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,19 +385,24 @@ def to_long(stype: DataType) -> list[str]:
)
return output

if stype in {I8_t, U8_t, F16_t}: # Byte to word
if stype in (I8_t, U8_t): # Byte to word
output = to_word(stype)
output.append("ld e, h")
output.append("ld d, h")

if stype != F16_t: # If it's a byte, just copy H to D,E
output.append("ld e, h")
output.append("ld d, h")
elif stype == I16_t: # Signed byte or fixed to word
output.extend(
[
"ld a, h",
"add a, a",
"sbc a, a",
"ld e, a",
"ld d, a",
]
)

elif stype in (I16_t, F16_t): # Signed byte or fixed to word
output.append("ld a, h")
output.append("add a, a")
output.append("sbc a, a")
output.append("ld e, a")
output.append("ld d, a")
elif stype == F16_t:
output.extend(["ex de, hl", "ld de, 0"])

elif stype in (U32_t, I32_t):
return []
Expand Down
49 changes: 49 additions & 0 deletions tests/functional/arch/zx48k/cast_f16_to_long.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 (.core.__CALL_BACK__), sp
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
_v1:
DEFB 00h
DEFB 80h
DEFB 01h
DEFB 00h
_v2:
DEFB 00, 00, 00, 00
.core.ZXBASIC_USER_DATA_END:
.core.__MAIN_PROGRAM__:
ld hl, (_v1)
ld de, (_v1 + 2)
ex de, hl
ld de, 0
ld (_v2), hl
ld (_v2 + 2), de
ld hl, 0
ld b, h
ld c, l
.core.__END_PROGRAM:
di
ld hl, (.core.__CALL_BACK__)
ld sp, hl
exx
pop hl
exx
pop iy
pop ix
ei
ret
;; --- end of user code ---
END
5 changes: 5 additions & 0 deletions tests/functional/arch/zx48k/cast_f16_to_long.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DIM v1 As Fixed = 1.5
DIM v2 As Long

v2 = v1

49 changes: 49 additions & 0 deletions tests/functional/arch/zx48k/cast_f16_to_ulong.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 (.core.__CALL_BACK__), sp
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
_v1:
DEFB 00h
DEFB 80h
DEFB 01h
DEFB 00h
_v2:
DEFB 00, 00, 00, 00
.core.ZXBASIC_USER_DATA_END:
.core.__MAIN_PROGRAM__:
ld hl, (_v1)
ld de, (_v1 + 2)
ex de, hl
ld de, 0
ld (_v2), hl
ld (_v2 + 2), de
ld hl, 0
ld b, h
ld c, l
.core.__END_PROGRAM:
di
ld hl, (.core.__CALL_BACK__)
ld sp, hl
exx
pop hl
exx
pop iy
pop ix
ei
ret
;; --- end of user code ---
END
5 changes: 5 additions & 0 deletions tests/functional/arch/zx48k/cast_f16_to_ulong.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DIM v1 As Fixed = 1.5
DIM v2 As ULong

v2 = v1

42 changes: 42 additions & 0 deletions tests/functional/arch/zxnext/cast_f16_to_long.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
org 32768
.core.__START_PROGRAM:
di
push iy
ld iy, 0x5C3A ; ZX Spectrum ROM variables address
ld (.core.__CALL_BACK__), sp
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
_v1:
DEFB 00h
DEFB 80h
DEFB 01h
DEFB 00h
_v2:
DEFB 00, 00, 00, 00
.core.ZXBASIC_USER_DATA_END:
.core.__MAIN_PROGRAM__:
ld hl, (_v1)
ld de, (_v1 + 2)
ex de, hl
ld de, 0
ld (_v2), hl
ld (_v2 + 2), de
ld hl, 0
ld b, h
ld c, l
.core.__END_PROGRAM:
di
ld hl, (.core.__CALL_BACK__)
ld sp, hl
pop iy
ei
ret
;; --- end of user code ---
END
5 changes: 5 additions & 0 deletions tests/functional/arch/zxnext/cast_f16_to_long.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DIM v1 As Fixed = 1.5
DIM v2 As Long

v2 = v1

42 changes: 42 additions & 0 deletions tests/functional/arch/zxnext/cast_f16_to_ulong.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
org 32768
.core.__START_PROGRAM:
di
push iy
ld iy, 0x5C3A ; ZX Spectrum ROM variables address
ld (.core.__CALL_BACK__), sp
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
_v1:
DEFB 00h
DEFB 80h
DEFB 01h
DEFB 00h
_v2:
DEFB 00, 00, 00, 00
.core.ZXBASIC_USER_DATA_END:
.core.__MAIN_PROGRAM__:
ld hl, (_v1)
ld de, (_v1 + 2)
ex de, hl
ld de, 0
ld (_v2), hl
ld (_v2 + 2), de
ld hl, 0
ld b, h
ld c, l
.core.__END_PROGRAM:
di
ld hl, (.core.__CALL_BACK__)
ld sp, hl
pop iy
ei
ret
;; --- end of user code ---
END
5 changes: 5 additions & 0 deletions tests/functional/arch/zxnext/cast_f16_to_ulong.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DIM v1 As Fixed = 1.5
DIM v2 As ULong

v2 = v1