Skip to content

Commit 05a61f8

Browse files
committed
optimized dy calculation in gfx_Line_NoClip
1 parent e1ed673 commit 05a61f8

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
@@ -2089,10 +2089,10 @@ OutcodeOutOutcode1:
20892089
gfx_Line_NoClip:
20902090
; Draws an unclipped arbitrary line
20912091
; Arguments:
2092-
; arg0 : X1 coordinate (hl)
2093-
; arg1 : Y1 coordinate (b)
2094-
; arg2 : X2 coordinate (de)
2095-
; arg3 : Y2 coordinate (c)
2092+
; arg0 : X0 coordinate (hl)
2093+
; arg1 : Y0 coordinate (b)
2094+
; arg2 : X1 coordinate (de)
2095+
; arg3 : Y1 coordinate (a)
20962096
; Returns:
20972097
; None
20982098
ld iy, 0
@@ -2101,18 +2101,24 @@ _Line_NoClip: ; <-- carry is cleared
21012101
ld hl, (iy + 3)
21022102
ld de, (iy + 9)
21032103
ld b, (iy + 6)
2104-
ld c, (iy + 12) ; line from hl, b to de, c
2104+
ld a, (iy + 12) ; line from hl, b to de, a
21052105
; or a, a
21062106
sbc hl, de
21072107
add hl, de
21082108
jr c, _draw_left_to_right ; draw left to right
21092109
ex de, hl
2110+
ld c, a
21102111
ld a, b
21112112
ld b, c
2112-
ld c, a
21132113
_draw_left_to_right:
2114-
push bc
2115-
pop iy
2114+
2115+
sub a, b ; dy = y1 - y0
2116+
ld iy, 320
2117+
jr nc, .positive_dy
2118+
ld iy, -320
2119+
neg ; abs(dy)
2120+
.positive_dy:
2121+
21162122
push hl
21172123
ld hl, (CurrentBuffer)
21182124
ld c, 160
@@ -2128,29 +2134,9 @@ _draw_left_to_right:
21282134
push hl
21292135
pop bc ; bc = dx
21302136

2131-
xor a, a
2132-
ld h, a
2133-
ld d, a
2134-
ld e, iyl ; y0
2135-
ex.s de, hl
2136-
ld e, iyh ; y1
2137-
2138-
sbc hl, de
2139-
2140-
jr nc, .positive_dy
2141-
ex de, hl
21422137
or a, a
21432138
sbc hl, hl
2144-
sbc hl, de ; abs(dy)
2145-
.positive_dy:
2146-
2147-
ld a, iyl
2148-
sub a, iyh
2149-
ld iy, -320
2150-
jr c, .use_negative_IY
2151-
ld iy, 320
2152-
.use_negative_IY:
2153-
or a, a
2139+
ld l, a
21542140
sbc hl, bc
21552141
add hl, bc ; hl = dy
21562142
jr nc, dl_vertical
@@ -2164,7 +2150,7 @@ dl_horizontal:
21642150
ld (_smc_dl_jr_0 + 0), a ; write smc
21652151
ld (_smc_dl_width_1 + 1), iy ; write smc
21662152
ex de, hl
2167-
; or a, a ; or a, h clears carry
2153+
; or a, a ; or a, h clears carry
21682154
sbc hl, hl
21692155
sbc hl, de
21702156
ld (_smc_dl_dx_1 + 1), bc ; write smc
@@ -2197,13 +2183,15 @@ _smc_dl_dx_1:
21972183
_smc_dl_dy_1:
21982184
ld de, 0 ; dy
21992185
jr dl_hloop
2186+
22002187
dl_vertical:
22012188
lea de, iy
22022189
ld b, c
22032190
ld a, l
22042191
ld iyl, a
22052192
ld c, a
2206-
srl a ; a = dy / 2
2193+
; or a, a
2194+
rra ; a = dy / 2
22072195
inc c
22082196
pop hl
22092197
wait_quick

0 commit comments

Comments
 (0)