Amiga Analog Joystick and endianess Golden Child 12/06/19 05:22 PM
Hi guys,

I was reading up on amiga analog joysticks and wanted to see if I could get one working with the amiga driver but something very strange is going on.

For some reason, the x and y axes are inverted. When the POT0DAT or POT1DAT registers are read, it's supposed to return a 16 bit word that has Y in the upper 8 bits and X in the lower 8 bits.
Code
Bit 	15 	14 	13 	12 	11 	10 	09 	08 	07 	06 	05 	04 	03 	02 	01 	00
        Y7 	Y6 	Y5 	Y4 	Y3 	Y2 	Y1 	Y0 	X7 	X6 	X5 	X4 	X3 	X2 	X1 	X0



I thought I'd just have a couple of analog input ports named m_analog0 and m_analog1 and then do a direct read to keep things simple.

Code
                case REG_POT1DAT:
                        if (m_pot1dat_port.found())
                        {
                                return m_pot1dat_port->read();
                        }
                        else
                        {
                                m_pot1dat  = m_analog0->read() | (m_analog1->read() << 8);
                                return m_pot1dat;
                        }


So it reads properly, but I can't figure out why the high and low bytes get swapped.

I set a watchpoint on POT1DAT = DFF014 and it looks like its getting the right data.


There's a few games that have analog joystick support, one is Nova9 which has a totally incorrect manual with regard to analog joystick support, you have to hit the period key to get it to enable (at least with the pal version).

Jet Pilot by Vulcan Software has a good calibration program (only the cracked version would load and run in mame)


./myamiga64 a500 -mouse -window -debug -fdc:0 35dd -fdc:1 35dd -fdc:2 35dd -fdc:3 35dd -flop1 "../../wbenc133_us/317746-04_workbench.adf" -flop2 "../../Jet Pilot (1996)(Vulcan Software)[cr HF](Disk 1 of 4)[WB].zip/Jet Pilot (1996)(Vulcan Software)[cr HF](Disk 1 of 4)[WB].adf" -flop3 "../../Jet Pilot (1996)(Vulcan Software)[cr HF](Disk 2 of 4)[WB].zip/Jet Pilot (1996)(Vulcan Software)[cr HF](Disk 2 of 4)[WB].adf" -flop4 "../../Jet Pilot (1996)(Vulcan Software)[cr HF](Disk 4 of 4)[WB].zip/Jet Pilot (1996)(Vulcan Software)[cr HF](Disk 4 of 4)[WB].adf"

[Linked Image from i.imgur.com]
[Linked Image from i.imgur.com]

so in the debugger I put in a watchpoint to see what's going on: I'm modifying the x axis and its the low bits that are changing but on the screen the Y axis values are changing.
[Linked Image from i.imgur.com]


It reads 78F0 from $dff014 and then writes 78F0 to $44332
[Linked Image from i.imgur.com]


Everything seems to work properly if I reverse the byte order with:

Code

                                m_pot1dat  = m_analog1->read() | (m_analog0->read() << 8);
                                return m_pot1dat;


[Linked Image from i.imgur.com]

Seems to work ok in reversing the order, x/y drives the intended axis. Player 2 right and left are the analog buttons 1 and 2 but since it thinks its a digital joystick it disallows simultaneous pressing.





I was also able to get Flight of the Intruder to run to where I could calibrate the joystick.

./myamiga64 a4000n -mouse -window -debug -fdc:0 35dd -fdc:1 35dd -fdc:2 35dd -fdc:3 35dd -flop1 "../../Flight of the Intruder (1991)(Spectrum HoloByte)[cr QTX](Disk 1 of 2).adf" -flop2 "../../Flight of the Intruder (1991)(Spectrum HoloByte)[cr QTX](Disk 2 of 2).adf"

[Linked Image from i.imgur.com]

Pressing ESC ingame brings up the menu:

[Linked Image from i.imgur.com]
[Linked Image from i.imgur.com]


Is this endian thing because I'm running on an intel little endian machine?
0 111 Read More