Skip to content

Commit 56a0c64

Browse files
committed
fix: fix circle algorithm (avoid dupe plots)
1 parent eed8ca0 commit 56a0c64

6 files changed

Lines changed: 36 additions & 5 deletions

File tree

src/arch/z80/translator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,7 @@ def visit_PLOT(self, node):
709709
self.ic_fparam(node.children[1].type_, node.children[1].t)
710710
self.runtime_call(RuntimeLabel.PLOT, 0)
711711
self.HAS_ATTR = TMP_HAS_ATTR is not None
712+
self.norm_attr()
712713

713714
def visit_DRAW(self, node):
714715
TMP_HAS_ATTR = self.check_attr(node, 2)
@@ -719,6 +720,7 @@ def visit_DRAW(self, node):
719720
self.ic_fparam(node.children[1].type_, node.children[1].t)
720721
self.runtime_call(RuntimeLabel.DRAW, 0)
721722
self.HAS_ATTR = TMP_HAS_ATTR is not None
723+
self.norm_attr()
722724

723725
def visit_DRAW3(self, node):
724726
TMP_HAS_ATTR = self.check_attr(node, 3)
@@ -731,6 +733,7 @@ def visit_DRAW3(self, node):
731733
self.ic_fparam(node.children[2].type_, node.children[2].t)
732734
self.runtime_call(RuntimeLabel.DRAW3, 0)
733735
self.HAS_ATTR = TMP_HAS_ATTR is not None
736+
self.norm_attr()
734737

735738
def visit_CIRCLE(self, node):
736739
TMP_HAS_ATTR = self.check_attr(node, 3)
@@ -743,6 +746,7 @@ def visit_CIRCLE(self, node):
743746
self.ic_fparam(node.children[2].type_, node.children[2].t)
744747
self.runtime_call(RuntimeLabel.CIRCLE, 0)
745748
self.HAS_ATTR = TMP_HAS_ATTR is not None
749+
self.norm_attr()
746750

747751
# endregion
748752

src/arch/zx48k/library-asm/circle.asm

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ __CIRCLE:
6262
ld a, h
6363
exx
6464
pop de ; D'E' = x0, y0
65-
ld h, a ; H' = r
65+
ld h, a ; H' = r
6666

6767
ld c, e
6868
ld a, h
@@ -107,6 +107,7 @@ __CIRCLE:
107107

108108
__CIRCLE_LOOP:
109109
ld a, b
110+
inc a
110111
cp c
111112
ret nc ; Returns when x >= y
112113

@@ -170,6 +171,10 @@ __CIRCLE_NEXT:
170171
ld c, a ; C = x0 - x
171172
call __CIRCLE_PLOT ; plot(x0 - x, y0 - y)
172173

174+
ld a, l
175+
cp h
176+
jr z, 1f
177+
173178
ld a, d
174179
add a, l
175180
ld b, a ; B = y0 + x
@@ -202,6 +207,7 @@ __CIRCLE_NEXT:
202207
ld c, a ; C = x0 + y
203208
call __CIRCLE_PLOT ; plot(x0 - y, y0 - x)
204209

210+
1:
205211
exx
206212
jp __CIRCLE_LOOP
207213

src/arch/zxnext/library-asm/circle.asm

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ __CIRCLE:
6262
ld a, h
6363
exx
6464
pop de ; D'E' = x0, y0
65-
ld h, a ; H' = r
65+
ld h, a ; H' = r
6666

6767
ld c, e
6868
ld a, h
@@ -107,6 +107,7 @@ __CIRCLE:
107107

108108
__CIRCLE_LOOP:
109109
ld a, b
110+
inc a
110111
cp c
111112
ret nc ; Returns when x >= y
112113

@@ -170,6 +171,10 @@ __CIRCLE_NEXT:
170171
ld c, a ; C = x0 - x
171172
call __CIRCLE_PLOT ; plot(x0 - x, y0 - y)
172173

174+
ld a, l
175+
cp h
176+
jr z, 1f
177+
173178
ld a, d
174179
add a, l
175180
ld b, a ; B = y0 + x
@@ -202,6 +207,7 @@ __CIRCLE_NEXT:
202207
ld c, a ; C = x0 + y
203208
call __CIRCLE_PLOT ; plot(x0 - y, y0 - x)
204209

210+
1:
205211
exx
206212
jp __CIRCLE_LOOP
207213

tests/functional/zx48k/circle.asm

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ __CIRCLE:
393393
ld a, h
394394
exx
395395
pop de ; D'E' = x0, y0
396-
ld h, a ; H' = r
396+
ld h, a ; H' = r
397397
ld c, e
398398
ld a, h
399399
add a, d
@@ -430,6 +430,7 @@ __CIRCLE:
430430
ex af, af' ; Saves it
431431
__CIRCLE_LOOP:
432432
ld a, b
433+
inc a
433434
cp c
434435
ret nc ; Returns when x >= y
435436
bit 7, h ; HL >= 0? : if (f >= 0)...
@@ -482,6 +483,9 @@ __CIRCLE_NEXT:
482483
sub l
483484
ld c, a ; C = x0 - x
484485
call __CIRCLE_PLOT ; plot(x0 - x, y0 - y)
486+
ld a, l
487+
cp h
488+
jr z, 1f
485489
ld a, d
486490
add a, l
487491
ld b, a ; B = y0 + x
@@ -510,6 +514,7 @@ __CIRCLE_NEXT:
510514
sub h
511515
ld c, a ; C = x0 + y
512516
call __CIRCLE_PLOT ; plot(x0 - y, y0 - x)
517+
1:
513518
exx
514519
jp __CIRCLE_LOOP
515520
__CIRCLE_PLOT:

tests/functional/zx48k/inktemp.asm

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ __CIRCLE:
354354
ld a, h
355355
exx
356356
pop de ; D'E' = x0, y0
357-
ld h, a ; H' = r
357+
ld h, a ; H' = r
358358
ld c, e
359359
ld a, h
360360
add a, d
@@ -391,6 +391,7 @@ __CIRCLE:
391391
ex af, af' ; Saves it
392392
__CIRCLE_LOOP:
393393
ld a, b
394+
inc a
394395
cp c
395396
ret nc ; Returns when x >= y
396397
bit 7, h ; HL >= 0? : if (f >= 0)...
@@ -443,6 +444,9 @@ __CIRCLE_NEXT:
443444
sub l
444445
ld c, a ; C = x0 - x
445446
call __CIRCLE_PLOT ; plot(x0 - x, y0 - y)
447+
ld a, l
448+
cp h
449+
jr z, 1f
446450
ld a, d
447451
add a, l
448452
ld b, a ; B = y0 + x
@@ -471,6 +475,7 @@ __CIRCLE_NEXT:
471475
sub h
472476
ld c, a ; C = x0 + y
473477
call __CIRCLE_PLOT ; plot(x0 - y, y0 - x)
478+
1:
474479
exx
475480
jp __CIRCLE_LOOP
476481
__CIRCLE_PLOT:

tests/functional/zx48k/spfill.asm

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ __CIRCLE:
969969
ld a, h
970970
exx
971971
pop de ; D'E' = x0, y0
972-
ld h, a ; H' = r
972+
ld h, a ; H' = r
973973
ld c, e
974974
ld a, h
975975
add a, d
@@ -1006,6 +1006,7 @@ __CIRCLE:
10061006
ex af, af' ; Saves it
10071007
__CIRCLE_LOOP:
10081008
ld a, b
1009+
inc a
10091010
cp c
10101011
ret nc ; Returns when x >= y
10111012
bit 7, h ; HL >= 0? : if (f >= 0)...
@@ -1058,6 +1059,9 @@ __CIRCLE_NEXT:
10581059
sub l
10591060
ld c, a ; C = x0 - x
10601061
call __CIRCLE_PLOT ; plot(x0 - x, y0 - y)
1062+
ld a, l
1063+
cp h
1064+
jr z, 1f
10611065
ld a, d
10621066
add a, l
10631067
ld b, a ; B = y0 + x
@@ -1086,6 +1090,7 @@ __CIRCLE_NEXT:
10861090
sub h
10871091
ld c, a ; C = x0 + y
10881092
call __CIRCLE_PLOT ; plot(x0 - y, y0 - x)
1093+
1:
10891094
exx
10901095
jp __CIRCLE_LOOP
10911096
__CIRCLE_PLOT:

0 commit comments

Comments
 (0)