Skip to content

Commit 94aec0d

Browse files
ZERICO2005mateoconlechuga
authored andcommitted
optimized dy calculation in gfx_Line_NoClip
1 parent c204289 commit 94aec0d

1 file changed

Lines changed: 19 additions & 31 deletions

File tree

src/graphx/graphx.asm

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2082,10 +2082,10 @@ OutcodeOutOutcode1:
20822082
gfx_Line_NoClip:
20832083
; Draws an unclipped arbitrary line
20842084
; Arguments:
2085-
; arg0 : X1 coordinate (hl)
2086-
; arg1 : Y1 coordinate (b)
2087-
; arg2 : X2 coordinate (de)
2088-
; arg3 : Y2 coordinate (c)
2085+
; arg0 : X0 coordinate (hl)
2086+
; arg1 : Y0 coordinate (b)
2087+
; arg2 : X1 coordinate (de)
2088+
; arg3 : Y1 coordinate (a)
20892089
; Returns:
20902090
; None
20912091
ld iy, 0
@@ -2094,18 +2094,24 @@ _Line_NoClip: ; <-- carry is cleared
20942094
ld hl, (iy + 3)
20952095
ld de, (iy + 9)
20962096
ld b, (iy + 6)
2097-
ld c, (iy + 12) ; line from hl, b to de, c
2097+
ld a, (iy + 12) ; line from hl, b to de, a
20982098
; or a, a
20992099
sbc hl, de
21002100
add hl, de
21012101
jr c, _draw_left_to_right ; draw left to right
21022102
ex de, hl
2103+
ld c, a
21032104
ld a, b
21042105
ld b, c
2105-
ld c, a
21062106
_draw_left_to_right:
2107-
push bc
2108-
pop iy
2107+
2108+
sub a, b ; dy = y1 - y0
2109+
ld iy, 320
2110+
jr nc, .positive_dy
2111+
ld iy, -320
2112+
neg ; abs(dy)
2113+
.positive_dy:
2114+
21092115
push hl
21102116
ld hl, (CurrentBuffer)
21112117
ld c, 160
@@ -2121,29 +2127,9 @@ _draw_left_to_right:
21212127
push hl
21222128
pop bc ; bc = dx
21232129

2124-
xor a, a
2125-
ld h, a
2126-
ld d, a
2127-
ld e, iyl ; y0
2128-
ex.s de, hl
2129-
ld e, iyh ; y1
2130-
2131-
sbc hl, de
2132-
2133-
jr nc, .positive_dy
2134-
ex de, hl
21352130
or a, a
21362131
sbc hl, hl
2137-
sbc hl, de ; abs(dy)
2138-
.positive_dy:
2139-
2140-
ld a, iyl
2141-
sub a, iyh
2142-
ld iy, -320
2143-
jr c, .use_negative_IY
2144-
ld iy, 320
2145-
.use_negative_IY:
2146-
or a, a
2132+
ld l, a
21472133
sbc hl, bc
21482134
add hl, bc ; hl = dy
21492135
jr nc, dl_vertical
@@ -2157,7 +2143,7 @@ dl_horizontal:
21572143
ld (_smc_dl_jr_0 + 0), a ; write smc
21582144
ld (_smc_dl_width_1 + 1), iy ; write smc
21592145
ex de, hl
2160-
; or a, a ; or a, h clears carry
2146+
; or a, a ; or a, h clears carry
21612147
sbc hl, hl
21622148
sbc hl, de
21632149
ld (_smc_dl_dx_1 + 1), bc ; write smc
@@ -2190,13 +2176,15 @@ _smc_dl_dx_1:
21902176
_smc_dl_dy_1:
21912177
ld de, 0 ; dy
21922178
jr dl_hloop
2179+
21932180
dl_vertical:
21942181
lea de, iy
21952182
ld b, c
21962183
ld a, l
21972184
ld iyl, a
21982185
ld c, a
2199-
srl a ; a = dy / 2
2186+
; or a, a
2187+
rra ; a = dy / 2
22002188
inc c
22012189
pop hl
22022190
wait_quick

0 commit comments

Comments
 (0)