forked from svofski/pretty-8080-assembler
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcircleArc.asm
393 lines (362 loc) · 5.25 KB
/
circleArc.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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
; 🐟 Рисование окружности по алгоритму Мичнера
; Иван Городецкий 28.11.2018-02.12.2018
; Версия с клиппингом и возможностью рисования эллипсов и дуг
;
; Пример рисования дуг
.project circlearc.rom
ARcorr .equ 400h
.org 100h
start:
xra a
out 10h
lxi sp,100h
mvi a,0C3h
sta 0
lxi h,Restart
shld 1
call Cls
mvi a,0C9h
sta 38h
ei
hlt
lxi h, colors+15
colorset:
mvi a, 88h
out 0
mvi c, 15
colorset1: mov a, c
out 2
mov a, m
out 0Ch
dcx h
out 0Ch
out 0Ch
dcr c
out 0Ch
out 0Ch
out 0Ch
jp colorset1
mvi a,255
out 3
jmp Restart
.org 200h
PixelMask:
.db 10000000b
.db 01000000b
.db 00100000b
.db 00010000b
.db 00001000b
.db 00000100b
.db 00000010b
.db 00000001b
Restart:
call Cls
call IniCircle
lxi h,08080h ;H=xc, L=yc
mvi b,127 ;радиус
mvi c,10000000b ; маска дуги
lxi d,13*256+16 ;D=xcorr, E=ycorr
loop:
push b
push h
push d
call circle
pop d
pop h
pop b
mvi a, -4
add b
mov b,a
mov a,c
rrc
mov c,a
jnc loop
jmp $
circle:
mvi a,15
ana d
adi ARcorr>>8
sta SetXcorr1+1
sta SetXcorr2+1
mvi a,15
ana e
adi ARcorr>>8
sta SetYcorr1+1
sta SetYcorr2+1
shld ycxc+1
lxi h,setpixel_xy
shld SetArc128+1
shld SetArc64+1
shld SetArc32+1
shld SetArc16+1
shld SetArc8+1
shld SetArc4+1
shld SetArc2+1
shld SetArc1+1
lxi h,setpixel_xy_ret
mov a,c
add a
jc $+6
shld SetArc128+1
add a
jc $+6
shld SetArc64+1
add a
jc $+6
shld SetArc32+1
add a
jc $+6
shld SetArc16+1
add a
jc $+6
shld SetArc8+1
add a
jc $+6
shld SetArc4+1
add a
jc $+6
shld SetArc2+1
add a
jc $+6
shld SetArc1+1
mov l,b
mvi h,0
dad h ;2*R
mvi a,3
sub l
mov l,a
mvi a,0
sbb h
mov h,a ;HL=3-2*R
mvi c,0FFh
circle_loop:
inr c
mov a,b
cmp c
rc
push h
push b
mov l,c
SetXcorr1:
mvi h,ARcorr>>8
mov c,m
mov l,b
SetYcorr1:
mvi h,ARcorr>>8
mov b,m
ycxc:
lxi d,0
;xc+x, yc+y
mov a,d
add c
mov h,a
cmp d
jc Clip1
mov a,e
add b
mov l,a
cmp e
SetArc128:
cnc setpixel_xy
;xc+x, yc-y
mov a,e
sub b
mov l,a
dcr a
cmp e
jnc Clip1
mov a,d
add c
mov h,a
SetArc16:
call setpixel_xy
Clip1:
;xc-x, yc-y
mov a,d
sub c
mov h,a
dcr a
cmp d
jnc Clip2
mov a,e
sub b
mov l,a
dcr a
cmp e
SetArc8:
cc setpixel_xy
;xc-x, yc+y
mov a,e
add b
mov l,a
cmp e
jc Clip2
mov a,d
sub c
mov h,a
SetArc1:
call setpixel_xy
Clip2:
pop b
push b
mov l,b
SetXcorr2:
mvi h,ARcorr>>8
mov b,m
mov l,c
SetYcorr2:
mvi h,ARcorr>>8
mov c,m
;xc+y, yc+x
mov a,d
add b
mov h,a
cmp d
jc Clip3
mov a,e
add c
mov l,a
cmp e
SetArc64:
cnc setpixel_xy
;xc+y, yc-x
mov a,e
sub c
mov l,a
dcr a
cmp e
jnc Clip3
mov a,d
add b
mov h,a
SetArc32:
call setpixel_xy
Clip3:
;xc-y, yc-x
mov a,d
sub b
mov h,a
dcr a
cmp d
jnc Clip4
mov a,e
sub c
mov l,a
dcr a
cmp e
SetArc4:
cc setpixel_xy
;xc-y, yc+x
mov a,e
add c
mov l,a
cmp e
jc Clip4
mov a,d
sub b
mov h,a
SetArc2:
call setpixel_xy
Clip4:
pop b
pop d
xra a
ora d
jp DmoreZ
;D<0
mov l,c
mvi h,0
dad h
dad h
dad d
lxi d,6
dad d
jmp circle_loop
DmoreZ:
mov a,c
sub b
mov l,a
mvi h,0FFh
dad h
dad h
dad d
lxi d,10
dad d
dcr b
jmp circle_loop
; ---
; вход:
; H - X
; L - Y
; адрес пикселя = base + (x / 8) << 8 + y
; номер пикселя = x % 8
setpixel_xy:
mvi a, 111b ; сначала вычисляем смещение
ana h ; пикселя в PixelMask
sta SetPixelMaskAdr_xy+1
xra h
rrc ;
rrc ;
stc ;
rar ;
mov h,a ; h = 0x8000 | (a >> 3)
SetPixelMaskAdr_xy:
lda PixelMask
ora m ; a = память с пикселем
mov m,a ; записать в память
setpixel_xy_ret:
ret
IniCircle:
mvi a,15
sta SetA+1
lxi b,16
lxi d,ARcorr+256
GenARcorr:
mov l,b
mov h,e
dad h\ jnc $+4\ dad b
dad h\ jnc $+4\ dad b
dad h\ jnc $+4\ dad b
dad h\ jnc $+4\ dad b
dad h\ jnc $+4\ dad b
dad h\ jnc $+4\ dad b
dad h\ jnc $+4\ dad b
dad h\ jnc $+4\ dad b
xra a
ora l
jp $+4
inr h
xchg
mov m,d
xchg
inr e
jnz GenARcorr
mvi a,16
add c
mov c,a
inr d
SetA:
mvi a,0
dcr a
sta SetA+1
jnz GenARcorr
lxi h,ARcorr
GenARcorr2:
mov m,l
inr l
jnz GenARcorr2
ret
Cls:
lxi h,08000h
mvi e,0
xra a
ClrScr:
mov m,e
inx h
cmp h
jnz ClrScr
ret
.end
colors:
.db 00000000b,00001001b,00010010b,00011011b,00100100b,00101101b,00110110b,00111111b
.db 11111111b,00001001b,00010010b,00011011b,00100100b,00101101b,00110110b,00111111b