-
Notifications
You must be signed in to change notification settings - Fork 10
/
f16tof32.z80
81 lines (74 loc) · 1.4 KB
/
f16tof32.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
80
81
#ifndef included_f16tof32
#define included_f16tof32
#include "pushpop.z80"
f16tof32:
;Inputs:
; HL is the f16 input
; BC is where to write the f32 float
;Destroys:
; none
call pushpop
;check for inf or NaN
ld a,h
and %01111100
jr z,f16tof32_zero
cp %01111100
jr z,f16tof32_inf_nan
;it is not a special value
; we need to shift in the sign and exponent from HL
; We need to make roomfor 3 more bits of exponent, and we need to subtract 15
; for the original bias, and add 127 for the new bias, for a net of +112
; We'll init A to this so that the RLA instructions will pre-add
ld a,%01100000
add hl,hl
rla ;A = 1100000s
rla ;A = 100000s0
rla ;A = 00000s00 + 1
rla ;A = 0000s000 + 3
add hl,hl
rla ;A = 000s000e + 6
inc a ;A = 000s000e + 7
add hl,hl
rla ;A = 00s000ee + 14
add hl,hl
rla ;A = 0s000eee + 28
add hl,hl
rla ;A = s000eeee + 56
ex de,hl
ld h,b
ld l,c
ld (hl),0
inc hl
ld (hl),e
inc hl
ld (hl),d
inc hl
ld (hl),a
ret
f16tof32_zero:
ld (bc),a
inc bc
ld (bc),a
inc bc
ld (bc),a
inc bc
ld a,h
and %10000000
ld (bc),a
ret
f16tof32_inf_NaN:
ld a,h
and %00000011
or l
ld (bc),a
inc bc
ld (bc),a
inc bc
or %10000000
ld (bc),a
inc bc
ld a,h
or %01111111
ld (bc),a
ret
#endif