--- /dev/null
+.sect .text
+.sect .rom
+.sect .data
+.sect .bss
+.sect .text
+
+! Does a tristate signed comparison of hl <> de.
+! Returns m flag if hl < de.
+! Returns p flag if hl >= de.
+! This doesn't set z coherently.
+
+.define .cmps_mag
+.cmps_mag:
+ mov a, d
+ xra h
+ jp .cmpu_mag ! signs are the same, so an unsigned comparison will do
+ xra h ! set A=H and set the sign flag
+ ret
--- /dev/null
+.sect .text
+.sect .rom
+.sect .data
+.sect .bss
+.sect .text
+
+! Does a tristate unsigned comparison of hl <> de.
+! Returns m flag if hl < de.
+! Returns p flag if hl >= de.
+! This doesn't set z coherently.
+
+.define .cmpu_mag
+.cmpu_mag:
+ mov a, e
+ sub l
+ mov a, d
+ sbb h
+ rar
+ ret
jmp {label,$1}
pat blt
- with const2 hl_or_de STACK
- uses areg
- gen
- mov a, %2.1
- xri {const1, 0x80}
- mov %2.1, a
- mov a, %2.2
- sui {const1, %1.num & 0xff}
- mov a, %2.1
- sbi {const1, (%1.num >> 8) ^ 0x80}
- jc {label, $1}
- with hl_or_de const2 STACK
- uses areg
- gen
- mov a, %1.1
- xri {const1, 0x80}
- mov %1.1, a
- mvi a, {const1, %2.num & 0xff}
- sub %1.2
- mvi a, {const1, (%2.num >> 8) ^ 0x80}
- sbb %1.1
- jc {label, $1}
- with hl_or_de hl_or_de STACK
+ with hlreg dereg STACK
uses areg
gen
- mov a, %2.1
- xri {const1, 0x80}
- mov %2.1, a
- mov a, %1.1
- xri {const1, 0x80}
- mov %1.1, a
- mov a, %2.2
- sub %1.2
- mov a, %2.1
- sbb %1.1
- jc {label,$1}
+ Call {label, ".cmps_mag"}
+ jm {label, $1}
pat bgt
leaving
blt $1
pat bge
- with const2 hl_or_de STACK
- uses areg
- gen
- mov a, %2.1
- xri {const1, 0x80}
- mov %2.1, a
- mov a, %2.2
- sui {const1, %1.num & 0xff}
- mov a, %2.1
- sbi {const1, (%1.num >> 8) ^ 0x80}
- jnc {label, $1}
- with hl_or_de const2 STACK
- uses areg
- gen
- mov a, %1.1
- xri {const1, 0x80}
- mov %1.1, a
- mvi a, {const1, %2.num & 0xff}
- sub %1.2
- mvi a, {const1, (%2.num >> 8) ^ 0x80}
- sbb %1.1
- jnc {label, $1}
- with hl_or_de hl_or_de STACK
+ with hlreg dereg STACK
uses areg
gen
- mov a, %2.1
- xri {const1, 0x80}
- mov %2.1, a
- mov a, %1.1
- xri {const1, 0x80}
- mov %1.1, a
- mov a,%2.2
- sub %1.2
- mov a,%2.1
- sbb %1.1
- jnc {label,$1}
+ Call {label, ".cmpu_mag"}
+ jp {label, $1}
pat ble
leaving