Skip to content

Commit f7c16b4

Browse files
runer112Matt Waltz
authored and
Matt Waltz
committed
Fix clipping off-by-one errors (#73)
1 parent be9fea4 commit f7c16b4

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

src/graphx/graphx.asm

+6-13
Original file line numberDiff line numberDiff line change
@@ -497,17 +497,15 @@ _FillRectangle:
497497
add hl,de
498498
ld (iy+12),hl
499499
call _ClipRectRegion_ASM \.r
500-
ret c ; return if offscreen
500+
ret c ; return if offscreen or degenerate
501501
ld de,(iy+3)
502502
ld hl,(iy+9)
503-
sbc hl,de ; make sure that the width is not 0
504-
ret z
503+
sbc hl,de
505504
push hl
506505
ld de,(iy+6)
507506
ld hl,(iy+12)
508507
sbc hl,de
509508
pop bc ; bc = new width
510-
ret z
511509
ld a,l ; a = new height
512510
ld hl,(iy+3) ; hl = new x, de = new y
513511
jr _FillRectangle_NoClip_ASM
@@ -4516,7 +4514,7 @@ _ClipRectRegion_ASM:
45164514
call _Min_ASM \.r
45174515
ld (iy+9),hl
45184516
ld de,(iy+3)
4519-
call _SignedCompare_ASM \.r
4517+
call _ClipRectRegion_Compare_ASM \.r
45204518
ret c
45214519
ld hl,(_ymin) \.r
45224520
ld de,(iy+6)
@@ -4527,20 +4525,15 @@ _ClipRectRegion_ASM:
45274525
call _Min_ASM \.r
45284526
ld (iy+12),hl
45294527
ld de,(iy+6)
4528+
_ClipRectRegion_Compare_ASM:
4529+
dec hl
45304530
_SignedCompare_ASM:
45314531
or a,a
45324532
sbc hl,de
45334533
add hl,hl
45344534
ret po
45354535
ccf
45364536
ret
4537-
_SignedCompareBC_ASM:
4538-
or a,a
4539-
sbc hl,bc
4540-
add hl,hl
4541-
ret po
4542-
ccf
4543-
ret
45444537

45454538
;-------------------------------------------------------------------------------
45464539
_SetFullScrnClip_ASM:
@@ -4556,7 +4549,7 @@ _SetFullScrnClip_ASM:
45564549
sbc hl,hl
45574550
ld (_xmin),hl \.r
45584551
inc h
4559-
ld l,lcdWidth-$ff
4552+
ld l,lcdWidth&$ff
45604553
ld (_xmax),hl \.r
45614554
ret
45624555

0 commit comments

Comments
 (0)