English Amiga Board


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

 
 
Thread Tools
Old 27 August 2017, 22:48   #1
jotd
This cat is no more
 
jotd's Avatar
 
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
after this code the 7th bit of CIAport A should be 0 but it isn't. Well, of course, I imagine that at some point, the actual joystick output overrides the value I just set there. So is the exercise pointless?
jotd is offline  
Old 28 August 2017, 14:04   #2
Toni Wilen
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
Toni Wilen is offline  
Old 28 August 2017, 21:52   #3
jotd
This cat is no more
 
jotd's Avatar
 
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!!)
jotd is offline  
Old 29 August 2017, 14:40   #4
hooverphonique
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!?
hooverphonique is offline  
Old 29 August 2017, 20:12   #5
Toni Wilen
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)
Toni Wilen is offline  
Old 03 December 2017, 17:47   #6
jotd
This cat is no more
 
jotd's Avatar
 
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...)
jotd is offline  
Old 03 December 2017, 18:24   #7
Toni Wilen
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.
Toni Wilen is offline  
Old 03 December 2017, 18:47   #8
jotd
This cat is no more
 
jotd's Avatar
 
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...
jotd is offline  
Old 03 December 2017, 19:22   #9
mark_k
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
   ...
For autofire, in the vertical blanking interrupt routine you'd do
Code:
   EORI.B #~CIAF_GAMEPORT1,(MyFakeButtons).L
   ...

MyFakeButtons:
   dc.b $FF              ;Set to ~CIAF_GAMEPORT1 for fake joystick fire press
mark_k is online now  
Old 03 December 2017, 19:30   #10
Toni Wilen
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.
Toni Wilen is offline  
Old 03 December 2017, 19:59   #11
Toni Wilen
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
Toni Wilen is offline  
Old 03 December 2017, 20:08   #12
mark_k
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.
mark_k is online now  
Old 03 December 2017, 21:00   #13
jotd
This cat is no more
 
jotd's Avatar
 
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!!
jotd is offline  
Old 03 December 2017, 21:40   #14
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,505
Quote:
Originally Posted by mark_k View Post
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.
I have heard about those extra features long time ago but they don't seem to exist. (lowlevel.library would 100% surely used it)

Quote:
Originally Posted by jotd View Post
@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!!
"buggy CIA" (391078-01) = the one that allow complete fire button software control. (when in output mode, connected joystick button's state does not affect IO port data value)

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.
Toni Wilen is offline  
Old 03 December 2017, 21:52   #15
jotd
This cat is no more
 
jotd's Avatar
 
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?
jotd is offline  
Old 03 December 2017, 22:03   #16
Toni Wilen
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.
Toni Wilen is offline  
Old 03 December 2017, 23:20   #17
jotd
This cat is no more
 
jotd's Avatar
 
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.
jotd is offline  
Old 04 December 2017, 14:32   #18
hooverphonique
ex. demoscener "Bigmama"
 
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
Quote:
Originally Posted by mark_k View Post
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.
I saw something yesterday which suggests that the cd32 cias are implemented in the akiko chip, so they could have different functionality than orignal 8520's..
hooverphonique is offline  
Old 04 December 2017, 17:01   #19
Toni Wilen
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..

Quote:
Originally Posted by hooverphonique View Post
I saw something yesterday which suggests that the cd32 cias are implemented in the akiko chip, so they could have different functionality than orignal 8520's..
They seem to be functionally identical, only difference being that most IO pins are not connected.
Toni Wilen is offline  
Old 06 December 2017, 17:26   #20
Toni Wilen
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
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
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

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 15:11.

Top

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