![]() |
Routines |
| Prev: 53436 | Up: Map | Next: 53906 |
|
Used by the routine at ScrollWorld.
Draws the terrain of the four tiles that are in view, by running the script of each tile. The number of the tile is kept in TileNumber: bit 0 is set for a tile below the first and bit 1 for a tile to the right. The scripts of the tiles are found from the table at TileScriptPointer. Each tile is a list of segments, and each segment is set up with SetUpSegment and ReadSegmentShapes and then drawn step by step, each step of a segment being a piece of picture. TilesChanged is non-zero when the tiles have changed, and then the routine also makes a record of each segment in the area from GameEntry: a count byte for the tile followed by five bytes for each segment (the position, the size and the code from SegmentCodes), which the routines that move objects use to test for collisions with the terrain. The segments that are not near the position at PositionAcross and PositionDown are not drawn.
|
||||
| DrawTerrain | 53437 | LD A,(23612) | The scroll-in flag. | |
| 53440 | AND A | Jump to DrawTerrain_Tables if A is zero. | ||
| 53441 | JR Z,DrawTerrain_Tables | |||
| 53443 | LD (23613),A | Update the tiles changed. | ||
|
Choose the table of shifted pictures for the horizontal offset, and the offsets table that goes with it.
|
||||
| DrawTerrain_Tables | 53446 | LD A,(52802) | The vertical offset. | |
| 53449 | ADD A,96 | Add 96 to A. | ||
| 53451 | LD (52802),A | Update the vertical offset. | ||
| 53454 | LD DE,52415 | The picture offsets. | ||
| 53457 | LD (52811),DE | Update the picture offsets pointer. | ||
| 53461 | EXX | Switch to the alternate registers. | ||
| 53462 | LD HL,58237 | The shape table shift zero. | ||
| 53465 | LD A,(52801) | The horizontal offset. | ||
| 53468 | AND %00000111 | Keep the bits of A that are set in 7. | ||
| 53470 | JR Z,DrawTerrain_Tile | Jump to DrawTerrain_Tile if the zero flag is set. | ||
| 53472 | EXX | Switch to the alternate registers. | ||
| 53473 | INC DE | Advance DE. | ||
| 53474 | LD (52811),DE | Update the picture offsets pointer. | ||
| 53478 | EXX | Switch to the alternate registers. | ||
| 53479 | LD HL,58045 | The shape table shift two. | ||
| 53482 | CP 2 | Jump to DrawTerrain_Tile if A is 2. | ||
| 53484 | JR Z,DrawTerrain_Tile | |||
| 53486 | LD HL,58109 | The shape table shift four. | ||
| 53489 | CP 4 | Jump to DrawTerrain_Tile if A is 4. | ||
| 53491 | JR Z,DrawTerrain_Tile | |||
| 53493 | LD HL,58173 | The shape table shift six. | ||
|
Run the script of each of the four tiles in turn.
|
||||
| DrawTerrain_Tile | 53496 | LD (52413),HL | Update the shape table pointer. | |
| 53499 | XOR A | Clear A. | ||
| 53500 | LD (23581),A | Update the tile number. | ||
|
This entry point is used by the routine at NextSegment.
|
||||
| DrawTerrain_Record | 53503 | LD IX,23424 | The decryption routine. | |
| 53507 | LD A,(23581) | The tile number. | ||
| 53510 | AND A | Jump to DrawTerrain_Script if A is zero. | ||
| 53511 | JR Z,DrawTerrain_Script | |||
| 53513 | LD IX,23461 | Use 23461. | ||
| 53517 | CP 1 | Jump to DrawTerrain_Script if A is 1. | ||
| 53519 | JR Z,DrawTerrain_Script | |||
| 53521 | LD IX,23498 | Use 23498. | ||
| 53525 | CP 2 | Jump to DrawTerrain_Script if A is 2. | ||
| 53527 | JR Z,DrawTerrain_Script | |||
| 53529 | LD IX,23535 | Use 23535. | ||
|
Read the address of the script of the tile and see if it starts with the prefix bytes that draw it upside down (153) and back to front (255).
|
||||
| DrawTerrain_Script | 53533 | LD HL,(56455) | Fetch the word at TileScriptPointer into HL. | |
| 53536 | LD E,(HL) | Read HL into E. | ||
| 53537 | INC HL | Advance HL. | ||
| 53538 | LD D,(HL) | Read HL into D. | ||
| 53539 | INC HL | Advance HL. | ||
| 53540 | LD (56455),HL | Update the tile script pointer. | ||
| 53543 | EX DE,HL | Swap DE and HL. | ||
| 53544 | XOR A | Clear A. | ||
| 53545 | LD (23600),A | Update the back to front flag. | ||
| 53548 | LD (23590),A | Update the upside down flag. | ||
| 53551 | LD (IX+0),A | Write A to offset 0 of IX. | ||
| 53554 | LD A,(HL) | Read HL. | ||
| 53555 | AND A | Jump to NextSegment_Tile if A is zero. | ||
| 53556 | JP Z,NextSegment_Tile | |||
| 53559 | CP 153 | Jump to DrawTerrain_BackToFront if A is not 153. | ||
| 53561 | JR NZ,DrawTerrain_BackToFront | |||
| 53563 | LD (23590),A | Update the upside down flag. | ||
| 53566 | INC HL | Advance HL. | ||
| DrawTerrain_BackToFront | 53567 | LD A,(HL) | Read HL. | |
| 53568 | CP 255 | Jump to DrawTerrain_Count if A is not 255. | ||
| 53570 | JR NZ,DrawTerrain_Count | |||
| 53572 | LD (23600),A | Update the back to front flag. | ||
| 53575 | INC HL | Advance HL. | ||
| DrawTerrain_Count | 53576 | LD A,(HL) | Read HL. | |
| 53577 | CP 149 | Jump to DrawTerrain_Remember if A is less than 149. | ||
| 53579 | JR C,DrawTerrain_Remember | |||
| 53581 | INC HL | Advance HL. | ||
| 53582 | LD A,(HL) | Read HL. | ||
| DrawTerrain_Remember | 53583 | LD (23584),A | Update the segments still to draw. | |
| 53586 | LD (IX+0),A | Write A to offset 0 of IX. | ||
| 53589 | INC IX | Advance IX. | ||
| 53591 | INC HL | Advance HL. | ||
| 53592 | LD (47625),IX | The segment record. | ||
|
This entry point is used by the routine at NextSegment.
Start a segment: clear the variables, read its position and type from the script and set up its slope and shapes.
|
||||
| DrawTerrain_Segment | 53596 | LD IX,57052 | The segment record. | |
| 53600 | XOR A | Clear A. | ||
| 53601 | LD (23599),A | Update the flagged steps. | ||
| 53604 | LD (52820),A | Update the steps already drawn. | ||
| 53607 | LD (23602),A | Update the last contact flags. | ||
| 53610 | LD (23591),A | Update the shape flag. | ||
| 53613 | LD (23604),A | Update the segment end shape. | ||
| 53616 | LD (23603),A | Update the segment start shape. | ||
| 53619 | LD (23605),A | Update the upside-down segment flag. | ||
| 53622 | LD (52826),A | Update the vertical step copy. | ||
| 53625 | LD (55389),A | Update the edge flag. | ||
| 53628 | LD (IX+1),A | Write A to offset 1 of IX. | ||
| 53631 | LD A,(HL) | Read HL. | ||
| 53632 | LD (52803),A | Update the segment column. | ||
| 53635 | INC HL | Advance HL. | ||
| 53636 | LD A,(HL) | Read HL. | ||
| 53637 | LD (52804),A | Update the segment row. | ||
| 53640 | LD (52796),A | The segment row. | ||
| 53643 | INC HL | Advance HL. | ||
| 53644 | LD A,(HL) | Read HL. | ||
| 53645 | RRCA | Rotate A right. | ||
| 53646 | RRCA | Rotate A right. | ||
| 53647 | RRCA | Rotate A right. | ||
| 53648 | RRCA | Rotate A right. | ||
| 53649 | AND %00001111 | Keep the bits of A that are set in 15. | ||
| 53651 | LD (IX+3),A | Write A to offset 3 of IX. | ||
| 53654 | EXX | Switch to the alternate registers. | ||
| 53655 | CALL SetUpSegment | Call SetUpSegment. | ||
| 53658 | EXX | Switch to the alternate registers. | ||
| 53659 | LD A,(HL) | Read HL. | ||
| 53660 | AND %00001111 | Keep the bits of A that are set in 15. | ||
| 53662 | JR NZ,DrawTerrain_Length | Jump to DrawTerrain_Length if the zero flag is clear. | ||
| 53664 | LD A,16 | A=16. | ||
| DrawTerrain_Length | 53666 | LD (23586),A | Update the segment length. | |
| 53669 | LD C,A | C=A. | ||
| 53670 | INC HL | Advance HL. | ||
| 53671 | CALL ReadSegmentShapes | Call ReadSegmentShapes. | ||
| 53674 | LD HL,52772 | The column phase table. | ||
| 53677 | LD B,(IX+3) | Read offset 3 of IX into B. | ||
| 53680 | EXX | Switch to the alternate registers. | ||
| 53681 | LD IX,(47625) | Fetch the word at 47625 into IX. | ||
|
If the tiles have changed, make the record of the segment.
|
||||
| DrawTerrain_Changed | 53685 | LD A,(23613) | The tiles changed. | |
| 53688 | AND A | Jump to DrawTerrain_Test if A is zero. | ||
| 53689 | JP Z,DrawTerrain_Test | |||
| 53692 | LD A,(57055) | The segment type. | ||
| 53695 | LD E,A | E=A. | ||
| 53696 | LD D,0 | Clear D. | ||
| 53698 | LD HL,53420 | The segment codes. | ||
| 53701 | ADD HL,DE | HL gains DE. | ||
| 53702 | LD A,(HL) | Read HL. | ||
| 53703 | LD (IX+4),A | Write A to offset 4 of IX. | ||
| 53706 | LD A,(23586) | The segment length. | ||
| 53709 | LD (IX+2),A | Write A to offset 2 of IX. | ||
| 53712 | LD A,(52803) | The segment column. | ||
| 53715 | LD (IX+0),A | Write A to offset 0 of IX. | ||
| 53718 | LD A,(52804) | The segment row. | ||
| 53721 | LD (IX+1),A | Write A to offset 1 of IX. | ||
| 53724 | LD A,(52791) | The vertical step. | ||
| 53727 | AND A | Jump to DrawTerrain_Sloped if A is not zero. | ||
| 53728 | JR NZ,DrawTerrain_Sloped | |||
| 53730 | LD B,(IX+2) | Read offset 2 of IX into B. | ||
| 53733 | XOR A | Clear A. | ||
| DrawTerrain_FlatWidth | 53734 | ADD A,24 | Add 24 to A. | |
| 53736 | DJNZ DrawTerrain_FlatWidth | Decrease B and jump to DrawTerrain_FlatWidth until none remain. | ||
| 53738 | LD (IX+2),A | Write A to offset 2 of IX. | ||
| 53741 | LD A,(57055) | The segment type. | ||
| 53744 | CP 7 | Compare A with 7. | ||
| 53746 | LD (IX+3),20 | Store 20 at offset 3 of IX. | ||
| 53750 | JP Z,DrawTerrain_Test | Jump to DrawTerrain_Test if the zero flag is set. | ||
| 53753 | LD A,(IX+1) | Read offset 1 of IX. | ||
| 53756 | ADD A,16 | Add 16 to A. | ||
| 53758 | LD (IX+1),A | Write A to offset 1 of IX. | ||
| 53761 | JP DrawTerrain_Test | Jump to DrawTerrain_Test. | ||
| DrawTerrain_Sloped | 53764 | LD A,(52825) | The horizontal step copy. | |
| 53767 | AND A | Jump to DrawTerrain_Extent if A is not zero. | ||
| 53768 | JR NZ,DrawTerrain_Extent | |||
| 53770 | LD B,(IX+2) | Read offset 2 of IX into B. | ||
| 53773 | XOR A | Clear A. | ||
| DrawTerrain_SlopeWidth | 53774 | ADD A,16 | Add 16 to A. | |
| 53776 | DJNZ DrawTerrain_SlopeWidth | Decrease B and jump to DrawTerrain_SlopeWidth until none remain. | ||
| 53778 | LD B,A | B=A. | ||
| 53779 | LD (IX+2),24 | Store 24 at offset 2 of IX. | ||
| 53783 | LD A,(57055) | The segment type. | ||
| 53786 | LD (IX+3),B | Write B to offset 3 of IX. | ||
| 53789 | CP 15 | Jump to DrawTerrain_Test if A is not 15. | ||
| 53791 | JP NZ,DrawTerrain_Test | |||
| 53794 | LD A,(IX+0) | Read offset 0 of IX. | ||
| 53797 | SUB 16 | Subtract 16 from A. | ||
| 53799 | LD (IX+0),A | Write A to offset 0 of IX. | ||
| 53802 | JP DrawTerrain_Test | Jump to DrawTerrain_Test. | ||
| DrawTerrain_Extent | 53805 | LD A,(58395) | The slope direction. | |
| 53808 | CP 255 | Jump to DrawTerrain_End if A is 255. | ||
| 53810 | JR Z,DrawTerrain_End | |||
| 53812 | LD A,(23589) | The horizontal step size. | ||
| 53815 | ADD A,(IX+0) | Add the byte at offset 0 of IX to A. | ||
| 53818 | LD (IX+0),A | Write A to offset 0 of IX. | ||
| DrawTerrain_End | 53821 | LD B,(IX+2) | Read offset 2 of IX into B. | |
| 53824 | LD D,(IX+0) | Read offset 0 of IX into D. | ||
| 53827 | LD E,(IX+1) | Read offset 1 of IX into E. | ||
| DrawTerrain_ExtentLoop | 53830 | LD A,(52789) | The horizontal step. | |
| 53833 | ADD A,D | A gains D. | ||
| 53834 | LD D,A | D=A. | ||
| 53835 | LD A,(52791) | The vertical step. | ||
| 53838 | NEG | Negate A. | ||
| 53840 | ADD A,E | A gains E. | ||
| 53841 | LD E,A | E=A. | ||
| 53842 | DJNZ DrawTerrain_ExtentLoop | Decrease B and jump to DrawTerrain_ExtentLoop until none remain. | ||
| 53844 | LD (IX+3),E | Write E to offset 3 of IX. | ||
| 53847 | LD (IX+2),D | Write D to offset 2 of IX. | ||
|
Test whether the segment is near the position at PositionAcross and PositionDown, and skip it if it is not.
|
||||
| DrawTerrain_Test | 53850 | LD A,(52805) | The position across. | |
| 53853 | LD B,A | B=A. | ||
| 53854 | LD A,(23581) | The tile number. | ||
| 53857 | BIT 1,A | Jump to DrawTerrain_TestVertical if bit 1 of A is clear. | ||
| 53859 | JR Z,DrawTerrain_TestVertical | |||
| 53861 | CALL TestRightColumn | Call TestRightColumn. | ||
| 53864 | JR DrawTerrain_Vertical | Jump to DrawTerrain_Vertical. | ||
| DrawTerrain_TestVertical | 53866 | CALL TestLeftColumn | Call TestLeftColumn. | |
| DrawTerrain_Vertical | 53869 | JP NZ,DrawTerrain_Skip | Jump to DrawTerrain_Skip if the zero flag is clear. | |
| 53872 | LD A,(52806) | The position down. | ||
| 53875 | LD B,A | B=A. | ||
| 53876 | LD A,(23581) | The tile number. | ||
| 53879 | BIT 0,A | Jump to DrawTerrain_Top if bit 0 of A is clear. | ||
| 53881 | JR Z,DrawTerrain_Top | |||
| 53883 | CALL TestBottomRow | Call TestBottomRow. | ||
| 53886 | JR DrawTerrain_Near | Jump to DrawTerrain_Near. | ||
| DrawTerrain_Top | 53888 | CALL TestTopRow | Call TestTopRow. | |
| DrawTerrain_Near | 53891 | JP NZ,DrawTerrain_Skip | Jump to DrawTerrain_Skip if the zero flag is clear. | |
| 53894 | CALL NextRecord | Call NextRecord. | ||
| 53897 | JP NextStep_Test | Jump to NextStep_Test. | ||
| DrawTerrain_Skip | 53900 | CALL NextRecord | Call NextRecord. | |
| 53903 | JP NextSegment | Jump to NextSegment. | ||
| Prev: 53436 | Up: Map | Next: 53906 |