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
19 changes: 9 additions & 10 deletions src/arch/zx48k/library-asm/random.asm
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ TAKE_FRAMES:
FRAMES EQU 23672
ENDP

RANDOM_SEED_HIGH EQU RAND+6 ; RANDOM seed, 16 higher bits
RANDOM_SEED_LOW EQU 23670 ; RANDOM seed, 16 lower bits
RANDOM_SEED_HIGH EQU RAND+6 ; RANDOM seed, 16 higher bits
RANDOM_SEED_LOW EQU 23670 ; RANDOM seed, 16 lower bits


RAND:
Expand All @@ -54,18 +54,17 @@ RAND_LOOP:
rra ; t = t ^ (t >> 1) ^ w
xor d
xor e
ld h,l ; y = z
ld l,a ; w = t
ld (RANDOM_SEED_HIGH),hl
ld d,l ; y = z
ld e,a ; w = t
ld (RANDOM_SEED_HIGH),de
push af
djnz RAND_LOOP
pop af
pop af
ld d, a
pop de
pop af
ld e, a
pop hl
pop af
ld h, a
ld l, a
ret
ENDP

Expand All @@ -89,7 +88,7 @@ RND:
; We already have a random 32 bit mantissa in ED CB
; From 0001h to FFFFh

ld l, 81h ; Exponent
ld l, 81h ; Exponent
; At this point we have [0 .. 1) FP number;

; Now we must shift mantissa left until highest bit goes into carry
Expand Down
40 changes: 20 additions & 20 deletions tests/functional/mcleod.asm
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ __END_PROGRAM:
ret
__CALL_BACK__:
DEFW 0
#line 1 "ftou32reg.asm"
#line 1 "neg32.asm"
;; --- end of user code ---
#line 1 "/zxbasic/src/arch/zx48k/library-asm/ftou32reg.asm"
#line 1 "/zxbasic/src/arch/zx48k/library-asm/neg32.asm"
__ABS32:
bit 7, d
ret z
Expand All @@ -71,7 +72,7 @@ __NEG32: ; Negates DEHL (Two's complement)
ret nz
inc de
ret
#line 2 "ftou32reg.asm"
#line 2 "/zxbasic/src/arch/zx48k/library-asm/ftou32reg.asm"
__FTOU32REG: ; Converts a Float to (un)signed 32 bit integer (NOTE: It's ALWAYS 32 bit signed)
; Input FP number in A EDCB (A exponent, EDCB mantissa)
; Output: DEHL 32 bit number (signed)
Expand Down Expand Up @@ -144,9 +145,9 @@ __FTOU8: ; Converts float in C ED LH to Unsigned byte in A
call __FTOU32REG
ld a, l
ret
#line 29 "mcleod.bas"
#line 1 "mulf.asm"
#line 1 "stackf.asm"
#line 30 "mcleod.bas"
#line 1 "/zxbasic/src/arch/zx48k/library-asm/mulf.asm"
#line 1 "/zxbasic/src/arch/zx48k/library-asm/stackf.asm"
; -------------------------------------------------------------
; Functions to manage FP-Stack of the ZX Spectrum ROM CALC
; -------------------------------------------------------------
Expand Down Expand Up @@ -183,7 +184,7 @@ __FPSTACK_I16: ; Pushes 16 bits integer in HL into the FP ROM STACK
xor a
ld b, a
jp __FPSTACK_PUSH
#line 2 "mulf.asm"
#line 2 "/zxbasic/src/arch/zx48k/library-asm/mulf.asm"
; -------------------------------------------------------------
; Floating point library using the FP ROM Calculator (ZX 48K)
; All of them uses A EDCB registers as 1st paramter.
Expand All @@ -199,8 +200,8 @@ __MULF: ; Multiplication
defb 04h ;
defb 38h; ; END CALC
jp __FPSTACK_POP
#line 30 "mcleod.bas"
#line 1 "random.asm"
#line 31 "mcleod.bas"
#line 1 "/zxbasic/src/arch/zx48k/library-asm/random.asm"
; RANDOM functions
RANDOMIZE:
; Randomize with 32 bit seed in DE HL
Expand All @@ -225,8 +226,8 @@ TAKE_FRAMES:
ret
FRAMES EQU 23672
ENDP
RANDOM_SEED_HIGH EQU RAND+6 ; RANDOM seed, 16 higher bits
RANDOM_SEED_LOW EQU 23670 ; RANDOM seed, 16 lower bits
RANDOM_SEED_HIGH EQU RAND+6 ; RANDOM seed, 16 higher bits
RANDOM_SEED_LOW EQU 23670 ; RANDOM seed, 16 lower bits
RAND:
PROC
LOCAL RAND_LOOP
Expand All @@ -248,18 +249,17 @@ RAND_LOOP:
rra ; t = t ^ (t >> 1) ^ w
xor d
xor e
ld h,l ; y = z
ld l,a ; w = t
ld (RANDOM_SEED_HIGH),hl
ld d,l ; y = z
ld e,a ; w = t
ld (RANDOM_SEED_HIGH),de
push af
djnz RAND_LOOP
pop af
pop af
ld d, a
pop de
pop af
ld e, a
pop hl
pop af
ld h, a
ld l, a
ret
ENDP
RND:
Expand All @@ -278,7 +278,7 @@ RND:
ret z ; Returns 0 if BC=DE=0
; We already have a random 32 bit mantissa in ED CB
; From 0001h to FFFFh
ld l, 81h ; Exponent
ld l, 81h ; Exponent
; At this point we have [0 .. 1) FP number;
; Now we must shift mantissa left until highest bit goes into carry
ld a, e ; Use A register for rotating E faster (using RLA instead of RL E)
Expand All @@ -299,5 +299,5 @@ RND_LOOP:
ld a, l ; exponent in A
ret
ENDP
#line 31 "mcleod.bas"
#line 32 "mcleod.bas"
END
52 changes: 26 additions & 26 deletions tests/functional/opt4_keepix.asm
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ _test__leave:
ld sp, ix
pop ix
ret
#line 1 "addf.asm"
#line 1 "stackf.asm"
;; --- end of user code ---
#line 1 "/zxbasic/src/arch/zx48k/library-asm/addf.asm"
#line 1 "/zxbasic/src/arch/zx48k/library-asm/stackf.asm"
; -------------------------------------------------------------
; Functions to manage FP-Stack of the ZX Spectrum ROM CALC
; -------------------------------------------------------------
Expand Down Expand Up @@ -108,7 +109,7 @@ __FPSTACK_I16: ; Pushes 16 bits integer in HL into the FP ROM STACK
xor a
ld b, a
jp __FPSTACK_PUSH
#line 2 "addf.asm"
#line 2 "/zxbasic/src/arch/zx48k/library-asm/addf.asm"
; -------------------------------------------------------------
; Floating point library using the FP ROM Calculator (ZX 48K)
; All of them uses A EDCB registers as 1st paramter.
Expand All @@ -124,8 +125,8 @@ __ADDF: ; Addition
defb 0fh ; ADD
defb 38h; ; END CALC
jp __FPSTACK_POP
#line 54 "opt4_keepix.bas"
#line 1 "mulf.asm"
#line 55 "opt4_keepix.bas"
#line 1 "/zxbasic/src/arch/zx48k/library-asm/mulf.asm"
; -------------------------------------------------------------
; Floating point library using the FP ROM Calculator (ZX 48K)
; All of them uses A EDCB registers as 1st paramter.
Expand All @@ -141,13 +142,13 @@ __MULF: ; Multiplication
defb 04h ;
defb 38h; ; END CALC
jp __FPSTACK_POP
#line 55 "opt4_keepix.bas"
#line 1 "ploadf.asm"
#line 56 "opt4_keepix.bas"
#line 1 "/zxbasic/src/arch/zx48k/library-asm/ploadf.asm"
; Parameter / Local var load
; A => Offset
; IX = Stack Frame
; RESULT: HL => IX + DE
#line 1 "iloadf.asm"
#line 1 "/zxbasic/src/arch/zx48k/library-asm/iloadf.asm"
; __FASTCALL__ routine which
; loads a 40 bits floating point into A ED CB
; stored at position pointed by POINTER HL
Expand All @@ -172,19 +173,19 @@ __LOADF: ; Loads a 40 bits FP number from address pointed by HL
inc hl
ld b, (hl)
ret
#line 7 "ploadf.asm"
#line 7 "/zxbasic/src/arch/zx48k/library-asm/ploadf.asm"
__PLOADF:
push ix
pop hl
add hl, de
jp __LOADF
#line 56 "opt4_keepix.bas"
#line 1 "pstoref.asm"
#line 57 "opt4_keepix.bas"
#line 1 "/zxbasic/src/arch/zx48k/library-asm/pstoref.asm"
; Stores FP number in A ED CB at location HL+IX
; HL = Offset
; IX = Stack Frame
; A ED CB = FP Number
#line 1 "storef.asm"
#line 1 "/zxbasic/src/arch/zx48k/library-asm/storef.asm"
__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
Expand All @@ -210,7 +211,7 @@ __STOREF: ; Stores the given FP number in A EDCB at address HL
inc hl
ld (hl), b
ret
#line 7 "pstoref.asm"
#line 7 "/zxbasic/src/arch/zx48k/library-asm/pstoref.asm"
; Stored a float number in A ED CB into the address pointed by IX + HL
__PSTOREF:
push de
Expand All @@ -220,8 +221,8 @@ __PSTOREF:
add hl, de ; HL <- IX + DE
pop de
jp __STOREF
#line 57 "opt4_keepix.bas"
#line 1 "random.asm"
#line 58 "opt4_keepix.bas"
#line 1 "/zxbasic/src/arch/zx48k/library-asm/random.asm"
; RANDOM functions
RANDOMIZE:
; Randomize with 32 bit seed in DE HL
Expand All @@ -246,8 +247,8 @@ TAKE_FRAMES:
ret
FRAMES EQU 23672
ENDP
RANDOM_SEED_HIGH EQU RAND+6 ; RANDOM seed, 16 higher bits
RANDOM_SEED_LOW EQU 23670 ; RANDOM seed, 16 lower bits
RANDOM_SEED_HIGH EQU RAND+6 ; RANDOM seed, 16 higher bits
RANDOM_SEED_LOW EQU 23670 ; RANDOM seed, 16 lower bits
RAND:
PROC
LOCAL RAND_LOOP
Expand All @@ -269,18 +270,17 @@ RAND_LOOP:
rra ; t = t ^ (t >> 1) ^ w
xor d
xor e
ld h,l ; y = z
ld l,a ; w = t
ld (RANDOM_SEED_HIGH),hl
ld d,l ; y = z
ld e,a ; w = t
ld (RANDOM_SEED_HIGH),de
push af
djnz RAND_LOOP
pop af
pop af
ld d, a
pop de
pop af
ld e, a
pop hl
pop af
ld h, a
ld l, a
ret
ENDP
RND:
Expand All @@ -299,7 +299,7 @@ RND:
ret z ; Returns 0 if BC=DE=0
; We already have a random 32 bit mantissa in ED CB
; From 0001h to FFFFh
ld l, 81h ; Exponent
ld l, 81h ; Exponent
; At this point we have [0 .. 1) FP number;
; Now we must shift mantissa left until highest bit goes into carry
ld a, e ; Use A register for rotating E faster (using RLA instead of RL E)
Expand All @@ -320,5 +320,5 @@ RND_LOOP:
ld a, l ; exponent in A
ret
ENDP
#line 58 "opt4_keepix.bas"
#line 59 "opt4_keepix.bas"
END
24 changes: 12 additions & 12 deletions tests/functional/randomize.asm
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ __END_PROGRAM:
ret
__CALL_BACK__:
DEFW 0
#line 1 "random.asm"
;; --- end of user code ---
#line 1 "/zxbasic/src/arch/zx48k/library-asm/random.asm"
; RANDOM functions
RANDOMIZE:
; Randomize with 32 bit seed in DE HL
Expand All @@ -65,8 +66,8 @@ TAKE_FRAMES:
ret
FRAMES EQU 23672
ENDP
RANDOM_SEED_HIGH EQU RAND+6 ; RANDOM seed, 16 higher bits
RANDOM_SEED_LOW EQU 23670 ; RANDOM seed, 16 lower bits
RANDOM_SEED_HIGH EQU RAND+6 ; RANDOM seed, 16 higher bits
RANDOM_SEED_LOW EQU 23670 ; RANDOM seed, 16 lower bits
RAND:
PROC
LOCAL RAND_LOOP
Expand All @@ -88,18 +89,17 @@ RAND_LOOP:
rra ; t = t ^ (t >> 1) ^ w
xor d
xor e
ld h,l ; y = z
ld l,a ; w = t
ld (RANDOM_SEED_HIGH),hl
ld d,l ; y = z
ld e,a ; w = t
ld (RANDOM_SEED_HIGH),de
push af
djnz RAND_LOOP
pop af
pop af
ld d, a
pop de
pop af
ld e, a
pop hl
pop af
ld h, a
ld l, a
ret
ENDP
RND:
Expand All @@ -118,7 +118,7 @@ RND:
ret z ; Returns 0 if BC=DE=0
; We already have a random 32 bit mantissa in ED CB
; From 0001h to FFFFh
ld l, 81h ; Exponent
ld l, 81h ; Exponent
; At this point we have [0 .. 1) FP number;
; Now we must shift mantissa left until highest bit goes into carry
ld a, e ; Use A register for rotating E faster (using RLA instead of RL E)
Expand All @@ -139,5 +139,5 @@ RND_LOOP:
ld a, l ; exponent in A
ret
ENDP
#line 24 "randomize.bas"
#line 25 "randomize.bas"
END