Equivalent of POKE 198,0 for joystick?

Basic and Machine Language

Moderator: Moderators

Post Reply
User avatar
LoadError
Vic 20 Hobbyist
Posts: 120
Joined: Sat Feb 17, 2007 2:44 pm
Website: http://digilander.libero.it/pyrotech/
Location: Italy
Occupation: FG Soft

Equivalent of POKE 198,0 for joystick?

Post 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
Commodore VIC-20 n. WG-C-275517 - manufactured in Western Germany in 1983
groepaz
Vic 20 Scientist
Posts: 1182
Joined: Wed Aug 25, 2010 5:30 pm

Re: Equivalent of POKE 198,0 for joystick?

Post 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"
I'm just a Software Guy who has no Idea how the Hardware works. Don't listen to me.
User avatar
tokra
Vic 20 Scientist
Posts: 1123
Joined: Tue Apr 27, 2010 5:32 pm
Location: Scheessel, Germany

Re: Equivalent of POKE 198,0 for joystick?

Post by tokra »

E.g.

Code: Select all

wait 37151,32,32:wait 37151,32
Waits for button-press and then waits for button-release
User avatar
LoadError
Vic 20 Hobbyist
Posts: 120
Joined: Sat Feb 17, 2007 2:44 pm
Website: http://digilander.libero.it/pyrotech/
Location: Italy
Occupation: FG Soft

Re: Equivalent of POKE 198,0 for joystick?

Post 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]
Last edited by LoadError on Tue Mar 15, 2016 8:28 am, edited 1 time in total.
Commodore VIC-20 n. WG-C-275517 - manufactured in Western Germany in 1983
groepaz
Vic 20 Scientist
Posts: 1182
Joined: Wed Aug 25, 2010 5:30 pm

Re: Equivalent of POKE 198,0 for joystick?

Post by groepaz »

that seems to be a lesser known feature of WAIT.... see here: http://www.c64-wiki.com/index.php/WAIT
I'm just a Software Guy who has no Idea how the Hardware works. Don't listen to me.
User avatar
LoadError
Vic 20 Hobbyist
Posts: 120
Joined: Sat Feb 17, 2007 2:44 pm
Website: http://digilander.libero.it/pyrotech/
Location: Italy
Occupation: FG Soft

Re: Equivalent of POKE 198,0 for joystick?

Post by LoadError »

Thanks, all clear now.
Commodore VIC-20 n. WG-C-275517 - manufactured in Western Germany in 1983
User avatar
Mike
Herr VC
Posts: 4831
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Equivalent of POKE 198,0 for joystick?

Post 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. :)
User avatar
LoadError
Vic 20 Hobbyist
Posts: 120
Joined: Sat Feb 17, 2007 2:44 pm
Website: http://digilander.libero.it/pyrotech/
Location: Italy
Occupation: FG Soft

Re: Equivalent of POKE 198,0 for joystick?

Post by LoadError »

Sorry.... I've edited my previous post, I wrote "POKE 198,1,1" whereas what I meant was WAIT 198,1,1
Commodore VIC-20 n. WG-C-275517 - manufactured in Western Germany in 1983
Post Reply