Prev: C6A4 Up: Map Next: C758
C6B6: Start of game cycle - control checks
Used by the routines at C677 and D94C.
Check and log game control inputs
C6B6 LD A,($BF19) Game flag - 0 = New/current game, 1 = Loaded game
C6B9 CP $00 If not a new/current game...
C6BB JP NZ,$C763 ...Launch the pause game (with music) routine
C6BE LD A,($EAB7) Get room number
C6C1 CP $E0 If <= 224, skip next two instructions
C6C3 JR C,$C6CA
C6C5 LD A,$01 If room number >= 224, it's a tunnel room - set Maroc's vertical facing direction to 1 (up)
C6C7 LD ($EAAC),A
Read keyboard/joystick input
Kempston controls dealt with separately at C6F2.
C6CA LD HL,($EB06) Address of the control values to check, e.g. keyboard, cursor, Kempston
C6CD LD DE,$EB2E Store for which keys/buttons are being pressed
C6D0 LD A,($BF18) Control option 1 = Kempston, 2 = AGF (Cursor), 3 = Sinclair, 4 = Keyboard
C6D3 CP $01 Check if Kempston joystick selected
C6D5 JR Z,$C6F2
Read keyboard input (includes Cursor, Sinclair joysticks)
Reads port for chosen control option (values at from EB06) for up, down, left, right and fire.
Stores values in control buffer at EB2E. 0 = Not pressed, 1 = Pressed
C6D7 LD C,(HL) Get port value of control method to check - store in BC register pair
C6D8 INC HL
C6D9 LD B,(HL)
C6DA INC HL
C6DB IN A,(C) Check if relevant control key pressed (up/down/left/right/fire)
C6DD OR (HL)
C6DE CP $FF
C6E0 JR Z,$C6E6
C6E2 LD A,$01 Key pressed - store 1 for this input
C6E4 JR $C6E8
C6E6 LD A,$00 Key not pressed - store 0 for this input
C6E8 LD (DE),A
C6E9 INC DE Move on to next control key/button
C6EA INC HL
C6EB LD A,$00 Check if we've reached the end of the controls (0 = end-of-data byte)
C6ED CP (HL)
C6EE JR NZ,$C6D7 If not, continue to read control directions until all 5 have been checked
C6F0 JR $C708
Read Kempston joystick input
C6F2 LD BC,$001F Kempston joystick port
C6F5 IN A,(C) Read control port
C6F7 LD B,A
C6F8 LD A,(HL) Check if direction/button being pressed
C6F9 AND B
C6FA LD A,$00 Store 0 (default) if button/control not being pressed
C6FC JR Z,$C700
C6FE LD A,$01 Store 1 if button/control being pressed
C700 LD (DE),A
C701 INC DE Move on to next control/button
C702 INC HL
C703 LD A,(HL)
C704 CP $00 Check if we've reached the end of the controls (0 = end-of-data byte)
C706 JR NZ,$C6F2 If not, continue to read control directions until all 5 have been checked
Evaluate control direction values
Horizontal movement control:
C708 LD A,($EB31) Check movement control - right
C70B LD C,A Store in C register (1 = right pressed, 0 = right not pressed)
C70C LD A,($EB30) Check movement control - left
C70F SUB C Calculate left minus right (0 = both/neither pressed, 1 = right pressed, -1 (255) = left pressed)
C710 LD C,A Store left/right calculated value in C
C711 LD A,($EAAB) Maroc's facing direction - 0, 254 (facing right), or 2 (facing left), depending on which door he's entered a room from.
When Maroc enters a new room, he's set to 'moving' so he doesn't just sit in the doorway
C714 ADD A,C Add to control value
C715 LD ($EAFD),A ...And store...
Vertical movement control:
C718 LD A,($EB2F) Check movement control - down
C71B LD C,A Store in C register (1 = down pressed, 0 = down not pressed)
C71C LD A,($EB2E) Check movement control - up
C71F SUB C Calculate up minus down (0 = both/neither pressed, 1 = up pressed, -1 (255) = down pressed)
C720 LD C,A Store up/down calculated value in C register
C721 LD A,($EAAC) Maroc's facing direction (1 = facing up, 255 = facing down)
C724 ADD A,C Add to control value
C725 LD ($EAFE),A ...And store...
The FIRE button flag is stored at EB32. Unlike other control directions, the byte at EAC6 is used to ensure that the control button is released after pressing, to prevent action auto-cancel if the fire control is held for too long.
This ensures that the player has to let go of the fire control button/key, before pressing it again to activate something.
C728 LD A,($EB32) Check FIRE control
C72B CP $00
C72D LD A,($EAC6) Get the 'fire release' flag ready to check
C730 JR Z,$C753 If fire hasn't been pressed, skip the next routine
FIRE pressed
C732 CP $00 Has the fire key been released from being pressed earlier?
C734 JR Z,$C73D
C736 LD A,$00 Set FIRE control to zero
C738 LD ($EB32),A
C73B JR $C758
Fire control has been pressed so set the fire control release byte at EAC6 to 1.
C73D LD A,$01
C73F LD ($EAC6),A
Play high pitched beep
C742 LD A,$10 16 = speaker bit (bit 4)
C744 LD C,$20 Outer loop counter - affects duration/sound effect
C746 OUT ($FE),A Play speaker
C748 XOR $10 Toggle speaker bit
C74A LD B,$30 Inner loop counter - affects pitch of beep sound
C74C DJNZ $C74C Decrement inner loop counter until zero for short pause
C74E DEC C Outer loop pause
C74F JR NZ,$C746
C751 JR $C758
Fire not pressed
C753 LD A,$00 Set the 'fire control release' control flag to 0, as no fire controls are being pressed
C755 LD ($EAC6),A
Prev: C6A4 Up: Map Next: C758