Here's a code example for flipping a standard sprite "in place".
You would need to call this only when the sprite changes it's facing direction.
This method doesn't need an additional buffer.
The sprite data is stored normally.
It should be good in cases when the sprite seldom changes the direction it is facing.
Maybe when the direction of the sprite's standing pose changes only after a jump then the sprite data for the standing animation could be reversed during the jumping animation...
The code is written for sprites with even width but can be modified to work with odd widths too...
Here there's a byte pair in the middle and for the odd version there would be a single byte to reverse.
The values to add to hl and de to get to the next line of the sprite data would slightly change too.
The lookup table at the end is for 16-color mode pixels.
flip_sprite:
ld b,reverse_table/256 ;; bc is used for accessing the reversed byte values
ld de,sprite_data+sprite_width_in_bytes-1 ;; de = address of the end of the first sprite data line
ld hl,sprite_data ;; hl = address of the sprite data
exx
ld b,sprite_height
flip_line_loop:
exx
ld a,(de) ;; get left byte
ld c,a ;;
ld a,(bc) ;; reverse left byte
ex af,af'
ld c,(hl) ;; get right byte
ld a,(bc) ;; reverse it
ld (de),a ;; store it on the left side of the sprite data line
ex af,af'
ld (hl),a ;; store the left byte on the right side of the sprite data line
dec e ;; here I assume that the sprite data is aligned (not necessarily page aligned)
inc l ;;
;; repeat the part above k = (sprite_width_in_bytes / 2 - 1 ) times
[...]
;; for the last pair of bytes in the line loop we can drop the dec/inc part:
ld a,(de)
ld c,a
ld a,(bc)
ex af,af'
ld c,(hl)
ld a,(bc)
ld (de),a
ex af,af'
ld (hl),a
;; get to the next sprite data line
ld a,l
add a,sprite_width_in_bytes/2+1
ld l,a
adc a,h
sub l
ld h,a
ld a,e
add a,3*sprite_width_in_bytes/2-1
ld e,a
adc a,d
sub e
ld d,a
exx
djnz flip_line_loop
exx
ret
org ($/256+1)*256
reverse_table:
db $00,$02,$01,$03,$08,$0A,$09,$0B,$04,$06,$05,$07,$0C,$0E,$0D,$0F
db $20,$22,$21,$23,$28,$2A,$29,$2B,$24,$26,$25,$27,$2C,$2E,$2D,$2F
db $10,$12,$11,$13,$18,$1A,$19,$1B,$14,$16,$15,$17,$1C,$1E,$1D,$1F
db $30,$32,$31,$33,$38,$3A,$39,$3B,$34,$36,$35,$37,$3C,$3E,$3D,$3F
db $80,$82,$81,$83,$88,$8A,$89,$8B,$84,$86,$85,$87,$8C,$8E,$8D,$8F
db $A0,$A2,$A1,$A3,$A8,$AA,$A9,$AB,$A4,$A6,$A5,$A7,$AC,$AE,$AD,$AF
db $90,$92,$91,$93,$98,$9A,$99,$9B,$94,$96,$95,$97,$9C,$9E,$9D,$9F
db $B0,$B2,$B1,$B3,$B8,$BA,$B9,$BB,$B4,$B6,$B5,$B7,$BC,$BE,$BD,$BF
db $40,$42,$41,$43,$48,$4A,$49,$4B,$44,$46,$45,$47,$4C,$4E,$4D,$4F
db $60,$62,$61,$63,$68,$6A,$69,$6B,$64,$66,$65,$67,$6C,$6E,$6D,$6F
db $50,$52,$51,$53,$58,$5A,$59,$5B,$54,$56,$55,$57,$5C,$5E,$5D,$5F
db $70,$72,$71,$73,$78,$7A,$79,$7B,$74,$76,$75,$77,$7C,$7E,$7D,$7F
db $C0,$C2,$C1,$C3,$C8,$CA,$C9,$CB,$C4,$C6,$C5,$C7,$CC,$CE,$CD,$CF
db $E0,$E2,$E1,$E3,$E8,$EA,$E9,$EB,$E4,$E6,$E5,$E7,$EC,$EE,$ED,$EF
db $D0,$D2,$D1,$D3,$D8,$DA,$D9,$DB,$D4,$D6,$D5,$D7,$DC,$DE,$DD,$DF
db $F0,$F2,$F1,$F3,$F8,$FA,$F9,$FB,$F4,$F6,$F5,$F7,$FC,$FE,$FD,$FF
Other methods will follow as I have to adapt the examples for the Enterprise...
EDIT: added a working example...