-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtext.asm
239 lines (211 loc) · 2.84 KB
/
text.asm
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
; vim: set syntax=z80:
#local
#code _CODE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Byte DrawGlyph(Pen *pen, char glyph) ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_DrawGlyph::
#local
; A = $glyph
; IY = $pen
pop bc
pop iy
dec sp
pop af
push af
inc sp
push iy
push bc
; store font record address
add a, a
add a, a
ld d, 0
rl d
add a, a
rl d
ld e, a
ld hl, _g_font-32*8
add hl, de
push hl
; check font width
ld e, (iy+0) ; x
ld a, (iy+4) ; x boundary
sub e
jr c, out_of_room
sub (hl) ; width
jr c, out_of_room
; update adjust_jump with correct jump address
ld a, e
and 111b
add a, a
add a, a
ld c, a
ld b, 0
ld hl, adjust_stage + 28
sbc hl, bc
ld (adjust_jump+1), hl
; DE = first write address
ld a, (iy+1) ; y
add a, a
ld l, a
ld h, 0
ld bc, glyphline_table
add hl, bc
ld e, (hl)
inc hl
ld d, (hl)
ld a, (iy+0) ; x
ld b, a
and 0xF8
rrca
rrca
rrca
ld l, a
ld h, 0
add hl, de
ex de, hl
; HL = first font bitmap address
pop hl
; update stored x position
ld a, b
add a, (hl)
ld (iy+0), a
inc hl
; CF = 0
xor a
; B = 7, C = 0
ld b, 7
ld c, a
draw_loop:
push bc
; B = glyph entry to copy, C = 0
ld b, (hl)
ld c, 0
; Adjust so B is first cell to write, C is second cell
adjust_jump:
jp 0x0000
adjust_stage:
rr b
rr c
rr b
rr c
rr b
rr c
rr b
rr c
rr b
rr c
rr b
rr c
rr b
rr c
inc hl
ex de, hl
; Write first cell
ld a, b
or (hl)
ld (hl), a
; Write second cell
inc l
ld a, c
or (hl)
ld (hl), a
; Next write address
dec l
inc h
ex de, hl
; Loop
pop bc
djnz draw_loop
; Done
ld l, c
ret
out_of_room:
; Return glyph 'width'
pop hl
ld l, (hl)
ret
glyphline_table:
dw 0x4100
dw 0x4120
dw 0x4140
dw 0x4160
dw 0x4180
dw 0x41A0
dw 0x41C0
dw 0x41E0
dw 0x4900
dw 0x4920
dw 0x4940
dw 0x4960
dw 0x4980
dw 0x49A0
dw 0x49C0
dw 0x49E0
dw 0x5100
dw 0x5120
dw 0x5140
dw 0x5160
dw 0x5180
dw 0x51A0
dw 0x51C0
dw 0x51E0
#endlocal
#code _CODE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; size_t MeasureTextLength(const char *text, size_t nChars) ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_MeasureTextLength::
#local
pop af
pop bc ; bc = $text
pop hl ; hl = $nChars
push hl
push bc
push af
; return zero if $nChars is zero
xor a
cp l
jp nz, not_zero
cp h
ret z
not_zero:
; otherwise calculate end_char_ld value to use
add hl, bc
ex de, hl
xor a
ld l, a
ld h, a
sbc hl, de
ld (end_char_ld+1), hl
; total starts at zero
ld iy, 0
loop:
; read character
ld a, (bc)
; locate font record
add a, a
add a, a
ld d, 0
rl d
add a, a
rl d
ld e, a
ld hl, _g_font-32*8
add hl, de
; read width and add to total
ld e, (hl)
ld d, 0
add iy, de
; increment string address, loop if not end
inc bc
end_char_ld:
ld hl, 0xBEEF
add hl, bc
jp nc, loop
; return total
push iy
pop hl
ret
#endlocal
#endlocal