Prev: 57158 Up: Map Next: 57517
57232: Find Scene
Used by the routines at GameEntryPoint and SelectionScreen.
Input
A Level
In order to find the scene data for the requested level, the code "counts" the number of terminator bytes found.
FindScene 57232 LD E,A E=level.
57233 LD HL,52706 HL=Scene_Data.
FindScene_Loop 57236 LD A,(HL) A=byte of scene data.
57237 INC HL Increment scene data pointer by one.
Check for a terminator byte.
57238 CP 255 Loop back to FindScene_Loop until A is equal to 255.
57240 JR NZ,FindScene_Loop
Only continue when the "level" has been decreased to zero. This is when the appropriate scene data has been found.
57242 DEC E Decrease level by one.
57243 JR NZ,FindScene_Loop Jump to FindScene_Loop until E is zero.
Process the scene data.
57245 LD A,(HL) A=byte of scene data.
57246 PUSH HL Stash the scene data pointer on the stack temporarily.
57247 CALL 54540 Call 54540.
57250 POP HL Restore the scene data pointer from the stack.
57251 INC HL Increment the scene data pointer by one.
57252 LD A,(HL) A=byte of scene data.
57253 PUSH HL Stash the scene data pointer on the stack temporarily.
57254 CALL 54619 Call 54619.
57257 POP HL Restore the scene data pointer from the stack.
57258 INC HL Increment the scene data pointer by one.
57259 LD A,(HL) A=byte of scene data.
57260 AND %01111000 Keep only bits 3-6.
57262 RRCA Rotate A right three positions (bits 3 to 6 are now in positions 0 to 3).
57263 RRCA
57264 RRCA
57265 PUSH HL Stash the scene data pointer on the stack temporarily.
57266 LD (54272),A Write A to *Scene_Type.
57269 CALL 54675 Call 54675.
57272 POP HL Restore the scene data pointer from the stack.
57273 XOR A Write 0 to:
57274 LD (53792),A
57277 LD (53794),A
Set the number of buildings for this level.
57280 LD A,(HL) A=*HL.
57281 AND %00000111 Keep only bits 0-2.
57283 LD (54259),A Write A to *BuildingsRemainingCount.
57286 INC HL Increment the scene data pointer by one.
FindScene_0 57287 PUSH AF Stash AF and HL on the stack.
57288 PUSH HL
57289 LD HL,54175 HL=Table_Buildings.
57292 LD A,(53792) A=*53792.
57295 LD D,0 D=0.
57297 LD E,A E=A.
57298 ADD HL,DE HL+=DE.
57299 PUSH HL IX=HL using the stack.
57300 POP IX
57302 ADD A,14 A+=14.
57304 LD (53792),A Write A to *53792.
57307 LD A,(53794) A=*53794.
57310 INC A Increment A by one.
57311 LD (53794),A Write A to *53794.
57314 POP HL Restore HL from the stack.
57315 LD A,(HL) A=*HL.
57316 AND %01111111 Keep only bits 0-6.
57318 LD E,A E=A.
57319 LD A,(HL) A=*HL.
57320 AND %10000000 Keep only bit 7.
57322 RLCA Move bit 7 to bit 0, and also set/ unset the carry flag.
57323 INC A Increment A by one.
57324 EX AF,AF' Exchange the AF register with the shadow AF register.
57325 INC HL Increment HL by one.
57326 LD A,(HL) A=*HL.
57327 AND %11100000 Keep only bits 5-7.
57329 RLCA Rotate A left three positions (bits 5 to 7 are now in positions 0 to 2).
57330 RLCA
57331 RLCA
57332 LD B,0 B=0.
57334 LD C,A C=A.
57335 PUSH HL Stash HL on the stack.
57336 LD HL,57509 HL=57509.
57339 ADD HL,BC HL+=BC.
57340 LD D,(HL) D=*HL.
57341 POP HL Restore HL from the stack.
57342 LD A,(HL) A=*HL.
57343 AND %00011111 Keep only bits 0-4.
57345 LD C,A C=A.
57346 INC HL Increment HL by one.
57347 PUSH HL Stash HL on the stack.
57348 LD HL,128 HL=0128.
57351 ADD HL,BC HL+=BC.
57352 LD C,8 C=8.
57354 LD A,E A=E.
57355 DEC A Decrease A by one.
FindScene_1 57356 DEC C Decrease C by one.
57357 SUB 6 A-=6.
57359 JR NC,FindScene_1 Jump to FindScene_1 if there's no carry (i.e. A was higher than 6).
57361 RRC C Rotate C right three positions.
57363 RRC C
57365 RRC C
57367 ADD HL,BC HL+=BC.
57368 LD B,H B=H.
57369 LD C,L C=L.
57370 EX AF,AF' Exchange the AF register with the shadow AF register.
57371 CALL 55921 Call 55921.
57374 LD HL,54047 HL=54047.
57377 LD A,(IX+7) A=*IX+7.
57380 RRCA Rotate A left one position, setting the carry flag if bit 0 was set.
57381 JR C,FindScene_2 Jump to FindScene_2 if the carry flag was set.
57383 LD HL,54111 HL=54111.
FindScene_2 57386 LD D,0 D=0.
57388 LD E,(IX+1) E=*IX+1.
57391 ADD HL,DE HL+=DE.
57392 LD A,(IX+2) A=*IX+2.
57395 SUB E A-=E.
57396 INC A Increment A by one.
57397 LD B,A B=A.
FindScene_3 57398 LD A,(53794) A=*53794.
57401 LD (HL),A Write A to *HL.
57402 PUSH HL Stash HL on the stack.
57403 LD E,32 E=32.
57405 ADD HL,DE HL+=DE.
57406 LD A,(IX+8) A=*IX+8.
57409 LD (HL),A Write A to *HL.
57410 POP HL Restore HL from the stack.
57411 INC HL Increment HL by one.
57412 DJNZ FindScene_3 Decrease counter by one and loop back to FindScene_3 until counter is zero.
57414 POP HL Restore HL and AF from the stack.
57415 POP AF
57416 DEC A Decrease A by one.
57417 JP NZ,FindScene_0 Jump to FindScene_0 until A is zero.
57420 LD HL,54047 HL=54047.
57423 LD DE,54111 DE=54111.
57426 LD B,32 B=32 (counter).
FindScene_4 57428 LD A,(DE) A=*DE.
57429 RLCA Rotate A left three positions.
57430 RLCA
57431 RLCA
57432 OR (HL) Set the bits from *HL.
57433 LD (HL),A Write A to *HL.
57434 INC HL Increment HL by one.
57435 INC DE Increment DE by one.
57436 DJNZ FindScene_4 Decrease counter by one and loop back to FindScene_4 until counter is zero.
Default to not using the train.
57438 LD A,254 Write 254 (spawning "off") to *TrainState.
57440 LD (54277),A
57443 LD A,(54272) Jump to Train_Enable if *Scene_Type is equal to 2.
57446 CP 2
57448 JR Z,Train_Enable
57450 CP 5 Jump to Vehicle_Disable if A is equal to 5.
57452 JR Z,Vehicle_Disable
Anything else uses vehicles.
57454 LD A,24 Write 24 to *VehicleCounter.
57456 LD (54273),A
Helicopters_CalculateCount 57459 LD A,(57156) A=*CurrentLevel.
Divide the level number by 8 but ensure the result is no higher than 7.
57462 RRCA Rotate A right three positions (bits 3 to 5 are now in positions 0 to 2).
57463 RRCA
57464 RRCA
57465 AND %00000111 Keep only bits 0-2.
Always ensure there are at least two helicopters.
57467 ADD A,2 A+=2.
Don't allow any more than six helicopters.
57469 CP 7 Jump to Helicopter_SetCount if A is lower than 7.
57471 JR C,Helicopter_SetCount
Else, set the limit of six which is the maximum the game can support.
57473 LD A,6 A=6.
Helicopter_SetCount 57475 LD (53778),A Write A to *MaxHelicopterCount.
57478 LD A,(57156) A=*CurrentLevel.
Divide the level number by 4 but ensure the result is no higher than 15.
57481 RRCA Rotate A right two positions (bits 2 to 5 are now in positions 0 to 3).
57482 RRCA
57483 AND %00001111 Keep only bits 0-3.
57485 ADD A,6 A+=6.
57487 CP 17 Jump to FindScene_5 if A is lower than 17.
57489 JR C,FindScene_5
57491 LD A,16 Write 16 to *MaxHumansCount.
FindScene_5 57493 LD (53777),A
57496 RET Return.
Sets the train countdown and turns off vehicles as they can't co-exist.
Train_Enable 57497 LD A,32 Write 32 to *TrainState.
57499 LD (54277),A
Vehicle_Disable 57502 LD A,254 Write 254 (spawning "off") to *VehicleCounter.
57504 LD (54273),A
57507 JR Helicopters_CalculateCount Jump to Helicopters_CalculateCount.
57509 DEFB 80,88,96,32,112,48,120,56
Prev: 57158 Up: Map Next: 57517