English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 03 September 2014, 14:54   #1
hukka
Wolf-bear thing
 
hukka's Avatar
 
Join Date: Jan 2014
Location: Finland
Age: 41
Posts: 56
Reading the second fire button

I'd like to have my game support the second fire button available on some joypads/joysticks (such as the C button on a Sega Megadrive joypad, which is all I have to test it with.)

To initialize that (along with the right mouse button), I do a
Code:
lea CUSTOM, a6
move.w    #BIT15|BIT14|BIT11|BIT10, POTGO(a6)  ; OUTRY+DATRY+OUTLY+DATLY
and to read,

Code:
btst    #14-8, POTGOR+CUSTOM        ; was secondary fire button hit?
bz    .Fire2                ; yes
However, it only works on WinUAE, and only if I reinitialize the POTGO register each frame. Otherwise the second fire button gets 'stuck' after being pressed once. Is that how it's supposed to work?

The real problem is that it doesn't work at all on my A1200. I'm seeing nothing in POTGOR when pressing the second fire button. The right mouse button is read fine. The pad is in working condition and the second button works in other games that support it. Any pointers please?

Last edited by hukka; 03 September 2014 at 14:59.
hukka is offline  
Old 03 September 2014, 17:58   #2
Mrs Beanbag
Glastonbridge Software
 
Mrs Beanbag's Avatar
 
Join Date: Jan 2012
Location: Edinburgh/Scotland
Posts: 2,243
all the many hardware eccentricities are not emulated exactly (i'm sure Toni Wilen can furnish us with the details) but you have to introduce a small delay between writing to POTGO and reading POTGOR because of physical electronics, there is a capacitor that has to charge up or something. It's to do with the way it handles these pins being both input and output capable. Why they didn't abstract this away from the programmer i don't know but there you go.

It is like a DMA wait, a few scanlines should do it i think although i've never tried it myself.
Mrs Beanbag is offline  
Old 03 September 2014, 17:59   #3
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by hukka View Post
Code:
lea CUSTOM, a6
move.w    #BIT15|BIT14|BIT11|BIT10, POTGO(a6)  ; OUTRY+DATRY+OUTLY+DATLY
I don't remember now which pin is connected to the second button, but I was successful by initializating POTGO with $ff00 in my game, just once during startup.

Quote:
The real problem is that it doesn't work at all on my A1200.
Yes, some Amigas might fail because of their aged capacitors(?).
phx is offline  
Old 03 September 2014, 18:54   #4
Mrs Beanbag
Glastonbridge Software
 
Mrs Beanbag's Avatar
 
Join Date: Jan 2012
Location: Edinburgh/Scotland
Posts: 2,243
"Mapping the Amiga" on p467 recommends waiting 300 microseconds between writing POTGO and reading POTGOR
Mrs Beanbag is offline  
Old 03 September 2014, 19:52   #5
Lonewolf10
AMOS Extensions Developer
 
Lonewolf10's Avatar
 
Join Date: Jun 2007
Location: near Cambridge, UK
Age: 44
Posts: 1,924
A quote from Toni from a thread somewhere on EAB (sorry I didn't record the exact location in my source code):

Quote:
Originally Posted by ToniWilen
; Reading Keyboard
; ================
;
; Check that CIA-A serial port (SP) interrupt is set (or use ports
; interrupt), if set, read SDR, then set bit 6 in CIA-A CRA, wait at least
; ~70us, clear bit 6. (this is one method to handle handshake, there is
; also another one)
;
; This tells keyboard micro controller that key code has been read and
; new code can be sent.

Here's my calculations from my own keyboard reading routine. In order to wait ~300uS, 4 scanlines should be sufficient assuming that 1) my calculations are correct and 2) you are designing this for a PAL system


Code:
;
;
;  PAL
;  ===
;
;  50 VBLs / second = 0.02 seconds per VBL
;  250 scanlines per VBL = 0.00008 seconds per scanline
;  0.00008 seconds = 0.08 milliseconds (mS)= 80 micro seconds (uS)
;
Lonewolf10 is offline  
Old 03 September 2014, 19:54   #6
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,505
Only need to set second button data direction and data bit to one. You sure your BITxx macro works? It looks like data direction is in input mode (only works if button has pullup resistor)
Toni Wilen is offline  
Old 03 September 2014, 21:14   #7
Asman
68k
 
Asman's Avatar
 
Join Date: Sep 2005
Location: Somewhere
Posts: 828
In Solomon's Key I used following code and as far as I remember it works. I tested it with cd32 pad on my a1200.

Code:
		btst	#14,$dff016
		bne.b	.exit

		st	fireballKey

.exit
		or.w	#$c001,$dff034
Routine is call one per frame.
Asman is offline  
Old 03 September 2014, 21:29   #8
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,505
Quote:
Originally Posted by Asman View Post
or.w #$c001,$dff034
That code reads from write-only register! (EDIT: It becomes write FFFF to POTGO!)

There is no need to write to bit 0 (only needed if other than red or blue CD32 pad needs to be read) or to write it each frame.

Note that KS vblank routine will reset POTGO: do not update POTGO until you have taken over the system or you will need to update it each frame to override KS POTGO write.

Last edited by Toni Wilen; 03 September 2014 at 21:37.
Toni Wilen is offline  
Old 04 September 2014, 10:54   #9
Asman
68k
 
Asman's Avatar
 
Join Date: Sep 2005
Location: Somewhere
Posts: 828
Quote:
Originally Posted by Toni Wilen View Post
That code reads from write-only register! (EDIT: It becomes write FFFF to POTGO!)

There is no need to write to bit 0 (only needed if other than red or blue CD32 pad needs to be read) or to write it each frame.

Note that KS vblank routine will reset POTGO: do not update POTGO until you have taken over the system or you will need to update it each frame to override KS POTGO write.
Oh, thank you Toni. So lets assume that I over taken system. Then I can do this in following manner, one time per frame
Code:
		btst	#14,$dff016
		bne.b	.exit

		st	fireballKey

.exit
		move.w	#$c000,$dff034
right ?
Asman is offline  
Old 04 September 2014, 11:09   #10
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,505
Quote:
Originally Posted by Asman View Post
Oh, thank you Toni. So lets assume that I over taken system. Then I can do this in following manner, one time per frame
Code:
		btst	#14,$dff016
		bne.b	.exit

		st	fireballKey

.exit
		move.w	#$c000,$dff034
right ?
It should work but if it does not, you probably have some other write to POTGO somewhere else and bit 0 write side-effect "overrides" it. (For example because pot capacitor is forced to discharge. POT lines are quite special, they have both digital and analog components)
Toni Wilen is offline  
Old 05 September 2014, 11:40   #11
hukka
Wolf-bear thing
 
hukka's Avatar
 
Join Date: Jan 2014
Location: Finland
Age: 41
Posts: 56
Thanks everyone for the replies!
So if I'm understanding correctly, although I have system enabled while running, this should still work:

Code:
VBL_interrupt:
    lea CUSTOM, a6
    move.w    POTGOR(a6), Pot
    ; (some other stuff)
    move.w    #$C000, POTGO(a6)
But it doesn't - the value I get from POTGOR reads $5500. I'm not touching POTGO/POTGOR anywhere else than the vblank interrupt.
hukka is offline  
Old 05 September 2014, 13:34   #12
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,505
Quote:
Originally Posted by hukka View Post
Thanks everyone for the replies!
So if I'm understanding correctly, although I have system enabled while running, this should still work:

Code:
VBL_interrupt:
    lea CUSTOM, a6
    move.w    POTGOR(a6), Pot
    ; (some other stuff)
    move.w    #$C000, POTGO(a6)
But it doesn't - the value I get from POTGOR reads $5500. I'm not touching POTGO/POTGOR anywhere else than the vblank interrupt.
Setting POTGO first, then reading POTGOR should work (You probably need delay between writing to POTGO and reading POTGOR to allow pot capacitor charge or discharge depending on button state, without delay you may get incorrect button state. I think I timed this sometime ago and delay needed was very short, less than 1 scanline)

Normally your VBL routine (if it is added using exec routines) has lower priority than OS routine that sets POTGO "incorrectly". You can also try using very high priority for your VBL routine.
Toni Wilen is offline  
Old 05 September 2014, 14:38   #13
hukka
Wolf-bear thing
 
hukka's Avatar
 
Join Date: Jan 2014
Location: Finland
Age: 41
Posts: 56
Okay, I took it out of the vbl routine and into the mainloop which does this now:

Code:
    WaitLine 270
    move.w    #$CC00, POTGO+CUSTOM

    WaitLine 276
    move.w    POTGOR+CUSTOM, Pot
And it still doesn't work, Pot still reads $5500. In both WinUAE and my 1200. I made sure that's the only place POTGO(R) gets touched in my code. The WaitLine macro works properly.

Quote:
Originally Posted by Toni Wilen View Post
Normally your VBL routine (if it is added using exec routines) has lower priority than OS routine that sets POTGO "incorrectly". You can also try using very high priority for your VBL routine.
Thanks for the tip - does anyone happen to have info on how to set the priority?
hukka is offline  
Old 05 September 2014, 15:42   #14
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,505
Quote:
Originally Posted by hukka View Post
Okay, I took it out of the vbl routine and into the mainloop which does this now:

Code:
    WaitLine 270
    move.w    #$CC00, POTGO+CUSTOM

    WaitLine 276
    move.w    POTGOR+CUSTOM, Pot
And it still doesn't work, Pot still reads $5500. In both WinUAE and my 1200. I made sure that's the only place POTGO(R) gets touched in my code. The WaitLine macro works properly.
It should work, it has to work. It is exact same method as reading right (or middle) mouse button. (You do remember that read data is inverted? 1 = not pressed, 0 = pressed)

Quote:
Thanks for the tip - does anyone happen to have info on how to set the priority?
Interrupt node priority field, check RKM
Toni Wilen is offline  
Old 05 September 2014, 15:50   #15
hukka
Wolf-bear thing
 
hukka's Avatar
 
Join Date: Jan 2014
Location: Finland
Age: 41
Posts: 56
Quote:
Originally Posted by Toni Wilen View Post
It should work, it has to work. It is exact same method as reading right (or middle) mouse button. (You do remember that read data is inverted? 1 = not pressed, 0 = pressed)
Well, time to make a minimal test program!
And a clarification because I'm not sure I mentioned this, I'm seeing the POTGOR register change from $5500 to $1500 when pressing the second fire button in WinUAE. But not on the Amiga. And those aren't the values I should be getting anyway, right?

Quote:
Interrupt node priority field, check RKM
Thanks for the pointer!
hukka is offline  
Old 05 September 2014, 15:53   #16
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,505
Quote:
Originally Posted by hukka View Post
Well, time to make a minimal test program!
And a clarification because I'm not sure I mentioned this, I'm seeing the POTGOR register change from $5500 to $1500 when pressing the second fire button in WinUAE. But not on the Amiga. And those aren't the values I should be getting anyway, right?
It looks correct. Bit 14 is data bit (1=not pressed, 0=pressed).
Does bit 10 toggle when pressing right mouse button?
If yes, does joystick port also work if you insert mouse in joystick port and press right mouse button?
Toni Wilen is offline  
Old 05 September 2014, 16:26   #17
hukka
Wolf-bear thing
 
hukka's Avatar
 
Join Date: Jan 2014
Location: Finland
Age: 41
Posts: 56
Quote:
Originally Posted by Toni Wilen View Post
Does bit 10 toggle when pressing right mouse button?
If yes, does joystick port also work if you insert mouse in joystick port and press right mouse button?
Yes to both. But nothing with either pads I tested with (a Megadrive pad and a brand new clone pad). I just tried the WHDload version of Great Giana Sisters which has the option of using the second button for jumping and it worked great with the MD pad, so I know it's not the hardware at fault.
hukka is offline  
Old 05 September 2014, 17:49   #18
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,505
Quote:
Originally Posted by hukka View Post
Yes to both. But nothing with either pads I tested with (a Megadrive pad and a brand new clone pad). I just tried the WHDload version of Great Giana Sisters which has the option of using the second button for jumping and it worked great with the MD pad, so I know it's not the hardware at fault.
Aah, I thought you used normally wired pad. Strange, according to pad schematics it should work. Does it work if you set POTGO data direction to input? (Mouse won't work anymore or normal joystick but this is only a test)
Toni Wilen is offline  
Old 06 September 2014, 11:19   #19
hukka
Wolf-bear thing
 
hukka's Avatar
 
Join Date: Jan 2014
Location: Finland
Age: 41
Posts: 56
Quote:
Originally Posted by Toni Wilen View Post
Does it work if you set POTGO data direction to input? (Mouse won't work anymore or normal joystick but this is only a test)
It does! So do I need to implement a routine to detect whether I should set the input bit, or is there something else I can do?
hukka is offline  
Old 06 September 2014, 13:07   #20
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,505
I think I start to understand what is going on.. (Megadrive pad does not really work like everything else..) But first we need to confirm all 3 possibilies:

- second button with pull up resistor, some game pads, original Commodore mice, 3rd party mice may not have it. (not pressed = second button pin pulled to +5v via 10k resistor, pressed = shorted to ground). CD32 pad in 2-button mode should be like this case too.

- second button without pull up resistor. (not pressed = second button pin is floating, pressed = shorted to ground)

- Megadrive pad which has TTL chip which apparently can't override signal when Paula is programmed to output mode = "pullup emulation".

Do you have all test cases? Could you check if your mouse has pullup? (Measure resistance between pin 9 and pin 7: infinite = no pullup, about 10k = pullup)

I still assume single read mode can't handle all 3 cases.
Toni Wilen is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Fire button configuration Rogue support.Amiga Forever 0 18 January 2014 12:38
Configure button 1 as fire and button 2 as autofire Harry support.WinUAE 1 21 December 2013 13:37
Can I configure second fire button on keyboard? NLS support.WinUAE 2 18 January 2008 23:00
Fire-Button oldpx Amiga websites reviews 19 30 September 2002 08:48
2nd Fire Button Doozy support.WinUAE 7 22 January 2002 19:21

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 01:24.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.11246 seconds with 16 queries