forked from gweg/rainpanic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
circle.s
548 lines (461 loc) · 7.08 KB
/
circle.s
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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
; History of timings...
; Using (10,160)
;1186
;1136
;993
;949
;874
;840
;820
;801
;785
;....
; Using (120,100)
;845
;612
; Using clipping to 10/190 vertically
;827
;754
;603
;588
;573
#include "params.h"
.zero
; Circle centre and radius
_CentreY .word 0
_CentreX .word 0
_Radius .word 0
; Variables for circlepoints
sy .word 0
sx .word 0
p .word 0
cxmx .dsb 2
cxpx .dsb 2
cxmy .dsb 2
cxpy .dsb 2
cymx .dsb 2
cypx .dsb 2
cymy .dsb 2
cypy .dsb 2
.text
circleExit
rts
_circleMidpoint
.(
; Check if circle is visible
;; _CentreX + _Radius < lhs of screen fails
lda _CentreX
clc
adc _Radius
tay
lda _CentreX+1
adc _Radius+1
cpy #(CLIP_LEFT)
sbc #0
.(
bvc ret
eor #$80
ret
.)
bmi circleExit
;; x - size > rhs of screen fails
lda _CentreX
sec
sbc _Radius
tay
lda _CentreX+1
sbc _Radius+1
cpy #(CLIP_RIGHT-1)
sbc #0
.(
bvc ret ; N eor V
eor #$80
ret
.)
bpl circleExit
;; y + size < top of screen fails
lda _CentreY
clc
adc _Radius
tay
lda _CentreY+1
adc _Radius+1
cpy #(CLIP_TOP)
sbc #0
.(
bvc ret ; N eor V
eor #$80
ret
.)
bmi circleExit
;; y - size > bot of screen fails
lda _CentreY
sec
sbc _Radius
tay
lda _CentreY+1
sbc _Radius+1
cpy #(CLIP_BOTTOM-1)
sbc #0
.(
bvc ret ; N eor V
eor #$80
ret
.)
bpl circleExit
drawit
;x=0;y=radius
lda #0
sta sx
sta sx+1
lda _Radius
sta sy
lda _Radius+1
sta sy+1
; p=1-radius
lda #1
sec
sbc _Radius
sta p
lda #0
sbc _Radius+1
sta p+1
; Init cx and co
lda _CentreX
sta cxmx
sta cxpx
lda _CentreX+1
sta cxmx+1
sta cxpx+1
lda _CentreY
sta cymx
sta cypx
lda _CentreY+1
sta cymx+1
sta cypx+1
clc
lda _CentreX
adc _Radius
sta cxpy
lda _CentreX+1
adc _Radius+1
sta cxpy+1
sec
lda _CentreX
sbc _Radius
sta cxmy
lda _CentreX+1
sbc _Radius+1
sta cxmy+1
clc
lda _CentreY
adc _Radius
sta cypy
lda _CentreY+1
adc _Radius+1
sta cypy+1
sec
lda _CentreY
sbc _Radius
sta cymy
lda _CentreY+1
sbc _Radius+1
sta cymy+1
draw
; circlePoints (xCenter, yCenter, x, y);
jmp _circlePoints
.)
circleExit2
rts
;while (x < y) {
; x++;
; if (p < 0)
; p += 2 * x + 1;
; else {
; y--;
; p += 2 * (x - y) + 1;
; }
; circlePoints (xCenter, yCenter, x, y);
; }
.dsb 256-(*&255)
positivep
.(
inc cymy
bne skip
inc cymy+1
skip
.)
.(
inc cxmy
bne skip
inc cxmy+1
skip
.)
.(
lda cypy
bne skip
dec cypy+1
skip
dec cypy
.)
.(
lda cxpy
bne skip
dec cxpy+1
skip
dec cxpy
.)
lda sy
bne nodec
dec sy+1
nodec
dec sy
lda sx
sec
sbc sy
sta tmp
lda sx+1
sbc sy+1
sta tmp+1
asl tmp
rol tmp+1
sec ; +1
lda p
adc tmp
sta p
lda p+1
adc tmp+1
sta p+1
jmp _circlePoints
loop
.(
sec
lda sx
sbc sy
lda sx+1
sbc sy+1
bpl circleExit2
.(
inc cxpx
bne skip
inc cxpx+1
skip
.)
.(
inc cypx
bne skip
inc cypx+1
skip
.)
.(
lda cxmx
bne skip
dec cxmx+1
skip
dec cxmx
.)
.(
lda cymx
bne skip
dec cymx+1
skip
dec cymx
.)
inc sx
bne noinc
inc sx+1
noinc
lda p+1
bpl positivep
lda sx
asl
sta tmp
lda sx+1
rol
sta tmp+1
sec ; +1
lda p
adc tmp
sta p
lda p+1
adc tmp+1
sta p+1
;jmp _circlePoints
.)
_circlePoints
.(
; +Y -----------------------------------
lda cypy+1
bne end_line_1
ldy cypy
cpy #(CLIP_BOTTOM)
bcs end_line_1
cpy #(CLIP_TOP)
bcc end_line_1
lda _HiresAddrLow,y ; 4
sta tmp0+0 ; 3
lda _HiresAddrHigh,y ; 4
sta tmp0+1 ; 3 => Total 14 cycles
.(
; (_CentreX+x,_CentreY+y)
lda cxpx+1
bne end
ldx cxpx
cpx #(CLIP_RIGHT)
bcs end
cpx #(CLIP_LEFT)
bcc end
ldy _TableDiv6,x
lda _TableBit6Reverse,x ; 4
ora (tmp0),y
sta (tmp0),y
end
.)
.(
; (_CentreX-x,_CentreY+y)
lda cxmx+1
bne end
ldx cxmx
cpx #(CLIP_RIGHT)
bcs end
cpx #(CLIP_LEFT)
bcc end
ldy _TableDiv6,x
lda _TableBit6Reverse,x ; 4
ora (tmp0),y
sta (tmp0),y
end
.)
end_line_1
; -Y -----------------------------------
lda cymy+1
bne end_line_2
ldy cymy
cpy #(CLIP_BOTTOM)
bcs end_line_2
cpy #(CLIP_TOP)
bcc end_line_2
lda _HiresAddrLow,y ; 4
sta tmp0+0 ; 3
lda _HiresAddrHigh,y ; 4
sta tmp0+1 ; 3 => Total 14 cycles
.(
; (_CentreX-x,_CentreY-y)
lda cxmx+1
bne end
ldx cxmx
cpx #(CLIP_RIGHT)
bcs end
cpx #(CLIP_LEFT)
bcc end
ldy _TableDiv6,x
lda _TableBit6Reverse,x ; 4
ora (tmp0),y
sta (tmp0),y
end
.)
.(
; (_CentreX+x,_CentreY-y)
lda cxpx+1
bne end
ldx cxpx
cpx #(CLIP_RIGHT)
bcs end
cpx #(CLIP_LEFT)
bcc end
ldy _TableDiv6,x
lda _TableBit6Reverse,x ; 4
ora (tmp0),y
sta (tmp0),y
end
.)
end_line_2
; +X -----------------------------------
lda cypx+1
bne end_line_3
ldy cypx
cpy #(CLIP_BOTTOM)
bcs end_line_3
cpy #(CLIP_TOP)
bcc end_line_3
lda _HiresAddrLow,y ; 4
sta tmp0+0 ; 3
lda _HiresAddrHigh,y ; 4
sta tmp0+1 ; 3 => Total 14 cycles
.(
; (_CentreX+y,_CentreY+x)
lda cxpy+1
bne end
ldx cxpy
cpx #(CLIP_RIGHT)
bcs end
cpx #(CLIP_LEFT)
bcc end
ldy _TableDiv6,x
lda _TableBit6Reverse,x ; 4
ora (tmp0),y
sta (tmp0),y
end
.)
.(
; (_CentreX-y,_CentreX+y)
lda cxmy+1
bne end
ldx cxmy
cpx #(CLIP_RIGHT)
bcs end
cpx #(CLIP_LEFT)
bcc end
ldy _TableDiv6,x
lda _TableBit6Reverse,x ; 4
ora (tmp0),y
sta (tmp0),y
end
.)
end_line_3
; -X -----------------------------------
skip6
lda cymx+1
bne end_line_4
ldy cymx
cpy #(CLIP_BOTTOM)
bcs end_line_4
cpy #(CLIP_TOP)
bcc end_line_4
lda _HiresAddrLow,y ; 4
sta tmp0+0 ; 3
lda _HiresAddrHigh,y ; 4
sta tmp0+1 ; 3 => Total 14 cycles
.(
; (_CentreX-y,_CentreY-x)
lda cxmy+1
bne end
ldx cxmy
cpx #(CLIP_RIGHT)
bcs end
cpx #(CLIP_LEFT)
bcc end
ldy _TableDiv6,x
lda _TableBit6Reverse,x ; 4
ora (tmp0),y
sta (tmp0),y
end
.)
.(
; (_CentreX+y,_CentreY-x)
lda cxpy+1
bne end
ldx cxpy
cpx #(CLIP_RIGHT)
bcs end
cpx #(CLIP_LEFT)
bcc end
ldy _TableDiv6,x
lda _TableBit6Reverse,x ; 4
ora (tmp0),y
sta (tmp0),y
end
.)
end_line_4
jmp loop
.)