tuatara21 Posted August 6, 2017 Share Posted August 6, 2017 I'm trying to implement a simple pause/resume feature using the standard keypad combo (1 and 9). Also tried with 3 and 7. Either attempt instead results in a button press. If I modify the first line of code to IF cont.key = 4 THEN it works as expected. I assume this is one of those key combination results in other button / disc pressed scenarios? Please advise as I'm under the impression that a workaround exists. 'check for pause key combination IF cont.key = 1 and cont.key = 9 THEN junk = 0 pause_loop: if junk = 0 THEN PRINT AT 84 COLOR ((RAND AND 5)+2)+BG_BLUE,"PAUSE" 'increment timer to change color of pause text junk = junk + 1 'if any key, button or disc is pressed, resume game Wait if cont.button or cont.left or cont.right or cont.up or cont.down then gosub checkforNOKeys: PRINT AT 84 COLOR FG_BLUE+BG_BLUE," ": Gosub WaitaBit: goto resume_game if junk = 25 THEN junk = 0 GOTO pause_loop resume_game: END IF checkforNOKeys: Procedure Rem wait for controller release clearloop: clearkey=cont1 wait if clearkey then goto clearloop wait end WaitaBit:Procedure For a=0 to 10 Wait Next a End 1 Quote Link to comment Share on other sites More sharing options...
intvnut Posted August 6, 2017 Share Posted August 6, 2017 (edited) I don't know the "best" way in IntyBASIC. I do know that cont.key can only decode one keypad key at a time, due to how they are encoded. So, your first IF statement (IF cont.key = 1 and cont.key = 9) won't ever do anything useful. The keypad matrix works by clearing pairs of bits in response to individual keys being pressed: . ;; DISC ACTION KEYPAD ;; ;; Bit 0: Down Row 0 keys --------- 1 2 3 ;; ;; Bit 1: Right Row 1 keys --------- 4 5 6 ;; ;; Bit 2: Up Row 2 keys --------- 7 8 9 ;; ;; Bit 3: Left Row 3 keys --------- C 0 E ;; ;; Bit 4: Corner | | | ;; ;; Bit 5: T/L Col 2 keys --------- | -- | ---+ ;; ;; Bit 6: L/R Col 1 keys --------- | ---+ ;; ;; Bit 7: T/R Col 0 keys ----------+ ;; ;; ;; . For example, if you press [1], that clears bits 7 and 0, by the diagram above. If you press [9], that clears bits 5 and 2. Thus, pressing [1]+[9] will clear bits 7, 5, 2, and 0. You'll notice the same bit pattern gets cleared by pressing [3]+[7]. So, in your IntyBASIC program, one way you might check for the "pause" combination on either controller is with a statement like: . IF PEEK($1FE) = $5A OR PEEK($1FF) = $5A THEN ...do pause stuff... . The hex value $5A is the bit pattern you get when you clear bits 7, 5, 2, and 0, and set the remaining bits in an 8-bit value. Edited August 6, 2017 by intvnut 1 Quote Link to comment Share on other sites More sharing options...
tuatara21 Posted August 6, 2017 Author Share Posted August 6, 2017 @Intvnut - Thank you for clarifying, I knew there was some "magic" behind the way the controller keys were decoded but I was having trouble finding the specific details. Appreciate the detailed response I implemented your suggestion and it "sort of" worked... the game pauses as long as the 1 and 9 keys are held down. However it still activated the code for the top button and the game resumes as soon as I release the key(s). I could just utilize a single key for the pause functionality, but hoped to use the 1 & 9 keys to be consistent with other Intellivision games. Quote Link to comment Share on other sites More sharing options...
intvnut Posted August 7, 2017 Share Posted August 7, 2017 You probably want to include some logic to ensure that both controllers are released before you allow tapping anything to restart the game. I just tested this program and it seems to work as intended. . loop: wait print at 82 color ((RAND AND 5) + 2), "NOT PAUSED" gosub CheckPause goto loop CheckPause: Procedure if peek($1FE) <> $5A and peek($1FF) <> $5A then return ' Require controllers to be released for 1 second before ' recognizing an input. pause = 60 do gosub PauseAnim ' If we see input before the end of 1 second, restart the ' counter. If we see input after 1 second, allow un-pause if pause > 0 then pause = pause - 1 if (peek($1FE) and peek($1FF)) <> $FF then if pause <> 0 then pause = 60 else pause = 255 end if loop while pause <> 255 ' Once we see input and decide to un-pause, wait for /that/ ' input to go away before restarting the game. do gosub PauseAnim loop while (peek($1FE) and peek($1FF)) <> $FF return end PauseAnim: Procedure print at 82 color ((RAND AND 5) + 2), " PAUSED " wait return End 1 Quote Link to comment Share on other sites More sharing options...
tuatara21 Posted August 7, 2017 Author Share Posted August 7, 2017 The code provided resolved most of my issues. I'm still experiencing an activation of the function mapped to CONT.B0 when I press 1 & 9 simultaneously. I confirmed that pressing 1 or 9 separately does not cause this function to activate. Thanks again for the prompt response! I appreciate the detailed explanations as I attempt to pick up where I left off with IntyBasic after a 15-month absence. Sincerely,Derek Quote Link to comment Share on other sites More sharing options...
intvnut Posted August 7, 2017 Share Posted August 7, 2017 That probably has to do with the fact that the upper 3 bits of the controller bit pattern look like an action button press when you press 1+9. (See the diagram I posted earlier.) That's the 5 part of $5A. To prevent that event from firing spuriously, you may need to wait for a short "debounce" period to ensure it is not part of a "pause" request. Quote Link to comment Share on other sites More sharing options...
intvnut Posted August 7, 2017 Share Posted August 7, 2017 More specifically: When your code checks for CONT.B0, you might delay recognizing it for a couple ticks in case it might be pause. The problem is that 1+9 requires four switches to close, and they don't all close together. IIRC, the EXEC method for reading the controller does have some filtering (debouncing). IntyBASIC implements its own controller scanning. Maybe one of the IntyBASIC experts can pipe up with a preferred way to handle this in IntyBASIC? I'm far from being an IntyBASIC expert. Quote Link to comment Share on other sites More sharing options...
tuatara21 Posted August 8, 2017 Author Share Posted August 8, 2017 @intvnut - thank you for the clarification, especially the follow-up post. So far I've been unable to find any tutorials or other sample code which includes any "debounce" code (at least, it's not commented as such). If there is an optimal way to handle this in IntyBasic, I'd appreciate if someone could share the solution. I must not be the only one struggling with this Quote Link to comment Share on other sites More sharing options...
intvnut Posted August 9, 2017 Share Posted August 9, 2017 The simplest debounce strategy is to wait some time before recognizing an input to determine that was indeed the desired input. That, of course, adds lag to your input, reducing the responsiveness of your game. In this case, I don't know if that's the right approach. If it were up to me, I'd modify the intybasic_epilogue.asm file (or is it intybasic_prologue.asm) to tweak the controller decoding, to prevent it recognizing B0 if it looks like we might be pausing, and add "pause" to the list of keys it decodes from the keypad (so you could just look for cont.pause, for example). Paging nanochess. :-) Quote Link to comment Share on other sites More sharing options...
+nanochess Posted August 13, 2017 Share Posted August 13, 2017 Just read the thread after receiving the telephatic message from intvnut pause = 64 ' ... somewhere at start of your code... ' ... this block of code replaces the WAIT in your main loop .... DO WAIT #c = cont1 IF #c = $FFA5 THEN IF pause = 65 THEN pause = 44 ELSE IF pause = 64 THEN pause = 84 IF pause > 65 THEN pause = pause - 1 ELSE IF pause < 64 THEN pause = pause + 1 LOOP WHILE pause > 64 How it works. While 'pause' contains 64 or less then the game isn't in pause. Once the combination 1+9 is pressed, it changes pause into 84 (as a way of debouncing the pressing) and decrement up to 65. When pause is 65, the combination 1+9 is accepted again, and changes pause into 44 resuming the game immediately but starts counting up to 64 as a way to not receive immediately the pause keys combination. I hope this helps. I remember publishing something like this before but I couldn't found the thread 1 Quote Link to comment Share on other sites More sharing options...
tuatara21 Posted August 15, 2017 Author Share Posted August 15, 2017 @nanochess and @intvnut - Thanks, the code listed above appears to work - 1 & 9 to pause and 1 & 9 to resume the game. I need to test further but so far, so good I appreciate the excellent and prompt support as always, along with the explanation and commented code. Sincerely, Derek 2 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.