Sprite to Bitmap

Страница 3/3
1 | 2 |

By Chilly Willy

Resident (64)

Аватар пользователя Chilly Willy

03-07-2021, 04:27

Micha wrote:

The more I looked into this, the more I appreciate the "Konami solution" posted by Guillian. It is a little gem and way faster (approx. 30%) than the other solutions posted. It cleverly uses the carry to copy bits from one register to the other. I also like that by using HL as input you can fetch the two coordinates from memory in once ( ld hl,(nn) ) instead of doing ld a,(nn) twice, which saves 11 cycles. It also doesn't use BC and DE, which is nice.
There is one drawback however: it is not easy anymore to provide offsets to the coordinates; in most cases you don't want the character behind the upperleft corner but the char behind the middle of the sprite.
The most efficient "Konami solution" with offsets I could come up with would then look like this (I switched l and h to leave out the ld l,h at the end):

ld a,(X)
add offsetX
ld l,a
ld a,(Y)
add offsetY
rra
rra
rra
rra
rr l
rra
rr l
rra
rr l
and 3
add a,bufstart/256
ld h,a
ld a,(hl)

It should be 22 cycles faster than the other solution. Anyone able to optimise this even further ?

I am using this at the end of the day over the one I posted but without the offset.

Before I move I do something as follows.

LD A, (SPRTBL+00)
DEC A ; Offset North
LD L, A
LD A, (SPRTBL+01)
ADD A, 07 ; Offset North East
LD H, A
CALL PLAYER_TO_TILE ; Get Pattern

CP .........;Check results

LD A, (SPRTBL+00)
DEC A ; Offset North
LD L, A
LD A, (SPRTBL+01)
; Offset North West (this case is no change)
LD H, A
CALL PLAYER_TO_TILE ; Get Pattern

CP....; check results.

Doing it this way you do not change the actual values of the sprite table unless you move.

This example is what I am currently using test my player sprite going north.

Страница 3/3
1 | 2 |