Jump to content
IGNORED

question about joysticks and how they are read


Shannon

Recommended Posts

Looking at the source Curt posted for Desert Falcon got me wondering. The code mentions changing to old-style/one button mode when a regular 2600 stick is hooked up. It implies that hardware damage can occur otherwise. So is it actually doing something to change the way the hardware reads the sticks? Or is it something else. I notice the value it sends to SWCHB uses bits that are designated as "not used". Is this true? Or is the 7800 documentation out there incorrect?

 

Here is a snipit of the code that reads the joystick..

 

*		 DOALLIO		 MAPS HARDWARE FIREBUTTON INTO SOFTWARE REGS. SAME FOR
* SWCHB.  COMPLEMENTS OF ETHAN
DOALLIO
	  LDA	 SWCHA				 ;FOR TRIGGERING BREAKPOINTS.  WILL BE
									;MADE INTO MECHANISM TO STUFF SOFTWARE
									;REGISTERS
	  LDA	 SWCHB				 ;GET SWCHB FOR RESETS AND SUCH
	  AND	 #$0B
	  STA	 SWCHBIO

CKJOY	 LDX	 #1					;DO PLAYERS 1 AND 0
ZNXTRJ	JSR	 READJOY			   ;READ HIS JOYSTICK
	  DEX
	  BPL	 ZNXTRJ
	  RTS

* READJOY: READ JOYSTICK/BUTTONS.  ON ENTRY X = PLAYER.  Y GETS TRASHED
READJOY   LDY	 INPT4,X
	  BPL	 GOTONE				;IF BIT 7 IS LO, OLD-STYLE BUTTON HIT

	  LDA	 ONEBUT				;ARE WE ALREADY IN OLD-STYLE MODE?
	  AND	 RJBITS,X
	  BNE	 GOTONE2			   ;YES.  GO RIGHT TO ONE-BUTTON HANDLER.

	  TXA						   ;OTHERWISE, COMPUTE INDEX INTO
	  ASL	 A					 ; PADDLE PORTS, FOR PLAYER X,
	  TAY						   ; IN Y (X * 2)

	  LDA	 INPT4L,Y			  ;READ LEFT BUTTON
	  EOR	 #$FF				  ;INVERT SENSE
	  STA	 LEFTBUT,X
	  LDA	 INPT4R,Y			  ; RIGHT BUTTON
	  EOR	 #$FF				  ;INVERT SENSE
RJSTORE   STA	 RIGHTBUT,X

RJRTS	 RTS

	 ;HERE ON OLD-STYLE SINGLE BUTTON JOYSTICK PRESS.
GOTONE	LDA	 ONEBUT				;SET ONE-BUTTON MODE IMMEDIATELY
	  ORA	 RJBITS,X			  ; TO AVOID DESTROYING HARDWARE!
	  STA	 SWCHB
	  STA	 ONEBUT				;UPDATE ONE BUTTON FLAG BYTE

	 ;HERE ON ANY OLD-STYLE JOYSTICK, WHETHER PRESSED OR NOT
GOTONE2   TYA
	  STA	 LEFTBUT,X			 ; (Y CONTAINS CURRENT VALUE OF INPT4)
	  STA	 RIGHTBUT,X			;CLEAR RIGHT BUTTON COPY

	  RTS

RJBITS	DB	  $04,$10			   ;MASK OF "ONE-BUTTON" BITS PER PLAYER
	  RTS

Just look at the routine DOALLIO I'm wondering why they do two LDA's in a row. Does that serve any purpose??

 

Any input is appreciated. Thanks..

Link to comment
Share on other sites

That is weird. They write something out to the SWCHB address, as if it's going to alter the RIOT behavior somehow. Maybe this is from an old implementation of the joysticks?

 

Is this a 2 button game? Because it looks like this code will detect an "old style" joystick even with a Proline, and never end up reading the independent signals. The code seems to assume that only an old joystick would send the 2600 style button signal, but a real-life Proline sends both.

Link to comment
Share on other sites

After tinkering around with the a7800 driver in mess I'm thinking that writing to the SWCHB address somehow alters the RIOT behavior. I managed to get it so two button games now work properly. Although I'm still not sure how INPT0-4 should act when nothing is written out to SWCHB.

 

I'll have to post the Maria Header file that clued me into this behavior. :lol:

Link to comment
Share on other sites

Here is the header file. At first what confused me was the part that says (D7=1 when pushed) and (D7=0 when pushed) had me thinking they were referring to the D7 settings for SWCHB listed below. When it was referring to bit 7 of that INPT#. Anyways this is just a small snipped with stuff removed to make it a little easy to see the relevant addresses.

 

;*
;*   ...LEFT AND RIGHT FIRE BUTTONS CAN BE READ FROM THE FOLLOWING 4 LOCATIONS:
;*
;*							  THESE ARE ALSO USED FOR PADDLE INPUT
INPT0		  equ	 $08	;PLAYER 0, RIGHT FIRE BUTTON (D7=1 WHEN PUSHED)
INPT1		  equ	 $09	;PLAYER 0, LEFT FIRE BUTTON  (D7=1 WHEN PUSHED)
INPT2		  equ	 $0A	;PLAYER 1, RIGHT FIRE BUTTON (D7=1 WHEN PUSHED)
INPT3		  equ	 $0B	;PLAYER 1, LEFT FIRE BUTTON  (D7=1 WHEN PUSHED)
;*
;*   LEFT OR RIGHT FIRE BUTTONS READ FROM THESE LOCATIONS:
;*
INPT4		  equ	 $0C	;PLAYER 0 FIRE BUTTON INPUT (D7=0 WHEN PUSHED)
INPT5		  equ	 $0D	;PLAYER 1 FIRE BUTTON INPUT (D7=0 WHEN PUSHED)
;*

SWCHB		  equ	 $282   ;CONSOLE SWITCHES
;*
;*	   D7-RITE DIFFICULTY
;*	   D6-LEFT DIFFICULTY
;*	   D5/D4 NOT USED
;*	   D3-PAUSE
;*	   D2-NOT USED
;*	   D1-GAME SELECT
;*	   D0-GAME RESET
;*
CTLSWB		 equ	 $283   ;SWCHB DATA DIRECTION (0=INPUT)
SWBCNT		 equ	 $283   ;synonym for CTLSWB
;*

Edited by Shannon
Link to comment
Share on other sites

Despite what the header files says Bits 2 and 4 on RIOT Port B actually have a function, they are used to setup 2 button mode on the joysticks. When these bits are set low you can read both button independently through the INPT0/INPT1 and INPT2/INPT3 inputs.

 

Dan

Link to comment
Share on other sites

ok thanks for confirming that. Any idea on how INPT0/INPT1 and INPT2/INPT3 act when the 7800 is in 1 button mode? If I could have that info it'd be great. I already figured out how INPT4 & INPT5 act when it is set to 2 button mode based on the desert falcon source.

 

Thanks..

Link to comment
Share on other sites

Ok, after studying the 7800 joystick circuit for a while I think I understand how this all works. Here is a schematic that shows one of the two 7800 joystick ports and how a 7800 stick and 2600 stick attaches to it:

 

post-184-1213574218_thumb.jpg

 

In 7800 2-button mode, TIAEN is low which turns on Q8, RIOT PB2 is low which turns on Q6 which effectively puts a +5 on pin 6 of the connector. As a result TIA-I4 will always read hi, TIA-I1 will read hi when the left button is pressed, and TIA-I0 will read hi when the right button is pressed.

 

In 7800 1-button mode, TIAEN is low which turns on Q8, but RIOT PB2 is high which turns off Q6. Pull-up resistor R40 will keep I4 high until either the left or right button is pressed which will pull TIA-I4 low. I am assuming that in this configuration TIA-I1 and TIA-I0 will always read low.

 

Dan

Link to comment
Share on other sites

DF is a two button game.
Yeah. That's why I was using it's source code because it was becoming apparent to me that the 7800 hardware does "something" differently that the emulators were not taking into consideration. :lol:

 

Of course Dan has the ability to be able to look at the schematic and see what is going on. I have to rely on text documents and source code. :D

 

Anyways thanks for the information Dan. I didn't really "need it" to get the games working right but I wanted the emulator to at least operate like it is supposed to. :lol: Anyways thanks for confirming what I suspected was how it worked. I had a feeling it had to do with how the ciruitry was laid out, but all that stuff is greek to me. :D

 

Any idea why the documentation would suggest that damage could occur if two button mode is activated when a single button stick is attached?

 

I'm also kinda wondering if while in two button mode whether the difficulty switches, etc can be read. No biggy, more of a curiosity thing and again thanks!! :D

Link to comment
Share on other sites

I'm also kinda wondering if while in two button mode whether the difficulty switches, etc can be read. No biggy, more of a curiosity thing and again thanks!! :D

As far as I can tell, yes. I had no idea there were modes to this thing, and I already wrote a procedure a long time ago that displays the status of all inputs. It worked fine[*]. I wonder though if the mode should be initialized at startup rather than assuming all the buttons are ready to work.

 

 

 

DF is a two button game.

I don't understand how that code can detect a Proline correctly. The Proline still activates the 2600 style button signal, so it will get detected as if it was a CX-40:

 

READJOY   LDY	 INPT4,X
	  BPL	 GOTONE			  ;IF BIT 7 IS LO, OLD-STYLE BUTTON HIT
...
...
GOTONE	LDA	 ONEBUT			  ;SET ONE-BUTTON MODE IMMEDIATELY
	  ORA	 RJBITS,X			; TO AVOID DESTROYING HARDWARE!
	  STA	 SWCHB

 

[* edit] But after looking closer at Boris' explanation, I think I need to double check. I *thought* the Prolines still send the 2600 signal, but I'm doubting everything now. All those competing pullups+pulldowns get me confused.

Edited by gdement
Link to comment
Share on other sites

The way I understood Dan's explanation. Setting TIA_EN to something other than 0 (or is it 1? :lol: ) causes the behavior to change, thus INPT4 no longer reads key presses but is always hi (value of 0x80).

 

Believe me the code had me baffled for a few days there until it dawned on me what was going on. :lol:

 

Kinda odd that your sample code would work with two buttons though.. Maybe INPT0-INPT3 always return button presses but INPT4 does not when TIA_EN is set? Seems kinda like an odd setup.. :?

Link to comment
Share on other sites

Any idea why the documentation would suggest that damage could occur if two button mode is activated when a single button stick is attached?

 

Now that I have drawn out the schematic, this actually makes sense. In this configuration both transistors would be on so when the button is pressed there would be almost a direct connection from +5 to GND which could cause exsesive current to flow through the transistors and possible damage them. In the 7800 sticks there are resistors to prevent this.

 

Dan

Link to comment
Share on other sites

Interesting. Considering that Commando does not seem to have the same "checks" as "Desert Falcon", "Dark Chambers", and "Asteroids". It makes me wonder if having a single button stick plugged into a real 7800 while playing Commando runs a chance of causing hardware "damage"... :ponder:

Link to comment
Share on other sites

  • 3 weeks later...

ok. Ran into an odd situation here. Seems the HSC cart is somehow switching the 7800 back into 1 button mode cause now when I finish a two button game (say asteroids) and it goes to the HSC screen it is not accepting any input (in the emulator). Looking at CTLSWB at this point still yields a value of $14. So something else must be factoring in here.. I wonder if it is doing something with SWCHB. :ponder:

Edited by Shannon
Link to comment
Share on other sites

Just look at the routine DOALLIO I'm wondering why they do two LDA's in a row. Does that serve any purpose??

 

It says "FOR TRIGGERING BREAKPOINTS". I wonder if that has something to do with a development system since reading SWCHA normally would.. well, just read SWCHA.

 

The joystick schematic looks like it makes the normally weakly pulled up fire buttons into a hard 5V source used to feed the resistor network tied to the paddle inputs. I was wondering why they did such a thing until I thought about compatibility issues. The Proline sticks would generally work on other systems as long as they used the TRIGGER pins rather than pin 7 for power.

 

What's interesting is that TIAEN signal. It comes from the hidden setup register and does indeed go to one of TIA's CS pins. Apparently you can start up the 7800 with TIA completely unavailable.

 

-Bry

Link to comment
Share on other sites

What's interesting is that TIAEN signal. It comes from the hidden setup register and does indeed go to one of TIA's CS pins. Apparently you can start up the 7800 with TIA completely unavailable.

 

-Bry

 

Not sure what schematics you are looking at but the TIAEN signal doesn't goto the TIA CS pins. It goes two places, one to control the joystick mode, and one to disable the TIA video output. You may be misreading CS2 which goes to the signal TIACS which comes from MARIA.

 

Dan

Link to comment
Share on other sites

What's interesting is that TIAEN signal. It comes from the hidden setup register and does indeed go to one of TIA's CS pins. Apparently you can start up the 7800 with TIA completely unavailable.

 

-Bry

 

Not sure what schematics you are looking at but the TIAEN signal doesn't goto the TIA CS pins. It goes two places, one to control the joystick mode, and one to disable the TIA video output. You may be misreading CS2 which goes to the signal TIACS which comes from MARIA.

 

Dan

 

You're right. I lost track of which signal I was following. So, if TIA's output is enabled then 2-button fire is automatically disabled.

Link to comment
Share on other sites

  • 8 months later...
Kinda odd that your sample code would work with two buttons though.. Maybe INPT0-INPT3 always return button presses but INPT4 does not when TIA_EN is set? Seems kinda like an odd setup.. :?

 

Just to follow up on this,

Last night I fixed a bug with my controller test, and tried it again on my 7800. Turns out my post from earlier was incorrect. By default, the 2 button controllers only send the legacy 2600 button signal. I tried it with both a Proline and a homemade RSI stick - both behaved the same way. The legacy signal was working and the 7800 button signals were inactive.

Clearly the 2 button mode has to be explicitly enabled for it to work.

Link to comment
Share on other sites

  • 2 months later...
post-184-1213574218_thumb.jpg

 

In 7800 2-button mode, TIAEN is low which turns on Q8, RIOT PB2 is low which turns on Q6 which effectively puts a +5 on pin 6 of the connector. As a result TIA-I4 will always read hi, TIA-I1 will read hi when the left button is pressed, and TIA-I0 will read hi when the right button is pressed.

 

In 7800 1-button mode, TIAEN is low which turns on Q8, but RIOT PB2 is high which turns off Q6. Pull-up resistor R40 will keep I4 high until either the left or right button is pressed which will pull TIA-I4 low. I am assuming that in this configuration TIA-I1 and TIA-I0 will always read low.

 

Dan

 

 

I accidentally discovered something interesting happens if you try to read a Genesis controller in 2 button mode. I was using a 6-button pad, didn't try a 3-button.

 

In the 2-button mode, the 2600 button always reads hi (inactive) as expected, but the other buttons also both stay high (which for those is the active state). Pressing "C" causes the left button to release (go low).

 

In 1 button mode button "B" works normally as the 2600 button.

 

So you could actually switch between the 2 modes each frame and support both "B" and "C" on an unmodded Genesis pad.

I don't know if using the 2-button mode with that controller is safe though. When I tried this on my console no smoke came out, but I didn't do it very long.

Link to comment
Share on other sites

This seems like an od way to go about adding a second button, why didn't they keep the circuitry layout identical to the CX-40 otherwise, and add a second button by using a pot circuit, much like was done for the keyboard controllers. (you could actually get 3 buttons this way, and you should even be able to program 2600 games to use this set-up)

Edited by kool kitty89
Link to comment
Share on other sites

I think activating 2 button mode and reading "C" on a Genesis pad should be safe. Based on the schematic I found online, it looks like pin 9 is held high through a pullup resistor, and shorts to pin 8 when C is pressed. I don't think that's dangerous, unless I'm wrong. :)

 

However, button "B" could be dangerous in the wrong mode. It has the same problem as the 2600 controller, as it can short the +5v from Q8 to ground. I'm curious if it would be safe as long as the console only switches to 2-button mode for a short moment while reading "C", then switches back again. It would stay in 1-button mode except for maybe <10 CPU cycles per frame.

 

It would be cool if future games could use this technique to read 2 buttons from an unmodified Genesis (maybe also SMS) pad.

Link to comment
Share on other sites

  • 12 years later...

Meganecrobump.

 

I'm hoping to support all 3 options — 7800 2-button, 2600 1-button, and Genesis — in my game.

 

I've read this thread, and controller pinouts for all 3, and other documents a bunch, I think I understand it, I think it should be possible. My code (in 3 parts):

 

; EDIT: broken code deleted; see post #26 for working code

 

Running on a Concerto cart, this still works fine with a 2-button 7800 controller. It also works fine in a7800.

 

But with either a 2600 controller or a Genesis controller, it does not respond to any buttons.

 

And over in a7800, I tried tab key -> Controller Selection -> joy1 -> vcs_joystick, but that doesn't seem to make any difference at all. Console & Controller Inputs still shows root:joy1:proline_joystick and it behaves as such. So I'm not sure how to emulate either a 2600 controller or a Genesis controller.

 

Questions:

  1. Currently I don't set the controller flag in the a78 header. Should I?
  2. Can you see anything wrong with my code?
  3. Does the second write to INPTCTRL even do anything, since the first write locked it?

TIA.

 

EDIT: mods feel free to move this to the 7800 Programming forum.

Link to comment
Share on other sites

1 hour ago, Pat Brady said:

...over in a7800, I tried tab key -> Controller Selection -> joy1 -> vcs_joystick, but that doesn't seem to make any difference at all. Console & Controller Inputs still shows root:joy1:proline_joystick and it behaves as such...

A7800 needs to be "Reset" after changing controllers.  The reset is a controller change handling requirement inherited from MAME:

 

Capture1.PNG.cb2bf0aa68dbe6b10738e3ac66bacb9b.PNG

 

After resetting, the change will be clear:

 

Capture2.PNG.f075aba001d2a48a73eee500541ce316.PNG

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

3 hours ago, Trebor said:

A7800 needs to be "Reset" after changing controllers.  The reset is a controller change handling requirement inherited from MAME:

 

Thank you! I was doing one very dumb thing that showed up almost immediately in the a7800 debugger. Once I fixed that, vcs_joystick works fine in a7800.

 

Unfortunately still nothing on real hardware. The fact that it's working in a7800 makes me think that my read logic is correct and something in initialization is wrong.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...