![]() |
Routines |
| Prev: 37694 | Up: Map | Next: 37781 |
|
Redraw the whole strip of moon surface along the bottom of the screen for the current scroll position, then colour the row of ground beneath it.
Jetman always stands at pixel column 120 so the left-hand edge of the screen is 120 pixels behind his world X in Jetman_Position. That is divided by 8 to find the terrain cell at the left edge, as the world is 8192 pixels wide and TerrainData_Active holds one cell for every 8 of them (1024 cells), wrapping round at the far end. The 32 cells from there are drawn side by side along character row 22.
|
||||
|
Work out which terrain cell sits at the left-hand edge of the screen.
|
||||
| DrawTerrain | 37718 | LD HL,(24698) | Fetch Jetman's world X from Jetman_Position. | |
| DrawTerrain_Target | 37721 | LD DE,65416 | DE=65416 (minus 120). | |
| 37724 | ADD HL,DE | Subtract 120 to find the world X of the left-hand edge of the screen. | ||
|
The world is 8192 pixels wide, so wrap anything left of its start back round to the far end.
|
||||
| 37725 | LD A,H | A=H. | ||
| 37726 | AND %00011111 | Keep only bits 0-4 so the position wraps round the world. | ||
| 37728 | LD H,A | H=A. | ||
| 37729 | SRA H | Divide the world X by 8 to give the terrain cell index. | ||
| 37731 | RR L | |||
| 37733 | SRA H | |||
| 37735 | RR L | |||
| 37737 | SRA H | |||
| 37739 | RR L | |||
|
Start at the left-hand end of the terrain row on the screen.
|
||||
| 37741 | LD DE,20672 | Set the screen address to 20672 (the start of character row 22). | ||
| 37744 | LD BC,28672 | Set the terrain base in BC to TerrainData_Active. | ||
| 37747 | LD A,32 | Set a column counter in A for 32 loops. | ||
|
Draw the graphic for one terrain cell.
|
||||
| DrawTerrain_Loop | 37749 | PUSH AF | Stash the counter and the cell index on the stack. | |
| 37750 | PUSH HL | |||
| 37751 | ADD HL,BC | Add the terrain base to get the address of the cell. | ||
| 37752 | PUSH BC | Stash the terrain base and the screen address on the stack. | ||
| 37753 | PUSH DE | |||
| 37754 | CALL DrawTerrainColumn | Call DrawTerrainColumn to copy the cell graphic onto the screen. | ||
| 37757 | POP DE | Restore the screen address from the stack. | ||
| 37758 | INC E | Move along to the next screen column. | ||
| 37759 | POP BC | Restore the terrain base and the cell index from the stack. | ||
| 37760 | POP HL | |||
|
Step on to the next terrain cell, wrapping round at the end of the world, and loop until every column is drawn.
|
||||
| 37761 | INC HL | Move onto the next cell index. | ||
| 37762 | LD A,H | A=H. | ||
| 37763 | AND %00000011 | Keep only bits 0-1 so the index wraps round after 1024 cells. | ||
| 37765 | LD H,A | H=A. | ||
| 37766 | POP AF | Restore the counter from the stack. | ||
| 37767 | DEC A | Decrease the column counter by one. | ||
| 37768 | JR NZ,DrawTerrain_Loop | Jump back to DrawTerrain_Loop until all 32 columns are drawn. | ||
|
Colour the ground beneath the terrain; the black border columns at either edge of the window are left alone.
|
||||
| 37770 | LD HL,23265 | Set the attribute pointer to 23265 (the second column of the bottom row). | ||
| 37773 | LD BC,7771 | Set a column counter in B for 30 loops and the ground colour in C to INK:MAGENTA, PAPER:MAGENTA (BRIGHT). | ||
| DrawTerrain_WriteByte | 37776 | LD (HL),C | Write the ground colour to the attribute buffer. | |
| 37777 | INC HL | Move onto the next column. | ||
| 37778 | DJNZ DrawTerrain_WriteByte | Decrease the column counter by one and loop back to DrawTerrain_WriteByte until the ground is coloured. | ||
| 37780 | RET | Return. | ||
| Prev: 37694 | Up: Map | Next: 37781 |