Prev: 9F80 Up: Map Next: 9FCA
9F9F: Work out where a sprite goes, and how far to shift it
Used by the routines at DRAW_THING and REDRAW_MOVED.
Sprites in this family are two bytes wide in the data and land on the screen straddling two or three, because x is a pixel position and not a character column. Rather than keep eight pre-shifted copies of every sprite, the game shifts at draw time -- and rather than loop, it computes where to jump into an unrolled chain of shifts and writes that into the jump itself.
The displacement is 2 * ((x - 1) AND 7), which SHIFT_AND_PLOT's JR turns into "skip this many bytes of the chain". More shifts for a small offset, fewer for a large one. The one case that would need none is redirected to a plot routine that does not shift at all.
Input
IX The thing being drawn
SETUP_SPRITE_DRAW 9F9F CALL SPRITE_OF_ACTOR Its graphics, through SPRITE_TABLE.
This entry point is used by the routines at SETUP_ALT_ENTRIES and SETUP_BOTH_BANKS.
SETUP_AT_POSITION 9FA2 LD L,(IX+$03) Its position.
9FA5 LD H,(IX+$04)
9FA8 LD A,L The low three bits of x, doubled: how far into the shift chain to start.
9FA9 DEC A
9FAA RLCA
9FAB AND $0E
9FAD CP $0E A shift of none is a special case...
9FAF JR NZ,SETUP_SPRITE_DRAW_0
9FB1 LD A,$E8 ...redirected right out of the chain to a plot with no shifting at all.
SETUP_SPRITE_DRAW_0 9FB3 LD ($9F2A),A Write it into the JR at DRAW_JR.
9FB6 LD A,$02 Two bytes of sprite cover three columns unless it lands square.
9FB8 JR Z,SETUP_SPRITE_DRAW_1
9FBA INC A
SETUP_SPRITE_DRAW_1 9FBB LD ($5E10),A How wide to erase and redraw.
9FBE CALL PIXEL_TO_SCREEN
9FC1 LD A,(DE) The first byte of a sprite's data is its height in rows.
9FC2 LD ($5E19),A
9FC5 LD ($5E11),A
9FC8 JR SETUP_DONE
Prev: 9F80 Up: Map Next: 9FCA