Prev: 64A4 Up: Map Next: 64FD
64AA: Level Object Placement And Special Terrain Generation
Used by the routine at InitialiseLevel.
Search the level buffer for special terrain markers (32) and replace with objects/ terrain.
ObjectPlacement_SpecialTerrain 64AA LD HL,$9E00 Load HL with LevelBuffer.
64AD LD BC,$0A00 Set the length of the level buffer in BC (0A00 bytes).
ObjectPlacement_SpecialTerrain_Loop 64B0 LD A,$32 Search for the next 32 markr in the level buffer.
64B2 CPIR
64B4 LD A,B Return if no more markers were found.
64B5 OR C
64B6 RET Z
A marker was found.
64B7 PUSH HL Stash the level buffer position and buffer counter on the stack.
64B8 PUSH BC
64B9 XOR A Clear A.
64BA NOP No operation.
64BB NOP
64BC LD B,$04 Set a counter in B for 04 bytes to process.
64BE LD E,A E=A.
64BF DEC L Decrease L by one.
Determine what to place based on a random number.
64C0 CALL GetRandomNumber Call GetRandomNumber.
64C3 AND %00000111 A=random number between 00 and 07.
64C5 CP E Jump to PlaceSimpleTerrain_Loop if A is lower than E.
64C6 JR C,PlaceSimpleTerrain_Loop
Generate terrain/ object from the data table.
This part of the routine takes a random number between 00-07 and uses it to fetch terrain data:
Random Number Calculation Address
00 6C Data_Terrain_01
01 72 Data_Terrain_02
02 78 Data_Terrain_03
03 7E Data_Terrain_04
04 84 Data_Terrain_05
05 8A Data_Terrain_06
06 90 Data_Terrain_07
07 96 Data_Terrain_08
64C8 CALL ContextualRandomNumber Call ContextualRandomNumber.
64CB AND %00000111 Ensure the random number is between 00-07.
Calculate the low-byte of the object data table address.
64CD ADD A,A E=(A*06)+6C.
64CE LD E,A
64CF ADD A,A
64D0 ADD A,E
64D1 ADD A,$6C
64D3 LD E,A
64D4 LD D,$B4 Set the high-byte in D to B4.
Copy a byte of the 04 bytes of object data into the level buffer.
PlaceObjectData 64D6 LD A,(DE) Fetch an object data byte.
64D7 LD (HL),A Write the object data byte into the level buffer.
64D8 INC E Move to the next object data byte.
64D9 INC L Move to the next position in the level buffer.
64DA DJNZ PlaceObjectData Decrease the byte counter by one and loop back to PlaceObjectData until all the object data bytes have been written into the level buffer.
Check if the object has a vertical component.
64DC LD A,(DE) Jump to ObjectPlacement_SpecialTerrain_Next if the current data byte is zero (no vertical component).
64DD AND A
64DE JR Z,ObjectPlacement_SpecialTerrain_Next
Place the vertical component of the object.
64E0 DEC L Decrease L by three.
64E1 DEC L
64E2 DEC L
64E3 INC H Increment H by one.
64E4 LD B,$02 B=02.
PlaceVerticalComponent 64E6 LD A,(HL) A=*HL.
64E7 AND A Set flags.
64E8 LD A,(DE) A=*DE.
64E9 JR Z,PlaceVerticalByte Jump to PlaceVerticalByte if *HL is zero.
64EB INC A Increment A by two.
64EC INC A
PlaceVerticalByte 64ED LD (HL),A Write A to *HL.
64EE INC L Increment L by one.
64EF INC E Increment E by one.
64F0 DJNZ PlaceVerticalComponent Decrease counter by one and loop back to PlaceVerticalComponent until counter is zero.
64F2 JR ObjectPlacement_SpecialTerrain_Next Jump to ObjectPlacement_SpecialTerrain_Next.
Place a simple terrain block (block type: 01).
PlaceSimpleTerrain_Loop 64F4 LD (HL),$01 Write block type 01 to the level buffer pointer.
64F6 INC L Move to the next buffer position.
64F7 DJNZ PlaceSimpleTerrain_Loop Decrease the byte counter by one and loop back to PlaceSimpleTerrain_Loop until all bytes have been written into the buffer.
Continue searching for the next terrain markers.
ObjectPlacement_SpecialTerrain_Next 64F9 POP BC Restore the buffer counter and level buffer position from the stack.
64FA POP HL
64FB JR ObjectPlacement_SpecialTerrain_Loop Jump to ObjectPlacement_SpecialTerrain_Loop.
Prev: 64A4 Up: Map Next: 64FD