![]() |
Routines |
| Prev: 54242 | Up: Map | Next: 54514 |
|
Used by the routine at RetrieveRoom.
Makes the objects of a room from its entry in the table of rooms. The colour of the room is the low three bits of the byte after the length, with bright added, and the size of the room is the high five bits. The size gives the size of the room in X, Y and Z, from the table at RoomSizeTable. Each type of background object is the number of an entry in the table at BackgroundTypeTable, which holds the address of a list of objects that already have their coordinates. Each of these is copied into the objects table, along with the number of the room. The background objects end at a 255, or at the end of the entry if there are no foreground objects. Each group of foreground objects starts with a byte that has the number of a block in bits 3 to 7 and one less than the number of times it is used in bits 0 to 2, followed by that many positions. A block is a list of objects from the table at BlockTypeTable, each with a graphic, a size, flags and an offset, but no coordinates. A position has the X coordinate in bits 0 to 2, the Y coordinate in bits 3 to 5 and the Z coordinate in bits 6 and 7.
|
||||||||||||
|
Set the colour of the room, the size and the floor.
|
||||||||||||
| MakeRoomObjects | 54256 | LD B,(HL) | Fetch the length of the entry. | |||||||||
| 54257 | INC HL | Point HL at the colour and size. | ||||||||||
| 54258 | LD A,(HL) | Fetch the colour and size. | ||||||||||
| 54259 | AND %00000111 | Keep the colour. | ||||||||||
| 54261 | OR %01000000 | Make it bright. | ||||||||||
| 54263 | LD (23469),A | Store it as the colour of the room at RoomAttribute. | ||||||||||
| 54266 | PUSH DE | Stash the address of the object to make on the stack. | ||||||||||
| 54267 | EX DE,HL | Point DE at the colour and size. | ||||||||||
| 54268 | LD A,(DE) | Fetch the colour and size. | ||||||||||
| 54269 | INC DE | Point DE at the types of background object. | ||||||||||
| 54270 | RRCA | Move the size into the low five bits. | ||||||||||
| 54271 | RRCA | |||||||||||
| 54272 | RRCA | |||||||||||
| 54273 | AND %00011111 | Keep it. | ||||||||||
| 54275 | LD C,A | Stash it in C. | ||||||||||
| 54276 | ADD A,A | Multiply it by three. | ||||||||||
| 54277 | ADD A,C | |||||||||||
| 54278 | LD HL,25160 | Point HL at RoomSizeTable. | ||||||||||
| 54281 | CALL AddAToHL | Add the offset to find the size. | ||||||||||
| 54284 | LD A,(HL) | Fetch the size of the room in X, and move on. | ||||||||||
| 54285 | INC HL | |||||||||||
| 54286 | LD (23467),A | Store it at RoomSizeX. | ||||||||||
| 54289 | LD A,(HL) | Fetch the size of the room in Y, and move on. | ||||||||||
| 54290 | INC HL | |||||||||||
| 54291 | LD (23468),A | Store it at RoomSizeY. | ||||||||||
| 54294 | LD A,(HL) | Fetch the size of the room in Z, which is the floor of the room. | ||||||||||
| 54295 | LD (23470),A | Store it at FloorHeight. | ||||||||||
| 54298 | DEC B | Take two off the length that is left. | ||||||||||
| 54299 | DEC B | |||||||||||
| 54300 | EX DE,HL | Point HL at the types of background object. | ||||||||||
| 54301 | POP DE | Restore the address of the object to make from the stack. | ||||||||||
|
Copy each type of background object from BackgroundTypeTable.
|
||||||||||||
| MakeRoomObjects_Background | 54302 | LD A,(HL) | Fetch the type of background object, and move on. | |||||||||
| 54303 | INC HL | |||||||||||
| 54304 | CP 255 | Jump to MakeRoomObjects_Foreground if it is the end of the types. | ||||||||||
| 54306 | JR Z,MakeRoomObjects_Foreground | |||||||||||
| 54308 | PUSH BC | Stash the length that is left and the address of the next type on the stack. | ||||||||||
| 54309 | PUSH HL | |||||||||||
|
Look up the list of objects of this type.
|
||||||||||||
| 54310 | LD L,A | Make the type into an offset. | ||||||||||
| 54311 | LD H,0 | |||||||||||
| 54313 | ADD HL,HL | Double it. | ||||||||||
| 54314 | LD BC,27874 | Point BC at BackgroundTypeTable. | ||||||||||
| 54317 | ADD HL,BC | Add the two. | ||||||||||
| 54318 | LD A,(HL) | Fetch the address of the list of objects of the background. | ||||||||||
| 54319 | INC HL | |||||||||||
| 54320 | LD H,(HL) | |||||||||||
| 54321 | LD L,A | |||||||||||
|
Copy one background object into the objects table.
|
||||||||||||
| MakeRoomObjects_Background_Copy | 54322 | LD BC,8 | Set the number of bytes to copy to 8. | |||||||||
| 54325 | LDIR | Copy the graphic number, the coordinates, the size and the flags of the object. | ||||||||||
| 54327 | LD A,(IX+8) | Fetch the room number of the player. | ||||||||||
| 54330 | LD (DE),A | Set the room number of the object, and move on. | ||||||||||
| 54331 | INC DE | |||||||||||
| 54332 | LD B,23 | Set the number of bytes to 23. | ||||||||||
| 54334 | CALL ClearBytes | Clear the rest of the object. | ||||||||||
| 54337 | LD A,(HL) | Jump to MakeRoomObjects_Background_Copy if the list has not ended. | ||||||||||
| 54338 | AND A | |||||||||||
| 54339 | JR NZ,MakeRoomObjects_Background_Copy | |||||||||||
| 54341 | POP HL | Restore the address of the next type and the length that is left from the stack. | ||||||||||
| 54342 | POP BC | |||||||||||
| 54343 | DJNZ MakeRoomObjects_Background | Jump to MakeRoomObjects_Background until all of the types have been used. | ||||||||||
| 54345 | JP ClearRemainingObjects | Jump to ClearRemainingObjects to clear the rest of the objects table. | ||||||||||
|
The foreground objects. IY points at the object that is being made.
|
||||||||||||
| MakeRoomObjects_Foreground | 54348 | DEC B | Take one off the length that is left, for the end of the types. | |||||||||
| 54349 | PUSH IY | Stash IY on the stack. | ||||||||||
| 54351 | PUSH DE | Point IY at the object to make (using the stack). | ||||||||||
| 54352 | POP IY | |||||||||||
|
Decode the block type and the number of places.
|
||||||||||||
| MakeRoomObjects_Block | 54354 | LD A,(HL) | Fetch the block and the count. | |||||||||
| 54355 | AND %00000111 | Keep the count. | ||||||||||
| 54357 | INC A | Add one to get the number of times. | ||||||||||
| 54358 | LD C,A | Stash it in C. | ||||||||||
| 54359 | LD A,(HL) | Fetch the block and the count again, and move on. | ||||||||||
| 54360 | INC HL | |||||||||||
| 54361 | DEC B | Take one off the length that is left. | ||||||||||
| 54362 | LD D,(HL) | Fetch the position of the first block, and move on. | ||||||||||
| 54363 | INC HL | |||||||||||
| 54364 | PUSH HL | Stash the address of the next byte on the stack. | ||||||||||
| 54365 | RRCA | Move the block into bits 1 to 5. | ||||||||||
| 54366 | RRCA | |||||||||||
| 54367 | AND %00111110 | Keep it, to make it twice the number of the block. | ||||||||||
| 54369 | LD HL,27601 | Point HL at BlockTypeTable. | ||||||||||
| 54372 | CALL AddAToHL | Add the offset to find the block. | ||||||||||
| 54375 | LD A,(HL) | Fetch the address of the list of objects of the block. | ||||||||||
| 54376 | INC HL | |||||||||||
| 54377 | LD H,(HL) | |||||||||||
| 54378 | LD L,A | |||||||||||
| MakeRoomObjects_Block_Object | 54379 | PUSH HL | Stash the address of the list of objects on the stack. | |||||||||
|
Copy the graphic, the size and the flags from the block.
|
||||||||||||
| MakeRoomObjects_Object | 54380 | LD A,(HL) | Fetch the graphic number, and move on. | |||||||||
| 54381 | INC HL | |||||||||||
| 54382 | LD (IY+0),A | Set the graphic number of the object. | ||||||||||
| 54385 | LD A,(HL) | Fetch the width, and move on. | ||||||||||
| 54386 | INC HL | |||||||||||
| 54387 | LD (IY+4),A | Set the width of the object. | ||||||||||
| 54390 | LD A,(HL) | Fetch the depth, and move on. | ||||||||||
| 54391 | INC HL | |||||||||||
| 54392 | LD (IY+5),A | Set the depth of the object. | ||||||||||
| 54395 | LD A,(HL) | Fetch the height, and move on. | ||||||||||
| 54396 | INC HL | |||||||||||
| 54397 | LD (IY+6),A | Set the height of the object. | ||||||||||
| 54400 | LD A,(HL) | Fetch the flags, and move on. | ||||||||||
| 54401 | INC HL | |||||||||||
| 54402 | LD (IY+7),A | Set the flags of the object. | ||||||||||
| 54405 | LD A,(IX+8) | Fetch the room number of the player. | ||||||||||
| 54408 | LD (IY+8),A | Set the room number of the object. | ||||||||||
|
The byte of offsets has the half step in X in bit 0, the half step in Y in bit 1, and the offset in Z in bits 2 to 7. The X coordinate is the X position times 16, plus eight if the half step is set, plus 72.
|
||||||||||||
| 54411 | LD A,(HL) | Fetch the offsets. | ||||||||||
| 54412 | RLCA | Move the half step in X into bit 3. | ||||||||||
| 54413 | RLCA | |||||||||||
| 54414 | RLCA | |||||||||||
| 54415 | AND %00001000 | Keep it. | ||||||||||
| 54417 | LD E,A | Stash it in E. | ||||||||||
| 54418 | LD A,D | Fetch the position. | ||||||||||
| 54419 | RLCA | Move the X position into bits 4 to 6. | ||||||||||
| 54420 | RLCA | |||||||||||
| 54421 | RLCA | |||||||||||
| 54422 | RLCA | |||||||||||
| 54423 | AND %01110000 | Keep it. | ||||||||||
| 54425 | ADD A,E | Add the half step. | ||||||||||
| 54426 | ADD A,72 | Add 72. | ||||||||||
| 54428 | LD (IY+1),A | Set the X coordinate of the object. | ||||||||||
|
The Y coordinate is worked out in the same way from the Y position and the half step in Y.
|
||||||||||||
| 54431 | LD A,(HL) | Fetch the offsets. | ||||||||||
| 54432 | RLCA | Move the half step in Y into bit 3. | ||||||||||
| 54433 | RLCA | |||||||||||
| 54434 | AND %00001000 | Keep it. | ||||||||||
| 54436 | LD E,A | Stash it in E. | ||||||||||
| 54437 | LD A,D | Fetch the position. | ||||||||||
| 54438 | RLCA | Move the Y position into bits 4 to 6. | ||||||||||
| 54439 | AND %01110000 | Keep it. | ||||||||||
| 54441 | ADD A,E | Add the half step. | ||||||||||
| 54442 | ADD A,72 | Add 72. | ||||||||||
| 54444 | LD (IY+2),A | Set the Y coordinate of the object. | ||||||||||
|
The Z coordinate is the Z position times 12, plus the offset in Z, plus the floor of the room.
|
||||||||||||
| 54447 | LD A,D | Fetch the position. | ||||||||||
| 54448 | RLCA | Move the Z position into the low two bits. | ||||||||||
| 54449 | RLCA | |||||||||||
| 54450 | AND %00000011 | Keep it. | ||||||||||
| 54452 | ADD A,A | Multiply it by four. | ||||||||||
| 54453 | ADD A,A | |||||||||||
| 54454 | LD E,A | Stash it in E. | ||||||||||
| 54455 | ADD A,A | Multiply it by eight. | ||||||||||
| 54456 | ADD A,E | Add the four times to make twelve times. | ||||||||||
| 54457 | ADD A,(HL) | Add the offsets, which includes the offset in Z. | ||||||||||
| 54458 | INC HL | Move on. | ||||||||||
| 54459 | AND %11111100 | Clear the two bits of the half steps. | ||||||||||
| 54461 | LD E,A | Stash it in E. | ||||||||||
| 54462 | LD A,(23470) | Fetch the floor of the room from FloorHeight. | ||||||||||
| 54465 | ADD A,E | Add it. | ||||||||||
| 54466 | LD (IY+3),A | Set the Z coordinate of the object. | ||||||||||
|
Clear the rest of the object.
|
||||||||||||
| 54469 | PUSH BC | Stash the count on the stack. | ||||||||||
| 54470 | LD BC,9 | Set the length of the part of the object that has been made to 9. | ||||||||||
| 54473 | ADD IY,BC | Point IY at the rest of the object. | ||||||||||
| 54475 | LD B,23 | Set the number of bytes to clear to 23. | ||||||||||
| MakeRoomObjects_Clear | 54477 | LD (IY+0),0 | Clear a byte. | |||||||||
| 54481 | INC IY | Move on. | ||||||||||
| 54483 | DJNZ MakeRoomObjects_Clear | Jump to MakeRoomObjects_Clear until the object is clear. | ||||||||||
|
Move on to the next object of the block, or the next place, or the next group.
|
||||||||||||
| 54485 | POP BC | Restore the count from the stack. | ||||||||||
| 54486 | LD A,(HL) | Jump to MakeRoomObjects_Object if the block has not ended. | ||||||||||
| 54487 | AND A | |||||||||||
| 54488 | JR NZ,MakeRoomObjects_Object | |||||||||||
| 54490 | POP DE | Restore the address of the block and the address of the next byte from the stack. | ||||||||||
| 54491 | POP HL | |||||||||||
| 54492 | DEC B | Jump to MakeRoomObjects_Finish if the entry has ended. | ||||||||||
| 54493 | JR Z,MakeRoomObjects_Finish | |||||||||||
| 54495 | DEC C | Jump to MakeRoomObjects_Block if the block has been used the number of times. | ||||||||||
| 54496 | JP Z,MakeRoomObjects_Block | |||||||||||
| 54499 | LD A,(HL) | Fetch the position for the next use of the block, and move on. | ||||||||||
| 54500 | INC HL | |||||||||||
| 54501 | PUSH HL | Stash the address of the next byte on the stack. | ||||||||||
| 54502 | EX DE,HL | Point HL at the list of objects of the block. | ||||||||||
| 54503 | LD D,A | Put the position in D. | ||||||||||
| 54504 | JR MakeRoomObjects_Block_Object | Jump to MakeRoomObjects_Block_Object. | ||||||||||
|
Finish, and clear any objects that were not made.
|
||||||||||||
| MakeRoomObjects_Finish | 54506 | PUSH IY | Point DE at the next object to make (using the stack). | |||||||||
| 54508 | POP DE | |||||||||||
| 54509 | POP IY | Restore IY from the stack. | ||||||||||
| 54511 | JP ClearRemainingObjects | Jump to ClearRemainingObjects to clear the rest of the objects table. | ||||||||||
| Prev: 54242 | Up: Map | Next: 54514 |