-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathto_ui32.z80
161 lines (145 loc) · 2.4 KB
/
to_ui32.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
;return the ui32 in DEHL
to_ui32_LUT:
.db (+_-$-1)/2
.dw ui8_convert_to_ui32
.dw ui16_convert_to_ui32
.dw ui32_convert_to_ui32
.dw fixed88_convert_to_ui32
.dw fixed1616_convert_to_ui32
.dw var_convert_to_ui32
.dw true_convert_to_ui32
.dw false_convert_to_ui32
.dw tstr_ref_convert_to_ui32
.dw raw_convert_to_ui32
.dw str_convert_to_ui32
.dw str_ref_convert_to_ui32
.dw single_convert_to_ui32
.dw xfloat_convert_to_ui32
.dw err_syntax
.dw err_syntax
.dw char_convert_to_ui32
_:
fixed88_convert_to_ui32:
inc de
char_convert_to_ui32:
ui8_convert_to_ui32:
;to DEHL
ld a,(de)
ld e,a
ld hl,0
ld d,h
ret
fixed1616_convert_to_ui32:
inc de
inc de
ui16_convert_to_ui32:
ex de,hl
ld e,(hl)
inc hl
ld d,(hl)
ex de,hl
ld hl,0
ret
ui32_convert_to_ui32:
ex de,hl
ld e,(hl)
inc hl
ld d,(hl)
inc hl
ld a,(hl)
inc hl
ld h,(hl)
ld l,a
ex de,hl
ret
true_convert_to_ui32:
ld hl,1
jr +_
false_convert_to_ui32:
ld hl,0
_:
ld d,h
ld e,h
ret
var_convert_to_ui32:
tstr_ref_convert_to_ui32:
raw_convert_to_ui32:
str_convert_to_ui32:
str_ref_convert_to_ui32:
single_convert_to_ui32:
jp err_syntax
xfloat_convert_to_ui32:
ld hl,8
add hl,de
ld e,(hl)
inc hl
ld d,(hl)
;If top bit of DE is 1, it is negative, so return 0
ld a,d
add a,a
jr c,set_DEHL_0
dec hl
dec hl
;Check special values, so DE = 0
or e
jr z,xfloat_convert_to_ui32_special
;now if D<0x40, then then the value is on [0,1]
ld a,d
add a,a
jp p,set_DEHL_0
;now if DE>=4020, then output 0xFFFFFFFF
;A is 2*D atm, so check if A>0x80 (A is at least 0x80)
add a,a
jr nz,set_DEHL_max
ld a,31
sub e
jr c,set_DEHL_max
; Good, now A is the number of times we need to shift the exponent right
ld d,(hl)
dec hl
ld e,(hl)
dec hl
ld c,(hl)
dec hl
ld l,(hl)
ld h,c
ret z ;don't have to shift at all
jr shift32_right_8_begin
_:
ld l,h
ld h,e
ld e,d
ld d,0
ret z
shift32_right_8_begin:
sub 8
jr nc,-_
add a,9
;A is the number of single shifts required, from 1 to 7
ld b,a
jr shift32_right_1_begin
_:
srl d
rr e
rr h
rr l
shift32_right_1_begin:
djnz -_
ret
xfloat_convert_to_ui32_special:
;1xxxxxxx ==> INF ==> 0xFFFFFFFF
;01xxxxxx ==> NaN ==> 0x00000000
;00xxxxxx ==> 0 ==> 0x00000000
ld a,(hl)
add a,a
jr nc,set_DEHL_0
set_DEHL_max:
ld de,$FFFF
ld h,d
ld l,e
ret
set_DEHL_0:
ld de,0
ld h,d
ld l,e
ret