Page 36 of 60

Re: TF CD32 Riser Revision 2 Design Complete

Posted: Thu Oct 22, 2020 9:45 pm
by arkadiusz.makarenko
I have added list todo in github under issues.
I think project is mature and I start to forget what is still broken.

https://github.com/arkadiuszmakarenko/T ... 722/issues

Re: TF CD32 Riser Revision 2 Design Complete

Posted: Thu Oct 22, 2020 10:06 pm
by terriblefire
arkadiusz.makarenko wrote: Thu Oct 22, 2020 8:14 pm
terriblefire wrote: Thu Oct 22, 2020 7:46 pm Dont forget CD32 joypad buttons :)
...yes... can we move it to phase 2 ? :D

I don't even know how to test it now.
The CD32 buttons are basically captured into a latch on the controller and then shifted out on a bit in the CIAs. This is what @Daedalus once sent me on the subject.

Code: Select all

; Read direction
  If port=1
    bytes.w=Peek.w($DFF00C)
  Else
    bytes.w=Peek.w($DFF00A)
  End If

  bit9.w=bytes&%0000001000000000
  bit8.w=bytes&%0000000100000000
  bit1.w=bytes&%0000000000000010
  bit0.w=bytes&%0000000000000001

  result = result | (((bit9 LSR 1) EOR bit8) LSR 8) ; Up
  result = result | (bit1 LSL 2)                    ; Right
  result = result | (bit1 EOR (bit0 LSL 1))         ; Down
  result = result | (bit9 LSR 7)     

function Return result

; Read CD32 Buttons

If port=1
  potgoon.w =%0010000000000000
  potgooff.w=%0011000000000000
  firepin.b=%10000000
  serbit.w=14
Else
  potgoon.w =%0000001000000000
  potgooff.w=%0000001100000000
  firepin.b=%01000000
  serbit.w=10
End If


Poke.b $BFE201,(Peek.b($BFE201)|firepin) ; Joystick fire to output

Poke.b $BFE001,(Peek.b($BFE001) & NOT firepin) ; Output low

savepotgo.w=Peek.w($DFF016)

Poke.w $DFF034,potgoon

ef.b=False

For i.w=1 To 5 ; Delay, 5 chipset word reads
  mybytes.w=Peek.w($DFF016)
Next i

If port=1
  For i.w=14 To 6 Step -1
    Poke.b $BFE001,(Peek.b($BFE001)|firepin) ; Output high
    bytes.w=Peek.w($DFF016)
    Poke.b $BFE001,(Peek.b($BFE001) & NOT firepin) ; %01111111) ; Output low

    result=result | ((bytes & (1 LSL 14)) LSR i) ; %0100000000000000

  Next i
Else ; Port 0
  For i.w=10 To 2 Step -1
    Poke.b $BFE001,(Peek.b($BFE001)|firepin) ; Output high
    bytes.w=Peek.w($DFF016)
    Poke.b $BFE001,(Peek.b($BFE001) & NOT firepin) ; %01111111) ; Output low
    result=result | ((bytes & (1 LSL 10)) LSR i) ; %0100000000000000
  Next i
End If

Poke.w $DFF034,potgooff

Poke.b $BFE001,(Peek.b($BFE001)|firepin) ; Output high
Poke.b $BFE201,(Peek.b($BFE201) & NOT firepin) ; Joystick fire to input

Poke.w $DFF034,savepotgo
..So basically, word reads from 0xDFF00A & 0xDFF00C for the direction, and for the buttons, write to 0xBFE201 and 0xBFE001 (pin 6 of the controller port), read from 0xDFF016, write to 0xDFF034, then read from 0xDFF016 while clocking a bit in 0xBFE001 high and low to read the serial data from the controller. Restore the registers afterwards...

Re: TF CD32 Riser Revision 2 Design Complete

Posted: Thu Oct 22, 2020 10:20 pm
by terriblefire
From http://gerdkautzmann.de/cd32gamepad/cd32gamepad.html

CD32 Gamepad A100 re-engineered documentation

This documentation about the game controll for the Amiga CD32, ist given like it is. There is now warranty about completeness, use it at your own risk.
Commodore, Amiga, CD32 and maybe even Gamepad are registered Trademarks of any company that owns them in the moment.
The CD32 Gamepad is one of the worst controll devices I ever saw. When playing CD32 game I usually gets into troubles cause the left handed joystick replacement thing turns around and stops to work.
There is a good CD32 Gamepad replacement available from CompetitionPro but it has the same disadvantage like any other Gamepads:


They are all designed for left-handers !


Cause I am a right-handed person, I would prefer to controll the movement of a game character or spaceship with my right hand. Pressing the fire button does not need much accuracy, it could be done by the left hand.

I decided to find out, if a normal joystick could be transformed into a CD32 compatible joystick with all its extra buttons. Unfortunately there was not any documentation about the CD32 Gamepad available and re-engineeering turned out to be more difficult than expected.

During a discussion on www.amiga-news.de Jens Schönfeld gave me a hand drawn schematic and told me some details about the CD32 Gamepad. He had done some re-engineering to make his new Catweazle MK4 (www.ami.ga ) more CD32 compatible for emulators like UAE.

Here is the documentation I have made out of all this information.There ar different CD32 Gampad out there, they have some minor changes, to suppress spikes or wrong signals. The Schematic is still missing some capazitators, but it should work the way it is drawn.


Pictures

Click on a picture for a detailed view
a100draufs.jpg
a100draufs.jpg (15.44 KiB) Viewed 2629 times
a100platdraufs.jpg
a100platdraufs.jpg (15.7 KiB) Viewed 2629 times
a100platdets.jpg
a100platdets.jpg (14.13 KiB) Viewed 2629 times
a100platdets.jpg
a100platdets.jpg (14.13 KiB) Viewed 2629 times
a100schematics.png
a100schematics.png (18.11 KiB) Viewed 2629 times
Screenshot 2020-10-22 at 22.18.38.png
Screenshot 2020-10-22 at 22.18.38.png (124.06 KiB) Viewed 2629 times
Functions

There are 2 different function modes, the joystick direction switches are used in both modes like in every Amiga compatible joystick.
Joystick Mode (default)

Pot-X (P5) is set to 1 by the CD32, this will set the shift register always to load, the clock will be ignored and the first bit (blue button) is switched to POT-Y (P9).

POT-X also switches the driver in 74LS125 so the red Button will be conducted to (P6) Joystick Fire. The Gamepad acts like a normal joystick.
Gamepad Mode

Pot-X (P5) is set to 0 by the CD32, this will switch the driver in 74LS125 to high imepdance an the signal from the fire button will not be switched to to fire (P6) any more.
With every rising edge on (P6) the state of the Gamepad buttons will be shifted from the inputs of the shift register over the 74LS125 driver to Pot-Y (P9). As long as shift/load on the shift register is switched to shift it will shift out the state of the buttons that where loaded before.
Screenshot 2020-10-22 at 22.19.52.png
Screenshot 2020-10-22 at 22.19.52.png (87.55 KiB) Viewed 2629 times
What is Missing ?

Some capazitators are missing in the schematic, every chip should have a blocking capazitator.
I have still not checked evrything.

Re: TF CD32 Riser Revision 2 Design Complete

Posted: Fri Oct 23, 2020 11:47 am
by arkadiusz.makarenko
Found my CD32 controller! I knew that I had it somwhere. Those are getting expensive these days!
20201023_114452.jpg
20201023_114452.jpg (329.29 KiB) Viewed 2590 times

Now I can see how extra buttons are behaving.

Only in Joystick mode. Gamepad mode need to be enabled.
Red button = fire
Blue button = right click

So
1. I need to detect either joystick or gamepad mode.
2. In gamepad mode populate POTxDAT with 7 button values
3. In joystick mode just leave it as above.

Re: TF CD32 Riser Revision 2 Design Complete

Posted: Fri Oct 23, 2020 2:10 pm
by arkadiusz.makarenko
Implemented - USB Gamepad button decode - limit only of 4 buttons enhancement . Now I can read all standard buttons from HID device.

Re: TF CD32 Riser Revision 2 Design Complete

Posted: Fri Oct 23, 2020 6:17 pm
by arkadiusz.makarenko
I can see that Turrican has own way of reading joystick directions. I guess I will need to mimic functionality of those chips a little bit better than only copying observed output values.
I will need to implement writing to registers anyway for detection of joystick/gamepad, and POTXDAT anyway.

Re: TF CD32 Riser Revision 2 Design Complete

Posted: Fri Oct 23, 2020 9:52 pm
by terriblefire
arkadiusz.makarenko wrote: Fri Oct 23, 2020 6:17 pm I can see that Turrican has own way of reading joystick directions. I guess I will need to mimic functionality of those chips a little bit better than only copying observed output values.
I will need to implement writing to registers anyway for detection of joystick/gamepad, and POTXDAT anyway.
One thing i keep meaning to ask is how do you program the STM32 so that it retains the data after a reboot. I seem to always need to flash after power on from CubeIDE. Maybe start a new thread for that.

Re: TF CD32 Riser Revision 2 Design Complete

Posted: Fri Oct 23, 2020 10:22 pm
by arkadiusz.makarenko
terriblefire wrote: Fri Oct 23, 2020 9:52 pm
arkadiusz.makarenko wrote: Fri Oct 23, 2020 6:17 pm I can see that Turrican has own way of reading joystick directions. I guess I will need to mimic functionality of those chips a little bit better than only copying observed output values.
I will need to implement writing to registers anyway for detection of joystick/gamepad, and POTXDAT anyway.
One thing i keep meaning to ask is how do you program the STM32 so that it retains the data after a reboot. I seem to always need to flash after power on from CubeIDE. Maybe start a new thread for that.
It should be written to flash on stm32 via cubeIDE. Most liekly stm32 simply doesn't boot at start.
Try to set jumper like this.
20201023_221419.jpg
20201023_221419.jpg (221.41 KiB) Viewed 2512 times
If this doesn't help in STM32 Link Utility set up address 0x08000000 (default). This is flash address, and erase chip, and write from there.

Re: TF CD32 Riser Revision 2 Design Complete

Posted: Fri Oct 23, 2020 10:59 pm
by arkadiusz.makarenko
Turrican 2 issue solved. Do they do some math one whole byte? When I set only first two bits all is good.

Re: TF CD32 Riser Revision 2 Design Complete

Posted: Sat Oct 24, 2020 10:19 am
by terriblefire
Sweet I’ll try that