Prev: BAE5 Up: Map Next: BD9E
BB17: Move one frame and check for input
Used by the routine at AF5D.
BB17 LD HL,($A408)
BB1A LD ($A441),HL
BB1D LD HL,$A403
BB20 LD A,(HL)
BB21 AND $C3
BB23 LD (HL),A
BB24 AND $01
BB26 LD A,$02
BB28 JR Z,$BB34
BB2A LD HL,($A404)
BB2D BIT 7,(HL)
BB2F JP NZ,$BC59
BB32 INC HL
BB33 LD A,(HL)
BB34 LD HL,($A40A)
BB37 LD BC,($A408)
BB3B ADD HL,BC
BB3C LD BC,$001E
BB3F ADD HL,BC
BB40 EX DE,HL
BB41 LD HL,($A406)
BB44 CP $02
BB46 LD A,H
BB47 JR NZ,$BB61
BB49 AND $07
BB4B JR Z,$BB65
BB4D CP $07
BB4F JR NZ,$BB87
BB51 LD A,($A403)
BB54 OR $04
BB56 LD ($A403),A
BB59 LD A,H
BB5A AND $F8
BB5C LD H,A
BB5D LD A,$60
BB5F JR $BB67
BB61 AND $07
BB63 JR NZ,$BB87
BB65 LD A,$40
BB67 ADD A,L
BB68 LD L,A
BB69 JR NC,$BB6F
BB6B LD A,H
BB6C ADD A,$08
BB6E LD H,A
BB6F LD A,($A40F)
BB72 LD C,A
BB73 CPL
BB74 LD B,A
BB75 LD A,(DE)
BB76 AND C
BB77 AND (HL)
BB78 JR NZ,$BBA0
BB7A INC DE
BB7B INC L
BB7C LD A,(DE)
BB7D AND (HL)
BB7E JR NZ,$BBA0
BB80 DEC DE
BB81 INC L
BB82 LD A,(DE)
BB83 AND B
BB84 AND (HL)
BB85 JR NZ,$BBA0
BB87 LD HL,$A403
BB8A BIT 0,(HL)
BB8C JP NZ,$BC59
BB8F LD A,$02
BB91 LD (HL),$20
BB93 LD HL,($A40C)
BB96 LD BC,$000A
BB99 ADD HL,BC
BB9A LD ($A40C),HL
BB9D JP $BC7D
BBA0 EX DE,HL
BBA1 LD HL,$A403
BBA4 BIT 2,(HL)
BBA6 JR Z,$BBAE
BBA8 RES 0,(HL)
BBAA LD A,$01
BBAC JR $BB93
BBAE EX DE,HL
BBAF CALL $BA34 Has Ted collided with anything?
BBB2 RET C If he has, and it's fatal, exit with carry flag set
BBB3 LD D,A
BBB4 LD HL,$A40E Get the fallen height
BBB7 LD A,$27 Is it more than the maximum to survive?
BBB9 CP (HL)
BBBA RET C If not, return with carry flag set to show life lost
BBBB LD (HL),$00 Set on the ground
BBBD LD HL,$A439 Mark that Ted will not get an infinite death loop now
BBC0 SET 0,(HL)
BBC2 LD HL,$010D
BBC5 LD ($A40C),HL
BBC8 XOR A
BBC9 LD ($A443),A
Check for LEFT
BBCC CALL $A72F
BBCF JR Z,$BBD8
BBD1 LD C,$82
BBD3 LD HL,$A47B
BBD6 JR $BBE2
Check for RIGHT
BBD8 CALL $A734
BBDB JR Z,$BBF0
BBDD LD C,$02
BBDF LD HL,$A57B
BBE2 LD ($A408),HL
BBE5 LD ($A443),BC
BBE9 LD A,($A403)
BBEC BIT 6,A
BBEE JR Z,$BBF2
Check for JUMP
BBF0 LD C,$00 No movement
BBF2 CALL $A739 Was "jump" pressed?
BBF5 JR Z,$BC04 Move on if not
BBF7 SET 0,C Set bit 0 to denote "mid jump"
BBF9 LD HL,$A76C Set automatic movement table to the "jump" table at A76C
BBFC LD ($A404),HL
BBFF LD HL,$A443
BC02 SET 0,(HL)
Check for conveyor belts
BC04 LD HL,($A41F)
BC07 LD A,(HL)
BC08 AND $7F
BC0A JR Z,$BC39
BC0C CP D
BC0D INC HL
BC0E JR NZ,$BC07
BC10 DEC HL
BC11 LD A,($A403)
BC14 CPL
BC15 AND $42
BC17 JR NZ,$BC24
BC19 LD A,($A403)
BC1C XOR (HL)
BC1D RLA
BC1E JR NC,$BC24
BC20 LD A,($A443)
BC23 LD C,A
BC24 LD A,C
BC25 BIT 1,A
BC27 JR NZ,$BC31
BC29 XOR (HL)
BC2A AND $7F
BC2C XOR (HL)
BC2D OR $42
BC2F JR $BC4D
BC31 XOR (HL)
BC32 RLA
BC33 JR NC,$BC4A
BC35 RES 1,C
BC37 JR $BC4C
BC39 LD HL,$A442
BC3C LD A,($A409)
BC3F CP (HL)
BC40 LD A,($A443)
BC43 LD C,A
BC44 JR Z,$BC4D
BC46 AND $01
BC48 JR $BC4D
BC4A SET 6,C
BC4C LD A,C
BC4D LD ($A403),A
BC50 BIT 0,A
BC52 JR NZ,$BC59
BC54 LD HL,($A406)
BC57 JR $BCD6
Ted is jumping (or otherwise moving automatically), handle the movement
BC59 LD HL,($A404) Point to next jump table entry
BC5C LD A,(HL) Get the first byte
BC5D LD C,A Copy into C
BC5E RLA Convert to note to play in BC
BC5F SBC A,A
BC60 LD B,A
BC61 PUSH HL Remember this
BC62 LD HL,($A40C) Get current sound to play
BC65 ADD HL,BC Add (or subtract) offset
BC66 LD ($A40C),HL Store new sound
BC69 POP HL Restore HL
BC6A INC HL Put the second byte in B
BC6B LD B,(HL)
BC6C INC HL Move to next entry and set it as active
BC6D LD ($A404),HL
BC70 LD A,(HL) Get the entry
BC71 LD HL,$A403 Get jump flags
BC74 SET 5,(HL)
BC76 CP $80 Is it the "end of table byte?"
BC78 LD A,B Put jump distance in A
BC79 JR NZ,$BC7D Loop back if it isn't
BC7B RES 0,(HL) Reset "Ted jumping" flag if the movement table has finished
BC7D LD HL,($A406)
BC80 AND A
BC81 JR Z,$BCD6
BC83 BIT 7,A
BC85 JR NZ,$BCB9
BC87 LD B,A
BC88 LD A,($A403) Set bit 3 (Ted falling) in flags
BC8B OR $08
BC8D LD ($A403),A
BC90 LD DE,$A40E Increase height fallen, unless it is at maximum already
BC93 LD A,(DE)
BC94 INC A
BC95 JR NZ,$BC98
BC97 DEC A
BC98 LD (DE),A
BC99 INC H Move Ted down a line
BC9A LD A,H Have we reached the end of an 8x8 block?
BC9B AND $07
BC9D JR NZ,$BCB5 No, so move on
BC9F LD A,L Jump to a new 8x8 block
BCA0 ADD A,$20
BCA2 LD L,A
BCA3 JR C,$BCA9 Move on if we are still on the same third of the screen
BCA5 LD A,H Move on to the next third of a screen
BCA6 SUB $08
BCA8 LD H,A
BCA9 BIT 3,H
BCAB JR Z,$BCB5 Jump forward if more screen to write to
BCAD LD A,L Check third of screen
BCAE AND $E0
BCB0 CP $C0
BCB2 LD A,$03
BCB4 RET Z Return if Ted has reached the floor
BCB5 DJNZ $BC93 Loop back round - still falling
BCB7 JR $BCD6
BCB9 NEG
BCBB LD B,A
BCBC LD A,H
BCBD DEC H
BCBE AND $07
BCC0 JR NZ,$BCD4
BCC2 LD A,L
BCC3 SUB $20
BCC5 LD L,A
BCC6 LD A,H
BCC7 JR C,$BCCC
BCC9 ADD A,$08
BCCB LD H,A
BCCC CP $80
BCCE JR NC,$BCD4
BCD0 XOR A
BCD1 LD A,$01
BCD3 RET
BCD4 DJNZ $BCBC
BCD6 LD A,($A403) Get flags
BCD9 BIT 1,A
BCDB LD C,A
BCDC EX DE,HL
BCDD LD HL,($A40A)
BCE0 LD A,($A40F)
BCE3 JR Z,$BD15
BCE5 BIT 7,C
BCE7 LD BC,$0020
BCEA JR NZ,$BD03
BCEC SRL A
BCEE JR NZ,$BD00
BCF0 LD A,E
BCF1 AND $1F
BCF3 CP $1E
BCF5 LD A,$02
BCF7 RET Z
BCF8 LD A,$FF
BCFA LD HL,$0000
BCFD INC E
BCFE JR $BD15
BD00 ADD HL,BC
BD01 JR $BD15
BD03 SCF
BD04 ADC A,A
BD05 JR NC,$BD13
BD07 LD A,E
BD08 AND $1F
BD0A RET Z
BD0B LD A,$01
BD0D LD HL,$00E0
BD10 DEC E
BD11 JR $BD15
BD13 SBC HL,BC
BD15 LD BC,($A408)
BD19 PUSH HL
BD1A ADD HL,BC
BD1B LD C,A
BD1C PUSH DE
BD1D EX DE,HL
BD1E CALL $B9EF
BD21 LD B,L
BD22 POP DE
BD23 POP HL
BD24 RET C
BD25 JR Z,$BD66
BD27 LD A,($A403)
BD2A BIT 4,A
BD2C JR NZ,$BD66
BD2E AND $09
BD30 CP $08
BD32 LD A,$10
BD34 LD ($A403),A
BD37 LD HL,($A406)
BD3A JR NZ,$BD57
BD3C LD A,B
BD3D LD B,$04
BD3F SRL C
BD41 JR NZ,$BD45
BD43 DEC C
BD44 INC E
BD45 DJNZ $BD3F
BD47 AND $1F
BD49 LD B,A
BD4A LD A,E
BD4B AND $1F
BD4D CP B
BD4E JR NZ,$BD52
BD50 EX AF,AF'
BD51 CP C
BD52 RRA
BD53 OR $7F
BD55 JR $BCDB
BD57 EX DE,HL
BD58 LD HL,($A441)
BD5B LD ($A408),HL
BD5E LD HL,($A40A)
BD61 LD A,($A40F)
BD64 JR $BD71
BD66 LD ($A40A),HL
BD69 LD A,C
BD6A LD ($A40F),A
BD6D LD ($A406),DE
BD71 LD BC,($A408)
BD75 ADD HL,BC
BD76 LD BC,$0210
BD79 LD ($A400),BC
BD7D LD C,A
BD7E EX DE,HL
BD7F JR Z,$BD89
BD81 PUSH HL
BD82 PUSH DE
BD83 CALL $B9EF
BD86 POP DE
BD87 POP HL
BD88 RET C
BD89 CALL $B7CC
BD8C LD A,($A403)
BD8F BIT 5,A
BD91 JR Z,$BD9B
BD93 LD B,$07
BD95 LD HL,($A40C)
BD98 CALL $BEF6
BD9B OR $FF
BD9D RET
Prev: BAE5 Up: Map Next: BD9E