Prev: 57079 Up: Map Next: 57405
57096: 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 28 and 29), are blank. While the world scrolls in at the start of a life tile 62 is replaced by 170. 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 57096 LD DE,96 DE=96.
57099 LD A,L A=L.
57100 CP 255 Jump to MakeTiles_Wrapped if A is not 255.
57102 JR NZ,MakeTiles_Wrapped
57104 LD L,95 L=95.
MakeTiles_Wrapped 57106 CP 96 Jump to MakeTiles_Start if A is not 96.
57108 JR NZ,MakeTiles_Start
57110 LD L,0 Clear L.
MakeTiles_Start 57112 LD (52823),HL Update the map position.
57115 LD BC,56457 Set BC to TileScriptAddresses.
57118 LD (56455),BC Update the tile script pointer.
57122 PUSH HL Stash HL on the stack.
57123 CALL GetTile Call GetTile.
57126 LD (56465),A Update the visible tiles.
57129 ADD HL,DE HL gains DE.
57130 LD A,(HL) Read HL.
57131 LD (56466),A The bottom tile of the left column.
57134 POP HL Bring HL back off the stack.
57135 INC L Advance L.
57136 CALL GetTile Call GetTile.
57139 LD (56467),A The top tile of the right column.
57142 ADD HL,DE HL gains DE.
57143 LD A,(HL) Read HL.
57144 LD (56468),A The bottom tile of the right column.
57147 LD A,(52824) The map row.
57150 CP 28 Jump to MakeTiles_Rows if A is not 28.
57152 JR NZ,MakeTiles_Rows
57154 LD A,32 A=32.
57156 LD (56466),A The bottom tile of the left column is empty.
57159 LD (56468),A The bottom tile of the right column is empty.
MakeTiles_Rows 57162 CP 29 Jump to MakeTiles_Scripts if A is not 29.
57164 JR NZ,MakeTiles_Scripts
57166 LD BC,8224 BC=8224.
57169 LD (56465),BC Update the visible tiles.
57173 LD (56467),BC The right column is empty.
MakeTiles_Scripts 57177 LD A,(23612) The scroll-in flag.
57180 BIT 7,A Jump to MakeTiles_Lookup if bit 7 of A is clear.
57182 JR Z,MakeTiles_Lookup
57184 LD B,4 B=4.
57186 LD HL,56465 The visible tiles.
MakeTiles_Search 57189 LD A,(HL) Read HL.
57190 CP 62 Jump to MakeTiles_Next if A is not 62.
57192 JR NZ,MakeTiles_Next
57194 LD (HL),170 Store 170 at the address in HL.
MakeTiles_Next 57196 INC HL Advance HL.
57197 DJNZ MakeTiles_Search Decrease B and jump to MakeTiles_Search until none remain.
MakeTiles_Lookup 57199 LD BC,56465 Set BC to VisibleTiles.
57202 LD A,4 A=4.
MakeTiles_Tile 57204 EX AF,AF' Switch to the alternate accumulator and flags.
57205 LD A,(BC) Read BC.
57206 LD L,A L=A.
57207 LD H,0 Clear H.
57209 LD DE,27708 The tile script pointers.
57212 ADD HL,HL Double HL.
57213 ADD HL,DE HL gains DE.
57214 LD E,(HL) Read HL into E.
57215 INC HL Advance HL.
57216 LD D,(HL) Read HL into D.
57217 LD HL,(56455) Fetch the word at TileScriptPointer into HL.
57220 LD (HL),E Write E where HL points.
57221 INC HL Advance HL.
57222 LD (HL),D Write D where HL points.
57223 INC HL Advance HL.
57224 LD (56455),HL Update the tile script pointer.
57227 INC BC Advance BC.
57228 EX AF,AF' Switch to the alternate accumulator and flags.
57229 DEC A Step A back.
57230 JR NZ,MakeTiles_Tile Jump to MakeTiles_Tile if the zero flag is clear.
57232 LD A,(23612) The scroll-in flag.
57235 AND A Return if A is not zero.
57236 RET NZ
MakeTiles_PickUps 57237 LD A,12 A=12.
57239 LD (23580),A The object type is 12.
57242 LD IX,43123 The fifth map-object slot.
57246 LD B,2 B=2.
57248 CALL FreeDistantSlots Call FreeDistantSlots.
57251 LD IX,62980 The item sites.
57255 LD HL,(52823) Fetch the word at MapPosition into HL.
57258 LD A,(56823) The next column.
57261 LD D,A D=A.
57262 LD BC,4864 BC=4864.
MakeTiles_NextSite 57265 LD A,C A=C.
57266 SUB 11 Subtract 11 from A.
57268 JR NZ,MakeTiles_Object Jump to MakeTiles_Object if the zero flag is clear.
57270 LD C,A C=A.
57271 LD A,30 A=30.
57273 LD (23580),A The object type is 30.
MakeTiles_Object 57276 BIT 7,(IX+0) Jump to MakeTiles_Skip if bit 7 of offset 0 of IX is set.
57280 JR NZ,MakeTiles_Skip
57282 LD A,(IX+0) Read offset 0 of IX.
57285 CP L Jump to MakeTiles_Compare if A is L.
57286 JR Z,MakeTiles_Compare
57288 CP D Jump to MakeTiles_Skip if A is not D.
57289 JR NZ,MakeTiles_Skip
MakeTiles_Compare 57291 LD A,H A=H.
57292 INC A Advance A.
57293 CP (IX+1) Jump to MakeTiles_Slot if A is the byte at offset 1 of IX.
57296 JR Z,MakeTiles_Slot
57298 LD A,H A=H.
57299 CP (IX+1) Jump to MakeTiles_Skip if A is not the byte at offset 1 of IX.
57302 JR NZ,MakeTiles_Skip
MakeTiles_Slot 57304 LD IY,43123 The fifth map-object slot.
57308 CALL CompareSlotWithSite Call CompareSlotWithSite.
57311 JR Z,MakeTiles_Skip Jump to MakeTiles_Skip if the zero flag is set.
57313 LD IY,43149 The sixth map-object slot.
57317 CALL CompareSlotWithSite Call CompareSlotWithSite.
57320 JR Z,MakeTiles_Skip Jump to MakeTiles_Skip if the zero flag is set.
57322 LD IY,43123 The fifth map-object slot.
57326 LD A,(IY+0) Read offset 0 of IY.
57329 INC A Advance A.
57330 JR Z,MakeTiles_FillSlot Jump to MakeTiles_FillSlot if the zero flag is set.
57332 LD IY,43149 The sixth map-object slot.
MakeTiles_FillSlot 57336 LD A,(IX+0) Read offset 0 of IX.
57339 LD (IY+1),A Write A to offset 1 of IY.
57342 LD A,(IX+1) Read offset 1 of IX.
57345 LD (IY+4),A Write A to offset 4 of IY.
57348 LD A,(IX+2) Read offset 2 of IX.
57351 LD (IY+2),A Write A to offset 2 of IY.
57354 LD A,(IX+3) Read offset 3 of IX.
57357 LD (IY+5),A Write A to offset 5 of IY.
57360 LD (IY+19),C Write C to offset 19 of IY.
57363 LD (IY+13),255 Store 255 at offset 13 of IY.
57367 LD A,(23580) The object type.
57370 LD (IY+0),A Write A to offset 0 of IY.
MakeTiles_Skip 57373 INC IX Advance IX.
57375 INC IX Advance IX.
57377 INC IX Advance IX.
57379 INC IX Advance IX.
57381 INC C Advance C.
57382 DJNZ MakeTiles_NextSite Decrease B and jump to MakeTiles_NextSite until none remain.
MakeTiles_Finish 57384 LD IX,43123 The fifth map-object slot.
57388 LD B,2 B=2.
57390 CALL ClearFreeSlotFlags Call ClearFreeSlotFlags.
57393 LD IX,43019 The map object slots.
57397 LD B,4 B=4.
57399 CALL FreeDistantSlots Call FreeDistantSlots.
57402 JP LoadMapObjects Jump to LoadMapObjects.
Prev: 57079 Up: Map Next: 57405