-
Notifications
You must be signed in to change notification settings - Fork 11
/
f24tou16.z80
69 lines (59 loc) · 856 Bytes
/
f24tou16.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
#ifndef included_f24tou16
#define included_f24tou16
f24tou16:
;AHL to a 16-bit unsigned integer
;NaN ==> 0
;too big ==> 65535 (even if neg)
;negative values in range are mod 65536
;save the sign
ld c,a
;Check if the input is 0
add a,a
jr z,f24tou16_return_0
;check if inf or NaN
cp $FE
jr nz,+_
ld a,h
or l
jr nz,f24tou16_return_0
f24tou16_return_inf:
ld hl,-1
ret
_:
;now if exponent is less than 0, just return 0
cp 63*2
jr nc,+_
f24tou16_return_0:
ld hl,0
ret
_:
;if the exponent is greater than 15, return 255
rra
sub 63
cp 16
jr nc,f24tou16_return_inf
;all is good!
;A is the exponent
;1+A is the number of bits to read
ld b,a
or a
ld a,1
ld d,0
jr z,+_
add hl,hl
rla
rl d
djnz $-4
_:
sla c
ld e,a
ex de,hl
ret nc
xor a
sub l
ld l,a
sbc a,a
sub h
ld h,a
ret
#endif