Previous Thread
Next Thread
Print Thread
Page 3 of 3 1 2 3
Re: C64 Joystick [Re: billb] #99984 05/30/15 10:28 AM
Joined: May 2003
Posts: 225
T
Trebor Offline
Senior Member
Offline
Senior Member
T
Joined: May 2003
Posts: 225
Thanks to the mention from this thread... http://forums.bannister.org/ubbthreads.php?ubb=showflat&Number=99797#Post99797
...and to add to, as well as keep, the list of games impacted together within the same thread, the following also rely on Port 2 mapped to 'player 1' and does not work under MESS MAME grin

Bubble Bobble
Friday the 13th
G.I. Joe
Grog's Revenge

Re: C64 Joystick [Re: Trebor] #100021 06/03/15 05:53 PM
Joined: Apr 2013
Posts: 71
G
geecab Offline
Member
Offline
Member
G
Joined: Apr 2013
Posts: 71
Thought I'd add this here as its purely c64 joystick related.

I have hacked mos6526.c to get joystick Port2 working. It seems to work ok (I've just been playing The Last Ninja without any problems), but I've probably broken Amiga joystick emulation in the process :P

The information earlier in this thread was really helpful. Pete Rittwage posted that Port2 was broken a while ago when the C64 & Amiga's cia 6526 code was merged, so that is where I looked/hacked first. In the src/emu/machine/mos6526.c I changed this bit of code:-

Code:
READ8_MEMBER( mos6526_device::read )
{
  if (space.debugger_access())
    return 0xff;

  UINT8 data = 0;

  switch (offset & 0x0f)
  {
    case PRA:		
      data = (m_read_pa(0) & ~m_ddra) | (m_pra & m_ddra);
      m_pa_in = data;
      break;


to look like this

Code:
READ8_MEMBER( mos6526_device::read )
{
  if (space.debugger_access())
    return 0xff;

  UINT8 data = 0;

  switch (offset & 0x0f)
  {
    case PRA:
      if(m_ddra != 0xFF)
      {		
        data = (m_read_pa(0) & ~m_ddra) | (m_pra & m_ddra);
      }
      else
      {
        data = m_read_pa(0) & m_pra;
      }	
      m_pa_in = data;
      break;


and it worked smile

I've been testing what the joystick ports are returning by running the following:
mess.exe c64 -window -autoboot_command "10 PRINTCHR$(147)\n20 PRINT"""JP1"""PEEK(56321)\n30 PRINT"""JP2"""PEEK(56320)\n40 GOTO 10\nRUN\n"

I also found this table useful (That I found here http://personalpages.tds.net/~rcarlsen/cbm/repairs/ctrlport.txt) when checking the joystick values returned are correct:

Code:
 PIN  FUNCTION      CONTROL PORT 1         CONTROL PORT 2
       NONE          255                    127
  1    UP            254 (1)                126 (C= & F3) 
  2    DOWN          253 (LEFT ARROW)       125 (C= & S)
  3    LEFT          251 (CTRL)             123 (C= & F)
  4    RIGHT         247 (2)                119 (C= & H)
  6    FIRE          239 (SPACEBAR)         111 (C= & K)

Note. The dual entries (example: Commodore key & F3) indicate two simultanious keypresses.


Hope this helps smile

Last edited by geecab; 06/03/15 06:06 PM.
Re: C64 Joystick [Re: billb] #100022 06/03/15 06:04 PM
Joined: May 2004
Posts: 1,611
H
Haze Offline
Very Senior Member
Offline
Very Senior Member
H
Joined: May 2004
Posts: 1,611
so basically just replace
Code:
data = (m_read_pa(0) & ~m_ddra) | (m_pra & m_ddra);

with
Code:
if (m_ddra != 0xFF)
    data = (m_read_pa(0) & ~m_ddra) | (m_pra & m_ddra);
else	
    data = m_read_pa(0) & m_pra;

it does indeed mean
mame64 c64p -flop1 "Donkey Kong (1986)(Ocean Software)[cr New Stars].d64" -joy2 joy

works again and can be played...

anybody familiar enough with the real hardware to comment on the correctness? it doesn't look entirely unreasonable, but I'm not sure.

Re: C64 Joystick [Re: billb] #100024 06/03/15 06:18 PM
Joined: Mar 2001
Posts: 16,499
R
R. Belmont Online Content
Very Senior Member
Online Content
Very Senior Member
R
Joined: Mar 2001
Posts: 16,499
Agreed, it looks reasonable (although if it's correct it should apply to both ports). Can we get whoever caused it in the first place (Curt?) to take a look?

Last edited by R. Belmont; 06/03/15 06:18 PM.
Re: C64 Joystick [Re: R. Belmont] #100027 06/03/15 08:35 PM
Joined: Apr 2013
Posts: 71
G
geecab Offline
Member
Offline
Member
G
Joined: Apr 2013
Posts: 71
Not sure if this helps, but thought I'd elaborate on my hack a little more:-

To begin with, I put a printf in the code just under the "data = (m_read_pa(0) & ~m_ddra) | (m_pra & m_ddra)" line like this...
Code:
data = (m_read_pa(0) & ~m_ddra) | (m_pra & m_ddra);
printf("data=0x%X m_read_pa=0x%X m_ddra=0x%X m_pra=0x%X\n", data, m_read_pa(0),  m_ddra, m_pra);


Then I ran the following:-
Code:
mess.exe c64 -window -autoboot_command "10 PRINTCHR$(147)\n20 PRINT"""JP1"""PEEK(56321)\n30 PRINT"""JP2"""P
EEK(56320)\n40 GOTO 10\nRUN\n"


and I saw this debug output from mess..
Code:
data=0x47 m_read_pa=0x44 m_ddra=0x3F m_pra=0x7
data=0x97 m_read_pa=0x84 m_ddra=0x3F m_pra=0x57
data=0x7F m_read_pa=0xFF m_ddra=0xFF m_pra=0x7F
data=0x7F m_read_pa=0xFF m_ddra=0xFF m_pra=0x7F
data=0x7F m_read_pa=0xFF m_ddra=0xFF m_pra=0x7F
data=0x7F m_read_pa=0xF7 m_ddra=0xFF m_pra=0x7F  <-- This is when I held the Joystick right
data=0x7F m_read_pa=0xFF m_ddra=0xFF m_pra=0x7F
data=0x7F m_read_pa=0xFF m_ddra=0xFF m_pra=0x7F
data=0x7F m_read_pa=0xFF m_ddra=0xFF m_pra=0x7F


I noticed the value being returned from m_read_pa() changed in accordance with the joystick control I was triggering, otherwise it was consistently m_read_pa=0xFF (no joystick controls triggered) - *apart* from the very first couple of reads that happen just after mess starts up (where m_read_pa is 0x44 and 0x84).

I think the m_ddra=0xFF means that PortA (Confusingly joystick Port2) has been configured for Output. So its "write only" which maybe why mess is not allowing us to read from it. I think this quote from what Pete Rittwage said is important (but I'm not totally sure I understand it)...
Quote:

The 6526 and 8520 code was merged a few releases back, but the way the chip is implemented is different in the C64 vs. Amiga. On the C64, the lines can be pulled low even when the selects are set to output, which was/is an PCB design decision. On the Amiga, this can't happen since those lines are buffered by other logic.


So I guessed that I had better not be altering the 'data' return value until after m_ddra was consistently 0xFF. As m_pra is set to a consistent 0x7F I thought I'd AND that with the m_read_pa giving the correct Joystick port 2 values (126/125 etc..).

Like I said, its a pretty dirty hack but hopefully gets us a bit closer a clean fix smile

Re: C64 Joystick [Re: billb] #100028 06/03/15 09:26 PM
Joined: May 2003
Posts: 225
T
Trebor Offline
Senior Member
Offline
Senior Member
T
Joined: May 2003
Posts: 225
Very cool, gentlemen. Thank you for your time and attention to the issue. It is very much appreciated.

Page 3 of 3 1 2 3

Who's Online Now
5 registered members (Golden Child, Pernod, Fake Shemp, R. Belmont, robcfg), 60 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
ShoutChat Box
Comment Guidelines: Do post respectful and insightful comments. Don't flame, hate, spam.
Forum Statistics
Forums9
Topics8,775
Posts115,470
Members4,899
Most Online890
Jan 17th, 2020
Powered by UBB.threads™ PHP Forum Software 7.7.3