-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathhpfp.asm
58 lines (56 loc) · 918 Bytes
/
hpfp.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
; Interfacing with the high-precision calculator in the ZX Spectrum ROM
FP_CALC: EQU $28
RSTK: EQU $3D ; No such thing needed on ZX81
END_CALC: EQU $38 ; $34 for ZX81
STK_STORE: EQU $2AB6 ; $12C3 for ZX81
; Store floating point number on the calculator stack
; Input: DE = number to stack
; Pollutes: AF, BC, DE, HL
STKFP: LD A,D
ADD A,A
RR E
LD BC,0
LD D,B
RR D
RRCA
ADD $41
JP STK_STORE
; Retrieve floating point number from the calculator stack
; Output: DE = retrieved floating point number
; Pollutes: AF, BC, BC', DE', HL, HL'
FPTODE: RST FP_CALC
DEFB RSTK ; Remove for ZX81
DEFB END_CALC
LD A,(HL)
INC HL
LD E,(HL)
SUB $41
JR C,UNDERF
ADD A,A
JR C,OVERF
INC HL
LD D,(HL)
SLA D
RL E
RRA
SLA D ; only need CF
LD D,A
RET NC
INC E
RET NZ
INC D
XOR D
ADD A,A
RET NC
DEC D
JR OVERFE
UNDERF: LD A,$80
AND E
LD D,A
LD E,0
RET
OVERF: LD A,$7F
OR E
LD D,A
OVERFE: LD E,$FF
RET