gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
gbdk-lib/libc/asm/z80/bcd.s
1 ;--------------------------------------------------------------------------
2 ; bcd.s
3 ;
4 ; Copyright (C) 2020, Tony Pavlov
5 ;
6 ; This library is free software; you can redistribute it and/or modify it
7 ; under the terms of the GNU General Public License as published by the
8 ; Free Software Foundation; either version 2, or (at your option) any
9 ; later version.
10 ;
11 ; This library is distributed in the hope that it will be useful,
12 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ; GNU General Public License for more details.
15 ;
16 ; You should have received a copy of the GNU General Public License
17 ; along with this library; see the file COPYING. If not, write to the
18 ; Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
19 ; MA 02110-1301, USA.
20 ;
21 ; As a special exception, if you link this library with other files,
22 ; some of which are compiled with SDCC, to produce an executable,
23 ; this library does not by itself cause the resulting executable to
24 ; be covered by the GNU General Public License. This exception does
25 ; not however invalidate any other reasons why the executable file
26 ; might be covered by the GNU General Public License.
27 ;--------------------------------------------------------------------------
28
29 .module bcd
30
31 .area _HOME
32 .ez80
33
34 ; void uint2bcd(uint16_t i, BCD * value) __naked
35 _uint2bcd::
36 ld iyh, d
37 ld iyl, e
38
39 ex DE, HL
40
41 ; clear value
42 xor A
43 ld 0(iy), A
44 ld 1(iy), A
45 ld 2(iy), A
46 ld 3(iy), A
47
48 ld B, #16
49 1$:
50 sla E
51 rl D
52
53 ld A, 0(iy)
54 adc A
55 daa
56 ld 0(iy), A
57 ld A, 1(iy)
58 adc A
59 daa
60 ld 1(iy), A
61 ld A, 2(iy)
62 adc A
63 daa
64 ld 2(iy), A
65
66 dec B
67 jr NZ, 1$
68
69 ret
70
71 ;void bcd_add(BCD * sour, BCD * value) __naked
72 _bcd_add::
73 or A ; clear C, HC
74
75 ld A,(DE)
76 add (HL)
77 daa
78 ld (HL), A
79 inc HL
80 inc DE
81
82 ld A,(DE)
83 adc (HL)
84 daa
85 ld (HL), A
86 inc HL
87 inc DE
88
89 ld A,(DE)
90 adc (HL)
91 daa
92 ld (HL), A
93 inc HL
94 inc DE
95
96 ld A,(DE)
97 adc (HL)
98 daa
99 ld (HL), A
100
101 ret
102
103 ; void bcd_sub(BCD * sour, BCD * value) __naked
104 _bcd_sub::
105 ex DE, HL
106 or A ; clear C, HC
107
108 ld A,(DE)
109 sub (HL)
110 daa
111 ld (DE), A
112 inc DE
113 inc HL
114
115 ld A,(DE)
116 sbc (HL)
117 daa
118 ld (DE), A
119 inc DE
120 inc HL
121
122 ld A,(DE)
123 sbc (HL)
124 daa
125 ld (DE), A
126 inc DE
127 inc HL
128
129 ld A,(DE)
130 sbc (HL)
131 daa
132 ld (DE), A
133
134 ret
135
136 ;uint8_t bcd2text(BCD * bcd, uint8_t tile_offset, uint8_t * buffer) __naked
137 _bcd2text::
138 ex DE, HL ; DE: bcd
139 pop IY
140 dec SP
141 pop BC
142 ld C, B ; C: digit offset
143 ex (SP), IY ; HL: buffer
144
145 inc DE
146 inc DE
147 inc DE
148
149 ld B, #0x0f
150
151 ld A, (DE)
152 rlca
153 rlca
154 rlca
155 rlca
156 and B
157 add C
158 ld 0(IY), A
159 ld A, (DE)
160 and B
161 add C
162 ld 1(IY), A
163 dec DE
164
165 ld A, (DE)
166 rlca
167 rlca
168 rlca
169 rlca
170 and B
171 add C
172 ld 2(IY), A
173 ld A, (DE)
174 and B
175 add C
176 ld 3(IY), A
177 dec DE
178
179 ld A, (DE)
180 rlca
181 rlca
182 rlca
183 rlca
184 and B
185 add C
186 ld 4(IY), A
187 ld A, (DE)
188 and B
189 add C
190 ld 5(IY), A
191 dec DE
192
193 ld A, (DE)
194 rlca
195 rlca
196 rlca
197 rlca
198 and B
199 add C
200 ld 6(IY), A
201 ld A, (DE)
202 and B
203 add C
204 ld 7(IY), A
205 dec DE
206
207 xor A
208 ld 8(IY), A
209
210 ld A, #0x08
211
212 ret
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.