Prev: 945C Up: Map Next: 9531
9466: Routine at 9466
Used by the routine at 8258.
9466 LD A,R A=random number.
9468 AND %00000011 Keep only bits 0-1.
946A RET NZ Return if the value is not zero.
946B LD A,($5E67) A=GameDelayTimer.
946E AND A Return if the value is not zero.
946F RET NZ
9470 CALL FindSlotAlien Call FindSlotAlien.
9473 RET NZ Return if there were no available alien slots.
9474 PUSH HL Stash HL (the free alien slot) on the stack.
9475 EX DE,HL Switch the DE and HL registers.
9476 LD A,($5E40) A=5E40.
9479 RLA Rotate A left once.
947A AND %00001110 Keep only bits 1-3.
947C LD C,A Create an offset in BC - max 0E (only even numbers).
947D LD B,$00
947F LD A,($5EA0) A=ActivePlayer_Level.
9482 CP $0C Compare the current level against 0C if there's any carry over then jump to 9488.
9484 JR C,$9488
9486 LD A,$0C A=0C.
9488 AND %00001110 Keep only bits 1-3.
948A LD L,A Create an offset in HL - number can be:
  • 0002
  • 0004
  • 0006
  • 0008
  • 000A
  • 000C
948B LD H,$00
948D LD DE,$9D72 HL+=LevelsAlienLookupTable.
9490 ADD HL,DE
9491 LD A,(HL) HL=alien lookup table appropriate for the current level.
9492 INC HL
9493 LD H,(HL)
9494 LD L,A
9495 ADD HL,BC HL+=BC.
9496 LD A,(HL) HL=an alien from the level lookup table.
9497 INC HL
9498 LD H,(HL)
9499 LD L,A
949A LD BC,$0018 BC=0018.
949D POP DE DE=the free alien slot (from earlier).
949E PUSH DE Stash DE (the free alien slot) on the stack again.
949F LDIR Copy the alien data to the free alien slot.
94A1 POP HL HL=the free alien slot.
94A2 LD A,(HL)
94A3 INC HL
94A4 INC HL
94A5 PUSH HL
94A6 LD HL,($607A)
94A9 CP $88
94AB JR Z,$94DB
94AD CP $B8
94AF JP Z,$9506
94B2 LD A,($5E40)
94B5 LD C,A
94B6 LD B,$00
94B8 LD DE,$0080
94BB AND $02
94BD JR Z,$94C5
94BF SBC HL,BC
94C1 SBC HL,DE
94C3 JR $94C7
94C5 ADD HL,BC
94C6 ADD HL,DE
94C7 LD A,H
94C8 AND %00011111 Keep only bits 0-4.
94CA LD H,A
94CB EX DE,HL
94CC POP HL
94CD LD (HL),E
94CE INC HL
94CF LD (HL),D
94D0 INC HL
94D1 INC HL
94D2 LD A,C
94D3 AND %10000000 Keep only bit 7.
94D5 RET Z
94D6 LD A,(HL)
94D7 NEG
94D9 LD (HL),A
94DA RET Return.
94DB LD A,($5E40) A=5E40.
94DE LD B,A B=A.
94DF AND %10000000 Keep only bit 7.
94E1 SUB $40
94E3 LD C,A
94E4 JP P,$94EC
94E7 LD DE,$0090 DE=0090.
94EA JR $94EF Jump to 94EF.
94EC LD DE,$FF70
94EF ADD HL,DE
94F0 LD A,H
94F1 AND %00011111 Keep only bits 0-4.
94F3 LD H,A
94F4 EX DE,HL
94F5 POP HL
94F6 LD (HL),E
94F7 INC HL
94F8 LD (HL),D
94F9 INC HL
94FA LD A,B
94FB AND %01111000 Keep only bits 3-6.
94FD JR NZ,$9500
94FF INC A
9500 ADD A,$37
9502 LD (HL),A
9503 INC HL
9504 LD (HL),C
9505 RET
9506 LD A,($5E40)
9509 LD B,A
950A AND %10000000 Keep only bit 7.
950C SUB $40
950E LD C,A
950F JP P,$9517
9512 LD DE,$0090 DE=0090.
9515 JR $951A Jump to 951A.
9517 LD DE,$FF70 DE=FF70.
951A ADD HL,DE
951B LD A,H
951C AND $1F
951E LD H,A
951F EX DE,HL
9520 POP HL
9521 LD (HL),E
9522 INC HL
9523 LD (HL),D
9524 INC HL
9525 LD A,B
9526 AND %01111000 Keep only bits 3-6.
9528 JR NZ,$952B
952A INC A
952B ADD A,$37
952D LD (HL),A
952E INC HL
952F LD (HL),C
9530 RET Return.
Prev: 945C Up: Map Next: 9531