Prev: D28D Up: Map Next: D352
D2A1: Game Initialisation
Used by the routine at Game_Loop.
Input
HL Pointer to level data
Game_Initialisation D2A1 LD C,(HL) The first byte is the length of the level data, store this in C.
D2A2 LD A,C A=data length.
D2A3 LD B,$00 Initialise B to 00 for the copy command.
D2A5 INC HL Increment the level data pointer by one.
D2A6 LD DE,$E2A7 Copy the level data from the current level data to E2A7.
D2A9 LDIR
D2AB LD DE,$D815 The next 0012 bytes are timers for the doors and cracks, each level has a different set. Copy these starting at Timer_DoorTop.
D2AE LD BC,$0012
D2B1 LDIR
D2B3 LD E,(HL) Fetch the pointer for the level graphics data and write this to *LevelGraphicsData.
D2B4 INC HL
D2B5 LD D,(HL)
D2B6 LD ($D892),DE
D2BA LD HL,$D85F HL=D85F.
D2BD LD B,$0C B=0C.
Game_Initialisation_0 D2BF LD (HL),$01 Write 01 to *HL.
D2C1 INC HL Increment HL by one.
D2C2 DJNZ Game_Initialisation_0 Decrease counter by one and loop back to Game_Initialisation_0 until counter is zero.
D2C4 LD DE,$E261 Copy 0031 bytes of data from D4F1 to InGame_Tiles_Top.
D2C7 LD HL,$D4F1
D2CA LD BC,$0031
D2CD LDIR
Populates Table_Tiles with:
E293 E294 E295 E296 E297
01 02 03 04 05
E298 E299 E29A E29B E29C
06 07 08 09 0A
E29D E29E E29F E2A0 E2A1
0B 0C 0D 0E 0F
E2A2 E2A3 E2A4 E2A5 E2A6
10 11 12 13 14
D2CF LD HL,$E293 HL=Table_Tiles.
D2D2 LD B,$14 Set a counter in B for each tile (5x4).
D2D4 LD A,$01 Tile numbering starts from 01.
PopulateTileTable_Loop D2D6 LD (HL),A Write the tile ID to *HL.
D2D7 INC HL Increment the tile table pointer by one.
D2D8 INC A Increment the tile ID by one.
D2D9 DJNZ PopulateTileTable_Loop Decrease the tile counter by one and loop back to PopulateTileTable_Loop until the table has been populated.
Copy default values to D828.
D2DB LD HL,$D879 HL=Defaults.
D2DE LD DE,$D828 DE=D828.
PopulateDefaults_Loop D2E1 LD A,(HL) Load the byte from *HL and store it in A.
D2E2 CP $FF Jump to PopulateDefaults_Done if this byte is the terminator (FF).
D2E4 JR Z,PopulateDefaults_Done
D2E6 LD B,A Load the byte into B this is the count/ repeater value.
D2E7 INC HL Increment the defaults pointer by one.
D2E8 LD A,(HL) Load the defaults byte from *HL and store it in A.
D2E9 INC HL Increment the defaults pointer by one.
RepeatDefault_Loop D2EA LD (DE),A Write the defaults byte to the destination.
D2EB INC DE Increment the destination pointer by one.
D2EC DJNZ RepeatDefault_Loop Decrease repeater count by one and loop back to RepeatDefault_Loop until the defaults byte has been written this number of times.
D2EE JR PopulateDefaults_Loop Jump back to PopulateDefaults_Loop.
The computed values are done, copy the last six values over.
PopulateDefaults_Done D2F0 INC HL Copy the last 0006 bytes from D888 to D84A.
D2F1 LD BC,$0006
D2F4 LDIR
Write three random numbers between 01-20 to D850, D851 and D852.
D2F6 LD B,$03 B=03.
PickThreeRandomNumbers_Loop D2F8 LD A,R A=the contents of the Memory Refresh Register.
D2FA AND %00011111 Ensure this number is between 01-20.
D2FC INC A
D2FD LD (DE),A Write this number to the destination pointer.
D2FE INC DE Increment the destination pointer by one.
D2FF DJNZ PickThreeRandomNumbers_Loop Decrease counter by one and loop back to PickThreeRandomNumbers_Loop until counter is zero.
D301 LD HL,$DA1F Write DA1F to:
D304 LD ($D853),HL
D307 LD ($D855),HL
D30A LD ($D857),HL
D30D LD ($D859),HL
D310 LD HL,$E292 HL=E292.
D313 LD BC,$07D0 BC=07D0.
D316 LD A,R A=the contents of the Memory Refresh Register.
D318 ADD A,C A+=C.
D319 LD C,A C=A.
Game_Initialisation_1 D31A PUSH BC Stash BC, HL and HL on the stack.
D31B PUSH HL
D31C PUSH HL
D31D CALL GenerateRandomNumber Call GenerateRandomNumber.
D320 ADD HL,BC HL+=random number.
D321 EX DE,HL Exchange the DE and HL registers.
D322 POP HL Restore HL from the stack.
D323 CALL GenerateRandomNumber Call GenerateRandomNumber.
D326 ADD HL,BC HL+=random number.
D327 LD B,(HL) B=*HL.
D328 LD A,(DE) Write *DE to *HL.
D329 LD (HL),A
D32A LD A,B Write B to *DE.
D32B LD (DE),A
D32C POP HL Restore HL and BC from the stack.
D32D POP BC
D32E DEC BC Decrease BC by one.
D32F LD A,B Jump to Game_Initialisation_1 if BC is not zero.
D330 OR C
D331 JR NZ,Game_Initialisation_1
Populate the level, bonus and score numbering in the dashboard.
D333 CALL Print_Level Call Print_Level.
D336 CALL Print_Bonus Call Print_Bonus.
D339 CALL Print_Score Call Print_Score.
Paint the preview grid pattern.
D33C CALL Colourise_PreviewGrid Call Colourise_PreviewGrid.
Small pause...
D33F LD BC,$9C40 BC=9C40.
SetUp_Pause_Loop D342 DEC BC Decrease BC by one.
D343 LD A,B Jump to SetUp_Pause_Loop until BC is zero.
D344 OR C
D345 JR NZ,SetUp_Pause_Loop
Play the "static" animation in the preview area.
D347 CALL StaticAnimation Call StaticAnimation.
Display the current preview image.
D34A LD IX,($D892) IX=*LevelGraphicsData.
D34E CALL GeneratePicture Call GeneratePicture.
D351 RET Return.
Prev: D28D Up: Map Next: D352