Skip to content

Commit 885bf0f

Browse files
committed
optimized sprite clipping/transparent routines
1 parent 37e49bb commit 885bf0f

File tree

1 file changed

+35
-39
lines changed

1 file changed

+35
-39
lines changed

src/graphx/graphx.asm

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2709,31 +2709,30 @@ gfx_TransparentSprite:
27092709
push ix ; save ix sp
27102710
call _ClipCoordinates
27112711
jr nc,.culled
2712+
; iyl = new width (next)
2713+
; iyh = new height
27122714
ld (.amount),a
2713-
ld a,c ; new width
2714-
ld (.next),a
2715-
ld ixh,b ; new height
2716-
ld b,0
27172715
.transparent_color := $+1
27182716
ld a,TRASPARENT_COLOR
27192717
smcByte _TransparentColor
27202718
wait_quick
27212719
.loop:
2722-
ld c,0
2723-
.next := $-1
2724-
lea de,iy
2720+
ld c,iyl ; next
2721+
lea de,ix
27252722
call _TransparentPlot ; call the transparent routine
27262723
ld c,0
27272724
.amount := $-1
27282725
add hl,bc
27292726
ld de,ti.lcdWidth ; move to next row
2730-
add iy,de
2731-
dec ixh
2727+
add ix,de
2728+
dec iyh
27322729
jr nz,.loop
27332730
.culled:
27342731
pop ix
27352732
ret
27362733

2734+
; Opaque unrolled 4 times
2735+
; Transparent unrolled 4 times
27372736
_TransparentPlot_Opaque: ; routine to handle transparent plotting
27382737
ldi
27392738
ret po
@@ -2790,26 +2789,22 @@ gfx_Sprite:
27902789
; None
27912790
push ix ; save ix sp
27922791
call _ClipCoordinates
2793-
pop ix ; restore ix sp
2794-
ret nc
2795-
ld (.amount),a
2796-
ld a,c ; new width
2797-
ld (.next),a
2798-
ld a,b ; new height
2799-
ld b,0
2792+
jr nc,.culled
2793+
; iyl = new width (next)
2794+
; iyh = new height
28002795
wait_quick
28012796
.loop:
2802-
ld c,0
2803-
.next := $-1
2804-
lea de,iy
2797+
ld c,iyl ; next
2798+
lea de,ix
28052799
ldir
28062800
ld de,ti.lcdWidth
2807-
add iy,de
2808-
ld c,0
2809-
.amount := $-1
2801+
add ix,de
2802+
ld c,a ; amount
28102803
add hl,bc ; move to next line
2811-
dec a
2804+
dec iyh
28122805
jr nz,.loop
2806+
.culled:
2807+
pop ix ; restore ix sp
28132808
ret
28142809

28152810
;-------------------------------------------------------------------------------
@@ -2928,33 +2923,33 @@ gfx_TransparentSprite_NoClip:
29282923
add iy,sp
29292924
ld hl,(iy+6) ; hl = x coordinate
29302925
ld c,(iy+9) ; c = y coordinate
2931-
ld iy,(iy+3) ; iy -> sprite struct
29322926
ld de,(CurrentBuffer)
29332927
add hl,de
29342928
ld b,ti.lcdWidth / 2
29352929
mlt bc
29362930
add hl,bc
29372931
add hl,bc ; hl -> place to draw
29382932
push hl
2939-
ld a,(iy+0)
2933+
ld hl,(iy+3) ; hl -> sprite struct
2934+
ld a,(hl)
2935+
inc hl
29402936
ld (.next),a
2941-
ld a,(iy+1)
2942-
lea hl,iy+2
2943-
pop iy
2944-
push ix
2945-
ld ixh,a ; ixh = height of sprite
2937+
ld a,(hl)
2938+
inc hl
2939+
ex (sp), ix ; preserve ix and load it with (sp)
2940+
ld iyh,a ; ixh = height of sprite
29462941
ld b,0 ; zero mid byte
29472942
ld a,TRASPARENT_COLOR
29482943
smcByte _TransparentColor
29492944
wait_quick
29502945
.loop:
29512946
ld c,0
29522947
.next := $-1
2953-
lea de,iy
2948+
lea de,ix
29542949
call _TransparentPlot ; call the plotter
29552950
ld de,ti.lcdWidth
2956-
add iy,de
2957-
dec ixh ; loop for height
2951+
add ix,de
2952+
dec iyh ; loop for height
29582953
jr nz,.loop
29592954
pop ix ; restore stack pointer
29602955
ret
@@ -2969,10 +2964,11 @@ _ClipCoordinates:
29692964
; Returns:
29702965
; A : How much to add to the sprite per iteration
29712966
; BCU: 0
2972-
; B : New sprite height
2973-
; C : New sprite width
2967+
; B : 0
2968+
; IYH: New sprite height
2969+
; IYL: New sprite width
29742970
; HL : Sprite pixel pointer
2975-
; IY : Buffer pixel pointer
2971+
; IX : Buffer pixel pointer
29762972
; NC : If offscreen
29772973
ld ix,6 ; get pointer to arguments
29782974
add ix,sp
@@ -3070,19 +3066,19 @@ smcWord _XMin
30703066
sub a,e ; calculate bytes to add per iteration
30713067
.xclipped:
30723068

3073-
lea.s bc,iy
30743069
ld l,(ix+9) ; l = y coordinate
30753070
ld h,ti.lcdWidth / 2
30763071
mlt hl
30773072
add hl,hl
30783073
ld de,(ix+6) ; de = x coordinate
30793074
add hl,de
30803075
ex de,hl
3081-
ld iy,(CurrentBuffer)
3082-
add iy,de
30833076
ld hl,(ix+3) ; hl -> sprite data
30843077
inc hl
30853078
inc hl
3079+
ld ix,(CurrentBuffer)
3080+
add ix,de
3081+
ld b,0
30863082
scf ; set carry for success
30873083
ret
30883084

0 commit comments

Comments
 (0)