Sprite flipping
I’ve filled in the other 3 frames required, and set it up so that it only loads one frame of animation into VRAM. There are enough scanlines to do this completely in VBlank with a comfortable amount of headroom; unfortunately, the method used isn’t fast enough to require me to slow it down during not-VBlank, and so this provides no speed advantage.
Anyhow, on the topic of sprite flipping. The TMS9918A provides a lovely feature which allows you to flip tile data horizontally and/or vertically. Unfortunately, this was not provided with sprites, despite the fact that there’s a blatantly unused section which would have been perfect for sticking these flags in. So you have to flip the sprites manually.
This is where we use a table to perform the flip. It looks like this:
(╯°□°)╯︵ ┻━┻
Erm, I mean THIS:
.macro m_build_fliptab_gen
.redefine mv_q 0
.rept 256
.redefine mv_x mv_q
.redefine mv_x (((mv_x<<1)&$AA)|((mv_x>>1)&$55))
.redefine mv_x (((mv_x<<2)&$CC)|((mv_x>>2)&$33))
.redefine mv_x (((mv_x<<4)&$F0)|((mv_x>>4)&$0F))
.db mv_x
.redefine mv_q 1+mv_q
.endr
.endm
I also have one which generates a “no flip table” which is just a bunch of bytes from 0 to 255.
Here’s the code:
ld de,$0000
–:
.rept 4
rst $08
.endr; load sprite
ld hl,$4000 + ($7C * 32)
ld bc,$80BF
out (c),l
out (c),hld hl,g_spriteset_plr
add hl,de
push de
ld d,fliptab>>8
-:
ld e,(hl) ; 19
inc l ; 23
ld a,(de) ; 30
out ($BE),a ; 41 – SAFE
djnz – ; START: 12
pop deex de,hl
ld de,$0080
add hl,de
ex de,hl
ld a,d
and $02 -1
ld d,a; there’s still plenty of breathing room
; mednafen reports $DA with the occasional flicker of $D5jp –
I hope you can work out whether the walk animation is any good or not. I’ve loaded it into an unused space of VRAM. If you look carefully, you’ll notice that one of the frames involves the player bobbing up. See, I put in effort!
