fire button, very strange...

Basic and Machine Language

Moderator: Moderators

Post Reply
User avatar
nbla000
Salmon Run
Posts: 2582
Joined: Thu Oct 13, 2005 8:58 am
Location: Italy

fire button, very strange...

Post by nbla000 »

I wish to create a small routine that check when a key is pressed or the Joy button is pressed and after released before to do something.

The routine seams really simple and it works very well on VICE but don't work on real vic when the joy button is used.

When the user presses the joy button, i wish to wait that the user releases the joy button to execute something but in real vic, it doesn't wait while in VICE does, what's wrong ?

I've tested 3 different Vics and 2 different joysticks without AutoFire function, of course.

Code: Select all

30e4   20 E4 FF   JSR $FFE4  ; GET a key
30e7   D0 12      BNE $30FB  ; Key Pressed 

30e9   AD 11 91   LDA $9111  ; Check Joy Button
30ec   49 FF      EOR #$FF
30ee   29 20      AND #$20
30f0   F0 F2      BEQ $30E4  ; Joy button not pressed, continue loop

30f2   AD 11 91   LDA $9111  ; wait Joy button release
30f5   49 FF      EOR #$FF
30f7   29 20      AND #$20
30f9   D0 F7      BNE $30F2  ; Joy button still pressed, continue wait

30fb   4C 00 20   JMP $2000  ; Main start point
Mega-Cart: the cartridge you plug in once and for all.
User avatar
Jeff-20
Denial Founder
Posts: 5759
Joined: Wed Dec 31, 1969 6:00 pm

Post by Jeff-20 »

Can't help with ML. But in basic, I use the WAIT command.

WAIT 197, 64, 64 (pressed). WAIT 197, 64 (released). That's for any key pressed. Of course, I use location 37152 for joystick fire button. Very simple and efficient, but the program cannot be RUN/STOPped when WAITing.
High Scores, Links, and Jeff's Basic Games page.
Richard James
Vic 20 Devotee
Posts: 269
Joined: Mon Feb 04, 2008 6:06 am

Post by Richard James »

Probably bounce.

Code: Select all

In VICE

5       +---------------------+
        |                     |
        |  Joystick Press     | Release
0-------+                     +--------


In Real Life
              _________
5        /\  /         \  /\
        /  \/           \/  \
0-------`                    `---------
As you can see in real life the button flickers on/off really quickly before the signal settles to on or off.

The answer to this problem is to put a pause in the program between the joystick presses. Such a routine is called debounce.

http://en.wikipedia.org/wiki/Debounce#Contact_bounce
Change is inevitable except from a vending machine.
User avatar
nbla000
Salmon Run
Posts: 2582
Joined: Thu Oct 13, 2005 8:58 am
Location: Italy

Post by nbla000 »

Richard James wrote:Probably bounce.

As you can see in real life the button flickers on/off really quickly before the signal settles to on or off.
Many thanks for your infos, this explain because similar routines works for my other games and not in this case.

When used in other games there is code between the first and second check so the code itself is a natural debounce routine...

Jeff-20 wrote:I use location 37152 for joystick fire button.
Strange, #37152 = $9120 and looking the vic memory map you may check the joy right only

from the Commodore VIC-20 Memory Map:
9120 37152 Port B output register
- keyboard column scan
- (PB3) Bit 3 =cassette write line
- (PB7) Bit 7 =Joy 3


While the correct location to check for fire button is $9111:
9111 37137 Port A output register
- (PA0) Bit 0=Serial CLK IN
- (PA1) Bit 1=Serial DATA IN
- (PA2) Bit 2=Joy 0
- (PA3) Bit 3=Joy 1
- (PA4) Bit 4=Joy 2
- (PA5) Bit 5 = Lightpen/Fire button
- (PA6) Bit 6=Cassette switch sense
- (PA7) Bit 7=Serial ATN out
Mega-Cart: the cartridge you plug in once and for all.
User avatar
Jeff-20
Denial Founder
Posts: 5759
Joined: Wed Dec 31, 1969 6:00 pm

Post by Jeff-20 »

I meant to write 37151, but now that I reread the original post, my input may not be relevant to your problem.
High Scores, Links, and Jeff's Basic Games page.
User avatar
nbla000
Salmon Run
Posts: 2582
Joined: Thu Oct 13, 2005 8:58 am
Location: Italy

Post by nbla000 »

Just to close this thread for future use of other Denial members, i've fixed it by using a small "debounce routine" between first and second joystick check like suggested by Richard James.

Code: Select all

30f2   A2 FF      LDX #$FF
30f4   CA         DEX
30f5   D0 FD      BNE $30F4
Mega-Cart: the cartridge you plug in once and for all.
Post Reply