Skip to content

Commit a90ffb2

Browse files
committed
added ez80sf to CRT (jacobly0/calc84maniac)
1 parent 9f66624 commit a90ffb2

27 files changed

+2073
-33
lines changed

src/crt/dabs.src

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
assume adl=1
2+
3+
section .text
4+
5+
public __dabs
6+
7+
; assumes BC:UDE:UHL
8+
__dabs:
9+
res 7, b
10+
ret

src/crt/fneg.src

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
;--------------------------------------------------------------
2+
;
3+
; Code Generation Helper
4+
; For the Zilog eZ80 C Compiler
5+
; Copyright 1992-2008 Zilog, Inc.
6+
;
7+
;--------------------------------------------------------------
8+
;--------------------------------------------------------------
9+
;
10+
; IEEE Negate.
11+
;
12+
; INPUTS:
13+
; AuBC: 32-bit IEEE Single Precision.
14+
;
15+
; OUTPUTS:
16+
; AuBC: 32-bit IEEE Single Precision.
17+
;
18+
;--------------------------------------------------------------
19+
assume adl=1
20+
21+
section .text
22+
public __fneg
23+
__fneg:
24+
or a,a
25+
jr nz,__noexit
26+
push hl
27+
sbc hl,hl
28+
sbc hl,bc
29+
pop hl
30+
ret z
31+
__noexit:
32+
xor a,80h
33+
ret

src/crt/fpabs.src

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
assume adl=1
2+
3+
section .text
4+
5+
public __fpabs
6+
7+
; IEEE single precision absolute value
8+
; aubc = |aubc|
9+
__fpabs: ; CHECK: bitcast(uint32_t, pair8_24_t, { out.BC, out.A }) == bitcast(uint32_t, float, fabsf(bitcast(float, pair8_24_t, { in.BC, in.A }))) && out.DE == in.DE && out.HL == in.HL && out.IX == in.IX && out.IY == in.IY
10+
and a, 07Fh
11+
ret

src/crt/fpaddsub.src

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
assume adl=1
2+
3+
;-------------------------------------------------------------------------------
4+
5+
section .text
6+
7+
public __fpsub
8+
9+
; IEEE single precision subtraction
10+
; aubc = aubc - euhl
11+
__fpsub: ; CHECK: same(bitcast(float, pair8_24_t, { out.BC, out.A }), bitcast(float, pair8_24_t, { in.BC, in.A }) - bitcast(float, pair8_24_t, { in.HL, in.E })) && out.DE == in.DE && out.HL == in.HL && out.IX == in.IX && out.IY == in.IY
12+
push de
13+
rl e
14+
ccf
15+
rr e
16+
; jq __fpadd.enter
17+
virtual
18+
ld d, 0
19+
load .ld_d : byte from $$
20+
end virtual
21+
db .ld_d
22+
23+
require __fpadd
24+
25+
;-------------------------------------------------------------------------------
26+
27+
section .text
28+
29+
public __fpadd
30+
31+
; IEEE single precision addition
32+
; aubc = aubc + euhl
33+
__fpadd: ; CHECK: same(bitcast(float, pair8_24_t, { out.BC, out.A }), bitcast(float, pair8_24_t, { in.BC, in.A }) + bitcast(float, pair8_24_t, { in.HL, in.E })) && out.DE == in.DE && out.HL == in.HL && out.IX == in.IX && out.IY == in.IY
34+
push de
35+
.enter:
36+
push hl
37+
push bc
38+
xor a, e
39+
ld d, a
40+
push de
41+
push bc
42+
xor a, e
43+
call __fppop1
44+
ex (sp), hl
45+
ld d, e
46+
ld e, a
47+
call __fppop2
48+
inc e
49+
jq z, .nonfinite1
50+
inc d
51+
jq z, .return2
52+
ld a, d
53+
sub a, e
54+
jq z, .rounded
55+
jq nc, .sorted
56+
inc c
57+
ex (sp), hl
58+
ld a, e
59+
sub a, d
60+
ld d, e
61+
.sorted:
62+
cp a, 26
63+
jq nc, .largest
64+
; Extend to 32 bits and shift left by ~(amount - 1) & 7
65+
dec a
66+
ld b, a
67+
xor a, a
68+
srl b
69+
jq c, .noshift1
70+
add hl, hl
71+
rla
72+
.noshift1:
73+
srl b
74+
jq c, .noshift2
75+
repeat 2
76+
add hl, hl
77+
rla
78+
end repeat
79+
.noshift2:
80+
srl b
81+
jq c, .noshift4
82+
repeat 4
83+
add hl, hl
84+
rla
85+
end repeat
86+
.noshift4:
87+
; Shift right by (amount + 7) / 8 * 8, truncating to 24 bits
88+
; The last 2 bits shifted out are in A, while any remaining non-zero
89+
; bits are aggregated into the lower bits of A
90+
push af
91+
inc sp
92+
push hl
93+
inc sp
94+
ld a, l
95+
jq nz, .shift16
96+
; Shift by 8 for amounts between 1 and 8
97+
pop hl
98+
inc sp
99+
jq .rounded
100+
101+
.shift16:
102+
; Shift by 16 for amounts between 9 and 16
103+
ld e, h
104+
inc sp
105+
pop hl
106+
dec b
107+
jq z, .flush
108+
.shift8more:
109+
; Shift by 24 for amounts between 17 and 24
110+
or a, e
111+
ld e, l
112+
ld l, h
113+
ld h, 0
114+
; Shift by 32 for amount of 25
115+
djnz .shift8more
116+
.flush:
117+
sub a, 1
118+
sbc a, a
119+
inc a
120+
or a, e
121+
.rounded:
122+
ld b, d
123+
pop de
124+
ex (sp), hl
125+
add.s hl, hl
126+
jq nc, .add
127+
ld l, h
128+
add hl, bc
129+
ld c, l
130+
pop hl
131+
djnz .subtract ;always taken
132+
133+
.nonfinite1:
134+
inc d
135+
jq z, .nonfinite
136+
.return1:
137+
pop bc
138+
.return1.pop1:
139+
pop de
140+
ld a, d
141+
.return1.pop2:
142+
xor a, e
143+
pop bc
144+
.return:
145+
pop hl
146+
pop de
147+
ret
148+
149+
.largest:
150+
ld a, d
151+
cp a, e
152+
jq z, .return1
153+
.return2:
154+
pop bc
155+
.return2.pop1:
156+
pop de
157+
.return2.pop2:
158+
ld a, e
159+
pop bc
160+
pop bc
161+
push bc
162+
jq .return
163+
164+
.add:
165+
ld c, h
166+
pop hl
167+
add hl, de
168+
dec b
169+
jq nc, .done
170+
ex de, hl
171+
sbc hl, hl
172+
add hl, sp
173+
push de
174+
rr (hl)
175+
pop hl
176+
rr h
177+
rr l
178+
rra
179+
jq nc, .flushed2
180+
or a, 1
181+
.flushed2:
182+
inc b
183+
inc b
184+
jq z, .infinite
185+
djnz .done ;always taken
186+
187+
.borrow:
188+
inc c
189+
add hl, de
190+
.subtract:
191+
ex de, hl
192+
neg
193+
sbc hl, de
194+
jq c, .borrow
195+
jq nz, .done
196+
or a, a
197+
.done:
198+
ld de, 0800000h
199+
call nz, __fppack
200+
pop bc
201+
ex (sp), hl
202+
pop bc
203+
pop de
204+
ret
205+
206+
.nonfinite:
207+
xor a, a
208+
sbc hl, bc
209+
jq nz, .return1
210+
pop hl
211+
sbc hl, bc
212+
jq nz, .return2.pop1
213+
pop de
214+
bit 7, d
215+
jq z, .return1.pop2
216+
ld bc, 0C00000h
217+
.infinite:
218+
ld a, c
219+
ld c, b ;0, also note BCU=080h from __fppop1 or 0C0h from .nonfinite
220+
rrca
221+
or a, 07Fh
222+
pop hl
223+
pop hl
224+
pop de
225+
ret
226+
227+
;-------------------------------------------------------------------------------
228+
229+
extern __fppop1
230+
extern __fppop2
231+
extern __fppack

0 commit comments

Comments
 (0)