-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ellipse.asm
1441 lines (1234 loc) · 40.6 KB
/
Ellipse.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
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
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;-------------------------------------------------------------------------------
;
; === ellipsePutPixel ===
;
; ellipsePutPixel a pixel plotting function.
;
; The co-ordinates are passed in D (x) and E (y)
;
; The routine must preserve BC, HL and IX
;
;
; === ellipseHLineFill ===
;
; ellipseHLineFill is a horizontal line filler.
;
; The y co-ordinate is passed in A. B and C contain x1 and x2. C will always
; be larger than B.
;
; The routine must preserve BC and IX.
;
;-------------------------------------------------------------------------------
ellipseFlags = 0
fClipSegment = 0
fClipArcBigAngle = 1
fClipArc = 2
fRejectC = 3
fRejectB = 4
fRejectL = 5
fRejectH = 6
fFillEllipse = 7
.define g_ellipseCX TransformedPoint0X
.define g_ellipseCY TransformedPoint0Y
.define g_ellipseRX TransformedPoint1X
.define g_ellipseRY TransformedPoint1Y
.define g_ellipseX TransformedPoint2X
.define g_ellipseY TransformedPoint2Y
g_ellipseA2 = allocVar(4)
g_ellipseB2 = allocVar(4)
g_ellipseCounter = allocVar(6)
g_ellipseXChange = allocVar(6)
g_ellipseYChange = allocVar(6)
g_ellipseError = allocVar(6)
g_finishEllipseX = allocVar(2)
g_ellipseClipADX = allocVar(2)
g_ellipseClipADY = allocVar(2)
g_ellipseClipBDX = allocVar(2)
g_ellipseClipBDY = allocVar(2)
g_ellipseClipAX = g_ellipseClipBDX
g_ellipseClipAY = g_ellipseClipBDY
;-------------------------------------------------------------------------------
; === DrawEllipse ===
;
; INPUTS:
;
; MEMORY
; * (g_wndXMin) - Drawing window left X co-ordinate (0..95)
; * (g_wndXMax) - Drawing window right X co-ordinate (0..95)
; * (g_wndYMin) - Drawing window top Y co-ordinate (0..63)
; * (g_wndYMax) - Drawing window bottom Y co-ordinate (0..63)
; * (g_ellipseCX) - Ellipse centre X co-ordinate (16-bits signed)
; * (g_ellipseCY) - Ellipse centre Y co-ordinate (16-bits signed)
; * (g_ellipseRX) - Ellipse X radius (16-bit unsigned)
; * (g_ellipseRY) - Ellipse Y radius (16-bit unsigned)
;
; FLAGS
; * fFillEllipse - Draws a filled ellipse
;
; LIMITS:
;
; Ellipses with a zero radii value are not drawn.
;
; DESTROYED:
;
; REGISTERS
; * AF, BC, DE, HL, IX
;-------------------------------------------------------------------------------
DrawEllipse:
;-------------------------------------------------------------------
; g_ellipseX = XRadius
; g_ellipseB2 = YRadius * YRadius
;-------------------------------------------------------------------
ld bc, (g_ellipseRX) ; [20]
ld a, b
or c
ret z
ld (g_ellipseX), bc ; [20]
call SquareBC ; [*] XRadius * XRadius
ld (g_ellipseA2 + $00), de ; [20]
ld (g_ellipseA2 + $02), hl ; [20]
;-------------------------------------------------------------------
; g_ellipseY = 0
; g_ellipseYChange = 0
;-------------------------------------------------------------------
ld bc, $0000 ; [10]
ld (g_ellipseY), bc ; [20]
ld (g_ellipseYChange + $00), bc ; [20]
ld (g_ellipseYChange + $02), bc ; [20]
ld (g_ellipseYChange + $04), bc ; [20]
;-------------------------------------------------------------------
; g_ellipseA2 = XRadius * XRadius
;-------------------------------------------------------------------
ld bc, (g_ellipseRY) ; [20]
ld a, b
or c
ret z
call SquareBC ; [*] YRadius * YRadius
ld (g_ellipseB2 + $00), de ; [20]
ld (g_ellipseB2 + $02), hl ; [20]
;-------------------------------------------------------------------
; g_ellipseCounter = g_ellipseB2 * XRadius
;-------------------------------------------------------------------
ld bc, (g_ellipseRX) ; [20]
call UMul32x16 ; [*] YRadius2 * XRadius
ld (g_ellipseCounter + $00), bc ; [20]
ld (g_ellipseCounter + $02), de ; [20]
ld (g_ellipseCounter + $04), hl ; [20]
;-------------------------------------------------------------------
; g_ellipseXChange = g_ellipseB2 * XRadius
;-------------------------------------------------------------------
ld (g_ellipseXChange + $00), bc ; [20]
ld (g_ellipseXChange + $02), de ; [20]
ld (g_ellipseXChange + $04), hl ; [20]
;-------------------------------------------------------------------
; g_ellipseError = g_ellipseB2 * XRadius / 2
;-------------------------------------------------------------------
srl h ; [8]
rr l ; [8]
rr d ; [8]
rr e ; [8]
rr b ; [8]
rr c ; [8]
ld (g_ellipseError + $04), hl ; [20]
ld (g_ellipseError + $02), de ; [20]
ld (g_ellipseError + $00), bc ; [20]
;-------------------------------------------------------------------
; BEGIN: 1st set of points
;
; g_ellipseCounter -= g_ellipseA2
;-------------------------------------------------------------------
_set1Loop:
call Plot4EllipsePoints
;-------------------------------------------------------------------
; Increment Y co-ordinate
;-------------------------------------------------------------------
ld hl, (g_ellipseY)
inc hl
ld (g_ellipseY), hl
;-------------------------------------------------------------------
; Increment g_ellipseYChange by g_ellipseA2
;-------------------------------------------------------------------
ld de, g_ellipseYChange
ld hl, g_ellipseA2
call EllipseInc32
;-------------------------------------------------------------------
; Decrement g_ellipseError by g_ellipseYChange
;-------------------------------------------------------------------
ld de, g_ellipseError
ld hl, g_ellipseYChange
call EllipseDec48
jr nc, _set1Next
;-------------------------------------------------------------------
; Decrement X co-ordinate
;-------------------------------------------------------------------
ld hl, (g_ellipseX)
ld (g_finishEllipseX),hl ; Hack
dec hl
ld (g_ellipseX), hl
;-------------------------------------------------------------------
; Decrement g_ellipseCounter by g_ellipseB2
;-------------------------------------------------------------------
ld de, g_ellipseCounter
ld hl, g_ellipseB2
call EllipseDec32
jr c, _set1Done
;-------------------------------------------------------------------
; Decrement g_ellipseXChange by g_ellipseB2
;-------------------------------------------------------------------
ld de, g_ellipseXChange
ld hl, g_ellipseB2
call EllipseDec32
;-------------------------------------------------------------------
; Increment g_ellipseError by g_ellipseXChange
;-------------------------------------------------------------------
ld de, g_ellipseError
ld hl, g_ellipseXChange
call EllipseInc48
_set1Next:
ld hl, g_ellipseA2 ; [10]
ld de, g_ellipseCounter ; [10]
call EllipseDec32 ; [219]
jr nc, _set1Loop ; [12/7]
_set1Done:
;-------------------------------------------------------------------
; g_ellipseX = 0
; g_ellipseXChange = 0
;-------------------------------------------------------------------
ld bc, $0000
ld (g_ellipseX), bc ; [20]
ld (g_ellipseXChange + $00), bc ; [20]
ld (g_ellipseXChange + $02), bc ; [20]
ld (g_ellipseXChange + $04), bc ; [20]
;-------------------------------------------------------------------
; g_ellipseY = g_ellipseRY
; g_ellipseCounter = g_ellipseRY * g_ellipseA2
;-------------------------------------------------------------------
ld bc, (g_ellipseRY) ; [20]
ld (g_ellipseY), bc ; [20]
ld de, (g_ellipseA2 + $00) ; [20]
ld hl, (g_ellipseA2 + $02) ; [20]
call UMul32x16 ; [*]
ld (g_ellipseCounter + $00), bc ; [20]
ld (g_ellipseCounter + $02), de ; [20]
ld (g_ellipseCounter + $04), hl ; [20]
;-------------------------------------------------------------------
; g_ellipseYChange = g_ellipseA2 * g_ellipseRY
;-------------------------------------------------------------------
ld (g_ellipseYChange + $00), bc ; [20]
ld (g_ellipseYChange + $02), de ; [20]
ld (g_ellipseYChange + $04), hl ; [20]
;-------------------------------------------------------------------
; g_ellipseError = g_ellipseA2 * g_ellipseRY / 2
;-------------------------------------------------------------------
srl h ; [8]
rr l ; [8]
rr d ; [8]
rr e ; [8]
rr b ; [8]
rr c ; [8]
ld (g_ellipseError + $04), hl ; [20]
ld (g_ellipseError + $02), de ; [20]
ld (g_ellipseError + $00), bc ; [20]
;-------------------------------------------------------------------
; BEGIN: 2nd set of points
;
; g_ellipseCounter -= g_ellipseB2
;-------------------------------------------------------------------
_set2Loop:
bit fFillEllipse, (iy+ellipseFlags) ; [20]
call z, Plot4EllipsePoints ; [*]
;-------------------------------------------------------------------
; Increment X co-ordinate
;-------------------------------------------------------------------
ld hl, (g_ellipseX)
inc hl
ld (g_ellipseX), hl
ld de,(g_finishEllipseX) ; Hack
or a
sbc hl,de
jr nz,_set2NotFinished
bit fFillEllipse, (iy+ellipseFlags)
call nz, Plot4EllipsePointsDecX
jr _set2Done
_set2NotFinished:
;-------------------------------------------------------------------
; Increment g_ellipseXChange by g_ellipseB2
;-------------------------------------------------------------------
ld de, g_ellipseXChange
ld hl, g_ellipseB2
call EllipseInc32
;-------------------------------------------------------------------
; Decrement g_ellipseError by g_ellipseXChange
;-------------------------------------------------------------------
ld de, g_ellipseError
ld hl, g_ellipseXChange
call EllipseDec48
jr nc, _set2Next
bit fFillEllipse, (iy+ellipseFlags) ; [20]
call nz, Plot4EllipsePointsDecX
;-------------------------------------------------------------------
; Decrement Y co-ordinate
;-------------------------------------------------------------------
ld hl, (g_ellipseY)
dec hl
ld (g_ellipseY), hl
;-------------------------------------------------------------------
; Decrement g_ellipseCounter by g_ellipseA2
;-------------------------------------------------------------------
ld de, g_ellipseCounter
ld hl, g_ellipseA2
call EllipseDec32
jr c, _set2Done
;-------------------------------------------------------------------
; Decrement g_ellipseYChange by g_ellipseA2
;-------------------------------------------------------------------
ld de, g_ellipseYChange
ld hl, g_ellipseA2
call EllipseDec32
;-------------------------------------------------------------------
; Increment g_ellipseError by g_ellipseYChange
;-------------------------------------------------------------------
ld de, g_ellipseError
ld hl, g_ellipseYChange
call EllipseInc48
_set2Next:
ld hl, g_ellipseB2 ; [10]
ld de, g_ellipseCounter ; [10]
call EllipseDec32 ; [219]
jr nc, _set2Loop ; [12/7]
_set2Done:
ret
Plot4EllipsePointsDecX:
ld hl, (g_ellipseX)
push hl
dec hl
ld (g_ellipseX), hl
call Plot4EllipsePoints
pop hl
ld (g_ellipseX), hl
ret
;-------------------------------------------------------------------------------
; INPUTS:
;
; MEMORY
; * (g_wndXMin) - Drawing window left X co-ordinate (0..95)
; * (g_wndXMax) - Drawing window right X co-ordinate (0..95)
; * (g_wndYMin) - Drawing window top Y co-ordinate (0..63)
; * (g_wndYMax) - Drawing window bottom Y co-ordinate (0..63)
; * (g_ellipseCX) - Centre X co-ordinate (16-bits signed)
; * (g_ellipseCY) - Centre Y co-ordinate (16-bits signed)
; * (g_ellipseX) - X displacement value (16-bits unsigned)
; * (g_ellipseY) - Y displacement value (16-bits unsigned)
;
;
; DESTROYED:
;
; REGISTERS
; * AF, BC, DE, HL, IX
;-------------------------------------------------------------------------------
Plot4EllipsePoints:
;-------------------------------------------------------------------
; Check if CY + Y is visible
;-------------------------------------------------------------------
ld hl, (g_ellipseCY) ; [20]
ld de, (g_ellipseY) ; [20]
ld bc, (g_wndYMin) ; [20]
ld ix, $ffff ; [14]
xor a ; [4]
res fRejectB,(iy+ellipseFlags)
res fRejectC,(iy+ellipseFlags)
bit 7, d ; [8]
jp z, _chkYMax ; [10]
add hl, de ; [11] always positive
jp _chkYMaxx ; [10]
_chkYMax:
adc hl, de ; [15] HL = Cy + Y
jp pe, _chkYMin ; [10] if Cy + Y > 32767
ret m ; [11/5] if Cy + Y < 0
_chkYMaxx:
or h ; [4]
jr nz, _chkYMin ; [12/7] if Cy + Y > 255
ld a, b ; [4]
cp l ; [4] g_wndYMax - (Cy + Y)
jr c, _chkYMin ; [12/7] if (Cy + Y) > g_wndYMax
ld a, l ; [4]
cp c ; [4] (Cy + Y) - g_wndYMin
ret c ; [11/5] if (Cy + Y) < g_wndYMin
ld ixh, a ; [8] store Cy + Y
;-------------------------------------------------------------------
; Check if CY - Y is visible
;-------------------------------------------------------------------
_chkYMin:
bit 7, d ; [8]
jr nz, _chkYBoth ; [12/7]
xor a ; [4]
sbc hl, de ; [15]
or a ; [4]
sbc hl, de ; [15]
jp pe, _chkYBoth ; [10] if Cy - Y < -32768
jp m, _chkYBoth ; [10] if Cy - Y < 0
or h ; [4]
ret nz ; [11/5] if Cy - Y > 255
ld a, b ; [4]
cp l ; [4] g_wndYMax - (Cy - Y)
ret c ; [11/5] if (Cy - Y) > g_wndYMax
ld a, l ; [4]
cp c ; [4] (Cy - Y) - g_wndYMin
jr c, _chkYBoth ; [12/7] if (Cy - Y) < g_wndYMin
ld ixl, a ; [8]
;-------------------------------------------------------------------
; Return if both IXL and IXH still have the sign bit set.
;-------------------------------------------------------------------
_chkYBoth:
ld a, ixl ; [8]
;and ixh ; [8]
;ret m ; [8]
inc a
jr nz,+
set fRejectC,(iy+ellipseFlags)
+:
ld a,ixh
inc a
jr nz,+
set fRejectB,(iy+ellipseFlags)
+:
ld hl, (g_ellipseCX) ; [20]
ld de, (g_ellipseX) ; [20]
ld bc, (g_wndXMin) ; [10] c = xmin, b = xmax
bit fFillEllipse, (iy + ellipseFlags) ; [23]
jr z, _chkXMinPx ; [12/7]
xor a ; [4]
bit 7, d ; [8]
jp z, _chkXMin2 ; [10]
add hl, de ; [11]
jp _chkXMin3 ; [10]
_chkXMin2:
adc hl, de ; [15] Cx + X
jp pe, _forceXMax ; [10] if Cx + X > 32767
ret m ; [11/5] if Cx + X < 0
_chkXMin3:
or h ; [4]
jr nz, _forceXMax ; [12/7] if Cx + X > 255
ld a, l ; [4]
cp c ; [4] (Cx + X) - g_wndXMin
ret c ; [11/5] if (Cx + X) < g_wndXMin
ld a, b ; [4]
cp l ; [4]
jr c, _forceXMax ; [12/7] if (Cx + X) > g_wndXMax
ld a, l ; [4]
jp _chkXMin ; [10] skip next instruction
_forceXMax:
ld a, b ; [4]
_chkXMin:
bit 7, d ; [8]
jr nz, _forceXMin ; [12/7]
or a ; [4] A = Cx + X
sbc hl, de ; [15] Cx + X - X
or a ; [4]
sbc hl, de ; [15] Cx - X
jp pe, _forceXMin ; [10] if (Cx - X) < -32768
jp m, _forceXMin ; [10] if (Cx - X) < 0
rlc h ; [8]
ret nz ; [11/5] if (Cx - X) > 255
ld h, a ; [4]
ld a, b ; [4]
cp l ; [4]
ret c ; [11/5] if (Cx - X) > g_wndXMax
ld a, l ; [4]
cp c ; [4] (Cx - X) - g_wndXMin
jr nc, _plotHLine ; [12/7]
ld a, h ; [4]
_forceXMin:
ld h, a ; [4]
ld l, c ; [8]
_plotHLine:
; L = x1
; H = x2
; IXL = y1
; IXH = y2
ld b, l
ld c, h
_fillYMin:
ld a, ixh
;or a
;jp m, _fillYMax
bit fRejectB,(iy+ellipseFlags)
jr nz,_fillYMax
call _hFill
_fillYMax:
ld a, ixl
;or a
;ret m
bit fRejectC,(iy+ellipseFlags)
ret nz
cp ixh
ret z
_hFill:
push bc
push ix
ld d,b
ld h,c
ld e,a
bit fClipArc,(iy+ellipseFlags)
call nz,ClipArcSpan
call z,PlotTransformedHorizontalSpan
pop ix
pop bc
ret
;-------------------------------------------------------------------
; The ellipse is being drawn in pixel plotting mode. Instead of
; clipping the x co-ordinates, we reject them if they lie off
; screen.
;-------------------------------------------------------------------
_chkXMinPx:
xor a ; [4]
res fRejectH,(iy+ellipseFlags)
res fRejectL,(iy+ellipseFlags)
bit 7, d ; [8]
jp z, _chkXMinP2 ; [10]
add hl, de ; [11]
jp _chkXMinP3 ; [10]
_chkXMinP2:
adc hl, de ; [15] Cx + X
jp pe, _chkXOutP ; [10] if Cx + X > 32767
ret m ; [11/5] if Cx + X < 0
_chkXMinP3:
or h ; [4]
jr nz, _chkXOutP ; [12/7] if Cx + X > 255
ld a, l ; [4]
cp c ; [4] (Cx + X) - g_wndXMin
ret c ; [11/5] if (Cx + X) < g_wndXMin
ld a, b ; [4]
cp l ; [4]
jr c, _chkXOutP ; [12/7] if (Cx + X) > g_wndXMax
ld a, l ; [4]
jp _chkXMinPt ; [10] skip next instruction
_chkXOutP:
ld a, $ff
set fRejectH,(iy+ellipseFlags)
_chkXMinPt:
bit 7, d ; [8]
jr nz, _chkXOutL ; [12/7]
or a ; [4] A = Cx + X
sbc hl, de ; [15] Cx + X - X
or a ; [4]
sbc hl, de ; [15] Cx - X
jp pe, _chkXOutL ; [10] if (Cx - X) < -32768
jp m, _chkXOutL ; [10] if (Cx - X) < 0
rlc h ; [8]
ret nz ; [11/5] if (Cx - X) > 255
ld h, a ; [4]
ld a, b ; [4]
cp l ; [4]
ret c ; [11/5] if (Cx - X) > g_wndXMax
ld a, l ; [4]
cp c ; [4] (Cx - X) - g_wndXMin
jr nc, _plotYMin ; [12/7] if (Cx - X) < g_wndXMin
ld l, $ff ; [4]
set fRejectL,(iy+ellipseFlags)
jp _plotYMin ; [10]
_chkXOutL:
ld h, a ; [4]
ld l, $ff ; [4]
set fRejectL,(iy+ellipseFlags)
_plotYMin:
ld b, ixh ; [8] HL = xmax:xminn
ld c, ixl ; [8] BC = ymax:ymin
;bit 7, c
bit fRejectC,(iy+ellipseFlags)
jr nz, _plotYMax
_plotYMinL:
;bit 7, l
bit fRejectL,(iy+ellipseFlags)
jr nz, _plotYMinR
ld d, l
ld e, c
call _putPixel
_plotYMinR:
;bit 7, h
bit fRejectH,(iy+ellipseFlags)
jr nz, _plotYMax
; Patch to prevent overdraw.
ld de,(g_ellipseX)
ld a,d
or e
jr z,_plotYMax
ld d, h
ld e, c
call _putPixel
_plotYMax:
; Patch to prevent overdraw.
ld a,b
cp c
ret z
;bit 7, b
bit fRejectB,(iy+ellipseFlags)
ret nz
_plotYMaxL:
;bit 7, l
bit fRejectL,(iy+ellipseFlags)
jr nz, _plotYMaxR
ld d, l
ld e, b
call _putPixel
_plotYMaxR:
;bit 7, h
bit fRejectH,(iy+ellipseFlags)
ret nz
; Patch to prevent overdraw.
ld de,(g_ellipseX)
ld a,d
or e
ret z
ld d, h
ld e, b
_putPixel:
push bc
push hl
push ix
bit fClipArc,(iy+ellipseFlags)
call nz,ClipArcPixel
call z,SetPixel
pop ix
pop hl
pop bc
ret
EllipseDec48:
ld b, 6
or a
ld a, (de)
sbc a, (hl)
ld (de), a
inc de
inc hl
djnz EllipseDec48 + $03
ret
EllipseInc48:
ld b, 6
or a
ld a, (de)
adc a, (hl)
ld (de), a
inc de
inc hl
djnz EllipseInc48 + $03
ret
;-------------------------------------------------------------------------------
;@doc:begin ellipse routine
;
; === EllipseDec32 ===
;
; Subtracts a 32-bit value from a 48-bit value
;
; INPUTS:
;
; REGISTERS
; * DE - Address of 48-bit variable to decrement
; * HL - Address of 32-bit decrement amount
;
; DESTROYED:
;
; REGISTERS
; * AF, DE
;
; TIMINGS:
; * 202 T-States
;
;@doc:end
;-------------------------------------------------------------------------------
EllipseDec32:
ld a, (de) ; [7]
sub (hl) ; [7]
ld (de), a ; [7]
inc de ; [6]
inc hl ; [6]
ld a, (de) ; [7]
sbc a, (hl) ; [7]
ld (de), a ; [7]
inc de ; [6]
inc hl ; [6]
ld a, (de) ; [7]
sbc a, (hl) ; [7]
ld (de), a ; [7]
inc de ; [6]
inc hl ; [6]
ld a, (de) ; [7]
sbc a, (hl) ; [7]
ld (de), a ; [7]
inc de ; [6]
dec hl ; [6]
dec hl ; [6]
dec hl ; [6]
ld a, (de) ; [7]
sbc a, 0 ; [7]
ld (de), a ; [7]
inc de ; [6]
ld a, (de) ; [7]
sbc a, 0 ; [7]
ld (de), a ; [7]
ret ; [10]
;-------------------------------------------------------------------------------
; End of EllipseDec32
;-------------------------------------------------------------------------------
;-------------------------------------------------------------------------------
;@doc:begin ellipse routine
;
; === EllipseInc32 ===
;
; Adds a 32-bit value to a 48-bit value
;
; INPUTS:
;
; REGISTERS
; * DE - Address of 48-bit variable to increment
; * HL - Address of 32-bit increment amount
;
; DESTROYED:
;
; REGISTERS
; * AF, DE
;
; TIMINGS:
; * 202 T-States
;
;@doc:end
;-------------------------------------------------------------------------------
EllipseInc32:
ld a, (de) ; [7]
add a, (hl) ; [7]
ld (de), a ; [7]
inc de ; [6]
inc hl ; [6]
ld a, (de) ; [7]
adc a, (hl) ; [7]
ld (de), a ; [7]
inc de ; [6]
inc hl ; [6]
ld a, (de) ; [7]
adc a, (hl) ; [7]
ld (de), a ; [7]
inc de ; [6]
inc hl ; [6]
ld a, (de) ; [7]
adc a, (hl) ; [7]
ld (de), a ; [7]
inc de ; [6]
dec hl ; [6]
dec hl ; [6]
dec hl ; [6]
ld a, (de) ; [7]
adc a, 0 ; [7]
ld (de), a ; [7]
inc de ; [6]
ld a, (de) ; [7]
adc a, 0 ; [7]
ld (de), a ; [7]
ret ; [10]
;-------------------------------------------------------------------------------
; End of EllipseInc32
;-------------------------------------------------------------------------------
;-------------------------------------------------------------------------------
;
; === UMul32x16 ===
;
; Unsigned multiplication of the 32-bit value in HL:DE by the 16-bit value in
; BC, returning a 48-bit result in HL:DE:BC.
;
; INPUTS:
;
; REGISTERS
; * HL:DE - 32-bit multiplicand
; * BC - 16-bit multiplier
;
; OUTPUTS:
;
; REGISTERS
; * HL:DE:BC - 48-bit result
;
; DESTROYED:
;
; REGISTERS
; * AF
;
;-------------------------------------------------------------------------------
UMul32x16:
push hl ; [11]
ld hl, $0000 ; [10]
call _mulBCxE ; [*]
call _mulBCxE ; [*]
ex de, hl ; [4]
ex (sp), hl ; [19]
ex de, hl ; [4]
call _mulBCxE ; [*]
call _mulBCxE ; [*]
pop bc ; [10]
ret ; [10]
; Subroutine that multiplies BC by E. The result is in HL:D. On
; exit, E will contain the original value of D.
; overhead = 26
;
_mulBCxE:
xor a ; [4]
scf ; [4] for marker bit
_nextBit:
rr e ; [8]
jr z, _endByte ; [12/7]
jr nc, $ + $03 ; [12/7]
add hl, bc ; [11]
rr h ; [8]
rr l ; [8]
rra ; [4]
jp _nextBit ; [10]
_endByte:
ld e, d ; [4]
ld d, a ; [4]
ret ; [10]
;-------------------------------------------------------------------------------
;
;
; INPUTS:
;
; * BC - Number to square
;
; OUTPUTS:
;
; * HL - High word of square(BC)
; * DE - Low word of square(BC)
;
; DESTROYED:
;
; * AF
;-------------------------------------------------------------------------------
SquareBC:
;-------------------------------------------------------------------
; Process the low 4 bits of BC using 8-bit arithmetic.
;
; A = sqrsum
; D = sqrbit
; E = result
;-------------------------------------------------------------------
push bc ; [11]
xor a ; [4]
ld de, $0100 ; [10]
_sqrLoop8:
add a, a ; [4] sqrsum * 2
sra c ; [8]
jr nc, _nextBit8 ; [12/7]
;-------------------------------------------------------------------
; When the next bit of BC is set...
;-------------------------------------------------------------------
ld l, a ; [4] save sqrsum
add a, e ; [4] += result
add a, d ; [4] += sqrbit
ld e, a ; [4] save result
ld a, l ; [4] restore sqrsum
sla d ; [8] sqrbit * 2
add a, d ; [4] sqrsum + sqrbit * 2
sla d ; [8]
jp nc, _sqrLoop8 ; [10]
jp _sqrDone8 ; [10]
;-------------------------------------------------------------------
; When the next bit of BC is reset...
;-------------------------------------------------------------------
_nextBit8:
sla d ; [8]
sla d ; [8]
jp nc, _sqrLoop8 ; [10]
;-------------------------------------------------------------------
; Clean up from 8-bit mode and check if there is more to do
;-------------------------------------------------------------------
_sqrDone8:
ld h, d ; [4] move sqrsuml into HL (D is zero).
ld l, a ; [4]
ld a, c ; [4] check if there is anything left
or b ; [4]
jp nz, _sqrGo16 ; [10]
ld l, d ; [4] zero HL and return
pop bc ; [10]
ret ; [10]
;-------------------------------------------------------------------
; Process the next 4 bits with 16-bit arithmetic
;
; HL = sqrsum
; DE = result
; BC = sqrbit
;-------------------------------------------------------------------
_sqrGo16:
ld a, c ; [4]
push bc ; [11]
ld b, 1 ; [7]
ld c, d ; [4]
_sqrLoop16:
add hl, hl ; [11] sqrsuml *= 2
rra ; [4] shift next bit
jr nc, _nextBit16 ; [12/7]
;-------------------------------------------------------------------
; When the next bit of BC is set...
;-------------------------------------------------------------------
ex de, hl ; [4] sqrsum <-> result
add hl, de ; [11] result += sqrsum
add hl, bc ; [15] result += sqrbit
ex de, hl ; [4] result += sqrsum
sla b ; [8]
add hl, bc ; [11] sqrsum += sqrbit
sla b ; [8]
jp nc, _sqrLoop16 ; [10]
jp _sqrDone16 ; [10]
;-------------------------------------------------------------------
; When the next bit of BC is reset...
;-------------------------------------------------------------------
_nextBit16:
sla b ; [8]
sla b ; [8]
jp nc, _sqrLoop16 ; [10]
;-------------------------------------------------------------------
; Check if there are more bits to process before continuing.
;-------------------------------------------------------------------
_sqrDone16:
pop af ; [10] restore high byte of initial BC