Prev: 50272 Up: Map Next: 50545
50433: Set up room foreground scenery objects - part 1
examples of foreground scenery objects
There are 16 foreground scenery objects, whose graphics addresses are held from 39063.
  • 'Brick' levels have an assortment of the first 8 (from 39063)
  • 'Cavern' levels have an assortment of the second 8 (from 39079)
This routine calculates the number, types, and X/Y co-ordinates of scenery objects in the room, and stashes the data for each one into a 7-byte data set in a table at 32513.
The following instructions identifies the level type. If it's a cavern-style level, sets the offset for the graphic address pointer to 8.
50433 LD A,(60087) Get room number
50436 LD L,A Store in L register
50437 CP 82 If room number is 1-81 it's a 'brick style level'.
For other scenery types it's actually rooms 1-82 (49528).
This means the first room in the High Temple of Chaos (room 82) is a hybrid room, with brickwork walls but cavern foreground scenery.
50439 LD A,0 ...So set graphics offset 60279 to 0...
50441 JR C,50445
50443 LD A,8 ...Otherwise it's a 'cavern' style level, so set the offset to 8.
50445 LD (60279),A Store the offset
Bytes in the ROM, picked using the room number, are used to generate a varied but repeatable selection of foreground object types.
50448 LD H,0 Multiply room number by 8
50450 ADD HL,HL
50451 ADD HL,HL
50452 ADD HL,HL
50453 EX DE,HL ...Store result in DE register to be used for the ROM address
50454 LD HL,(60272) Get address pointer to the foreground object data table at 32513
CALCULATE NUMBER OF FOREGROUND SCENERY OBJECTS
The first of the room data bytes at 25001 reflects the size of the room.
The number of foreground objects in a room is this room size byte divided by two (rounded down).
50457 LD A,(60284) Get (first) room data byte from banks at 25001, which indicates the size of the room
50460 LD C,A Temp store in C register
50461 RRA Divide by 2
50462 AND 127 Filter out any carry bits caused by the RRA
50464 LD B,A ...and store in B register as a counter for number-of-objects
SET LEFTMOST OBJECT POSITION
The next bit calculates the first (leftmost) item's horizontal position (in 4-pixel/half-character steps) within the room, based on room size.
50465 LD A,C Retrieve (first) room data byte from C register
50466 RLA x 2
50467 NEG Make the value negative as the first object will be to the left of (or near) the leftmost screen wall
50469 ADD A,8 Add 8 to the value as a small offset, to move it over to the right slightly
50471 LD (60232),A
IDENTIFY SCENERY OBJECT TYPE AND GRAPHIC ADDRESS POINTER
DE is currently pointing at a ROM address based on room number (x 8, so room 1 = memory address location 00008).
A combination of the room number and bytes from addresses in ROM are used to create a repeatable, but varied pattern of foreground scenery objects for each room.
50474 LD A,(DE) Get byte from ROM
50475 INC DE ...and move pointer along to next ROM address
50476 ADD A,B Add byte from B register (which contains the first room data byte divided by 2) to added variation
50477 AND 7 There are only 8 types of foreground object for each level type, so we only need bits 0-2 (values 0-7)
50479 ADD A,106 Add to the graphic address pointer table at 38851. An offset of 106 puts the address pointer at the scenery objects at 39063.
50481 LD C,A
50482 LD A,(60279) Add the offset calculated earlier (either 0 or 8 depending on the level type). Offset should now be between 106 and 121
50485 ADD A,C
50486 LD (60094),HL Store address pointer to the foreground object data set at 32513
50489 LD (60282),DE Store ROM address pointer
50493 LD D,0 Double the offset value to create an address pointer offset in DE
50495 RLA
50496 RL D Filter out bit 0 to ensure it's an even number
50498 AND 254
50500 LD E,A
50501 LD HL,(60266) Get the base graphics address pointer
50504 ADD HL,DE Add the offset
50505 LD E,(HL) Get the scenery graphics address in the DE register, e.g. 43611 for the skeleton
50506 INC HL
50507 LD D,(HL)
COPY FOREGROUND SCENERY DATA VARIABLES INTO DATA SETS
Foreground scenery object data is stored in the data tables at 32513.
50508 LD HL,(60094) Retrieve address pointer to foreground object data sets at 32513
50511 LD (HL),0 First byte default value = 0 (item not on screen)
50513 INC HL
50514 LD (HL),0 Horizontal position precision/fraction byte = 0 (item starting position will be a multiple of 8 pixels)
50516 INC HL
50517 LD A,(60232) Horizontal position in room. This is in 1-character/8-pixel steps (foreground scenery moves in larger distance increments than other scenery)
50520 LD (HL),A
50521 INC HL
50522 ADD A,16 Add 16 to the horizontal position and re-store. The value of 16 puts a gap of 16 character squares between foreground objects.
50524 LD (60232),A
50527 LD (HL),0 Vertical position precision/fraction byte (not needed here)
50529 INC HL
50530 LD (HL),104 Vertical position from top of playing area, in pixels - default position = 104
50532 INC HL
50533 LD (HL),E Address pointer to the scenery graphic to draw, e.g. 43611
50534 INC HL
50535 LD (HL),D
50536 INC HL
50537 LD DE,(60282) Retrieve ROM address pointer
50541 DJNZ 50474 Continue to store object details in the 7 byte scenery data banks at 32513. B register = count of objects that need storing.
50543 LD (HL),255 Set end-of-data byte to indicate the end of room foreground scenery object sets
Prev: 50272 Up: Map Next: 50545