![]() |
Routines |
| Prev: DF46 | Up: Map | Next: E0AD |
|
Used by the routines at GameEntryPoint and SelectionScreen.
|
||||||||
|
In order to find the scene data for the requested level, the code "counts" the number of terminator bytes found.
|
||||||||
| FindScene | DF90 | LD E,A | E=level. | |||||
| DF91 | LD HL,$CDE2 | HL=Scene_Data. | ||||||
| FindScene_Loop | DF94 | LD A,(HL) | A=byte of scene data. | |||||
| DF95 | INC HL | Increment scene data pointer by one. | ||||||
|
Check for a terminator byte.
|
||||||||
| DF96 | CP $FF | Loop back to FindScene_Loop until A is equal to FF. | ||||||
| DF98 | JR NZ,FindScene_Loop | |||||||
|
Only continue when the "level" has been decreased to zero. This is when the appropriate scene data has been found.
|
||||||||
| DF9A | DEC E | Decrease level by one. | ||||||
| DF9B | JR NZ,FindScene_Loop | Jump to FindScene_Loop until E is zero. | ||||||
|
Process the scene data.
|
||||||||
| DF9D | LD A,(HL) | A=byte of scene data. | ||||||
| DF9E | PUSH HL | Stash the scene data pointer on the stack temporarily. | ||||||
| DF9F | CALL $D50C | Call D50C. | ||||||
| DFA2 | POP HL | Restore the scene data pointer from the stack. | ||||||
| DFA3 | INC HL | Increment the scene data pointer by one. | ||||||
| DFA4 | LD A,(HL) | A=byte of scene data. | ||||||
| DFA5 | PUSH HL | Stash the scene data pointer on the stack temporarily. | ||||||
| DFA6 | CALL $D55B | Call D55B. | ||||||
| DFA9 | POP HL | Restore the scene data pointer from the stack. | ||||||
| DFAA | INC HL | Increment the scene data pointer by one. | ||||||
| DFAB | LD A,(HL) | A=byte of scene data. | ||||||
| DFAC | AND %01111000 | Keep only bits 3-6. | ||||||
| DFAE | RRCA | Rotate A right three positions (bits 3 to 6 are now in positions 0 to 3). | ||||||
| DFAF | RRCA | |||||||
| DFB0 | RRCA | |||||||
| DFB1 | PUSH HL | Stash the scene data pointer on the stack temporarily. | ||||||
| DFB2 | LD ($D400),A | Write A to *Scene_Type. | ||||||
| DFB5 | CALL $D593 | Call D593. | ||||||
| DFB8 | POP HL | Restore the scene data pointer from the stack. | ||||||
| DFB9 | XOR A | Write 00 to: | ||||||
| DFBA | LD ($D220),A | |||||||
| DFBD | LD ($D222),A | |||||||
|
Set the number of buildings for this level.
|
||||||||
| DFC0 | LD A,(HL) | A=*HL. | ||||||
| DFC1 | AND %00000111 | Keep only bits 0-2. | ||||||
| DFC3 | LD ($D3F3),A | Write A to *BuildingsRemainingCount. | ||||||
| DFC6 | INC HL | Increment the scene data pointer by one. | ||||||
| FindScene_0 | DFC7 | PUSH AF | Stash AF and HL on the stack. | |||||
| DFC8 | PUSH HL | |||||||
| DFC9 | LD HL,$D39F | HL=Table_Buildings. | ||||||
| DFCC | LD A,($D220) | A=*D220. | ||||||
| DFCF | LD D,$00 | D=00. | ||||||
| DFD1 | LD E,A | E=A. | ||||||
| DFD2 | ADD HL,DE | HL+=DE. | ||||||
| DFD3 | PUSH HL | IX=HL using the stack. | ||||||
| DFD4 | POP IX | |||||||
| DFD6 | ADD A,$0E | A+=0E. | ||||||
| DFD8 | LD ($D220),A | Write A to *D220. | ||||||
| DFDB | LD A,($D222) | A=*D222. | ||||||
| DFDE | INC A | Increment A by one. | ||||||
| DFDF | LD ($D222),A | Write A to *D222. | ||||||
| DFE2 | POP HL | Restore HL from the stack. | ||||||
| DFE3 | LD A,(HL) | A=*HL. | ||||||
| DFE4 | AND %01111111 | Keep only bits 0-6. | ||||||
| DFE6 | LD E,A | E=A. | ||||||
| DFE7 | LD A,(HL) | A=*HL. | ||||||
| DFE8 | AND %10000000 | Keep only bit 7. | ||||||
| DFEA | RLCA | Move bit 7 to bit 0, and also set/ unset the carry flag. | ||||||
| DFEB | INC A | Increment A by one. | ||||||
| DFEC | EX AF,AF' | Exchange the AF register with the shadow AF register. | ||||||
| DFED | INC HL | Increment HL by one. | ||||||
| DFEE | LD A,(HL) | A=*HL. | ||||||
| DFEF | AND %11100000 | Keep only bits 5-7. | ||||||
| DFF1 | RLCA | Rotate A left three positions (bits 5 to 7 are now in positions 0 to 2). | ||||||
| DFF2 | RLCA | |||||||
| DFF3 | RLCA | |||||||
| DFF4 | LD B,$00 | B=00. | ||||||
| DFF6 | LD C,A | C=A. | ||||||
| DFF7 | PUSH HL | Stash HL on the stack. | ||||||
| DFF8 | LD HL,$E0A5 | HL=E0A5. | ||||||
| DFFB | ADD HL,BC | HL+=BC. | ||||||
| DFFC | LD D,(HL) | D=*HL. | ||||||
| DFFD | POP HL | Restore HL from the stack. | ||||||
| DFFE | LD A,(HL) | A=*HL. | ||||||
| DFFF | AND %00011111 | Keep only bits 0-4. | ||||||
| E001 | LD C,A | C=A. | ||||||
| E002 | INC HL | Increment HL by one. | ||||||
| E003 | PUSH HL | Stash HL on the stack. | ||||||
| E004 | LD HL,$0080 | HL=0080. | ||||||
| E007 | ADD HL,BC | HL+=BC. | ||||||
| E008 | LD C,$08 | C=08. | ||||||
| E00A | LD A,E | A=E. | ||||||
| E00B | DEC A | Decrease A by one. | ||||||
| FindScene_1 | E00C | DEC C | Decrease C by one. | |||||
| E00D | SUB $06 | A-=06. | ||||||
| E00F | JR NC,FindScene_1 | Jump to FindScene_1 if there's no carry (i.e. A was higher than 06). | ||||||
| E011 | RRC C | Rotate C right three positions. | ||||||
| E013 | RRC C | |||||||
| E015 | RRC C | |||||||
| E017 | ADD HL,BC | HL+=BC. | ||||||
| E018 | LD B,H | B=H. | ||||||
| E019 | LD C,L | C=L. | ||||||
| E01A | EX AF,AF' | Exchange the AF register with the shadow AF register. | ||||||
| E01B | CALL $DA71 | Call DA71. | ||||||
| E01E | LD HL,$D31F | HL=D31F. | ||||||
| E021 | LD A,(IX+$07) | A=*IX+07. | ||||||
| E024 | RRCA | Rotate A left one position, setting the carry flag if bit 0 was set. | ||||||
| E025 | JR C,FindScene_2 | Jump to FindScene_2 if the carry flag was set. | ||||||
| E027 | LD HL,$D35F | HL=D35F. | ||||||
| FindScene_2 | E02A | LD D,$00 | D=00. | |||||
| E02C | LD E,(IX+$01) | E=*IX+01. | ||||||
| E02F | ADD HL,DE | HL+=DE. | ||||||
| E030 | LD A,(IX+$02) | A=*IX+02. | ||||||
| E033 | SUB E | A-=E. | ||||||
| E034 | INC A | Increment A by one. | ||||||
| E035 | LD B,A | B=A. | ||||||
| FindScene_3 | E036 | LD A,($D222) | A=*D222. | |||||
| E039 | LD (HL),A | Write A to *HL. | ||||||
| E03A | PUSH HL | Stash HL on the stack. | ||||||
| E03B | LD E,$20 | E=20. | ||||||
| E03D | ADD HL,DE | HL+=DE. | ||||||
| E03E | LD A,(IX+$08) | A=*IX+08. | ||||||
| E041 | LD (HL),A | Write A to *HL. | ||||||
| E042 | POP HL | Restore HL from the stack. | ||||||
| E043 | INC HL | Increment HL by one. | ||||||
| E044 | DJNZ FindScene_3 | Decrease counter by one and loop back to FindScene_3 until counter is zero. | ||||||
| E046 | POP HL | Restore HL and AF from the stack. | ||||||
| E047 | POP AF | |||||||
| E048 | DEC A | Decrease A by one. | ||||||
| E049 | JP NZ,FindScene_0 | Jump to FindScene_0 until A is zero. | ||||||
| E04C | LD HL,$D31F | HL=D31F. | ||||||
| E04F | LD DE,$D35F | DE=D35F. | ||||||
| E052 | LD B,$20 | B=20 (counter). | ||||||
| FindScene_4 | E054 | LD A,(DE) | A=*DE. | |||||
| E055 | RLCA | Rotate A left three positions. | ||||||
| E056 | RLCA | |||||||
| E057 | RLCA | |||||||
| E058 | OR (HL) | Set the bits from *HL. | ||||||
| E059 | LD (HL),A | Write A to *HL. | ||||||
| E05A | INC HL | Increment HL by one. | ||||||
| E05B | INC DE | Increment DE by one. | ||||||
| E05C | DJNZ FindScene_4 | Decrease counter by one and loop back to FindScene_4 until counter is zero. | ||||||
|
Default to not using the train.
|
||||||||
| E05E | LD A,$FE | Write FE (spawning "off") to *TrainState. | ||||||
| E060 | LD ($D405),A | |||||||
| E063 | LD A,($D400) | Jump to Train_Enable if *Scene_Type is equal to 02. | ||||||
| E066 | CP $02 | |||||||
| E068 | JR Z,Train_Enable | |||||||
| E06A | CP $05 | Jump to Vehicle_Disable if A is equal to 05. | ||||||
| E06C | JR Z,Vehicle_Disable | |||||||
|
Anything else uses vehicles.
|
||||||||
| E06E | LD A,$18 | Write 18 to *VehicleCounter. | ||||||
| E070 | LD ($D401),A | |||||||
| Helicopters_CalculateCount | E073 | LD A,($DF44) | A=*CurrentLevel. | |||||
|
Divide the level number by 08 but ensure the result is no higher than 07.
|
||||||||
| E076 | RRCA | Rotate A right three positions (bits 3 to 5 are now in positions 0 to 2). | ||||||
| E077 | RRCA | |||||||
| E078 | RRCA | |||||||
| E079 | AND %00000111 | Keep only bits 0-2. | ||||||
|
Always ensure there are at least two helicopters.
|
||||||||
| E07B | ADD A,$02 | A+=02. | ||||||
|
Don't allow any more than six helicopters.
|
||||||||
| E07D | CP $07 | Jump to Helicopter_SetCount if A is lower than 07. | ||||||
| E07F | JR C,Helicopter_SetCount | |||||||
|
Else, set the limit of six which is the maximum the game can support.
|
||||||||
| E081 | LD A,$06 | A=06. | ||||||
| Helicopter_SetCount | E083 | LD ($D212),A | Write A to *MaxHelicopterCount. | |||||
| E086 | LD A,($DF44) | A=*CurrentLevel. | ||||||
|
Divide the level number by 04 but ensure the result is no higher than 0F.
|
||||||||
| E089 | RRCA | Rotate A right two positions (bits 2 to 5 are now in positions 0 to 3). | ||||||
| E08A | RRCA | |||||||
| E08B | AND %00001111 | Keep only bits 0-3. | ||||||
| E08D | ADD A,$06 | A+=06. | ||||||
| E08F | CP $11 | Jump to FindScene_5 if A is lower than 11. | ||||||
| E091 | JR C,FindScene_5 | |||||||
| E093 | LD A,$10 | Write 10 to *MaxHumansCount. | ||||||
| FindScene_5 | E095 | LD ($D211),A | ||||||
| E098 | RET | Return. | ||||||
|
Sets the train countdown and turns off vehicles as they can't co-exist.
|
||||||||
| Train_Enable | E099 | LD A,$20 | Write 20 to *TrainState. | |||||
| E09B | LD ($D405),A | |||||||
| Vehicle_Disable | E09E | LD A,$FE | Write FE (spawning "off") to *VehicleCounter. | |||||
| E0A0 | LD ($D401),A | |||||||
| E0A3 | JR Helicopters_CalculateCount | Jump to Helicopters_CalculateCount. | ||||||
| E0A5 | DEFB $50,$58,$60,$20,$70,$30,$78,$38 | |||||||
| Prev: DF46 | Up: Map | Next: E0AD |