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
2 changes: 1 addition & 1 deletion src/arch/z80/backend/runtime/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ class CoreLabels:
CoreLabels.PISTORE_STR: "storestr.asm",
CoreLabels.PISTORE_STR2: "storestr2.asm",
CoreLabels.PLOADF: "ploadf.asm",
CoreLabels.POWF: "pow.asm",
CoreLabels.POWF: "math/pow.asm",
CoreLabels.PSTOREF: "pstoref.asm",
CoreLabels.PSTORE32: "pstore32.asm",
CoreLabels.PSTORE_STR: "pstorestr.asm",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,3 @@ __POW: ; Exponentiation
ENDP

pop namespace

Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,3 @@ __POW: ; Exponentiation
ENDP

pop namespace

181 changes: 181 additions & 0 deletions tests/functional/arch/zx48k/addf.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
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
_a:
DEFB 00, 00, 00, 00, 00
.core.ZXBASIC_USER_DATA_END:
.core.__MAIN_PROGRAM__:
ld a, (_a)
ld de, (_a + 1)
ld bc, (_a + 3)
ld hl, _a + 4
call .core.__FP_PUSH_REV
call .core.__ADDF
push bc
push de
push af
ld hl, _a + 4
call .core.__FP_PUSH_REV
ld a, 082h
ld de, 00000h
ld bc, 00000h
call .core.__ADDF
push bc
push de
push af
ld a, (_a)
ld de, (_a + 1)
ld bc, (_a + 3)
call .core.__ADDF
call .core.__ADDF
ld hl, _a
call .core.__STOREF
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 ---
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arith/addf.asm"
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/stackf.asm"
; -------------------------------------------------------------
; Functions to manage FP-Stack of the ZX Spectrum ROM CALC
; -------------------------------------------------------------
push namespace core
__FPSTACK_PUSH EQU 2AB6h ; Stores an FP number into the ROM FP stack (A, ED CB)
__FPSTACK_POP EQU 2BF1h ; Pops an FP number out of the ROM FP stack (A, ED CB)
__FPSTACK_PUSH2: ; Pushes Current A ED CB registers and top of the stack on (SP + 4)
; Second argument to push into the stack calculator is popped out of the stack
; Since the caller routine also receives the parameters into the top of the stack
; four bytes must be removed from SP before pop them out
call __FPSTACK_PUSH ; Pushes A ED CB into the FP-STACK
exx
pop hl ; Caller-Caller return addr
exx
pop hl ; Caller return addr
pop af
pop de
pop bc
push hl ; Caller return addr
exx
push hl ; Caller-Caller return addr
exx
jp __FPSTACK_PUSH
__FPSTACK_I16: ; Pushes 16 bits integer in HL into the FP ROM STACK
; This format is specified in the ZX 48K Manual
; You can push a 16 bit signed integer as
; 0 SS LL HH 0, being SS the sign and LL HH the low
; and High byte respectively
ld a, h
rla ; sign to Carry
sbc a, a ; 0 if positive, FF if negative
ld e, a
ld d, l
ld c, h
xor a
ld b, a
jp __FPSTACK_PUSH
pop namespace
#line 2 "/zxbasic/src/lib/arch/zx48k/runtime/arith/addf.asm"
; -------------------------------------------------------------
; Floating point library using the FP ROM Calculator (ZX 48K)
; All of them uses A EDCB registers as 1st paramter.
; For binary operators, the 2n operator must be pushed into the
; stack, in the order AF DE BC (F not used).
;
; Uses CALLEE convention
; -------------------------------------------------------------
push namespace core
__ADDF: ; Addition
call __FPSTACK_PUSH2
; ------------- ROM ADD
rst 28h
defb 0fh ; ADD
defb 38h; ; END CALC
jp __FPSTACK_POP
pop namespace
#line 42 "arch/zx48k/addf.bas"
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/pushf.asm"
; Routine to push Float pointed by HL
; Into the stack. Notice that the hl points to the last
; byte of the FP number.
; Uses H'L' B'C' and D'E' to preserve ABCDEHL registers
push namespace core
__FP_PUSH_REV:
push hl
exx
pop hl
pop bc ; Return Address
ld d, (hl)
dec hl
ld e, (hl)
dec hl
push de
ld d, (hl)
dec hl
ld e, (hl)
dec hl
push de
ld d, (hl)
push de
push bc ; Return Address
exx
ret
pop namespace
#line 43 "arch/zx48k/addf.bas"
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/storef.asm"
push namespace core
__PISTOREF: ; Indect Stores a float (A, E, D, C, B) at location stored in memory, pointed by (IX + HL)
push de
ex de, hl ; DE <- HL
push ix
pop hl ; HL <- IX
add hl, de ; HL <- IX + HL
pop de
__ISTOREF: ; Load address at hl, and stores A,E,D,C,B registers at that address. Modifies A' register
ex af, af'
ld a, (hl)
inc hl
ld h, (hl)
ld l, a ; HL = (HL)
ex af, af'
__STOREF: ; Stores the given FP number in A EDCB at address HL
ld (hl), a
inc hl
ld (hl), e
inc hl
ld (hl), d
inc hl
ld (hl), c
inc hl
ld (hl), b
ret
pop namespace
#line 44 "arch/zx48k/addf.bas"
END
3 changes: 3 additions & 0 deletions tests/functional/arch/zx48k/addf.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
REM another Float test
DIM a As Float
a = a + a + (a + 2 + a)
171 changes: 171 additions & 0 deletions tests/functional/arch/zx48k/fp_pow.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
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
_x:
DEFB 00, 00, 00, 00, 00
.core.ZXBASIC_USER_DATA_END:
.core.__MAIN_PROGRAM__:
ld hl, _x + 4
call .core.__FP_PUSH_REV
ld a, 082h
ld de, 00020h
ld bc, 00000h
call .core.__POW
ld hl, _x
call .core.__STOREF
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 ---
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/pow.asm"
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/stackf.asm"
; -------------------------------------------------------------
; Functions to manage FP-Stack of the ZX Spectrum ROM CALC
; -------------------------------------------------------------
push namespace core
__FPSTACK_PUSH EQU 2AB6h ; Stores an FP number into the ROM FP stack (A, ED CB)
__FPSTACK_POP EQU 2BF1h ; Pops an FP number out of the ROM FP stack (A, ED CB)
__FPSTACK_PUSH2: ; Pushes Current A ED CB registers and top of the stack on (SP + 4)
; Second argument to push into the stack calculator is popped out of the stack
; Since the caller routine also receives the parameters into the top of the stack
; four bytes must be removed from SP before pop them out
call __FPSTACK_PUSH ; Pushes A ED CB into the FP-STACK
exx
pop hl ; Caller-Caller return addr
exx
pop hl ; Caller return addr
pop af
pop de
pop bc
push hl ; Caller return addr
exx
push hl ; Caller-Caller return addr
exx
jp __FPSTACK_PUSH
__FPSTACK_I16: ; Pushes 16 bits integer in HL into the FP ROM STACK
; This format is specified in the ZX 48K Manual
; You can push a 16 bit signed integer as
; 0 SS LL HH 0, being SS the sign and LL HH the low
; and High byte respectively
ld a, h
rla ; sign to Carry
sbc a, a ; 0 if positive, FF if negative
ld e, a
ld d, l
ld c, h
xor a
ld b, a
jp __FPSTACK_PUSH
pop namespace
#line 2 "/zxbasic/src/lib/arch/zx48k/runtime/pow.asm"
; -------------------------------------------------------------
; Floating point library using the FP ROM Calculator (ZX 48K)
; All of them uses A EDCB registers as 1st paramter.
; For binary operators, the 2n operator must be pushed into the
; stack, in the order A DE BC.
;
; Uses CALLEE convention
;
; Operands comes swapped:
; 1 st parameter is the BASE (A ED CB)
; 2 nd parameter (Top of the stack) is Exponent
; -------------------------------------------------------------
push namespace core
__POW: ; Exponentiation
PROC
call __FPSTACK_PUSH2
; ------------- ROM POW
rst 28h
defb 01h ; Exchange => 1, Base
defb 06h ; POW
defb 38h; ; END CALC
jp __FPSTACK_POP
ENDP
pop namespace
#line 25 "arch/zx48k/fp_pow.bas"
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/pushf.asm"
; Routine to push Float pointed by HL
; Into the stack. Notice that the hl points to the last
; byte of the FP number.
; Uses H'L' B'C' and D'E' to preserve ABCDEHL registers
push namespace core
__FP_PUSH_REV:
push hl
exx
pop hl
pop bc ; Return Address
ld d, (hl)
dec hl
ld e, (hl)
dec hl
push de
ld d, (hl)
dec hl
ld e, (hl)
dec hl
push de
ld d, (hl)
push de
push bc ; Return Address
exx
ret
pop namespace
#line 26 "arch/zx48k/fp_pow.bas"
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/storef.asm"
push namespace core
__PISTOREF: ; Indect Stores a float (A, E, D, C, B) at location stored in memory, pointed by (IX + HL)
push de
ex de, hl ; DE <- HL
push ix
pop hl ; HL <- IX
add hl, de ; HL <- IX + HL
pop de
__ISTOREF: ; Load address at hl, and stores A,E,D,C,B registers at that address. Modifies A' register
ex af, af'
ld a, (hl)
inc hl
ld h, (hl)
ld l, a ; HL = (HL)
ex af, af'
__STOREF: ; Stores the given FP number in A EDCB at address HL
ld (hl), a
inc hl
ld (hl), e
inc hl
ld (hl), d
inc hl
ld (hl), c
inc hl
ld (hl), b
ret
pop namespace
#line 27 "arch/zx48k/fp_pow.bas"
END
3 changes: 3 additions & 0 deletions tests/functional/arch/zx48k/fp_pow.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DIM x as Float

LET x = x ^ 2.5
Loading