![]() |
Routines |
| Prev: 9531 | Up: Map | Next: 9654 |
|
Write crater tiles into TerrainData_Active under the current actor and redraw them on the screen.
|
||||||||
| StampTerrainTile | 95B6 | CALL ReadTerrainCell | Call ReadTerrainCell. | |||||
| 95B9 | PUSH HL | Stash the cell index on the stack. | ||||||
| 95BA | LD DE,$7000 | DE=TerrainData_Active. | ||||||
| 95BD | EX DE,HL | Switch the DE and HL registers. | ||||||
| 95BE | ADD HL,DE | Point HL at that terrain cell. | ||||||
| 95BF | BIT 3,(HL) | Jump to StampTerrainTile_WriteFirstCell if bit 3 of the tile is reset. | ||||||
| 95C1 | JR Z,StampTerrainTile_WriteFirstCell | |||||||
| 95C3 | LD (HL),$0A | Write 0A to the cell. ![]() |
||||||
| 95C5 | JR StampTerrainTile_Neighbour | Jump to StampTerrainTile_Neighbour. | ||||||
| StampTerrainTile_WriteFirstCell | 95C7 | LD (HL),$08 | Write 08 to the cell. ![]() |
|||||
|
Stamp the neighbouring cell.
|
||||||||
| StampTerrainTile_Neighbour | 95C9 | INC DE | Move onto the next cell. | |||||
| 95CA | LD A,D | Fetch the high byte. | ||||||
| 95CB | AND %00000011 | Keep only bits 0-1. | ||||||
| 95CD | LD D,A | Write it back to D. | ||||||
| 95CE | LD HL,$7000 | HL=TerrainData_Active. | ||||||
| 95D1 | ADD HL,DE | Point HL at that terrain cell. | ||||||
|
Pick the tile for the neighbouring cell: 0A if bit 3 is set, else 09.
|
||||||||
| 95D2 | BIT 3,(HL) | Jump to StampTerrainTile_WriteSecondCell if bit 3 of the tile is reset. | ||||||
| 95D4 | JR Z,StampTerrainTile_WriteSecondCell | |||||||
| 95D6 | LD (HL),$0A | Write 0A to the cell. ![]() |
||||||
| 95D8 | JR StampTerrainTile_Redraw | Jump to StampTerrainTile_Redraw. | ||||||
| StampTerrainTile_WriteSecondCell | 95DA | LD (HL),$09 | Write 09 to the cell. ![]() |
|||||
|
Redraw the stamped columns onto the play area.
|
||||||||
| StampTerrainTile_Redraw | 95DC | CALL ClearTerrainUnderActor | Jump to StampTerrainTile_Restore if ClearTerrainUnderActor returns non-zero. | |||||
| 95DF | JP NZ,StampTerrainTile_Restore | |||||||
| 95E2 | LD A,H | Subtract 08 from the high byte. | ||||||
| 95E3 | SUB $08 | |||||||
| 95E5 | LD H,A | Write it back to H. | ||||||
|
Wrap the cell index and point DE at its terrain cell.
|
||||||||
| 95E6 | EX (SP),HL | Exchange the cell index with the stacked pointer. | ||||||
| 95E7 | LD A,H | Fetch the high byte. | ||||||
| 95E8 | AND %00011111 | Keep only bits 0-4. | ||||||
| 95EA | LD H,A | Write it back to H. | ||||||
| 95EB | LD DE,$7000 | DE=TerrainData_Active. | ||||||
| 95EE | EX DE,HL | Point DE at that terrain cell. | ||||||
| 95EF | ADD HL,DE | |||||||
| 95F0 | EX DE,HL | |||||||
| 95F1 | EX (SP),HL | Exchange the cell index with the stacked pointer. | ||||||
|
Move onto the next screen column if the scroll is on a character boundary.
|
||||||||
| 95F2 | LD A,($607A) | Fetch Jetman_Position. | ||||||
| 95F5 | AND %00000111 | Keep only bits 0-2. | ||||||
| 95F7 | JR NZ,StampTerrainTile_XORColumn | Jump to StampTerrainTile_XORColumn if the scroll is not on a character boundary, else move onto the next screen column. | ||||||
| 95F9 | INC HL | |||||||
|
OR the first graphic column onto the screen.
|
||||||||
| StampTerrainTile_XORColumn | 95FA | PUSH HL | Stash the screen pointer on the stack. | |||||
| 95FB | LD A,(DE) | Fetch the tile index from *DE into HL. | ||||||
| 95FC | LD L,A | |||||||
| 95FD | LD H,$00 | |||||||
| 95FF | LD DE,$F66E | DE=TerrainUDGs. | ||||||
| 9602 | ADD HL,HL | Multiply the tile index by 08 and add the graphic base. | ||||||
| 9603 | ADD HL,HL | |||||||
| 9604 | ADD HL,HL | |||||||
| 9605 | ADD HL,DE | |||||||
| 9606 | EX DE,HL | Point DE at that graphic. | ||||||
|
Work out the pixel shift from the scroll position.
|
||||||||
| 9607 | EXX | Switch to the shadow registers. | ||||||
| 9608 | LD A,($607A) | Fetch Jetman_Position. | ||||||
| 960B | NEG | Negate the low byte. | ||||||
| 960D | AND %00000111 | Keep only bits 0-2. | ||||||
| 960F | LD C,A | Store the pixel shift in C. | ||||||
| 9610 | EXX | Switch back to the main registers. | ||||||
| 9611 | POP HL | Restore the screen pointer from the stack, but stash a copy of it on the stack again. | ||||||
| 9612 | PUSH HL | |||||||
| 9613 | LD B,$08 | Set a pixel row counter in B for 08 loops. | ||||||
| 9615 | CALL StampTerrainTile_Loop | Call StampTerrainTile_Loop. | ||||||
|
Fetch the next terrain cell's graphic and draw it in the next screen column.
|
||||||||
| 9618 | POP HL | Restore the screen pointer from the stack. | ||||||
| 9619 | EX (SP),HL | Exchange it with the stacked cell index. | ||||||
| 961A | INC HL | Move onto the next cell. | ||||||
| 961B | LD A,H | Fetch the high byte. | ||||||
| 961C | AND %00000011 | Keep only bits 0-1. | ||||||
| 961E | LD H,A | Write it back to H. | ||||||
|
Look up the graphic for that cell.
|
||||||||
| 961F | LD DE,$7000 | DE=TerrainData_Active. | ||||||
| 9622 | ADD HL,DE | Point HL at that terrain cell. | ||||||
| 9623 | LD L,(HL) | Fetch the tile index from *HL into HL. | ||||||
| 9624 | LD H,$00 | |||||||
| 9626 | ADD HL,HL | Multiply the tile index by 08. | ||||||
| 9627 | ADD HL,HL | |||||||
| 9628 | ADD HL,HL | |||||||
| 9629 | LD DE,$F66E | DE=TerrainUDGs. | ||||||
| 962C | ADD HL,DE | Point DE at that graphic. | ||||||
| 962D | EX DE,HL | |||||||
|
Aim at the next screen column and reset the row counter.
|
||||||||
| 962E | POP HL | Restore the screen pointer from the stack. | ||||||
| 962F | INC L | Move onto the next screen column. | ||||||
| 9630 | LD B,$08 | Set a pixel row counter in B for 08 loops. | ||||||
|
Shift a graphic byte by the scroll and OR it onto two neighbouring screen bytes.
|
||||||||
| StampTerrainTile_Loop | 9632 | LD A,(DE) | Fetch the graphic byte. | |||||
| 9633 | EXX | Switch to the shadow registers. | ||||||
| 9634 | LD H,A | Store it in H and clear L. | ||||||
| 9635 | LD L,$00 | |||||||
| 9637 | LD B,C | B=the pixel shift. | ||||||
| 9638 | LD A,C | Jump to StampTerrainTile_MergeBytes if there is no shift. | ||||||
| 9639 | AND A | |||||||
| 963A | JR Z,StampTerrainTile_MergeBytes | |||||||
| StampTerrainTile_ShiftPixel | 963C | SRL H | Shift the graphic right by one pixel. | |||||
| 963E | RR L | |||||||
| 9640 | DJNZ StampTerrainTile_ShiftPixel | Decrease the shift counter by one and loop back to StampTerrainTile_ShiftPixel until the shift is done. | ||||||
|
OR the shifted graphic onto the two screen bytes.
|
||||||||
| StampTerrainTile_MergeBytes | 9642 | LD A,L | Stash the low byte and fetch the high byte. | |||||
| 9643 | EX AF,AF' | |||||||
| 9644 | LD A,H | |||||||
| 9645 | EXX | Switch back to the main registers. | ||||||
| 9646 | OR (HL) | Merge the high byte onto the current screen byte. | ||||||
| 9647 | LD (HL),A | |||||||
| 9648 | INC L | |||||||
| 9649 | EX AF,AF' | Fetch the stashed low byte. | ||||||
| 964A | OR (HL) | Merge the low byte onto the next screen byte. | ||||||
| 964B | LD (HL),A | |||||||
| 964C | INC DE | Move onto the next graphic byte. | ||||||
| 964D | DEC L | Step back and down one pixel row. | ||||||
| 964E | INC H | |||||||
| 964F | DJNZ StampTerrainTile_Loop | Decrease the row counter by one and loop back to StampTerrainTile_Loop until the column is drawn. | ||||||
| 9651 | RET | Return. | ||||||
| StampTerrainTile_Restore | 9652 | POP HL | Restore the cell index from the stack. | |||||
| 9653 | RET | Return. | ||||||
| Prev: 9531 | Up: Map | Next: 9654 |