![]() |
Routines |
| Prev: 54806 | Up: Map | Next: 55153 |
|
Used by the routines at GoldfishGame_UpdatePlayer and Handler_SeaCreatures.
Copies the blank tiles from Graphics_MaskSprite into Working_Shift_Buffer, bit-rotates the sprite into that buffer by its sub-cell offsets, then prints the result. Clone used in the main game is at PrintShiftedSprite.
|
||||||||
|
Clear the working shift buffer to blank tiles.
|
||||||||
| GoldfishGame_PrintShiftedSprite | 54855 | LD DE,41196 | Copy 128 blank tiles from Graphics_MaskSprite to Working_Shift_Buffer. | |||||
| 54858 | LD HL,41068 | |||||||
| 54861 | LD BC,128 | |||||||
| 54864 | LDIR | |||||||
|
Set the print colour and keep the current character set.
|
||||||||
| 54866 | LD A,16 | Set INK from the sprite attribute. | ||||||
| 54868 | RST 16 | |||||||
| 54869 | LD A,(IX+9) | |||||||
| 54872 | RST 16 | |||||||
| 54873 | LD HL,(23606) | HL=*CHARS. | ||||||
| 54876 | PUSH HL | Stash the character set, IY and the sprite slot on the stack. | ||||||
| 54877 | PUSH IY | |||||||
| 54879 | PUSH IX | |||||||
|
Point HL at this frame's source UDGs.
|
||||||||
| 54881 | LD E,(IX+6) | DE=the sprite frame ID*8. | ||||||
| 54884 | LD D,0 | |||||||
| 54886 | SLA E | |||||||
| 54888 | RL D | |||||||
| 54890 | SLA E | |||||||
| 54892 | RL D | |||||||
| 54894 | SLA E | |||||||
| 54896 | RL D | |||||||
| 54898 | ADD HL,DE | Add that offset to the current character set. | ||||||
|
Count how many bit-pairs to rotate (horizontal offset+1).
|
||||||||
| 54899 | LD B,(IX+2) | Write the pixel-shift count to *GoldfishGame_SpriteShiftWork. | ||||||
| 54902 | INC B | |||||||
| 54903 | LD C,0 | |||||||
| 54905 | LD (56120),BC | |||||||
|
Fetch the sprite size.
|
||||||||
| 54909 | LD E,(IX+7) | E=the sprite width. | ||||||
| 54912 | LD D,(IX+8) | D=the sprite height. | ||||||
|
Point IY one character column beyond the sprite so the bits rotated out of the current column land in the next one.
|
||||||||
| 54915 | LD A,D | Point IY at the overflow column in the shift buffer. | ||||||
| 54916 | INC A | |||||||
| 54917 | SLA A | |||||||
| 54919 | SLA A | |||||||
| 54921 | SLA A | |||||||
| 54923 | LD C,A | |||||||
| 54924 | LD B,0 | |||||||
| 54926 | LD IY,41204 | |||||||
| 54930 | ADD IY,BC | |||||||
|
Byte width of one source pixel-row, for stepping HL.
|
||||||||
| 54932 | LD C,E | Write the source row stride to *GoldfishGame_SpriteRowStride. | ||||||
| 54933 | SLA C | |||||||
| 54935 | SLA C | |||||||
| 54937 | SLA C | |||||||
| 54939 | LD B,0 | |||||||
| 54941 | LD (56118),BC | |||||||
| 54945 | LD IX,41204 | IX=Working_Shift_Output. | ||||||
|
For each source column, rotate 8 pixel rows into the current and next buffer columns.
|
||||||||
| GoldfishGame_PrintShiftedSprite_ColumnLoop | 54949 | PUSH HL | Stash the source-column pointer and the remaining size on the stack. | |||||
| 54950 | PUSH DE | |||||||
| GoldfishGame_PrintShiftedSprite_RowLoop | 54951 | PUSH HL | Stash the source pointer on the stack. | |||||
| 54952 | LD B,8 | B=8 (pixel rows). | ||||||
| GoldfishGame_PrintShiftedSprite_CopyLoop | 54954 | PUSH BC | Stash the pixel-row counter on the stack. | |||||
| 54955 | LD A,(HL) | Fetch the source byte and the pixel-shift count. | ||||||
| 54956 | LD BC,(56120) | |||||||
|
Rotate two pixels per pass into the overflow byte.
|
||||||||
| GoldfishGame_PrintShiftedSprite_ShiftLoop | 54960 | SLA A | Shift two pixels from the source byte into the overflow byte. | |||||
| 54962 | RL C | |||||||
| 54964 | SLA A | |||||||
| 54966 | RL C | |||||||
| 54968 | DJNZ GoldfishGame_PrintShiftedSprite_ShiftLoop | Decrease the shift count and loop back to GoldfishGame_PrintShiftedSprite_ShiftLoop until the rotation is complete. | ||||||
| 54970 | LD (IY+0),A | Write the overflow pixels to the next column. | ||||||
| 54973 | LD A,C | Merge the shifted pixels into the current column. | ||||||
| 54974 | OR (IX+0) | |||||||
| 54977 | LD (IX+0),A | |||||||
| 54980 | INC HL | Advance the source and both column pointers. | ||||||
| 54981 | INC IX | |||||||
| 54983 | INC IY | |||||||
| 54985 | POP BC | Restore the pixel-row counter from the stack. | ||||||
| 54986 | DJNZ GoldfishGame_PrintShiftedSprite_CopyLoop | Decrease the pixel-row counter and loop back to GoldfishGame_PrintShiftedSprite_CopyLoop until all 8 rows are copied. | ||||||
| 54988 | POP HL | Restore the source pointer from the stack. | ||||||
| 54989 | LD BC,(56118) | Advance it by one sprite row and loop back to GoldfishGame_PrintShiftedSprite_RowLoop until every character row is done. | ||||||
| 54993 | ADD HL,BC | |||||||
| 54994 | DEC D | |||||||
| 54995 | JR NZ,GoldfishGame_PrintShiftedSprite_RowLoop | |||||||
| 54997 | POP DE | Restore the remaining size from the stack. | ||||||
| 54998 | LD BC,8 | Step both buffer pointers on to the next character column. | ||||||
| 55001 | ADD IX,BC | |||||||
| 55003 | ADD IY,BC | |||||||
| 55005 | POP HL | Restore the source-column pointer from the stack. | ||||||
| 55006 | ADD HL,BC | Step it on and loop back to GoldfishGame_PrintShiftedSprite_ColumnLoop until every column is done. | ||||||
| 55007 | DEC E | |||||||
| 55008 | JR NZ,GoldfishGame_PrintShiftedSprite_ColumnLoop | |||||||
|
Character 32 is 256 bytes after Graphics_GoldfishGamePlayer, which lands on Working_Shift_Buffer. Add twice the vertical offset plus 2 so printing starts on the correct scanline.
|
||||||||
| 55010 | LD HL,40940 | HL=Graphics_GoldfishGamePlayer. | ||||||
| 55013 | POP IX | Restore the sprite slot from the stack. | ||||||
| 55015 | LD A,(IX+3) | Point the character set at the working buffer, offset by the vertical sub-cell position. | ||||||
| 55018 | INC A | |||||||
| 55019 | SLA A | |||||||
| 55021 | LD E,A | |||||||
| 55022 | LD D,0 | |||||||
| 55024 | ADD HL,DE | |||||||
| 55025 | LD (23606),HL | |||||||
|
Print one extra column or row unless the sprite is already on the last sub-cell (3).
|
||||||||
| 55028 | LD D,(IX+8) | DE=the sprite height and width. | ||||||
| 55031 | LD E,(IX+7) | |||||||
| 55034 | LD A,(IX+2) | Jump to GoldfishGame_PrintShiftedSprite_AdjustRow if the horizontal offset is already 3. | ||||||
| 55037 | CP 3 | |||||||
| 55039 | JR Z,GoldfishGame_PrintShiftedSprite_AdjustRow | |||||||
| 55041 | INC E | Add one extra printed column. | ||||||
| GoldfishGame_PrintShiftedSprite_AdjustRow | 55042 | INC D | Add one extra printed row. | |||||
| 55043 | LD A,D | Store the tile-to-tile character step in *GoldfishGame_SpriteShiftWork. | ||||||
| 55044 | LD (56120),A | |||||||
| 55047 | LD A,3 | Jump to GoldfishGame_PrintShiftedSprite_LoadHeight if the vertical offset is not 3. | ||||||
| 55049 | CP (IX+3) | |||||||
| 55052 | JR NZ,GoldfishGame_PrintShiftedSprite_LoadHeight | |||||||
| 55054 | DEC D | Keep the original printed height (no extra row). | ||||||
| GoldfishGame_PrintShiftedSprite_LoadHeight | 55055 | LD B,(IX+1) | BC=the sprite row and column. | |||||
| 55058 | LD C,(IX+0) | |||||||
| 55061 | LD A,D | This load is unused; the next instruction overwrites A. | ||||||
| 55062 | LD A,32 | A=32 (first shifted-buffer character). | ||||||
| 55064 | POP IY | Restore IY from the stack. | ||||||
| 55066 | LD A,32 | A=32 (first shifted-buffer character). | ||||||
|
Print the shifted buffer row by row.
|
||||||||
| GoldfishGame_PrintShiftedSprite_PrintRow | 55068 | PUSH AF | Stash the character code, remaining size and print position on the stack. | |||||
| 55069 | PUSH DE | |||||||
| 55070 | PUSH BC | |||||||
| 55071 | LD D,A | D=the starting character code. | ||||||
| 55072 | LD A,C | Jump to GoldfishGame_PrintShiftedSprite_NextRow if the print column is off the left of the screen. | ||||||
| 55073 | CP 34 | |||||||
| 55075 | JR NC,GoldfishGame_PrintShiftedSprite_NextRow | |||||||
| GoldfishGame_PrintShiftedSprite_PrintTile | 55077 | PUSH DE | Stash the character code and remaining width on the stack. | |||||
|
Set the co-ordinates of where we're going to PRINT AT.
|
||||||||
| 55078 | CALL 3545 | Call CL_SET. | ||||||
| 55081 | POP DE | Restore the character code, remaining width and print position from the stack. | ||||||
| 55082 | POP BC | |||||||
| 55083 | PUSH BC | Stash the print position on the stack. | ||||||
| 55084 | LD A,D | A=the character code. | ||||||
| GoldfishGame_PrintShiftedSprite_PrintTileLoop | 55085 | CALL GoldfishGame_PrintColourUDG | Print this colour UDG using GoldfishGame_PrintColourUDG. | |||||
| 55088 | LD A,C | Call GoldfishGame_PrintShiftedSprite_SkipColumn if the print column is the right-edge column (2). | ||||||
| 55089 | CP 2 | |||||||
| 55091 | CALL Z,GoldfishGame_PrintShiftedSprite_SkipColumn | |||||||
| 55094 | DEC C | Move one column right. | ||||||
| 55095 | LD A,(56120) | Advance the character code by one printed column. | ||||||
| 55098 | ADD A,D | |||||||
| 55099 | LD D,A | |||||||
| 55100 | DEC E | Decrease the remaining width and loop back to GoldfishGame_PrintShiftedSprite_PrintTileLoop until this row is done. | ||||||
| 55101 | JR NZ,GoldfishGame_PrintShiftedSprite_PrintTileLoop | |||||||
| 55103 | POP BC | Restore the print position, remaining size and character code from the stack. | ||||||
| 55104 | POP DE | |||||||
| 55105 | POP AF | |||||||
| 55106 | DEC B | Move one row down. | ||||||
| 55107 | INC A | Advance the starting character code. | ||||||
| 55108 | DEC D | Decrease the remaining printed height and loop back to GoldfishGame_PrintShiftedSprite_PrintRow until every row is printed. | ||||||
| 55109 | JR NZ,GoldfishGame_PrintShiftedSprite_PrintRow | |||||||
|
Restore the original character set and return.
|
||||||||
| GoldfishGame_PrintShiftedSprite_RestoreSource | 55111 | POP HL | Restore the original character set pointer from the stack. | |||||
| 55112 | LD (23606),HL | Write it back to *CHARS. | ||||||
| 55115 | RET | Return. | ||||||
|
The print column has reached the right-hand screen edge; skip the rest of this row.
|
||||||||
| GoldfishGame_PrintShiftedSprite_SkipColumn | 55116 | DEC E | Return if this was the last tile in the row. | |||||
| 55117 | PUSH AF | |||||||
| 55118 | INC E | |||||||
| 55119 | POP AF | |||||||
| 55120 | RET Z | |||||||
| 55121 | DEC E | Skip one remaining tile and loop back to GoldfishGame_PrintShiftedSprite_SkipColumn. | ||||||
| 55122 | LD A,(56120) | |||||||
| 55125 | ADD A,D | |||||||
| 55126 | LD D,A | |||||||
| 55127 | JR GoldfishGame_PrintShiftedSprite_SkipColumn | |||||||
|
The print column is off the left of the screen; skip tiles until it is back on-screen.
|
||||||||
| GoldfishGame_PrintShiftedSprite_NextRow | 55129 | LD A,(56120) | Advance the character code and consume one tile. | |||||
| 55132 | ADD A,D | |||||||
| 55133 | LD D,A | |||||||
| 55134 | DEC E | |||||||
| 55135 | JP Z,GoldfishGame_PrintShiftedSprite_RestoreRegisters | Jump to GoldfishGame_PrintShiftedSprite_RestoreRegisters if no tiles remain. | ||||||
| 55138 | DEC C | Move one column right. | ||||||
| 55139 | LD A,C | Jump to GoldfishGame_PrintShiftedSprite_NextRow if the print column is still off the left. | ||||||
| 55140 | CP 34 | |||||||
| 55142 | JR NC,GoldfishGame_PrintShiftedSprite_NextRow | |||||||
| 55144 | JP GoldfishGame_PrintShiftedSprite_PrintTile | Jump to GoldfishGame_PrintShiftedSprite_PrintTile. | ||||||
|
Discard the stacked print state and restore the character set.
|
||||||||
| GoldfishGame_PrintShiftedSprite_RestoreRegisters | 55147 | POP BC | Discard the stacked character code, size and print position. | |||||
| 55148 | POP BC | |||||||
| 55149 | POP BC | |||||||
| 55150 | JP GoldfishGame_PrintShiftedSprite_RestoreSource | Jump to GoldfishGame_PrintShiftedSprite_RestoreSource. | ||||||
| Prev: 54806 | Up: Map | Next: 55153 |