-
Notifications
You must be signed in to change notification settings - Fork 11
/
f32tox.z80
79 lines (77 loc) · 1.09 KB
/
f32tox.z80
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifndef included_f32tox
#define included_f32tox
#include "pushpop.z80"
f32tox:
;convert an IEEE-754 binary32 to an extended-precision float.
;Input: HL points to the input float, BC points to where to output
;Destroys: None
call pushpop
ld d,b
ld e,c
xor a
ld (de),a
inc de
ld (de),a
inc de
ld (de),a
inc de
ld (de),a
inc de
ld (de),a
inc de
ldi
ldi
ld a,(hl)
inc hl
ld c,a
or %10000000
ld (de),a
inc de
ld a,c
add a,a
ld a,(hl)
adc a,a
jr z,f32tox_return_0
inc a
jr z,f32tox_return_infnan
;A-128+16384 is the exponent
rr c ; save the sign
sub 128
ld (de),a
inc de
ld a,%10000000
sbc a,0
rl c
rra
ld (de),a
ret
f32tox_return_infnan:
rr c ; save the sign
ex de,hl
dec hl
ld a,(hl)
add a,a
dec hl
or (hl)
dec hl
or (hl)
inc hl
inc hl
sub 1 ; if A was 0 (inf),sets carry, else resets
ld a,$80
rra
ld (hl),a
xor a
ex de,hl
rl c ; restore the sign
.db 1 ; start of `ld bc,**` to eat the next two bytes
f32tox_return_0:
dec de
ld (de),a
inc de
ld (de),a
inc de
rra
ld (de),a
ret
#endif