![]() |
Routines |
| Prev: 49363 | Up: Map | Next: 49567 |
|
Used by the routine at InitialiseGame.
Called every frame. In the town, it draws the walls and the objects of the cells which are around the sheriff, in an order which is chosen so that the cells nearer the viewer are drawn after the ones behind them. The order depends on which of five of the cells next to the sheriff's cell have buildings in them, and is taken from five-byte entries in a table at DrawingOrders. Each of the five bytes holds the offset of a cell from the sheriff's cell (bits 4 and 5 for the offset in the column, bits 6 and 7 for the offset in the row) and a kind of drawing to do in it (bits 0 and 1): 0 draws the objects in the cell, 1 draws the walls and 2 draws the edges. The sheriff's cell and three of its neighbours are drawn last. The town is a map of sixteen cells by sixteen, and when the view is rotated the cell numbers are turned round.
|
|||||
|
Return if this is not the town.
|
|||||
| DrawTown | 49400 | LD A,(41575) | Fetch TownOffset. | ||
| 49403 | AND A | Return if it is not. | |||
| 49404 | RET Z | ||||
|
The walls are not drawn on columns of the screen which already have a wall in them. The sixteen flags at ColumnFlags cover columns of sixteen pixels. The left sixteen pixels and the right forty eight sit outside the play area, so they are marked as done.
|
|||||
| 49405 | LD HL,57345 | Set ColumnFlags. | |||
| 49408 | LD (41544),HL | ||||
|
Fetch the sheriff's cell.
|
|||||
| 49411 | LD A,(41599) | Fetch the horizontal cell of the sheriff from 41599 and keep it in L. | |||
| 49414 | LD L,A | ||||
| 49415 | LD A,(41601) | Fetch the vertical cell of the sheriff from 41601 and keep it in H. | |||
| 49418 | LD H,A | ||||
|
Turn the cell round if the view is rotated.
|
|||||
| 49419 | CALL ConvertCell | Call ConvertCell. | |||
| 49422 | PUSH HL | Stash the cell of the sheriff on the stack. | |||
| 49423 | LD E,0 | Clear the flags for the neighbouring cells. | |||
|
Find out which of five neighbouring cells have something in them. Taking the column and row of the sheriff's cell as x and y, they are the cells (x-1, y+1), (x-1, y), (x, y+1), (x-1, y-1) and (x+1, y+1).
|
|||||
| 49425 | DEC L | Take one off the column... | |||
| 49426 | INC H | ...and add one to the row. | |||
|
Find the contents of the cell.
|
|||||
| 49427 | CALL GetMapCell | Call GetMapCell. | |||
| 49430 | JR Z,DrawTown_TestSecondCell | Jump to DrawTown_TestSecondCell if it is empty. | |||
| 49432 | SET 0,E | Set the bit for the first cell. | |||
|
Test the cell at (x-1, y).
|
|||||
| DrawTown_TestSecondCell | 49434 | POP HL | Restore the cell of the sheriff from the stack. | ||
| 49435 | PUSH HL | Stash the cell of the sheriff on the stack. | |||
| 49436 | DEC L | Take one off the column. | |||
|
Find the contents of the cell.
|
|||||
| 49437 | CALL GetMapCell | Call GetMapCell. | |||
| 49440 | JR Z,DrawTown_TestThirdCell | Jump to DrawTown_TestThirdCell if it is empty. | |||
| 49442 | SET 1,E | Set the bit for the second cell. | |||
|
Test the cell at (x, y+1).
|
|||||
| DrawTown_TestThirdCell | 49444 | POP HL | Restore the cell of the sheriff from the stack. | ||
| 49445 | PUSH HL | Stash the cell of the sheriff on the stack. | |||
| 49446 | INC H | Add one to the row. | |||
|
Find the contents of the cell.
|
|||||
| 49447 | CALL GetMapCell | Call GetMapCell. | |||
| 49450 | JR Z,DrawTown_TestFourthCell | Jump to DrawTown_TestFourthCell if it is empty. | |||
| 49452 | SET 2,E | Set the bit for the third cell. | |||
|
Test the cell at (x-1, y-1).
|
|||||
| DrawTown_TestFourthCell | 49454 | POP HL | Restore the cell of the sheriff from the stack. | ||
| 49455 | PUSH HL | Stash the cell of the sheriff on the stack. | |||
| 49456 | DEC L | Take one off the column... | |||
| 49457 | DEC H | ...and take one off the row. | |||
|
Find the contents of the cell.
|
|||||
| 49458 | CALL GetMapCell | Call GetMapCell. | |||
| 49461 | JR Z,DrawTown_TestFifthCell | Jump to DrawTown_TestFifthCell if it is empty. | |||
| 49463 | SET 3,E | Set the bit for the fourth cell. | |||
|
Test the cell at (x+1, y+1).
|
|||||
| DrawTown_TestFifthCell | 49465 | POP HL | Restore the cell of the sheriff from the stack. | ||
| 49466 | PUSH HL | Stash the cell of the sheriff on the stack. | |||
| 49467 | INC L | Add one to the column... | |||
| 49468 | INC H | ...and add one to the row. | |||
|
Find the contents of the cell.
|
|||||
| 49469 | CALL GetMapCell | Call GetMapCell. | |||
| 49472 | JR Z,DrawTown_FindEntry | Jump to DrawTown_FindEntry if it is empty. | |||
| 49474 | SET 4,E | Set the bit for the fifth cell. | |||
|
Point at the entry in the table of five bytes for the cells which have been found.
|
|||||
| DrawTown_FindEntry | 49476 | LD D,0 | Clear D. | ||
| 49478 | LD A,E | Fetch the flags for the cells. | |||
| 49479 | EX DE,HL | Move the flags into HL. | |||
| 49480 | LD E,L | Copy them into DE. | |||
| 49481 | LD D,H | ||||
| 49482 | ADD HL,HL | Multiply them by four. | |||
| 49483 | ADD HL,HL | ||||
| 49484 | ADD HL,DE | Add them again, to make five times. | |||
| 49485 | LD DE,24753 | Point DE at DrawingOrders. | |||
| 49488 | ADD HL,DE | Point HL at the entry. | |||
| 49489 | EX DE,HL | Keep the address of the entry in DE. | |||
| 49490 | LD B,5 | Set the number of bytes to five. | |||
|
Draw the next cell from the entry.
|
|||||
| DrawTown_NextCell | 49492 | POP HL | Restore the cell of the sheriff from the stack. | ||
| 49493 | PUSH HL | Stash the cell of the sheriff on the stack. | |||
| 49494 | LD A,(DE) | Fetch the byte from the entry. | |||
| 49495 | INC DE | Move on to the next byte. | |||
| 49496 | BIT 5,A | Jump to DrawTown_TestRow if the cell is in the same column as the sheriff. | |||
| 49498 | JR NZ,DrawTown_TestRow | ||||
| 49500 | BIT 4,A | Jump to DrawTown_ColumnOffset if this is not the next column. | |||
| 49502 | JR Z,DrawTown_ColumnOffset | ||||
| 49504 | INC L | Add two to the column. | |||
| 49505 | INC L | ||||
| DrawTown_ColumnOffset | 49506 | DEC L | Take one off the column, to make it one lower or one higher. | ||
| DrawTown_TestRow | 49507 | BIT 7,A | Jump to DrawTown_KeepKind if the cell is in the same row as the sheriff. | ||
| 49509 | JR NZ,DrawTown_KeepKind | ||||
| 49511 | BIT 6,A | Jump to DrawTown_RowOffset if this is not the next row. | |||
| 49513 | JR Z,DrawTown_RowOffset | ||||
| 49515 | INC H | Add two to the row. | |||
| 49516 | INC H | ||||
| DrawTown_RowOffset | 49517 | DEC H | Take one off the row, to make it one lower or one higher. | ||
|
Choose what to draw in the cell.
|
|||||
| DrawTown_KeepKind | 49518 | AND %00000011 | Keep the kind of drawing. | ||
| 49520 | PUSH BC | Stash the number of bytes left and the address in the entry on the stack. | |||
| 49521 | PUSH DE | ||||
|
Make the draw routine return to DrawTown_AfterDraw.
|
|||||
| 49522 | LD DE,49538 | Point DE at DrawTown_AfterDraw. | |||
| 49525 | PUSH DE | Stash it on the stack. | |||
|
Draw the objects in the cell if the kind is zero.
|
|||||
| 49526 | JP Z,DrawCellObjects | Jump to DrawCellObjects if it is. | |||
| 49529 | DEC A | Take one off the kind. | |||
|
Draw the walls of the cell if the kind is one.
|
|||||
| 49530 | JP Z,DrawCellWithWalls | Jump to DrawCellWithWalls if it is. | |||
| 49533 | DEC A | Take one off the kind. | |||
|
Draw the edges of the cell if the kind is two.
|
|||||
| 49534 | JP Z,DrawCell | Jump to DrawCell if it is. | |||
|
The kind is three, which is nothing.
|
|||||
| 49537 | POP DE | Throw away the return address from the stack. | |||
| DrawTown_AfterDraw | 49538 | POP DE | Restore the address in the entry and the number of bytes left from the stack. | ||
| 49539 | POP BC | ||||
|
Go back for the next byte of the entry.
|
|||||
| 49540 | DJNZ DrawTown_NextCell | Jump to DrawTown_NextCell if there are any left. | |||
|
Draw the sheriff's cell and the three cells after it: the cells with the row one lower, the column one higher, and both of those.
|
|||||
| 49542 | POP HL | Restore the cell of the sheriff from the stack. | |||
| 49543 | PUSH HL | Stash the cell of the sheriff on the stack. | |||
|
Draw the edges and the objects in the cell.
|
|||||
| 49544 | CALL DrawCellAndObjects | Call DrawCellAndObjects. | |||
| 49547 | POP HL | Restore the cell of the sheriff from the stack. | |||
| 49548 | PUSH HL | Stash the cell of the sheriff on the stack. | |||
| 49549 | DEC H | Take one off the row. | |||
|
Draw the edges and the objects in the cell.
|
|||||
| 49550 | CALL DrawCellAndObjects | Call DrawCellAndObjects. | |||
| 49553 | POP HL | Restore the cell of the sheriff from the stack. | |||
| 49554 | PUSH HL | Stash the cell of the sheriff on the stack. | |||
| 49555 | INC L | Add one to the column. | |||
|
Draw the edges and the objects in the cell.
|
|||||
| 49556 | CALL DrawCellAndObjects | Call DrawCellAndObjects. | |||
| 49559 | POP HL | Restore the cell of the sheriff from the stack. | |||
| 49560 | INC L | Add one to the column... | |||
| 49561 | DEC H | ...and take one off the row. | |||
|
The last cell goes on into the routine, which returns to the caller.
|
|||||
| DrawCellAndObjects | 49562 | PUSH HL | Stash the cell on the stack. | ||
|
Draw the edges of the cell.
|
|||||
| 49563 | CALL DrawCell | Call DrawCell. | |||
| 49566 | POP HL | Restore the cell from the stack. | |||
|
Continue on to DrawCellObjects.
View the equivalent code in;
|
|||||
| Prev: 49363 | Up: Map | Next: 49567 |