@@ -1992,14 +1992,15 @@ gfx_Line:
19921992 call _ComputeOutcode
19931993 ld (iy - 2 ) , a
19941994CohenSutherlandLoop:
1995- ld b , (iy - 1 ) ; b = outcode0
19961995 ld a , (iy - 2 ) ; a = outcode1
1996+ .skip_ld_A:
1997+ ld b , (iy - 1 ) ; b = outcode0
19971998 tst a , b
1998- jp nz , TrivialReject ; if(outcode0|outcode1)
1999+ jr nz , TrivialReject ; if(outcode0|outcode1)
19992000 or a , a
20002001 jr nz , GetOutOutcode
20012002 or a , b
2002- jp z , TrivialAccept
2003+ jr z , TrivialAccept
20032004GetOutOutcode: ; select correct outcode
20042005 push af ; a = outoutcode
20052006 rra
@@ -2042,6 +2043,14 @@ NotBottom:
20422043 ld hl , ti.lcdWidth - 1
20432044smcWord _XMaxMinus1
20442045 jr ComputeNewY
2046+
2047+ TrivialReject:
2048+ ld sp , iy
2049+ ret
2050+ TrivialAccept:
2051+ ld sp , iy
2052+ jr _Line_NoClip ; line routine handler
2053+
20452054NotRight:
20462055 rra
20472056 jr nc , FinishComputations ; if (outcodeOut & LEFT)
@@ -2085,17 +2094,7 @@ OutcodeOutOutcode1:
20852094 ld (iy + 12 ) , de
20862095 call _ComputeOutcode
20872096 ld (iy - 2 ) , a ; c = outcode1
2088- jp CohenSutherlandLoop
2089- TrivialReject:
2090- inc sp
2091- inc sp
2092- inc sp
2093- ret
2094- TrivialAccept:
2095- inc sp
2096- inc sp
2097- inc sp
2098- ; jr _Line_NoClip ; line routine handler
2097+ jp CohenSutherlandLoop.skip_ld_A
20992098
21002099;-------------------------------------------------------------------------------
21012100gfx_Line_NoClip:
@@ -2109,19 +2108,21 @@ gfx_Line_NoClip:
21092108; None
21102109 ld iy , 0
21112110 add iy , sp
2111+ _Line_NoClip: ; <-- carry is cleared
21122112 ld hl , (iy + 3 )
21132113 ld de , (iy + 9 )
21142114 ld b , (iy + 6 )
21152115 ld c , (iy + 12 ) ; line from hl,b to de,c
2116- or a , a
2116+ ; or a,a
21172117 sbc hl , de
21182118 add hl , de
2119- jr c ,+ _ ; draw left to right
2119+ jr c , _draw_left_to_right ; draw left to right
21202120 ex de , hl
21212121 ld a , b
21222122 ld b , c
21232123 ld c , a
2124- _: push bc
2124+ _draw_left_to_right:
2125+ push bc
21252126 pop iy
21262127 push hl
21272128 ld hl , (CurrentBuffer)
@@ -2137,26 +2138,29 @@ _: push bc
21372138 sbc hl , bc ; xe - xs
21382139 push hl
21392140 pop bc ; bc = dx
2140- ld a , iyh
2141- or a , a
2142- sbc hl , hl
2143- ld l , a ; y1
2144- ex de , hl
2145- ld a , iyl
2146- sbc hl , hl
2147- ld l , a ; y0
2148- sbc hl , de
2149- jr nc , $ + 9
2150- ex de , hl
2151- sbc hl , hl
2152- ccf
2153- sbc hl , de
2154- inc hl ; abs(dy)
2141+
2142+ xor a , a
2143+ ld h , a
2144+ ld d , a
2145+ ld e , iyl ; y0
2146+ ex.s de , hl
2147+ ld e , iyh ; y1
2148+
2149+ sbc hl , de
2150+
2151+ jr nc , .positive_dy
2152+ ex de , hl
2153+ or a , a
2154+ sbc hl , hl
2155+ sbc hl , de ; abs(dy)
2156+ .positive_dy:
2157+
21552158 ld a , iyl
21562159 sub a , iyh
21572160 ld iy ,- 320
2158- jr c , $ + 7
2161+ jr c , .use_negative_IY
21592162 ld iy , 320
2163+ .use_negative_IY:
21602164 or a , a
21612165 sbc hl , bc
21622166 add hl , bc ; hl = dy
@@ -2165,19 +2169,19 @@ dl_horizontal:
21652169 ld a , l
21662170 or a , h
21672171 ld a , $ 38
2168- jr nz , $ + 4
2172+ jr nz , .dl_nz
21692173 xor a , $ 20
2174+ .dl_nz:
21702175 ld (_smc_dl_jr_0 + 0 ) , a ; write smc
21712176 ld (_smc_dl_width_1 + 1 ) , iy ; write smc
21722177 ex de , hl
2178+ ; or a,a ; or a,h clears carry
21732179 sbc hl , hl
2174- ccf
21752180 sbc hl , de
2176- inc hl
2181+ ld (_smc_dl_dx_1 + 1 ) , bc ; write smc
2182+ ld (_smc_dl_dy_1 + 1 ) , hl ; write smc
21772183 ex de , hl ; de = -dy
21782184 pop hl ; restore buffer
2179- ld (_smc_dl_dx_1 + 1 ) , bc ; write smc
2180- ld (_smc_dl_dy_1 + 1 ) , de ; write smc
21812185 push bc
21822186 srl b
21832187 rr c
0 commit comments