1
0
mirror of https://github.com/UzixLS/pacemuzx.git synced 2025-07-19 07:11:20 +03:00

Improved tunnel trimming

The old method used a mix of black attributes and data masking to trim sprites at the screen edges, with every sprite trimmed separately.

The new method no longer uses attributes, so it's compatible with the colour version.  It also finds the extent of the trim block for all sprites, for more efficient clearing.
This commit is contained in:
Simon Owen
2012-01-08 01:44:59 +00:00
parent a7cfef97b2
commit eba439a3ba

View File

@ -1589,65 +1589,87 @@ ENDIF
; Trim sprites that overlap the maze edges, as the real hardware does automatically ; Trim sprites that overlap the maze edges, as the real hardware does automatically
; Here we trim partial bytes, as full blocks are hidden behind black on black attrs ; Here we trim partial bytes, as full blocks are hidden behind black on black attrs
; ;
do_trim: ld de,&5062 ; start of sprite data do_trim: ld hl,&5062 ; sprite x for first sprite
ld b,&07 ; 7 sprites to check ld de,&ff00 ; no trim yet
ld b,7 ; 7 sprites to check
trim_lp: ld a,(de) ; sprite x trim_lp: ld a,(hl) ; sprite x
inc e inc l
cp &10 ; hidden sprite? cp &10 ; hidden?
jr c,no_trim jr c,trim_next
cp &20 ; clipped at right edge? cp &20 ; clipped at right edge?
jr c,may_trim jr c,may_trim
cp &f0 ; clipped at left edge? cp &f0 ; clipped at left edge?
jr nc,may_trim jr c,trim_next
no_trim: inc e
may_trim: ld a,(hl) ; sprite y
cp &10 ; hidden?
jr c,trim_next
cp d ; compare min
jr nc,no_trim_min
ld d,a ; update min
no_trim_min: cp e ; compare max
jr c,trim_next
ld e,a ; update max
jr trim_next
trim_next: inc l ; skip sprite y
djnz trim_lp djnz trim_lp
ret
may_trim: ld a,(de) ; sprite y ld a,e ; max
cp &10 ; hidden sprite? and a
jr c,no_trim jp z,page_rom ; zero means no trim
sub d ; subtract min to give block
add a,12 ; add sprite height to give span
ld b,a ; line count for trim
ld e,12 ; height of sprite ld l,e ; top line, due to mirrored y!
ld hl,&4f45 ; left of tunnel ld h,conv_y/256
cp &8c ; sprite y for tunnel? ld l,(hl) ; convert y to Speccy line
jr z,trim_edge ld h,scradtab/256
ld e,24 ; height of 2 sprites ld c,(hl) ; LSB of line start
ld hl,&4d65 ; left of intermission row inc h
trim_edge: ld a,(hl) ; MSB of line start
ld a,h add a,ixh ; current screen offset
or ixh ; offset to current screen
ld h,a ld h,a
ld l,c
ld a,%00000100 ; +3 normal paging, R3/5/2/7 call page_screen
ld bc,&1ffd
out (c),a ; normal paging (screen)
ld b,e ; line count ld de,&0300 ; D=left mask, E=clear byte
ld de,&03fc ; masks for below trim_r_lp: ld c,l ; save line start LSB
trim_line_lp: ld a,(hl) ld a,c
and d ; clear 6 pixels add a,4
ld (hl),a
ld c,l
ld a,l
add a,&15 ; advance to right edge
ld l,a ld l,a
ld (hl),e ; full byte to trim 6 pixels
inc l
ld a,(hl) ld a,(hl)
and e ; clear 2 pixels and d ; trim 6 pixels at maze left
ld (hl),a ld (hl),a
ld l,c ; restore left position
ld a,c
add a,26 ; right tunnel offset
ld l,a
ld a,(hl)
and &fc ; trim 2 pixels at maze right
ld (hl),a
inc l
ld (hl),e ; full byte
inc l
ld (hl),e ; full byte for final 2 pixels
ld l,c ; restore original LSB
inc h ; next line inc h ; next line
ld a,h ld a,h
and %00000111 and %00000111
call z,blockdown_hl call z,blockdown_hl
djnz trim_line_lp
ld a,%00000001 ; +3 special paging, banks 0/1/2/3 djnz trim_r_lp
ld bc,&1ffd jp page_rom
out (c),a ; page ROM
ret
; Clear a sprite-sized hole, used for blank tiles in our fruit and lives display ; Clear a sprite-sized hole, used for blank tiles in our fruit and lives display