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/visitor/translator_inst_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,4 @@ def ic_varx(self, name: str, type_: TYPE | sym.BASICTYPE, default_value: list) -
self.emit("varx", name, self.TSUFFIX(type_), default_value)

def ic_xor(self, type_: TYPE | sym.BASICTYPE, t, t1, t2) -> None:
self.emit("xor" + self.TSUFFIX(type_), t, t1, t2)
self.emit(f"xor{self._no_bool(type_)}", t, t1, t2)
30 changes: 29 additions & 1 deletion tests/functional/arch/zx48k/and16.asm
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,23 @@ _b:
ld de, (_a)
ld hl, (_a)
call .core.__AND16
sub 1
sbc a, a
inc a
ld (_b), a
ld de, (_a)
ld hl, (_a)
call .core.__EQ16
push af
ld de, (_a)
ld hl, (_a)
call .core.__EQ16
ld h, a
pop af
or a
jr z, .LABEL.__LABEL0
ld a, h
.LABEL.__LABEL0:
sub 1
sbc a, a
inc a
Expand Down Expand Up @@ -80,5 +97,16 @@ __AND16:
or e
ret
pop namespace
#line 44 "arch/zx48k/and16.bas"
#line 61 "arch/zx48k/and16.bas"
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/cmp/eq16.asm"
push namespace core
__EQ16: ; Test if 16bit values HL == DE
; Returns result in A: 0 = False, FF = True
xor a ; Reset carry flag
sbc hl, de
ret nz
inc a
ret
pop namespace
#line 62 "arch/zx48k/and16.bas"
END
2 changes: 2 additions & 0 deletions tests/functional/arch/zx48k/and16.bas
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ b = a AND 1
b = 0 AND a
b = 1 AND a
b = a AND a
b = (a = a) AND (a = a)

53 changes: 52 additions & 1 deletion tests/functional/arch/zx48k/and32.asm
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,31 @@ _b:
ld hl, (_a)
ld de, (_a + 2)
call .core.__AND32
sub 1
sbc a, a
inc a
ld (_b), a
ld hl, (_a + 2)
push hl
ld hl, (_a)
push hl
ld hl, (_a)
ld de, (_a + 2)
call .core.__EQ32
push af
ld hl, (_a + 2)
push hl
ld hl, (_a)
push hl
ld hl, (_a)
ld de, (_a + 2)
call .core.__EQ32
ld h, a
pop af
or a
jr z, .LABEL.__LABEL0
ld a, h
.LABEL.__LABEL0:
sub 1
sbc a, a
inc a
Expand Down Expand Up @@ -98,5 +123,31 @@ __AND32:
#line 28 "/zxbasic/src/lib/arch/zx48k/runtime/bool/and32.asm"
ret
pop namespace
#line 54 "arch/zx48k/and32.bas"
#line 79 "arch/zx48k/and32.bas"
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/cmp/eq32.asm"
push namespace core
__EQ32: ; Test if 32bit value HLDE equals top of the stack
; Returns result in A: 0 = False, FF = True
exx
pop bc ; Return address
exx
xor a ; Reset carry flag
pop bc
sbc hl, bc ; Low part
ex de, hl
pop bc
sbc hl, bc ; High part
exx
push bc ; CALLEE
exx
ld a, h
or l
or d
or e ; a = 0 and Z flag set only if HLDE = 0
ld a, 1
ret z
xor a
ret
pop namespace
#line 80 "arch/zx48k/and32.bas"
END
2 changes: 2 additions & 0 deletions tests/functional/arch/zx48k/and32.bas
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ b = a AND 1
b = 0 AND a
b = 1 AND a
b = a AND a
b = (a = a) AND (a = a)

21 changes: 21 additions & 0 deletions tests/functional/arch/zx48k/and8.asm
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,27 @@ _b:
jr z, .LABEL.__LABEL0
ld a, h
.LABEL.__LABEL0:
sub 1
sbc a, a
inc a
ld (_b), a
ld hl, (_a - 1)
ld a, (_a)
sub h
sub 1
sbc a, a
push af
ld hl, (_a - 1)
ld a, (_a)
sub h
sub 1
sbc a, a
ld h, a
pop af
or a
jr z, .LABEL.__LABEL1
ld a, h
.LABEL.__LABEL1:
sub 1
sbc a, a
inc a
Expand Down
2 changes: 2 additions & 0 deletions tests/functional/arch/zx48k/and8.bas
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ b = a AND 1
b = 0 AND a
b = 1 AND a
b = a AND a
b = (a = a) AND (a = a)

48 changes: 46 additions & 2 deletions tests/functional/arch/zx48k/andf.asm
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,29 @@ _b:
call .core.__FP_PUSH_REV
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.__EQF
push af
ld a, (_a)
ld de, (_a + 1)
ld bc, (_a + 3)
ld hl, _a + 4
call .core.__FP_PUSH_REV
call .core.__EQF
ld h, a
pop af
or a
jr z, .LABEL.__LABEL0
ld a, h
.LABEL.__LABEL0:
sub 1
sbc a, a
inc a
ld (_b), a
ld hl, 0
ld b, h
ld c, l
Expand Down Expand Up @@ -311,7 +334,28 @@ __ANDF: ; A & B
call __FPSTACK_POP
jp __FTOU8 ; Convert to 8 bits
pop namespace
#line 60 "arch/zx48k/andf.bas"
#line 83 "arch/zx48k/andf.bas"
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/cmp/eqf.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
__EQF: ; A = B
call __FPSTACK_PUSH2
; ------------- ROM NOS-EQL
ld b, 0Eh ; For comparison operators, OP must be in B also
rst 28h
defb 0Eh
defb 38h; ; END CALC
call __FPSTACK_POP
jp __FTOU8 ; Convert to 8 bits
pop namespace
#line 84 "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
Expand Down Expand Up @@ -339,5 +383,5 @@ __FP_PUSH_REV:
exx
ret
pop namespace
#line 61 "arch/zx48k/andf.bas"
#line 85 "arch/zx48k/andf.bas"
END
2 changes: 2 additions & 0 deletions tests/functional/arch/zx48k/andf.bas
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ b = a AND 1
b = 0 AND a
b = 1 AND a
b = a AND a
b = (a = a) AND (a = a)

18 changes: 18 additions & 0 deletions tests/functional/arch/zx48k/not16.asm
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ _b:
sbc a, a
neg
ld (_b), a
ld de, (_a)
ld hl, (_a)
call .core.__EQ16
sub 1
sbc a, a
neg
ld (_b), a
ld hl, 0
ld b, h
ld c, l
Expand All @@ -50,4 +57,15 @@ _b:
ei
ret
;; --- end of user code ---
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/cmp/eq16.asm"
push namespace core
__EQ16: ; Test if 16bit values HL == DE
; Returns result in A: 0 = False, FF = True
xor a ; Reset carry flag
sbc hl, de
ret nz
inc a
ret
pop namespace
#line 35 "arch/zx48k/not16.bas"
END
2 changes: 2 additions & 0 deletions tests/functional/arch/zx48k/not16.bas
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ DIM b as Ubyte
b = NOT 0
b = NOT 1
b = NOT a
b = NOT (a = a)

39 changes: 38 additions & 1 deletion tests/functional/arch/zx48k/not32.asm
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ _b:
call .core.__NOT32
neg
ld (_b), a
ld hl, (_a + 2)
push hl
ld hl, (_a)
push hl
ld hl, (_a)
ld de, (_a + 2)
call .core.__EQ32
sub 1
sbc a, a
neg
ld (_b), a
ld hl, 0
ld b, h
ld c, l
Expand Down Expand Up @@ -62,5 +73,31 @@ __NOT32: ; A = ¬A
sbc a, a; Gives 0 if not carry, FF otherwise
ret
pop namespace
#line 26 "arch/zx48k/not32.bas"
#line 37 "arch/zx48k/not32.bas"
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/cmp/eq32.asm"
push namespace core
__EQ32: ; Test if 32bit value HLDE equals top of the stack
; Returns result in A: 0 = False, FF = True
exx
pop bc ; Return address
exx
xor a ; Reset carry flag
pop bc
sbc hl, bc ; Low part
ex de, hl
pop bc
sbc hl, bc ; High part
exx
push bc ; CALLEE
exx
ld a, h
or l
or d
or e ; a = 0 and Z flag set only if HLDE = 0
ld a, 1
ret z
xor a
ret
pop namespace
#line 38 "arch/zx48k/not32.bas"
END
2 changes: 2 additions & 0 deletions tests/functional/arch/zx48k/not32.bas
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ DIM b as Ubyte
b = NOT 0
b = NOT 1
b = NOT a
b = NOT (a = a)

7 changes: 7 additions & 0 deletions tests/functional/arch/zx48k/not8.asm
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ _b:
sbc a, a
neg
ld (_b), a
ld hl, (_a - 1)
ld a, (_a)
sub h
sub 1
sbc a, a
inc a
ld (_b), a
ld hl, 0
ld b, h
ld c, l
Expand Down
4 changes: 3 additions & 1 deletion tests/functional/arch/zx48k/not8.bas
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
' TEST for Booleand NOT 8 bits
' TEST for Booleand NOT 8 bits

DIM a as Ubyte
DIM b as Ubyte

b = NOT 0
b = NOT 1
b = NOT a
b = NOT (a = a)

Loading
Loading