27 August 2017, 22:48 | #1 |
This cat is no more
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,163
|
how to fake a joy/mouse button press
I want to code a software autofire feature for CD32load.
Now I have this code to simulate a buttonpress but it doesn't work in any game I tried, any idea why? Code:
OR.B #$C0,CIAADDRA move.b d0,d1 and.w #$F,d1 cmp.b #0,D1 bne.b .up AND.B #$3F,CIAAPRA bra.b .tt .up or.B #$C0,CIAAPRA .tt |
28 August 2017, 14:04 | #2 |
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,505
|
Yes, external signal always "wins" internal state. But that should work if button is not pressed, at least if it is normal joystick (=button not connected when not pressed). CD32 pad button probably always pulls the signal high when not pressed.
btw, never use cmp.x #0,dn, it is waste of space and time |
28 August 2017, 21:52 | #3 |
This cat is no more
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,163
|
oh tst.b dn, sorry. Thanks for confirming & for the invaluable info. So CD32 pad red button doesn't act like normal joy? (I'm not even trying to autofire the other buttons!!)
|
29 August 2017, 14:40 | #4 |
ex. demoscener "Bigmama"
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
|
You're setting the port pins to output and then setting their hi/lo state depending on if you want button press or not, right!?
|
29 August 2017, 20:12 | #5 |
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,505
|
CD32 pad has internal circuitry and pullup resistors which means CD32 pad buttons are never "floating" -> signal from pad probably (I haven't tested) "wins" CIA's internal state.
This is also the reason why some games only work with CD32 pad (or some 3rd party game pads that have internal pullups in button lines), game forgot to set pin in output mode and without output mode normal joystick button state gets stuck after first press. (This is usually much more common with games that use 2nd button because CIA IO port state is always set correctly by OS anyway but POTGO isn't and it depends on KS version too) |
03 December 2017, 17:47 | #6 |
This cat is no more
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,163
|
so Toni you've implemented this in WinUAE when CD32 pad is connected? cos the "floating" behaviour doesn't seem to work with "joystick" controller type either...
and is the "output" direction OK to write in the register? or is it "input" (this input/output concept depends heavily on where you're standing...) |
03 December 2017, 18:24 | #7 |
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,505
|
Lets start from the beginning. I just did more tests and I get different results when using A1200 vs A500..
A500 CIA works as documented, if button IO port is in output mode and data port is set to one, pressing button will always read zero (because standard joystick pulls it to ground when pressed and floating when not pressed) A1200 joystick button IO port in output always reads whatever was written to data IO port. If 1 is written to data, reading data will always return 1, button pressed or not. Input mode works identically, internal pullup always pulls it to 1 when not pressed and returns 0 when pressed. Writing to data does nothing. Same joystick was used in both testes. So it seems forced state can fully work when using A1200 but the question is: what causes the difference? Schematics don't show any extra components between CIA pins and joystick port. I need to do more tests (Other A500, A600, A4000 etc) to confirm if it is CIA model internal change. |
03 December 2017, 18:47 | #8 |
This cat is no more
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,163
|
> A1200 joystick button IO port in output always reads whatever was written to data IO port. If 1 is written to data, reading data will always return 1, button pressed or not.
> Input mode works identically, internal pullup always pulls it to 1 when not pressed and returns 0 when pressed. Writing to data does nothing. And did you test on your CD32 with your superb floppy disk? That would be great for the autofire feature thanks. Another mystery to investigate... |
03 December 2017, 19:22 | #9 |
Registered User
Join Date: Aug 2004
Location:
Posts: 3,335
|
Instead of messing with CIA registers yourself, if you can modify the game code, maybe you could change the button-reading routine to something like this:
Code:
move.b (_ciaa+ciapra).L,D0 and.b (MyFakeButtons,PC),D0 ;This instruction inserted btst #CIAB_GAMEPORT1,D0 ... Code:
EORI.B #~CIAF_GAMEPORT1,(MyFakeButtons).L ... MyFakeButtons: dc.b $FF ;Set to ~CIAF_GAMEPORT1 for fake joystick fire press |
03 December 2017, 19:30 | #10 |
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,505
|
I am quite sure the main point was to have generic method that works with nearly all programs (that don't touch data direction register all the time) without modifications.
|
03 December 2017, 19:59 | #11 |
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,505
|
After testing A600 and A4000: It seems difference is CIA revision: 391078-01 CIA has the "stuck" behavior in output mode, 391078-02 CIA has same behavior as original DIP CIA.
My A600 and A1200 has 391078-01, A4000 has 391078-02. I have another A4000 that has 391078-01 but it lacks KS ROMs so test will be done later.. CD32 seems to also have fixed CIA. (I used floppy adapter setup but using CIA addresses that are not mapped to adapter emulated CIAs but they may also cause some side-effects so this test is can't be 100% confirmed) So, apparently -01 had this bug (perhaps also some others?) that was fixed in -02 revision. I guess I need to add yet another advanced chipset option |
03 December 2017, 20:08 | #12 |
Registered User
Join Date: Aug 2004
Location:
Posts: 3,335
|
There's a document in the OS 3.1 leak: os-source/cdgs/doc/cdgs_hw.doc dated November 1992 which might (or might not, I guess) relate to the CD32 and faking joystick input.
It says "Special hardware is provided to make the 8520s think that the fire buttons are pressed." Also mentions magic remapped registers $DFC00A for joy0dat etc. I wonder whether those features made it into actual shipped hardware. |
03 December 2017, 21:00 | #13 |
This cat is no more
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,163
|
@Toni: yes, I don't want to modify games, that would mean a huge work. I'd do it for the ones which would "resist" the generic feature (some games resist keyboard injection you provided, but the vast majority believe a key has been pressed!)
So what is "the bug" and what is "not the bug"? The bug is the floating register value that would make me happy for my autofire feature, or the other way round? thanks 1000 times for all this testing work. Yes, adding the feature to winuae would be damn great!! |
03 December 2017, 21:40 | #14 | ||
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,505
|
Quote:
Quote:
Assuming both CIA IO ports (port A and B) are affected, this could have affected compatibility with some 3rd party parallel/serial/floppy port hardware. |
||
03 December 2017, 21:52 | #15 |
This cat is no more
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,163
|
Damn, so no autofire for the CD32. So you're confirming that it has nothing to do with joystick/joypad, but just CIA revision?
|
03 December 2017, 22:03 | #16 |
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,505
|
I think there is still chance it works in real world. CD32 pad in CD32 mode uses fire button in output mode.
This is annoying to handle because pad size is partially analog. |
03 December 2017, 23:20 | #17 |
This cat is no more
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,163
|
I see what you mean: I wanted to trigger autofire if player presses another button (since pressing RED/fire isn't convenient for other parts than game: menus, "press fire"...)
that could be tricky, but doable since my code handles the CD32 pad controls in most cases. |
04 December 2017, 14:32 | #18 | |
ex. demoscener "Bigmama"
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
|
Quote:
|
|
04 December 2017, 17:01 | #19 |
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,505
|
CD32 testing..
It seems there may be 2 types of CD32 pads, there are 2 different schematics floating around, one uses all 4 tri-state buffers, another only 2 (out of 4 in 74LS125). First variant disconnects red to fire button line connection when pad is in CD32 line which means as long as pad is in cd32 mode, fire button CIA is fully under software control. Red button does nothing. Second variant does not disconnect it which means CIA pin can be software controlled if button is not pressed. If button is pressed, CIA button bit always reads zero. (Just like normal joystick does) I only have Boomerang pad and it has second variant behavior. Perhaps official pad has better behavior.. They seem to be functionally identical, only difference being that most IO pins are not connected. |
06 December 2017, 17:26 | #20 |
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,505
|
Could anyone who owns official CD32 pad run program linked below? Check and report also type of CIA chips (If A600/A1200/A4000) because it will affect return values.
http://www.winuae.net/files/b/ciabuttontest.zip I only have boomerang pad and I suspect Commodore CD32 pad is not identical (see above). Any Amiga is fine but do not use CD32 if it has any expansions that add floppy drive, parallel or serial port(s) because they can affect Akiko internal CIA behavior. Insert pad in joystick port. Run program in shell (any KS, any CPU), it will output 4+4 character string every ~second or so. Include the string, then press red button, some or all of values may change, include it too. Left mouse = exit. If you don't want to open your Amiga, you can use standard 1-button joystick to confirm CIA type: run the program and press fire button, "***- ***-" = 391078-01 CIA. "**** ****" = other type. Technical info: First 4 characters are CIA fire button value in 2-button pad mode, following 4 in cd32 pad mode. 1: data = 0, dir = 0 2: data = 1, dir = 0 3: data = 0, dir = 1 4: data = 1, dir = 1 |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
edit joy 2nd button ? | turrican3 | support.WinUAE | 4 | 15 November 2012 10:30 |
Regarding auto joy/mouse switcher | VoltureX | support.Hardware | 0 | 12 January 2012 15:26 |
CLI program to resturn joy direction or fire button. | olesio | request.Apps | 26 | 04 November 2011 18:18 |
cd32 problem phantom joy button action | heerschop | support.Hardware | 5 | 19 September 2010 06:09 |
'Wait' program that checks for a joy button press instead of 'Return' key... | Heavy Stylus | request.Apps | 7 | 10 May 2009 19:01 |
|
|