Intellivision Brasil Posted November 22, 2022 Share Posted November 22, 2022 Hello guys. The routine below shows the difficulty level that can be changed in a loop with the control to left or right. The problem is that, when pressing ENTER, the chosen level "goes back" to the previous level before exiting as if the control was pressed to the left (the procedure "Loop2" shows the chosen level, but it should be 1 level above the one shown in the corner of the screen). Is there any way to avoid this? I made several attempts, but none were successful. Thanks! INCLUDE "constants.bas" Level=1: GOSUB LevelName Loop1: WAIT IF CONT.LEFT=0 AND CONT.RIGHT=0 THEN NoCtl=0 IF CONT.RIGHT>0 AND NoCtl=0 THEN IF Level<3 THEN Level=Level+1 ELSE Level=1 GOSUB LevelName ELSEIF CONT.LEFT>0 AND NoCtl=0 THEN IF Level>1 THEN Level=Level-1 ELSE Level=3 GOSUB LevelName END IF IF CONT.KEY=11 THEN GOTO Loop2 GOTO Loop1 Loop2: PRINT AT 1 COLOR 7,<>Level Loop3: GOTO Loop3 LevelName: PROCEDURE FOR a=0 to 5: #backtab(147+a)=Levels(a+((Level-1)*6))*8+FG_WHITE: NEXT a NoCtl=1 END Levels: DATA " EASY ","MEDIUM", " HARD " Quote Link to comment Share on other sites More sharing options...
DZ-Jay Posted November 23, 2022 Share Posted November 23, 2022 (edited) It's because the keypad code for the Enter key (101000) includes the bit that signals the Left disc position (001000). So, you select your level, then when you press Enter, it first passes by the test for the Left position, and decrements the level before acknowledging the key. You need to disambiguate your input by making sure that it is exclusively either a disc, or a keypad entry. IntyBASIC already takes care of decoding the keypad, so you are guaranteed to have a valid key; but for the disc, you are on your own. You should isolate the bits for the disc, and ensure that the signal you got does not contain bits resembling the keypad. Personally, my recommendation is to go with a more robust decoding that handles the above. However, you can get around it easily in your code by moving the test for the Enter key to the top. Still, there is a chance that the input will arrive before the loop recycles and be caught by the Left test again. dZ. Edited November 23, 2022 by DZ-Jay Quote Link to comment Share on other sites More sharing options...
DZ-Jay Posted November 23, 2022 Share Posted November 23, 2022 (edited) I forgot to mention that IntyBASIC "debounces" the keypad input for two or three frames before acknowledging it, so you have at least that many loop iterations in which your Enter key input may be caught by your other tests if it "looks" sufficiently like a disc code. dZ. Edited November 23, 2022 by DZ-Jay Quote Link to comment Share on other sites More sharing options...
Intellivision Brasil Posted November 23, 2022 Author Share Posted November 23, 2022 (edited) 8 hours ago, DZ-Jay said: It's because the keypad code for the Enter key (101000) includes the bit that signals the Left disc position (001000). So, you select your level, then when you press Enter, it first passes by the test for the Left position, and decrements the level before acknowledging the key. You need to disambiguate your input by making sure that it is exclusively either a disc, or a keypad entry. IntyBASIC already takes care of decoding the keypad, so you are guaranteed to have a valid key; but for the disc, you are on your own. You should isolate the bits for the disc, and ensure that the signal you got does not contain bits resembling the keypad. Personally, my recommendation is to go with a more robust decoding that handles the above. However, you can get around it easily in your code by moving the test for the Enter key to the top. Still, there is a chance that the input will arrive before the loop recycles and be caught by the Left test again. dZ. Thank you, DZ. I had already tried moving the test for ENTER to the top with no success. But after your explanation, I made a small modification to the main loop to delay the keypress checking for a few cycles. Maybe not the best way, but now the routine runs as expected. c=0 Loop1: WAIT IF CONT.KEY=11 AND NoCtl=0 THEN GOTO Loop2 IF c>2 AND CONT.KEY=12 THEN c=0 IF Level>1 THEN Level=Level-1 ELSE Level=3 GOSUB LevelName END IF IF CONT.LEFT=0 AND CONT.RIGHT=0 THEN NoCtl=0 IF CONT.RIGHT>0 AND NoCtl=0 THEN IF Level<3 THEN Level=Level+1 ELSE Level=1 GOSUB LevelName ELSEIF CONT.LEFT>0 AND NoCtl=0 THEN c=c+1 END IF GOTO Loop1 Edited November 23, 2022 by Intellivision Brasil Error pasting Quote Link to comment Share on other sites More sharing options...
DZ-Jay Posted November 23, 2022 Share Posted November 23, 2022 (edited) Like I mentioned, the root of your problem is that the input is not being properly decoded and disambiguated. Understand that CONT.KEY is decoded and validated by IntyBASIC automatically, but CONT is not. When you write “CONT.LEFT,” all it is doing is telling you whether the code in the input signal contains the bits for the LEFT direction — but it won’t tell you whether those are the only bits set in the signal. That is important, because the Intellivision hand-controller has only eight wires to transmit data, but 32 distinct inputs. This means that the wires are reused and overlap in various inputs — specifically those of the disc and keypad. So, checking for CONT.LEFT is only useful if you can guarantee that there is only Disc input, because some keypad entries may overlap with it. And even guaranteeing that it is Disc input is not sufficient, because there are a range of directions on the disc that overlap with CONT.LEFT, including most of the diagonals on the left half of the Disc. Therefore, delaying the test will not solve the problem in all cases. There remains a race condition. I personally recommend you actually isolate the signal to determine if it is a valid Disc input first — then and only then accept it. That will prevent the signals for the Enter key and the disc from beobg confused. There are various ways to do this: you could use a look up table of valid values, or you could look for invalid combinations, etc. In my opinion, bad or flakey control schemes are the biggest sort of frustration for players. dZ. Edited November 23, 2022 by DZ-Jay 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.