Prev: DEF7 Up: Map Next: E03D
DF08: Make Tiles
Used by the routines at BeginLife, LookForGround, FinishScrollIn and ScrollWorld.
Finds the four tiles that are on the screen for a position on the map. The tile numbers are read from the map for two columns and two rows, and are stored in the table at VisibleTiles. Tiles that are above the first row, or below the last row (rows 1C and 1D), are blank. While the world scrolls in at the start of a life tile 3E is replaced by AA. The address of the script of each tile is looked up in the table at TileScriptPointers and stored in the list at TileScriptAddresses. Unless the world is being scrolled in, the pick-ups and the map objects for the position are then put in their slots, and the slots of any that are no longer on the screen are freed.
Input
HL Map position (L is the column and H is the row)
MakeTiles DF08 LD DE,$0060 DE=60.
DF0B LD A,L A=L.
DF0C CP $FF Jump to MakeTiles_Wrapped if A is not FF.
DF0E JR NZ,MakeTiles_Wrapped
DF10 LD L,$5F L=5F.
MakeTiles_Wrapped DF12 CP $60 Jump to MakeTiles_Start if A is not 60.
DF14 JR NZ,MakeTiles_Start
DF16 LD L,$00 Clear L.
MakeTiles_Start DF18 LD ($CE57),HL Update the map position.
DF1B LD BC,$DC89 Set BC to TileScriptAddresses.
DF1E LD ($DC87),BC Update the tile script pointer.
DF22 PUSH HL Stash HL on the stack.
DF23 CALL GetTile Call GetTile.
DF26 LD ($DC91),A Update the visible tiles.
DF29 ADD HL,DE HL gains DE.
DF2A LD A,(HL) Read HL.
DF2B LD ($DC92),A The bottom tile of the left column.
DF2E POP HL Bring HL back off the stack.
DF2F INC L Advance L.
DF30 CALL GetTile Call GetTile.
DF33 LD ($DC93),A The top tile of the right column.
DF36 ADD HL,DE HL gains DE.
DF37 LD A,(HL) Read HL.
DF38 LD ($DC94),A The bottom tile of the right column.
DF3B LD A,($CE58) The map row.
DF3E CP $1C Jump to MakeTiles_Rows if A is not 1C.
DF40 JR NZ,MakeTiles_Rows
DF42 LD A,$20 A=20.
DF44 LD ($DC92),A The bottom tile of the left column is empty.
DF47 LD ($DC94),A The bottom tile of the right column is empty.
MakeTiles_Rows DF4A CP $1D Jump to MakeTiles_Scripts if A is not 1D.
DF4C JR NZ,MakeTiles_Scripts
DF4E LD BC,$2020 BC=2020.
DF51 LD ($DC91),BC Update the visible tiles.
DF55 LD ($DC93),BC The right column is empty.
MakeTiles_Scripts DF59 LD A,($5C3C) The scroll-in flag.
DF5C BIT 7,A Jump to MakeTiles_Lookup if bit 7 of A is clear.
DF5E JR Z,MakeTiles_Lookup
DF60 LD B,$04 B=04.
DF62 LD HL,$DC91 The visible tiles.
MakeTiles_Search DF65 LD A,(HL) Read HL.
DF66 CP $3E Jump to MakeTiles_Next if A is not 3E.
DF68 JR NZ,MakeTiles_Next
DF6A LD (HL),$AA Store AA at the address in HL.
MakeTiles_Next DF6C INC HL Advance HL.
DF6D DJNZ MakeTiles_Search Decrease B and jump to MakeTiles_Search until none remain.
MakeTiles_Lookup DF6F LD BC,$DC91 Set BC to VisibleTiles.
DF72 LD A,$04 A=04.
MakeTiles_Tile DF74 EX AF,AF' Switch to the alternate accumulator and flags.
DF75 LD A,(BC) Read BC.
DF76 LD L,A L=A.
DF77 LD H,$00 Clear H.
DF79 LD DE,$6C3C The tile script pointers.
DF7C ADD HL,HL Double HL.
DF7D ADD HL,DE HL gains DE.
DF7E LD E,(HL) Read HL into E.
DF7F INC HL Advance HL.
DF80 LD D,(HL) Read HL into D.
DF81 LD HL,($DC87) Fetch the word at TileScriptPointer into HL.
DF84 LD (HL),E Write E where HL points.
DF85 INC HL Advance HL.
DF86 LD (HL),D Write D where HL points.
DF87 INC HL Advance HL.
DF88 LD ($DC87),HL Update the tile script pointer.
DF8B INC BC Advance BC.
DF8C EX AF,AF' Switch to the alternate accumulator and flags.
DF8D DEC A Step A back.
DF8E JR NZ,MakeTiles_Tile Jump to MakeTiles_Tile if the zero flag is clear.
DF90 LD A,($5C3C) The scroll-in flag.
DF93 AND A Return if A is not zero.
DF94 RET NZ
MakeTiles_PickUps DF95 LD A,$0C A=0C.
DF97 LD ($5C1C),A The object type is 0C.
DF9A LD IX,$A873 The fifth map-object slot.
DF9E LD B,$02 B=02.
DFA0 CALL FreeDistantSlots Call FreeDistantSlots.
DFA3 LD IX,$F604 The item sites.
DFA7 LD HL,($CE57) Fetch the word at MapPosition into HL.
DFAA LD A,($DDF7) The next column.
DFAD LD D,A D=A.
DFAE LD BC,$1300 BC=1300.
MakeTiles_NextSite DFB1 LD A,C A=C.
DFB2 SUB $0B Subtract 0B from A.
DFB4 JR NZ,MakeTiles_Object Jump to MakeTiles_Object if the zero flag is clear.
DFB6 LD C,A C=A.
DFB7 LD A,$1E A=1E.
DFB9 LD ($5C1C),A The object type is 1E.
MakeTiles_Object DFBC BIT 7,(IX+$00) Jump to MakeTiles_Skip if bit 7 of offset 00 of IX is set.
DFC0 JR NZ,MakeTiles_Skip
DFC2 LD A,(IX+$00) Read offset 00 of IX.
DFC5 CP L Jump to MakeTiles_Compare if A is L.
DFC6 JR Z,MakeTiles_Compare
DFC8 CP D Jump to MakeTiles_Skip if A is not D.
DFC9 JR NZ,MakeTiles_Skip
MakeTiles_Compare DFCB LD A,H A=H.
DFCC INC A Advance A.
DFCD CP (IX+$01) Jump to MakeTiles_Slot if A is the byte at offset 01 of IX.
DFD0 JR Z,MakeTiles_Slot
DFD2 LD A,H A=H.
DFD3 CP (IX+$01) Jump to MakeTiles_Skip if A is not the byte at offset 01 of IX.
DFD6 JR NZ,MakeTiles_Skip
MakeTiles_Slot DFD8 LD IY,$A873 The fifth map-object slot.
DFDC CALL CompareSlotWithSite Call CompareSlotWithSite.
DFDF JR Z,MakeTiles_Skip Jump to MakeTiles_Skip if the zero flag is set.
DFE1 LD IY,$A88D The sixth map-object slot.
DFE5 CALL CompareSlotWithSite Call CompareSlotWithSite.
DFE8 JR Z,MakeTiles_Skip Jump to MakeTiles_Skip if the zero flag is set.
DFEA LD IY,$A873 The fifth map-object slot.
DFEE LD A,(IY+$00) Read offset 00 of IY.
DFF1 INC A Advance A.
DFF2 JR Z,MakeTiles_FillSlot Jump to MakeTiles_FillSlot if the zero flag is set.
DFF4 LD IY,$A88D The sixth map-object slot.
MakeTiles_FillSlot DFF8 LD A,(IX+$00) Read offset 00 of IX.
DFFB LD (IY+$01),A Write A to offset 01 of IY.
DFFE LD A,(IX+$01) Read offset 01 of IX.
E001 LD (IY+$04),A Write A to offset 04 of IY.
E004 LD A,(IX+$02) Read offset 02 of IX.
E007 LD (IY+$02),A Write A to offset 02 of IY.
E00A LD A,(IX+$03) Read offset 03 of IX.
E00D LD (IY+$05),A Write A to offset 05 of IY.
E010 LD (IY+$13),C Write C to offset 13 of IY.
E013 LD (IY+$0D),$FF Store FF at offset 0D of IY.
E017 LD A,($5C1C) The object type.
E01A LD (IY+$00),A Write A to offset 00 of IY.
MakeTiles_Skip E01D INC IX Advance IX.
E01F INC IX Advance IX.
E021 INC IX Advance IX.
E023 INC IX Advance IX.
E025 INC C Advance C.
E026 DJNZ MakeTiles_NextSite Decrease B and jump to MakeTiles_NextSite until none remain.
MakeTiles_Finish E028 LD IX,$A873 The fifth map-object slot.
E02C LD B,$02 B=02.
E02E CALL ClearFreeSlotFlags Call ClearFreeSlotFlags.
E031 LD IX,$A80B The map object slots.
E035 LD B,$04 B=04.
E037 CALL FreeDistantSlots Call FreeDistantSlots.
E03A JP LoadMapObjects Jump to LoadMapObjects.
Prev: DEF7 Up: Map Next: E03D