Page 1 of 1

Equivalent of POKE 198,0 for joystick?

Posted: Mon Mar 14, 2016 11:41 am
by LoadError
Hello!
Like many of you, I have decided to write a little game for the VIC-20, something I'd never got round to when I should have i.e. as a kid.
In my game there are a series of consecutive informational screens before/after each stage (eg.: the start screen followed by the level info screen; the game over screen followed by the home screen) each one of which requires to hit the fire button to go on. If the button is kept pressed, or is pressed long enough, the first screen is kinda skipped (the VIC registers two consecutive hits of the button in a row).
Is there any way to make sure that the player releases the button if pressed, and then hits it again to go on?
Thanks

Re: Equivalent of POKE 198,0 for joystick?

Posted: Mon Mar 14, 2016 11:56 am
by groepaz
you first check for button press, and then loop/wait until its no more pressed.... there is no other way than doing it "manually"

Re: Equivalent of POKE 198,0 for joystick?

Posted: Mon Mar 14, 2016 1:14 pm
by tokra
E.g.

Code: Select all

wait 37151,32,32:wait 37151,32
Waits for button-press and then waits for button-release

Re: Equivalent of POKE 198,0 for joystick?

Posted: Mon Mar 14, 2016 2:38 pm
by LoadError
Great, thanks, this code works well. Now, I'd like to understand _why_ it works :lol:
I did not even know you could use more than one argument with WAIT.
Is 32 the button press/release momentum? Hence, wait for press-release-press?
Why does not WAIT 198,1,1 work the same way (WAIT 198,1 returns control after a key is pressed, WAIT 198,1,1 returns control immediately)?

[edited: mind trip, wrote POKE meant WAIT]

Re: Equivalent of POKE 198,0 for joystick?

Posted: Mon Mar 14, 2016 2:57 pm
by groepaz
that seems to be a lesser known feature of WAIT.... see here: http://www.c64-wiki.com/index.php/WAIT

Re: Equivalent of POKE 198,0 for joystick?

Posted: Tue Mar 15, 2016 1:59 am
by LoadError
Thanks, all clear now.

Re: Equivalent of POKE 198,0 for joystick?

Posted: Tue Mar 15, 2016 2:58 am
by Mike
I should add, that POKE 198,0 does not at all "wait" until there's no more any key pressed. Rather it will clear the keyboard input buffer. This buffer can hold up to 10 non-processed key-strokes (those with an equivalent PETSCII-Code - Shift and other control keys don't count here). That means, in the construction:

Code: Select all

10 POKE198,0
20 GETA$:IFA$=""THEN20
the POKE just makes sure that all unprocessed keys in the buffer entered before line 10 are discarded.

Another, quite often used construction is "POKE198,0:WAIT198,1". Here, once again POKE198,0 clears the buffer, and then WAIT198,1 (doh!) waits untils there's one key in the buffer. BTW, that key is then still unread, and would need to be cleared by either another POKE198,0 or a GETA$, where A$ then isn't used later.

So, actually there's *no* equivalent to POKE198,0 for the joystick. There is no buffer for joystick movements or fire, the directions and the buttons are read out directly. And then, of course, you just need to check that the button is released before you check that it is (once again) pressed.

I would thus actually revert the WAIT instructions tokra gave, to: WAIT 37151,32:WAIT37151,32,32 so the program already continues to the next page of text with the button press, not upon its release. If the user then keeps the fire button pressed, the next use of WAIT37151,32:WAIT37151,32,32 then will first make sure that fire button is released. :)

Re: Equivalent of POKE 198,0 for joystick?

Posted: Tue Mar 15, 2016 8:27 am
by LoadError
Sorry.... I've edited my previous post, I wrote "POKE 198,1,1" whereas what I meant was WAIT 198,1,1