Prev: D865 Up: Map Next: D8D7
D88E: Put the four objects in random cells at a new game
Used by the routine at NEW_GAME.
Called at a new game (NEW_GAME). The random number's low 12 bits give an address in the ROM, and the bytes from there are read in pairs as a column and a row (each masked to 0-31) until one is a cell a knight can stand in -- not type 1 or 2. Each object gets a copy of OBJECT_RECORD, the cell, and its graphic: 7, 6, 5 and 4 for records 0 to 3, so that thing 1 (PICK_UP_THING takes graphic 4 as thing 1) is the object in record 3. Nothing stops two objects, or an object and a villain, sharing a cell.
PLACE_OBJECTS D88E CALL NEXT_TURN Advance the turn count and stir the random number
D891 LD IY,OBJECTS Four records from OBJECTS
D895 LD B,$04
D897 LD DE,(RANDOM) DE: an address in the ROM, from the random number
D89B LD A,D
D89C AND $0F
D89E LD D,A
PLACE_OBJECTS_0 D89F LD A,(DE) Read a column and a row from it
D8A0 INC DE
D8A1 AND $1F
D8A3 LD L,A
D8A4 LD A,(DE)
D8A5 INC DE
D8A6 AND $1F
D8A8 LD H,A
D8A9 PUSH BC Look the cell up; try the next pair if it is solid (type 1 or 2)
D8AA PUSH HL
D8AB CALL LOOK_UP_CELL
D8AE POP HL
D8AF POP BC
D8B0 DEC A
D8B1 CP $02
D8B3 JR C,PLACE_OBJECTS_0
D8B5 PUSH BC Copy OBJECT_RECORD into the record, and point IY at the next one
D8B6 PUSH DE
D8B7 PUSH HL
D8B8 LD HL,OBJECT_RECORD
D8BB LD BC,$0010
D8BE PUSH IY
D8C0 POP DE
D8C1 ADD IY,BC
D8C3 LDIR
D8C5 POP HL Graphic 3 plus the count: 7 for record 0 down to 4 for record 3
D8C6 POP DE
D8C7 POP BC
D8C8 LD A,B
D8C9 ADD A,$03
D8CB LD (IY-$10),A
D8CE LD (IY-$0E),L The cell's column and row, at its middle (the low bytes are 128 from the copy)
D8D1 LD (IY-$0C),H
D8D4 DJNZ PLACE_OBJECTS_0 Next record
D8D6 RET
Prev: D865 Up: Map Next: D8D7