From cb53c45ad3b6beb1c044297bd479c7121e83cdf8 Mon Sep 17 00:00:00 2001 From: zerico <71151164+ZERICO2005@users.noreply.github.com> Date: Fri, 13 Mar 2026 20:32:26 -0600 Subject: [PATCH 1/2] added reference implementations of __*test --- src/crt/i48test.src | 19 +++++++++++++++++++ src/crt/itest.src | 18 ++++++++++++++++++ src/crt/lltest.src | 36 ++++++++++++++++++++++++++++++++++++ src/crt/ltest.src | 20 ++++++++++++++++++++ src/crt/stest.src | 18 ++++++++++++++++++ 5 files changed, 111 insertions(+) create mode 100644 src/crt/i48test.src create mode 100644 src/crt/itest.src create mode 100644 src/crt/lltest.src create mode 100644 src/crt/ltest.src create mode 100644 src/crt/stest.src diff --git a/src/crt/i48test.src b/src/crt/i48test.src new file mode 100644 index 000000000..1bf3c8489 --- /dev/null +++ b/src/crt/i48test.src @@ -0,0 +1,19 @@ + .assume adl=1 + + .section .text + .global __i48test + .type __i48test, @function + +__i48test: + ; Z flag = ((UDE:UHL & UIY:UBC) == 0) + ; all other flags are destroyed + push hl + push de + call __i48and + call __i48cmpzero + pop de + pop hl + ret + + .extern __i48and + .extern __i48cmpzero diff --git a/src/crt/itest.src b/src/crt/itest.src new file mode 100644 index 000000000..d913ee32a --- /dev/null +++ b/src/crt/itest.src @@ -0,0 +1,18 @@ + .assume adl=1 + + .section .text + .global __itest + .type __itest, @function + +__itest: + ; Z flag = ((UHL & UBC) == 0) + ; all other flags are destroyed + push hl + call __iand + add hl, bc + or a, a + sbc hl, bc + pop hl + ret + + .extern __iand diff --git a/src/crt/lltest.src b/src/crt/lltest.src new file mode 100644 index 000000000..5f7e2e63b --- /dev/null +++ b/src/crt/lltest.src @@ -0,0 +1,36 @@ + .assume adl=1 + + .section .text + .global __lltest + .type __lltest, @function + +__lltest: + ; Z flag = ((BC:UDE:UHL & SP64) == 0) + ; all other flags are destroyed + ; (sp + 18) = [48:63] + ; (sp + 15) = [24:47] + ; (sp + 12) = [ 0:23] + ; (sp + 9) = ret + push bc ; (sp + 6) + push de ; (sp + 3) + push hl ; (sp + 0) + ld hl, 18 + add hl, sp + ld bc, (hl) + dec hl + dec hl + dec hl + ld de, (hl) + dec hl + dec hl + dec hl + ld hl, (hl) + call __lland + call __llcmpzero + pop hl + pop de + pop bc + ret + + .extern __lland + .extern __llcmpzero diff --git a/src/crt/ltest.src b/src/crt/ltest.src new file mode 100644 index 000000000..77924eedd --- /dev/null +++ b/src/crt/ltest.src @@ -0,0 +1,20 @@ + .assume adl=1 + + .section .text + .global __ltest + .type __ltest, @function + +__ltest: + ; Z flag = ((E:UHL & A:UBC) == 0) + ; all other flags are destroyed + tst a, e + ret nz + push hl + call __iand + add hl, bc + or a, a + sbc hl, bc + pop hl + ret + + .extern __iand diff --git a/src/crt/stest.src b/src/crt/stest.src new file mode 100644 index 000000000..b3ab1d195 --- /dev/null +++ b/src/crt/stest.src @@ -0,0 +1,18 @@ + .assume adl=1 + + .section .text + .global __stest + .type __stest, @function + +__stest: + ; Z flag = ((HL & BC) == 0) + ; all other flags are destroyed + push hl + call __sand + add hl, bc + or a, a + sbc.s hl, bc + pop hl + ret + + .extern __sand From be6fbe27519e672a43e2e2e11ef0faf4f2c125d5 Mon Sep 17 00:00:00 2001 From: zerico <71151164+ZERICO2005@users.noreply.github.com> Date: Sun, 15 Mar 2026 00:46:53 -0600 Subject: [PATCH 2/2] optimized stest/itest/ltest --- src/crt/itest.src | 18 ---------------- src/crt/ltest.src | 20 ------------------ src/crt/stest.src | 20 +++++++++++------- src/crt/test.src | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 46 deletions(-) delete mode 100644 src/crt/itest.src delete mode 100644 src/crt/ltest.src create mode 100644 src/crt/test.src diff --git a/src/crt/itest.src b/src/crt/itest.src deleted file mode 100644 index d913ee32a..000000000 --- a/src/crt/itest.src +++ /dev/null @@ -1,18 +0,0 @@ - .assume adl=1 - - .section .text - .global __itest - .type __itest, @function - -__itest: - ; Z flag = ((UHL & UBC) == 0) - ; all other flags are destroyed - push hl - call __iand - add hl, bc - or a, a - sbc hl, bc - pop hl - ret - - .extern __iand diff --git a/src/crt/ltest.src b/src/crt/ltest.src deleted file mode 100644 index 77924eedd..000000000 --- a/src/crt/ltest.src +++ /dev/null @@ -1,20 +0,0 @@ - .assume adl=1 - - .section .text - .global __ltest - .type __ltest, @function - -__ltest: - ; Z flag = ((E:UHL & A:UBC) == 0) - ; all other flags are destroyed - tst a, e - ret nz - push hl - call __iand - add hl, bc - or a, a - sbc hl, bc - pop hl - ret - - .extern __iand diff --git a/src/crt/stest.src b/src/crt/stest.src index b3ab1d195..3c30a00ab 100644 --- a/src/crt/stest.src +++ b/src/crt/stest.src @@ -7,12 +7,16 @@ __stest: ; Z flag = ((HL & BC) == 0) ; all other flags are destroyed - push hl - call __sand - add hl, bc - or a, a - sbc.s hl, bc - pop hl + push de + ld e, a + ; test low 8 bits + ld a, l + and a, c + jr nz, .L.non_zero + ; test high 8 bits + ld a, h + and a, b +.L.non_zero: + ld a, e + pop de ret - - .extern __sand diff --git a/src/crt/test.src b/src/crt/test.src new file mode 100644 index 000000000..4f6317f79 --- /dev/null +++ b/src/crt/test.src @@ -0,0 +1,54 @@ + .assume adl=1 + +;------------------------------------------------------------------------------- + + .section .text + .global __ltest + .type __ltest, @function + +__ltest: + ; Z flag = ((E:UHL & A:UBC) == 0) + ; all other flags are destroyed + tst a, e + ret nz + +; REQUIRE require __itest + +;------------------------------------------------------------------------------- + +; REQUIRE .section .text + .global __itest + .type __itest, @function + +__itest: + ; Z flag = ((UHL & UBC) == 0) + ; all other flags are destroyed + push de + ld e, a + ; test low 8 bits + ld a, l + and a, c + jr nz, .L.non_zero + ; test high 8 bits + ld a, h + and a, b + jr nz, .L.non_zero + ; test upper 8 bits + push hl + scf + sbc hl, hl + add hl, sp + push bc + ld a, (hl) + inc hl + ld sp, hl + inc hl + inc hl + and a, (hl) + pop hl +.L.non_zero: + ld a, e + pop de + ret + +;-------------------------------------------------------------------------------