From 0bb335e6ab48ce69695159456233fad004eca84e Mon Sep 17 00:00:00 2001 From: Jose Rodriguez Date: Wed, 13 Nov 2024 14:58:43 +0100 Subject: [PATCH] refact: move runtime bool functions to bool/ --- src/arch/z80/backend/runtime/core.py | 22 +- .../arch/zx48k/runtime/{ => bool}/and16.asm | 1 - .../arch/zx48k/runtime/{ => bool}/and32.asm | 0 .../arch/zx48k/runtime/{ => bool}/and8.asm | 1 - .../runtime => zx48k/runtime/bool}/andf.asm | 1 - .../runtime => zx48k/runtime/bool}/not32.asm | 2 - .../arch/zx48k/runtime/{ => bool}/notf.asm | 1 - .../runtime => zx48k/runtime/bool}/or32.asm | 1 - .../runtime => zx48k/runtime/bool}/orf.asm | 1 - .../arch/zx48k/runtime/{ => bool}/xor16.asm | 2 +- .../runtime => zx48k/runtime/bool}/xor32.asm | 3 +- .../runtime => zx48k/runtime/bool}/xor8.asm | 1 - .../runtime => zx48k/runtime/bool}/xorf.asm | 1 - .../arch/zxnext/runtime/{ => bool}/and16.asm | 1 - .../arch/zxnext/runtime/{ => bool}/and32.asm | 0 .../arch/zxnext/runtime/{ => bool}/and8.asm | 1 - .../runtime => zxnext/runtime/bool}/andf.asm | 1 - .../runtime => zxnext/runtime/bool}/not32.asm | 2 - .../arch/zxnext/runtime/{ => bool}/notf.asm | 1 - .../runtime => zxnext/runtime/bool}/or32.asm | 1 - .../runtime => zxnext/runtime/bool}/orf.asm | 1 - .../arch/zxnext/runtime/{ => bool}/xor16.asm | 2 +- .../runtime => zxnext/runtime/bool}/xor32.asm | 3 +- .../runtime => zxnext/runtime/bool}/xor8.asm | 1 - .../runtime => zxnext/runtime/bool}/xorf.asm | 1 - tests/functional/arch/zx48k/andf.asm | 343 +++++++++++++++++ tests/functional/arch/zx48k/andf.bas | 10 + tests/functional/arch/zx48k/not16.asm | 52 +++ tests/functional/arch/zx48k/not16.bas | 8 + tests/functional/arch/zx48k/not32.asm | 65 ++++ tests/functional/arch/zx48k/not32.bas | 8 + tests/functional/arch/zx48k/not8.asm | 50 +++ tests/functional/arch/zx48k/not8.bas | 8 + tests/functional/arch/zx48k/notf.asm | 281 ++++++++++++++ tests/functional/arch/zx48k/notf.bas | 8 + tests/functional/arch/zx48k/orf.asm | 343 +++++++++++++++++ tests/functional/arch/zx48k/orf.bas | 10 + tests/functional/arch/zx48k/xorf.asm | 353 ++++++++++++++++++ tests/functional/arch/zx48k/xorf.bas | 10 + 39 files changed, 1564 insertions(+), 37 deletions(-) rename src/lib/arch/zx48k/runtime/{ => bool}/and16.asm (99%) rename src/lib/arch/zx48k/runtime/{ => bool}/and32.asm (100%) rename src/lib/arch/zx48k/runtime/{ => bool}/and8.asm (99%) rename src/lib/arch/{zxnext/runtime => zx48k/runtime/bool}/andf.asm (99%) rename src/lib/arch/{zxnext/runtime => zx48k/runtime/bool}/not32.asm (99%) rename src/lib/arch/zx48k/runtime/{ => bool}/notf.asm (99%) rename src/lib/arch/{zxnext/runtime => zx48k/runtime/bool}/or32.asm (99%) rename src/lib/arch/{zxnext/runtime => zx48k/runtime/bool}/orf.asm (99%) rename src/lib/arch/zx48k/runtime/{ => bool}/xor16.asm (55%) rename src/lib/arch/{zxnext/runtime => zx48k/runtime/bool}/xor32.asm (92%) rename src/lib/arch/{zxnext/runtime => zx48k/runtime/bool}/xor8.asm (99%) rename src/lib/arch/{zxnext/runtime => zx48k/runtime/bool}/xorf.asm (99%) rename src/lib/arch/zxnext/runtime/{ => bool}/and16.asm (99%) rename src/lib/arch/zxnext/runtime/{ => bool}/and32.asm (100%) rename src/lib/arch/zxnext/runtime/{ => bool}/and8.asm (99%) rename src/lib/arch/{zx48k/runtime => zxnext/runtime/bool}/andf.asm (99%) rename src/lib/arch/{zx48k/runtime => zxnext/runtime/bool}/not32.asm (99%) rename src/lib/arch/zxnext/runtime/{ => bool}/notf.asm (99%) rename src/lib/arch/{zx48k/runtime => zxnext/runtime/bool}/or32.asm (99%) rename src/lib/arch/{zx48k/runtime => zxnext/runtime/bool}/orf.asm (99%) rename src/lib/arch/zxnext/runtime/{ => bool}/xor16.asm (55%) rename src/lib/arch/{zx48k/runtime => zxnext/runtime/bool}/xor32.asm (92%) rename src/lib/arch/{zx48k/runtime => zxnext/runtime/bool}/xor8.asm (99%) rename src/lib/arch/{zx48k/runtime => zxnext/runtime/bool}/xorf.asm (99%) create mode 100644 tests/functional/arch/zx48k/andf.asm create mode 100644 tests/functional/arch/zx48k/andf.bas create mode 100644 tests/functional/arch/zx48k/not16.asm create mode 100644 tests/functional/arch/zx48k/not16.bas create mode 100644 tests/functional/arch/zx48k/not32.asm create mode 100644 tests/functional/arch/zx48k/not32.bas create mode 100644 tests/functional/arch/zx48k/not8.asm create mode 100644 tests/functional/arch/zx48k/not8.bas create mode 100644 tests/functional/arch/zx48k/notf.asm create mode 100644 tests/functional/arch/zx48k/notf.bas create mode 100644 tests/functional/arch/zx48k/orf.asm create mode 100644 tests/functional/arch/zx48k/orf.bas create mode 100644 tests/functional/arch/zx48k/xorf.asm create mode 100644 tests/functional/arch/zx48k/xorf.bas diff --git a/src/arch/z80/backend/runtime/core.py b/src/arch/z80/backend/runtime/core.py index ed1452635..58bdb1272 100644 --- a/src/arch/z80/backend/runtime/core.py +++ b/src/arch/z80/backend/runtime/core.py @@ -142,9 +142,9 @@ class CoreLabels: CoreLabels.ALLOC_INITIALIZED_LOCAL_ARRAY_WITH_BOUNDS: "arrayalloc.asm", CoreLabels.ALLOC_LOCAL_ARRAY: "arrayalloc.asm", CoreLabels.ALLOC_LOCAL_ARRAY_WITH_BOUNDS: "arrayalloc.asm", - CoreLabels.AND16: "and16.asm", - CoreLabels.AND32: "and32.asm", - CoreLabels.ANDF: "andf.asm", + CoreLabels.AND16: "bool/and16.asm", + CoreLabels.AND32: "bool/and32.asm", + CoreLabels.ANDF: "bool/andf.asm", CoreLabels.ARRAY: "array.asm", CoreLabels.ARRAY_PTR: "array.asm", CoreLabels.ARRAYSTR_FREE_MEM: "arraystrfree.asm", @@ -214,12 +214,12 @@ class CoreLabels: CoreLabels.NEGF: "negf.asm", CoreLabels.NEGHL: "neg16.asm", CoreLabels.NORMALIZE_BOOLEAN: "strictbool.asm", - CoreLabels.NOT32: "not32.asm", - CoreLabels.NOTF: "notf.asm", + CoreLabels.NOT32: "bool/not32.asm", + CoreLabels.NOTF: "bool/notf.asm", CoreLabels.ON_GOTO: "ongoto.asm", CoreLabels.ON_GOSUB: "ongoto.asm", - CoreLabels.OR32: "or32.asm", - CoreLabels.ORF: "orf.asm", + CoreLabels.OR32: "bool/or32.asm", + CoreLabels.ORF: "bool/orf.asm", CoreLabels.PISTORE16: "istore16.asm", CoreLabels.PISTORE32: "pistore32.asm", CoreLabels.PISTOREF: "storef.asm", @@ -255,8 +255,8 @@ class CoreLabels: CoreLabels.U32TOFREG: "u32tofreg.asm", CoreLabels.U8TOFREG: "u32tofreg.asm", CoreLabels.UBOUND: "bound.asm", - CoreLabels.XOR16: "xor16.asm", - CoreLabels.XOR8: "xor8.asm", - CoreLabels.XOR32: "xor32.asm", - CoreLabels.XORF: "xorf.asm", + CoreLabels.XOR16: "bool/xor16.asm", + CoreLabels.XOR8: "bool/xor8.asm", + CoreLabels.XOR32: "bool/xor32.asm", + CoreLabels.XORF: "bool/xorf.asm", } diff --git a/src/lib/arch/zx48k/runtime/and16.asm b/src/lib/arch/zx48k/runtime/bool/and16.asm similarity index 99% rename from src/lib/arch/zx48k/runtime/and16.asm rename to src/lib/arch/zx48k/runtime/bool/and16.asm index f0f9e3dfd..829a0bb9b 100644 --- a/src/lib/arch/zx48k/runtime/and16.asm +++ b/src/lib/arch/zx48k/runtime/bool/and16.asm @@ -15,4 +15,3 @@ __AND16: ret pop namespace - diff --git a/src/lib/arch/zx48k/runtime/and32.asm b/src/lib/arch/zx48k/runtime/bool/and32.asm similarity index 100% rename from src/lib/arch/zx48k/runtime/and32.asm rename to src/lib/arch/zx48k/runtime/bool/and32.asm diff --git a/src/lib/arch/zx48k/runtime/and8.asm b/src/lib/arch/zx48k/runtime/bool/and8.asm similarity index 99% rename from src/lib/arch/zx48k/runtime/and8.asm rename to src/lib/arch/zx48k/runtime/bool/and8.asm index c1e067c5a..1e6795eff 100644 --- a/src/lib/arch/zx48k/runtime/and8.asm +++ b/src/lib/arch/zx48k/runtime/bool/and8.asm @@ -12,4 +12,3 @@ __AND8: ret pop namespace - diff --git a/src/lib/arch/zxnext/runtime/andf.asm b/src/lib/arch/zx48k/runtime/bool/andf.asm similarity index 99% rename from src/lib/arch/zxnext/runtime/andf.asm rename to src/lib/arch/zx48k/runtime/bool/andf.asm index 4a364f5cd..fabbc00e6 100644 --- a/src/lib/arch/zxnext/runtime/andf.asm +++ b/src/lib/arch/zx48k/runtime/bool/andf.asm @@ -26,4 +26,3 @@ __ANDF: ; A & B jp __FTOU8 ; Convert to 8 bits pop namespace - diff --git a/src/lib/arch/zxnext/runtime/not32.asm b/src/lib/arch/zx48k/runtime/bool/not32.asm similarity index 99% rename from src/lib/arch/zxnext/runtime/not32.asm rename to src/lib/arch/zx48k/runtime/bool/not32.asm index 135a0a921..e354698ed 100644 --- a/src/lib/arch/zxnext/runtime/not32.asm +++ b/src/lib/arch/zx48k/runtime/bool/not32.asm @@ -14,5 +14,3 @@ __NOT32: ; A = ¬A ret pop namespace - - diff --git a/src/lib/arch/zx48k/runtime/notf.asm b/src/lib/arch/zx48k/runtime/bool/notf.asm similarity index 99% rename from src/lib/arch/zx48k/runtime/notf.asm rename to src/lib/arch/zx48k/runtime/bool/notf.asm index 6844b005a..bced6ef9f 100644 --- a/src/lib/arch/zx48k/runtime/notf.asm +++ b/src/lib/arch/zx48k/runtime/bool/notf.asm @@ -26,4 +26,3 @@ __NOTF: ; A = ¬A jp __FTOU8 ; Convert to 8 bits pop namespace - diff --git a/src/lib/arch/zxnext/runtime/or32.asm b/src/lib/arch/zx48k/runtime/bool/or32.asm similarity index 99% rename from src/lib/arch/zxnext/runtime/or32.asm rename to src/lib/arch/zx48k/runtime/bool/or32.asm index bd4a0e2d0..e1cb1689b 100644 --- a/src/lib/arch/zxnext/runtime/or32.asm +++ b/src/lib/arch/zx48k/runtime/bool/or32.asm @@ -26,4 +26,3 @@ __OR32: ; Performs logical operation A AND B ret pop namespace - diff --git a/src/lib/arch/zxnext/runtime/orf.asm b/src/lib/arch/zx48k/runtime/bool/orf.asm similarity index 99% rename from src/lib/arch/zxnext/runtime/orf.asm rename to src/lib/arch/zx48k/runtime/bool/orf.asm index b032a8aed..7a89a2bf6 100644 --- a/src/lib/arch/zxnext/runtime/orf.asm +++ b/src/lib/arch/zx48k/runtime/bool/orf.asm @@ -26,4 +26,3 @@ __ORF: ; A | B jp __FTOU8 ; Convert to 32 bits pop namespace - diff --git a/src/lib/arch/zx48k/runtime/xor16.asm b/src/lib/arch/zx48k/runtime/bool/xor16.asm similarity index 55% rename from src/lib/arch/zx48k/runtime/xor16.asm rename to src/lib/arch/zx48k/runtime/bool/xor16.asm index 6b3fe96ab..85b1b3288 100644 --- a/src/lib/arch/zx48k/runtime/xor16.asm +++ b/src/lib/arch/zx48k/runtime/bool/xor16.asm @@ -1,3 +1,3 @@ ; XOR16 implemented in XOR8.ASM file -#include once +#include once diff --git a/src/lib/arch/zxnext/runtime/xor32.asm b/src/lib/arch/zx48k/runtime/bool/xor32.asm similarity index 92% rename from src/lib/arch/zxnext/runtime/xor32.asm rename to src/lib/arch/zx48k/runtime/bool/xor32.asm index 7f6fba94e..4be3918d5 100644 --- a/src/lib/arch/zxnext/runtime/xor32.asm +++ b/src/lib/arch/zx48k/runtime/bool/xor32.asm @@ -3,7 +3,7 @@ ; __FASTCALL__ version (operands: A, H) ; Performs 32bit xor 32bit and returns the boolean -#include once +#include once push namespace core @@ -25,4 +25,3 @@ __XOR32: jp __XOR8 pop namespace - diff --git a/src/lib/arch/zxnext/runtime/xor8.asm b/src/lib/arch/zx48k/runtime/bool/xor8.asm similarity index 99% rename from src/lib/arch/zxnext/runtime/xor8.asm rename to src/lib/arch/zx48k/runtime/bool/xor8.asm index 683ef2553..a40d24729 100644 --- a/src/lib/arch/zxnext/runtime/xor8.asm +++ b/src/lib/arch/zx48k/runtime/bool/xor8.asm @@ -26,4 +26,3 @@ __XOR8: ret pop namespace - diff --git a/src/lib/arch/zxnext/runtime/xorf.asm b/src/lib/arch/zx48k/runtime/bool/xorf.asm similarity index 99% rename from src/lib/arch/zxnext/runtime/xorf.asm rename to src/lib/arch/zx48k/runtime/bool/xorf.asm index a92d0d984..0c76f6f83 100644 --- a/src/lib/arch/zxnext/runtime/xorf.asm +++ b/src/lib/arch/zx48k/runtime/bool/xorf.asm @@ -36,4 +36,3 @@ __XORF: ; A XOR B jp __FTOU8 ; Convert to 8 bits pop namespace - diff --git a/src/lib/arch/zxnext/runtime/and16.asm b/src/lib/arch/zxnext/runtime/bool/and16.asm similarity index 99% rename from src/lib/arch/zxnext/runtime/and16.asm rename to src/lib/arch/zxnext/runtime/bool/and16.asm index f0f9e3dfd..829a0bb9b 100644 --- a/src/lib/arch/zxnext/runtime/and16.asm +++ b/src/lib/arch/zxnext/runtime/bool/and16.asm @@ -15,4 +15,3 @@ __AND16: ret pop namespace - diff --git a/src/lib/arch/zxnext/runtime/and32.asm b/src/lib/arch/zxnext/runtime/bool/and32.asm similarity index 100% rename from src/lib/arch/zxnext/runtime/and32.asm rename to src/lib/arch/zxnext/runtime/bool/and32.asm diff --git a/src/lib/arch/zxnext/runtime/and8.asm b/src/lib/arch/zxnext/runtime/bool/and8.asm similarity index 99% rename from src/lib/arch/zxnext/runtime/and8.asm rename to src/lib/arch/zxnext/runtime/bool/and8.asm index c1e067c5a..1e6795eff 100644 --- a/src/lib/arch/zxnext/runtime/and8.asm +++ b/src/lib/arch/zxnext/runtime/bool/and8.asm @@ -12,4 +12,3 @@ __AND8: ret pop namespace - diff --git a/src/lib/arch/zx48k/runtime/andf.asm b/src/lib/arch/zxnext/runtime/bool/andf.asm similarity index 99% rename from src/lib/arch/zx48k/runtime/andf.asm rename to src/lib/arch/zxnext/runtime/bool/andf.asm index 4a364f5cd..fabbc00e6 100644 --- a/src/lib/arch/zx48k/runtime/andf.asm +++ b/src/lib/arch/zxnext/runtime/bool/andf.asm @@ -26,4 +26,3 @@ __ANDF: ; A & B jp __FTOU8 ; Convert to 8 bits pop namespace - diff --git a/src/lib/arch/zx48k/runtime/not32.asm b/src/lib/arch/zxnext/runtime/bool/not32.asm similarity index 99% rename from src/lib/arch/zx48k/runtime/not32.asm rename to src/lib/arch/zxnext/runtime/bool/not32.asm index 135a0a921..e354698ed 100644 --- a/src/lib/arch/zx48k/runtime/not32.asm +++ b/src/lib/arch/zxnext/runtime/bool/not32.asm @@ -14,5 +14,3 @@ __NOT32: ; A = ¬A ret pop namespace - - diff --git a/src/lib/arch/zxnext/runtime/notf.asm b/src/lib/arch/zxnext/runtime/bool/notf.asm similarity index 99% rename from src/lib/arch/zxnext/runtime/notf.asm rename to src/lib/arch/zxnext/runtime/bool/notf.asm index 6844b005a..bced6ef9f 100644 --- a/src/lib/arch/zxnext/runtime/notf.asm +++ b/src/lib/arch/zxnext/runtime/bool/notf.asm @@ -26,4 +26,3 @@ __NOTF: ; A = ¬A jp __FTOU8 ; Convert to 8 bits pop namespace - diff --git a/src/lib/arch/zx48k/runtime/or32.asm b/src/lib/arch/zxnext/runtime/bool/or32.asm similarity index 99% rename from src/lib/arch/zx48k/runtime/or32.asm rename to src/lib/arch/zxnext/runtime/bool/or32.asm index bd4a0e2d0..e1cb1689b 100644 --- a/src/lib/arch/zx48k/runtime/or32.asm +++ b/src/lib/arch/zxnext/runtime/bool/or32.asm @@ -26,4 +26,3 @@ __OR32: ; Performs logical operation A AND B ret pop namespace - diff --git a/src/lib/arch/zx48k/runtime/orf.asm b/src/lib/arch/zxnext/runtime/bool/orf.asm similarity index 99% rename from src/lib/arch/zx48k/runtime/orf.asm rename to src/lib/arch/zxnext/runtime/bool/orf.asm index b032a8aed..7a89a2bf6 100644 --- a/src/lib/arch/zx48k/runtime/orf.asm +++ b/src/lib/arch/zxnext/runtime/bool/orf.asm @@ -26,4 +26,3 @@ __ORF: ; A | B jp __FTOU8 ; Convert to 32 bits pop namespace - diff --git a/src/lib/arch/zxnext/runtime/xor16.asm b/src/lib/arch/zxnext/runtime/bool/xor16.asm similarity index 55% rename from src/lib/arch/zxnext/runtime/xor16.asm rename to src/lib/arch/zxnext/runtime/bool/xor16.asm index 6b3fe96ab..85b1b3288 100644 --- a/src/lib/arch/zxnext/runtime/xor16.asm +++ b/src/lib/arch/zxnext/runtime/bool/xor16.asm @@ -1,3 +1,3 @@ ; XOR16 implemented in XOR8.ASM file -#include once +#include once diff --git a/src/lib/arch/zx48k/runtime/xor32.asm b/src/lib/arch/zxnext/runtime/bool/xor32.asm similarity index 92% rename from src/lib/arch/zx48k/runtime/xor32.asm rename to src/lib/arch/zxnext/runtime/bool/xor32.asm index 7f6fba94e..4be3918d5 100644 --- a/src/lib/arch/zx48k/runtime/xor32.asm +++ b/src/lib/arch/zxnext/runtime/bool/xor32.asm @@ -3,7 +3,7 @@ ; __FASTCALL__ version (operands: A, H) ; Performs 32bit xor 32bit and returns the boolean -#include once +#include once push namespace core @@ -25,4 +25,3 @@ __XOR32: jp __XOR8 pop namespace - diff --git a/src/lib/arch/zx48k/runtime/xor8.asm b/src/lib/arch/zxnext/runtime/bool/xor8.asm similarity index 99% rename from src/lib/arch/zx48k/runtime/xor8.asm rename to src/lib/arch/zxnext/runtime/bool/xor8.asm index 683ef2553..a40d24729 100644 --- a/src/lib/arch/zx48k/runtime/xor8.asm +++ b/src/lib/arch/zxnext/runtime/bool/xor8.asm @@ -26,4 +26,3 @@ __XOR8: ret pop namespace - diff --git a/src/lib/arch/zx48k/runtime/xorf.asm b/src/lib/arch/zxnext/runtime/bool/xorf.asm similarity index 99% rename from src/lib/arch/zx48k/runtime/xorf.asm rename to src/lib/arch/zxnext/runtime/bool/xorf.asm index a92d0d984..0c76f6f83 100644 --- a/src/lib/arch/zx48k/runtime/xorf.asm +++ b/src/lib/arch/zxnext/runtime/bool/xorf.asm @@ -36,4 +36,3 @@ __XORF: ; A XOR B jp __FTOU8 ; Convert to 8 bits pop namespace - diff --git a/tests/functional/arch/zx48k/andf.asm b/tests/functional/arch/zx48k/andf.asm new file mode 100644 index 000000000..9b4bb70b8 --- /dev/null +++ b/tests/functional/arch/zx48k/andf.asm @@ -0,0 +1,343 @@ + 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 +_b: + DEFB 00 +.core.ZXBASIC_USER_DATA_END: +.core.__MAIN_PROGRAM__: + ld hl, _a + 4 + call .core.__FP_PUSH_REV + ld a, 000h + ld de, 00000h + ld bc, 00000h + call .core.__ANDF + ld (_b), a + ld hl, _a + 4 + call .core.__FP_PUSH_REV + ld a, 081h + ld de, 00000h + ld bc, 00000h + call .core.__ANDF + ld (_b), a + ld a, (_a) + ld de, (_a + 1) + ld bc, (_a + 3) + ld hl, 00000h + push hl + ld hl, 00000h + push hl + ld h, 000h + push hl + call .core.__ANDF + ld (_b), a + ld a, (_a) + ld de, (_a + 1) + ld bc, (_a + 3) + ld hl, 00000h + push hl + ld hl, 00000h + push hl + ld h, 081h + push hl + call .core.__ANDF + ld (_b), a + ld a, (_a) + ld de, (_a + 1) + ld bc, (_a + 3) + ld hl, _a + 4 + call .core.__FP_PUSH_REV + call .core.__ANDF + ld (_b), a + 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/bool/andf.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/u32tofreg.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/neg32.asm" + push namespace core +__ABS32: + bit 7, d + ret z +__NEG32: ; Negates DEHL (Two's complement) + ld a, l + cpl + ld l, a + ld a, h + cpl + ld h, a + ld a, e + cpl + ld e, a + ld a, d + cpl + ld d, a + inc l + ret nz + inc h + ret nz + inc de + ret + pop namespace +#line 2 "/zxbasic/src/lib/arch/zx48k/runtime/u32tofreg.asm" + push namespace core +__I8TOFREG: + ld l, a + rlca + sbc a, a ; A = SGN(A) + ld h, a + ld e, a + ld d, a +__I32TOFREG: ; Converts a 32bit signed integer (stored in DEHL) + ; to a Floating Point Number returned in (A ED CB) + ld a, d + or a ; Test sign + jp p, __U32TOFREG ; It was positive, proceed as 32bit unsigned + call __NEG32 ; Convert it to positive + call __U32TOFREG ; Convert it to Floating point + set 7, e ; Put the sign bit (negative) in the 31bit of mantissa + ret +__U8TOFREG: + ; Converts an unsigned 8 bit (A) to Floating point + ld l, a + ld h, 0 + ld e, h + ld d, h +__U32TOFREG: ; Converts an unsigned 32 bit integer (DEHL) + ; to a Floating point number returned in A ED CB + PROC + LOCAL __U32TOFREG_END + ld a, d + or e + or h + or l + ld b, d + ld c, e ; Returns 00 0000 0000 if ZERO + ret z + push de + push hl + exx + pop de ; Loads integer into B'C' D'E' + pop bc + exx + ld l, 128 ; Exponent + ld bc, 0 ; DEBC = 0 + ld d, b + ld e, c +__U32TOFREG_LOOP: ; Also an entry point for __F16TOFREG + exx + ld a, d ; B'C'D'E' == 0 ? + or e + or b + or c + jp z, __U32TOFREG_END ; We are done + srl b ; Shift B'C' D'E' >> 1, output bit stays in Carry + rr c + rr d + rr e + exx + rr e ; Shift EDCB >> 1, inserting the carry on the left + rr d + rr c + rr b + inc l ; Increment exponent + jp __U32TOFREG_LOOP +__U32TOFREG_END: + exx + ld a, l ; Puts the exponent in a + res 7, e ; Sets the sign bit to 0 (positive) + ret + ENDP + pop namespace +#line 2 "/zxbasic/src/lib/arch/zx48k/runtime/bool/andf.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/ftou32reg.asm" + push namespace core +__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) + PROC + LOCAL __IS_FLOAT + LOCAL __NEGATE + or a + jr nz, __IS_FLOAT + ; Here if it is a ZX ROM Integer + ld h, c + ld l, d + ld d, e + ret +__IS_FLOAT: ; Jumps here if it is a true floating point number + ld h, e + push hl ; Stores it for later (Contains Sign in H) + push de + push bc + exx + pop de ; Loads mantissa into C'B' E'D' + pop bc ; + set 7, c ; Highest mantissa bit is always 1 + exx + ld hl, 0 ; DEHL = 0 + ld d, h + ld e, l + ;ld a, c ; Get exponent + sub 128 ; Exponent -= 128 + jr z, __FTOU32REG_END ; If it was <= 128, we are done (Integers must be > 128) + jr c, __FTOU32REG_END ; It was decimal (0.xxx). We are done (return 0) + ld b, a ; Loop counter = exponent - 128 +__FTOU32REG_LOOP: + exx ; Shift C'B' E'D' << 1, output bit stays in Carry + sla d + rl e + rl b + rl c + exx ; Shift DEHL << 1, inserting the carry on the right + rl l + rl h + rl e + rl d + djnz __FTOU32REG_LOOP +__FTOU32REG_END: + pop af ; Take the sign bit + or a ; Sets SGN bit to 1 if negative + jp m, __NEGATE ; Negates DEHL + ret +__NEGATE: + exx + ld a, d + or e + or b + or c + exx + jr z, __END + inc l + jr nz, __END + inc h + jr nz, __END + inc de + LOCAL __END +__END: + jp __NEG32 + ENDP +__FTOU8: ; Converts float in C ED LH to Unsigned byte in A + call __FTOU32REG + ld a, l + ret + pop namespace +#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/bool/andf.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 4 "/zxbasic/src/lib/arch/zx48k/runtime/bool/andf.asm" + ; ------------------------------------------------------------- + ; Floating point library using the FP ROM Calculator (ZX 48K) + ; All of them uses C EDHL registers as 1st paramter. + ; For binary operators, the 2n operator must be pushed into the + ; stack, in the order BC DE HL (B not used). + ; + ; Uses CALLEE convention + ; ------------------------------------------------------------- + push namespace core +__ANDF: ; A & B + call __FPSTACK_PUSH2 + ; ------------- ROM NO-&-NO + rst 28h + defb 08h ; + defb 38h; ; END CALC + call __FPSTACK_POP + jp __FTOU8 ; Convert to 8 bits + pop namespace +#line 60 "arch/zx48k/andf.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 61 "arch/zx48k/andf.bas" + END diff --git a/tests/functional/arch/zx48k/andf.bas b/tests/functional/arch/zx48k/andf.bas new file mode 100644 index 000000000..4e6a0412a --- /dev/null +++ b/tests/functional/arch/zx48k/andf.bas @@ -0,0 +1,10 @@ +' TEST for Boolean AND 32 bits + +DIM a as Float +DIM b as UByte + +b = a AND 0 +b = a AND 1 +b = 0 AND a +b = 1 AND a +b = a AND a diff --git a/tests/functional/arch/zx48k/not16.asm b/tests/functional/arch/zx48k/not16.asm new file mode 100644 index 000000000..53ad82071 --- /dev/null +++ b/tests/functional/arch/zx48k/not16.asm @@ -0,0 +1,52 @@ + 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 +_b: + DEFB 00 +.core.ZXBASIC_USER_DATA_END: +.core.__MAIN_PROGRAM__: + ld a, 1 + ld (_b), a + xor a + ld (_b), a + ld hl, (_a) + ld a, h + or l + sub 1 + sbc a, a + ld (_b), a + 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 diff --git a/tests/functional/arch/zx48k/not16.bas b/tests/functional/arch/zx48k/not16.bas new file mode 100644 index 000000000..c159772a1 --- /dev/null +++ b/tests/functional/arch/zx48k/not16.bas @@ -0,0 +1,8 @@ +' TEST for Booleand NOT 16 bits + +DIM a as Uinteger +DIM b as Ubyte + +b = NOT 0 +b = NOT 1 +b = NOT a diff --git a/tests/functional/arch/zx48k/not32.asm b/tests/functional/arch/zx48k/not32.asm new file mode 100644 index 000000000..829a128b7 --- /dev/null +++ b/tests/functional/arch/zx48k/not32.asm @@ -0,0 +1,65 @@ + 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 +_b: + DEFB 00 +.core.ZXBASIC_USER_DATA_END: +.core.__MAIN_PROGRAM__: + ld a, 1 + ld (_b), a + xor a + ld (_b), a + ld hl, (_a) + ld de, (_a + 2) + call .core.__NOT32 + ld (_b), a + 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/bool/not32.asm" + ; ------------------------------------------------------------- + ; 32 bit logical NOT + ; ------------------------------------------------------------- + push namespace core +__NOT32: ; A = ¬A + ld a, d + or e + or h + or l + sub 1 ; Gives CARRY only if 0 + sbc a, a; Gives 0 if not carry, FF otherwise + ret + pop namespace +#line 25 "arch/zx48k/not32.bas" + END diff --git a/tests/functional/arch/zx48k/not32.bas b/tests/functional/arch/zx48k/not32.bas new file mode 100644 index 000000000..3988e8fa6 --- /dev/null +++ b/tests/functional/arch/zx48k/not32.bas @@ -0,0 +1,8 @@ +' TEST for Booleand NOT 32 bits + +DIM a as Ulong +DIM b as Ubyte + +b = NOT 0 +b = NOT 1 +b = NOT a diff --git a/tests/functional/arch/zx48k/not8.asm b/tests/functional/arch/zx48k/not8.asm new file mode 100644 index 000000000..57c273ce6 --- /dev/null +++ b/tests/functional/arch/zx48k/not8.asm @@ -0,0 +1,50 @@ + 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 +_b: + DEFB 00 +.core.ZXBASIC_USER_DATA_END: +.core.__MAIN_PROGRAM__: + ld a, 1 + ld (_b), a + xor a + ld (_b), a + ld a, (_a) + sub 1 + sbc a, a + ld (_b), a + 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 diff --git a/tests/functional/arch/zx48k/not8.bas b/tests/functional/arch/zx48k/not8.bas new file mode 100644 index 000000000..dc59750cf --- /dev/null +++ b/tests/functional/arch/zx48k/not8.bas @@ -0,0 +1,8 @@ +' TEST for Booleand NOT 8 bits + +DIM a as Ubyte +DIM b as Ubyte + +b = NOT 0 +b = NOT 1 +b = NOT a diff --git a/tests/functional/arch/zx48k/notf.asm b/tests/functional/arch/zx48k/notf.asm new file mode 100644 index 000000000..9a9b32b64 --- /dev/null +++ b/tests/functional/arch/zx48k/notf.asm @@ -0,0 +1,281 @@ + 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 +_b: + DEFB 00 +.core.ZXBASIC_USER_DATA_END: +.core.__MAIN_PROGRAM__: + ld a, 1 + ld (_b), a + xor a + ld (_b), a + ld a, (_a) + ld de, (_a + 1) + ld bc, (_a + 3) + call .core.__NOTF + ld (_b), a + 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/bool/notf.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/u32tofreg.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/neg32.asm" + push namespace core +__ABS32: + bit 7, d + ret z +__NEG32: ; Negates DEHL (Two's complement) + ld a, l + cpl + ld l, a + ld a, h + cpl + ld h, a + ld a, e + cpl + ld e, a + ld a, d + cpl + ld d, a + inc l + ret nz + inc h + ret nz + inc de + ret + pop namespace +#line 2 "/zxbasic/src/lib/arch/zx48k/runtime/u32tofreg.asm" + push namespace core +__I8TOFREG: + ld l, a + rlca + sbc a, a ; A = SGN(A) + ld h, a + ld e, a + ld d, a +__I32TOFREG: ; Converts a 32bit signed integer (stored in DEHL) + ; to a Floating Point Number returned in (A ED CB) + ld a, d + or a ; Test sign + jp p, __U32TOFREG ; It was positive, proceed as 32bit unsigned + call __NEG32 ; Convert it to positive + call __U32TOFREG ; Convert it to Floating point + set 7, e ; Put the sign bit (negative) in the 31bit of mantissa + ret +__U8TOFREG: + ; Converts an unsigned 8 bit (A) to Floating point + ld l, a + ld h, 0 + ld e, h + ld d, h +__U32TOFREG: ; Converts an unsigned 32 bit integer (DEHL) + ; to a Floating point number returned in A ED CB + PROC + LOCAL __U32TOFREG_END + ld a, d + or e + or h + or l + ld b, d + ld c, e ; Returns 00 0000 0000 if ZERO + ret z + push de + push hl + exx + pop de ; Loads integer into B'C' D'E' + pop bc + exx + ld l, 128 ; Exponent + ld bc, 0 ; DEBC = 0 + ld d, b + ld e, c +__U32TOFREG_LOOP: ; Also an entry point for __F16TOFREG + exx + ld a, d ; B'C'D'E' == 0 ? + or e + or b + or c + jp z, __U32TOFREG_END ; We are done + srl b ; Shift B'C' D'E' >> 1, output bit stays in Carry + rr c + rr d + rr e + exx + rr e ; Shift EDCB >> 1, inserting the carry on the left + rr d + rr c + rr b + inc l ; Increment exponent + jp __U32TOFREG_LOOP +__U32TOFREG_END: + exx + ld a, l ; Puts the exponent in a + res 7, e ; Sets the sign bit to 0 (positive) + ret + ENDP + pop namespace +#line 2 "/zxbasic/src/lib/arch/zx48k/runtime/bool/notf.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/ftou32reg.asm" + push namespace core +__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) + PROC + LOCAL __IS_FLOAT + LOCAL __NEGATE + or a + jr nz, __IS_FLOAT + ; Here if it is a ZX ROM Integer + ld h, c + ld l, d + ld d, e + ret +__IS_FLOAT: ; Jumps here if it is a true floating point number + ld h, e + push hl ; Stores it for later (Contains Sign in H) + push de + push bc + exx + pop de ; Loads mantissa into C'B' E'D' + pop bc ; + set 7, c ; Highest mantissa bit is always 1 + exx + ld hl, 0 ; DEHL = 0 + ld d, h + ld e, l + ;ld a, c ; Get exponent + sub 128 ; Exponent -= 128 + jr z, __FTOU32REG_END ; If it was <= 128, we are done (Integers must be > 128) + jr c, __FTOU32REG_END ; It was decimal (0.xxx). We are done (return 0) + ld b, a ; Loop counter = exponent - 128 +__FTOU32REG_LOOP: + exx ; Shift C'B' E'D' << 1, output bit stays in Carry + sla d + rl e + rl b + rl c + exx ; Shift DEHL << 1, inserting the carry on the right + rl l + rl h + rl e + rl d + djnz __FTOU32REG_LOOP +__FTOU32REG_END: + pop af ; Take the sign bit + or a ; Sets SGN bit to 1 if negative + jp m, __NEGATE ; Negates DEHL + ret +__NEGATE: + exx + ld a, d + or e + or b + or c + exx + jr z, __END + inc l + jr nz, __END + inc h + jr nz, __END + inc de + LOCAL __END +__END: + jp __NEG32 + ENDP +__FTOU8: ; Converts float in C ED LH to Unsigned byte in A + call __FTOU32REG + ld a, l + ret + pop namespace +#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/bool/notf.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 4 "/zxbasic/src/lib/arch/zx48k/runtime/bool/notf.asm" + ; ------------------------------------------------------------- + ; Floating point library using the FP ROM Calculator (ZX 48K) + ; All of them uses C EDHL registers as 1st paramter. + ; For binary operators, the 2n operator must be pushed into the + ; stack, in the order BC DE HL (B not used). + ; + ; Uses CALLEE convention + ; ------------------------------------------------------------- + push namespace core +__NOTF: ; A = ¬A + call __FPSTACK_PUSH + ; ------------- ROM NOT + rst 28h + defb 30h ; + defb 38h; ; END CALC + call __FPSTACK_POP + jp __FTOU8 ; Convert to 8 bits + pop namespace +#line 26 "arch/zx48k/notf.bas" + END diff --git a/tests/functional/arch/zx48k/notf.bas b/tests/functional/arch/zx48k/notf.bas new file mode 100644 index 000000000..7cd58d2dd --- /dev/null +++ b/tests/functional/arch/zx48k/notf.bas @@ -0,0 +1,8 @@ +' TEST for Booleand NOT Float + +DIM a as Float +DIM b as Ubyte + +b = NOT 0 +b = NOT 1 +b = NOT a diff --git a/tests/functional/arch/zx48k/orf.asm b/tests/functional/arch/zx48k/orf.asm new file mode 100644 index 000000000..62ffed9a0 --- /dev/null +++ b/tests/functional/arch/zx48k/orf.asm @@ -0,0 +1,343 @@ + 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 +_b: + DEFB 00 +.core.ZXBASIC_USER_DATA_END: +.core.__MAIN_PROGRAM__: + ld hl, _a + 4 + call .core.__FP_PUSH_REV + ld a, 000h + ld de, 00000h + ld bc, 00000h + call .core.__ORF + ld (_b), a + ld hl, _a + 4 + call .core.__FP_PUSH_REV + ld a, 081h + ld de, 00000h + ld bc, 00000h + call .core.__ORF + ld (_b), a + ld a, (_a) + ld de, (_a + 1) + ld bc, (_a + 3) + ld hl, 00000h + push hl + ld hl, 00000h + push hl + ld h, 000h + push hl + call .core.__ORF + ld (_b), a + ld a, (_a) + ld de, (_a + 1) + ld bc, (_a + 3) + ld hl, 00000h + push hl + ld hl, 00000h + push hl + ld h, 081h + push hl + call .core.__ORF + ld (_b), a + ld a, (_a) + ld de, (_a + 1) + ld bc, (_a + 3) + ld hl, _a + 4 + call .core.__FP_PUSH_REV + call .core.__ORF + ld (_b), a + 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/bool/orf.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/u32tofreg.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/neg32.asm" + push namespace core +__ABS32: + bit 7, d + ret z +__NEG32: ; Negates DEHL (Two's complement) + ld a, l + cpl + ld l, a + ld a, h + cpl + ld h, a + ld a, e + cpl + ld e, a + ld a, d + cpl + ld d, a + inc l + ret nz + inc h + ret nz + inc de + ret + pop namespace +#line 2 "/zxbasic/src/lib/arch/zx48k/runtime/u32tofreg.asm" + push namespace core +__I8TOFREG: + ld l, a + rlca + sbc a, a ; A = SGN(A) + ld h, a + ld e, a + ld d, a +__I32TOFREG: ; Converts a 32bit signed integer (stored in DEHL) + ; to a Floating Point Number returned in (A ED CB) + ld a, d + or a ; Test sign + jp p, __U32TOFREG ; It was positive, proceed as 32bit unsigned + call __NEG32 ; Convert it to positive + call __U32TOFREG ; Convert it to Floating point + set 7, e ; Put the sign bit (negative) in the 31bit of mantissa + ret +__U8TOFREG: + ; Converts an unsigned 8 bit (A) to Floating point + ld l, a + ld h, 0 + ld e, h + ld d, h +__U32TOFREG: ; Converts an unsigned 32 bit integer (DEHL) + ; to a Floating point number returned in A ED CB + PROC + LOCAL __U32TOFREG_END + ld a, d + or e + or h + or l + ld b, d + ld c, e ; Returns 00 0000 0000 if ZERO + ret z + push de + push hl + exx + pop de ; Loads integer into B'C' D'E' + pop bc + exx + ld l, 128 ; Exponent + ld bc, 0 ; DEBC = 0 + ld d, b + ld e, c +__U32TOFREG_LOOP: ; Also an entry point for __F16TOFREG + exx + ld a, d ; B'C'D'E' == 0 ? + or e + or b + or c + jp z, __U32TOFREG_END ; We are done + srl b ; Shift B'C' D'E' >> 1, output bit stays in Carry + rr c + rr d + rr e + exx + rr e ; Shift EDCB >> 1, inserting the carry on the left + rr d + rr c + rr b + inc l ; Increment exponent + jp __U32TOFREG_LOOP +__U32TOFREG_END: + exx + ld a, l ; Puts the exponent in a + res 7, e ; Sets the sign bit to 0 (positive) + ret + ENDP + pop namespace +#line 2 "/zxbasic/src/lib/arch/zx48k/runtime/bool/orf.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/ftou32reg.asm" + push namespace core +__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) + PROC + LOCAL __IS_FLOAT + LOCAL __NEGATE + or a + jr nz, __IS_FLOAT + ; Here if it is a ZX ROM Integer + ld h, c + ld l, d + ld d, e + ret +__IS_FLOAT: ; Jumps here if it is a true floating point number + ld h, e + push hl ; Stores it for later (Contains Sign in H) + push de + push bc + exx + pop de ; Loads mantissa into C'B' E'D' + pop bc ; + set 7, c ; Highest mantissa bit is always 1 + exx + ld hl, 0 ; DEHL = 0 + ld d, h + ld e, l + ;ld a, c ; Get exponent + sub 128 ; Exponent -= 128 + jr z, __FTOU32REG_END ; If it was <= 128, we are done (Integers must be > 128) + jr c, __FTOU32REG_END ; It was decimal (0.xxx). We are done (return 0) + ld b, a ; Loop counter = exponent - 128 +__FTOU32REG_LOOP: + exx ; Shift C'B' E'D' << 1, output bit stays in Carry + sla d + rl e + rl b + rl c + exx ; Shift DEHL << 1, inserting the carry on the right + rl l + rl h + rl e + rl d + djnz __FTOU32REG_LOOP +__FTOU32REG_END: + pop af ; Take the sign bit + or a ; Sets SGN bit to 1 if negative + jp m, __NEGATE ; Negates DEHL + ret +__NEGATE: + exx + ld a, d + or e + or b + or c + exx + jr z, __END + inc l + jr nz, __END + inc h + jr nz, __END + inc de + LOCAL __END +__END: + jp __NEG32 + ENDP +__FTOU8: ; Converts float in C ED LH to Unsigned byte in A + call __FTOU32REG + ld a, l + ret + pop namespace +#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/bool/orf.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 4 "/zxbasic/src/lib/arch/zx48k/runtime/bool/orf.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 + ; ------------------------------------------------------------- + push namespace core +__ORF: ; A | B + call __FPSTACK_PUSH2 + ; ------------- ROM NO-OR-NO + rst 28h + defb 07h ; + defb 38h; ; END CALC + call __FPSTACK_POP + jp __FTOU8 ; Convert to 32 bits + pop namespace +#line 60 "arch/zx48k/orf.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 61 "arch/zx48k/orf.bas" + END diff --git a/tests/functional/arch/zx48k/orf.bas b/tests/functional/arch/zx48k/orf.bas new file mode 100644 index 000000000..222c86f96 --- /dev/null +++ b/tests/functional/arch/zx48k/orf.bas @@ -0,0 +1,10 @@ +' TEST for Boolean OR 32 bits + +DIM a as Float +DIM b as UByte + +b = a OR 0 +b = a OR 1 +b = 0 OR a +b = 1 OR a +b = a OR a diff --git a/tests/functional/arch/zx48k/xorf.asm b/tests/functional/arch/zx48k/xorf.asm new file mode 100644 index 000000000..b49887c24 --- /dev/null +++ b/tests/functional/arch/zx48k/xorf.asm @@ -0,0 +1,353 @@ + 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 +_b: + DEFB 00 +.core.ZXBASIC_USER_DATA_END: +.core.__MAIN_PROGRAM__: + ld hl, _a + 4 + call .core.__FP_PUSH_REV + ld a, 000h + ld de, 00000h + ld bc, 00000h + call .core.__XORF + ld (_b), a + ld hl, _a + 4 + call .core.__FP_PUSH_REV + ld a, 081h + ld de, 00000h + ld bc, 00000h + call .core.__XORF + ld (_b), a + ld a, (_a) + ld de, (_a + 1) + ld bc, (_a + 3) + ld hl, 00000h + push hl + ld hl, 00000h + push hl + ld h, 000h + push hl + call .core.__XORF + ld (_b), a + ld a, (_a) + ld de, (_a + 1) + ld bc, (_a + 3) + ld hl, 00000h + push hl + ld hl, 00000h + push hl + ld h, 081h + push hl + call .core.__XORF + ld (_b), a + ld a, (_a) + ld de, (_a + 1) + ld bc, (_a + 3) + ld hl, _a + 4 + call .core.__FP_PUSH_REV + call .core.__XORF + ld (_b), a + 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/bool/xorf.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/u32tofreg.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/neg32.asm" + push namespace core +__ABS32: + bit 7, d + ret z +__NEG32: ; Negates DEHL (Two's complement) + ld a, l + cpl + ld l, a + ld a, h + cpl + ld h, a + ld a, e + cpl + ld e, a + ld a, d + cpl + ld d, a + inc l + ret nz + inc h + ret nz + inc de + ret + pop namespace +#line 2 "/zxbasic/src/lib/arch/zx48k/runtime/u32tofreg.asm" + push namespace core +__I8TOFREG: + ld l, a + rlca + sbc a, a ; A = SGN(A) + ld h, a + ld e, a + ld d, a +__I32TOFREG: ; Converts a 32bit signed integer (stored in DEHL) + ; to a Floating Point Number returned in (A ED CB) + ld a, d + or a ; Test sign + jp p, __U32TOFREG ; It was positive, proceed as 32bit unsigned + call __NEG32 ; Convert it to positive + call __U32TOFREG ; Convert it to Floating point + set 7, e ; Put the sign bit (negative) in the 31bit of mantissa + ret +__U8TOFREG: + ; Converts an unsigned 8 bit (A) to Floating point + ld l, a + ld h, 0 + ld e, h + ld d, h +__U32TOFREG: ; Converts an unsigned 32 bit integer (DEHL) + ; to a Floating point number returned in A ED CB + PROC + LOCAL __U32TOFREG_END + ld a, d + or e + or h + or l + ld b, d + ld c, e ; Returns 00 0000 0000 if ZERO + ret z + push de + push hl + exx + pop de ; Loads integer into B'C' D'E' + pop bc + exx + ld l, 128 ; Exponent + ld bc, 0 ; DEBC = 0 + ld d, b + ld e, c +__U32TOFREG_LOOP: ; Also an entry point for __F16TOFREG + exx + ld a, d ; B'C'D'E' == 0 ? + or e + or b + or c + jp z, __U32TOFREG_END ; We are done + srl b ; Shift B'C' D'E' >> 1, output bit stays in Carry + rr c + rr d + rr e + exx + rr e ; Shift EDCB >> 1, inserting the carry on the left + rr d + rr c + rr b + inc l ; Increment exponent + jp __U32TOFREG_LOOP +__U32TOFREG_END: + exx + ld a, l ; Puts the exponent in a + res 7, e ; Sets the sign bit to 0 (positive) + ret + ENDP + pop namespace +#line 2 "/zxbasic/src/lib/arch/zx48k/runtime/bool/xorf.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/ftou32reg.asm" + push namespace core +__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) + PROC + LOCAL __IS_FLOAT + LOCAL __NEGATE + or a + jr nz, __IS_FLOAT + ; Here if it is a ZX ROM Integer + ld h, c + ld l, d + ld d, e + ret +__IS_FLOAT: ; Jumps here if it is a true floating point number + ld h, e + push hl ; Stores it for later (Contains Sign in H) + push de + push bc + exx + pop de ; Loads mantissa into C'B' E'D' + pop bc ; + set 7, c ; Highest mantissa bit is always 1 + exx + ld hl, 0 ; DEHL = 0 + ld d, h + ld e, l + ;ld a, c ; Get exponent + sub 128 ; Exponent -= 128 + jr z, __FTOU32REG_END ; If it was <= 128, we are done (Integers must be > 128) + jr c, __FTOU32REG_END ; It was decimal (0.xxx). We are done (return 0) + ld b, a ; Loop counter = exponent - 128 +__FTOU32REG_LOOP: + exx ; Shift C'B' E'D' << 1, output bit stays in Carry + sla d + rl e + rl b + rl c + exx ; Shift DEHL << 1, inserting the carry on the right + rl l + rl h + rl e + rl d + djnz __FTOU32REG_LOOP +__FTOU32REG_END: + pop af ; Take the sign bit + or a ; Sets SGN bit to 1 if negative + jp m, __NEGATE ; Negates DEHL + ret +__NEGATE: + exx + ld a, d + or e + or b + or c + exx + jr z, __END + inc l + jr nz, __END + inc h + jr nz, __END + inc de + LOCAL __END +__END: + jp __NEG32 + ENDP +__FTOU8: ; Converts float in C ED LH to Unsigned byte in A + call __FTOU32REG + ld a, l + ret + pop namespace +#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/bool/xorf.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 4 "/zxbasic/src/lib/arch/zx48k/runtime/bool/xorf.asm" + ; ------------------------------------------------------------- + ; Floating point library using the FP ROM Calculator (ZX 48K) + ; All of them uses C EDHL registers as 1st paramter. + ; For binary operators, the 2n operator must be pushed into the + ; stack, in the order BC DE HL (B not used). + ; + ; Uses CALLEE convention + ; ------------------------------------------------------------- + push namespace core +__XORF: ; A XOR B + call __FPSTACK_PUSH2 + ; A XOR B == A ^ ¬B v ¬A ^ B + rst 28h + defb 0C0h ; STORE 0 + defb 02h ; DELETE + defb 31h ; DUP + defb 30h ; NOT A + defb 0E0h ; Recall 0 + defb 08h ; AND + defb 01h ; SWAP + defb 0E0h ; Recall 0 + defb 30h ; NOT B + defb 08h ; AND + defb 07h ; OR + defb 38h ; END CALC + call __FPSTACK_POP + jp __FTOU8 ; Convert to 8 bits + pop namespace +#line 60 "arch/zx48k/xorf.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 61 "arch/zx48k/xorf.bas" + END diff --git a/tests/functional/arch/zx48k/xorf.bas b/tests/functional/arch/zx48k/xorf.bas new file mode 100644 index 000000000..5b191f2a5 --- /dev/null +++ b/tests/functional/arch/zx48k/xorf.bas @@ -0,0 +1,10 @@ +' TEST for Boolean XOR Float + +DIM a as Float +DIM b as UByte + +b = a XOR 0 +b = a XOR 1 +b = 0 XOR a +b = 1 XOR a +b = a XOR a