Post by spinal on May 17, 2018 9:47:32 GMT
I will quickly show how to create an arduino based c64 joystick for the c64 mini. I will assume you already know a bit about arduino and require no help when attaching the joystick to your arduino board.
I can't remember which joystick library I used, but there seem to be a handful of them and it looks like they all work exactly the same way.
For this particular joystick, I will be using the autofire switch to toggle between normal and 'extra button' mode. In normal mode, The joystick will work as you'd expect. With Up, Down, Left, Right, Fire1 and Fire2 representing those functions. In 'extra button' mode, Fire1 = button 3, Fire2 = button 4, Up = button 5, Down = button 6, Left = button 7 and Right = button 8. This allows us to use the full functionality of the c64 mini without needing the original joystick.
Here is the code, I used pins 6,2,3,7,8,9,10 for my joystick, you can use whatever you want. I only used those pins because my arduino was damaged and some pins don't work.
For this to work, you need an arduino with one of the Atmega32U2 or Atmega32U4. I used an arduino leonardo clone called pro micro.Once you have the joystick wired up and the sketch uploaded, you can test it in windows if you like, just to make sure.
For the finishing touch, you need to add the joystick layout to the C64mini. The file you need to edit is - \usr\share\the64\ui\data\gamecontrollerdb.txtSimply add the following line to the end of the file.
03000000412300003680000001010000,Arduino LLC Arduino Leonardo,a:b4,b:b5,x:b3,y:b2,back:b6,start:b7,lefttrigger:b0,righttrigger:b1,leftx:a0,lefty:a1,platform:Linux,
I currently don't know how to add this directly on the c64mini, I'm using the USB boot method at the moment.
So that's it, You can use your old C64 joystick on the mini without loosing functionality.
I can't remember which joystick library I used, but there seem to be a handful of them and it looks like they all work exactly the same way.
For this particular joystick, I will be using the autofire switch to toggle between normal and 'extra button' mode. In normal mode, The joystick will work as you'd expect. With Up, Down, Left, Right, Fire1 and Fire2 representing those functions. In 'extra button' mode, Fire1 = button 3, Fire2 = button 4, Up = button 5, Down = button 6, Left = button 7 and Right = button 8. This allows us to use the full functionality of the c64 mini without needing the original joystick.
Here is the code, I used pins 6,2,3,7,8,9,10 for my joystick, you can use whatever you want. I only used those pins because my arduino was damaged and some pins don't work.
#include <Joystick.h>
// Use whichever pins you like, I used these bcause some of the other pins were damaged.
// I will be using the autofire swith on my zipstick to emulate the last 6 buttons on the c64 joystick.
// up, down, left, right, fire1, fire2, auto switch
char myPin[]={6, 2, 3, 7, 8, 9, 10};
// Set up the arduino as an 8 button gamepad.
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,JOYSTICK_TYPE_GAMEPAD,
8, 0, // Button Count, Hat Switch Count
true, true, false, // X and Y, but no Z Axis
false, false, false, // No Rx, Ry, or Rz
false, false, // No rudder or throttle
false, false, false); // No accelerator, brake, or steering
//------------------------[ Button handling, very accurate ]------------------------
#define HELD 0
#define NEW 1
#define RELEASE 2
byte CompletePad, ExPad, TempPad, myPad;
bool _A[3], _B[3], _C[3], _Up[3], _Down[3], _Left[3], _Right[3];
void UPDATEPAD(int pad, int var) {
_C[pad] = (var >> 1)&1;
_B[pad] = (var >> 2)&1;
_A[pad] = (var >> 3)&1;
_Down[pad] = (var >> 4)&1;
_Left[pad] = (var >> 5)&1;
_Right[pad] = (var >> 6)&1;
_Up[pad] = (var >> 7)&1;
}
byte updateButtons(byte var){
var = 0;
if (!digitalRead(myPin[6])) var |= (1<<1);
if (!digitalRead(myPin[5])) var |= (1<<2);
if (!digitalRead(myPin[4])) var |= (1<<3); // P1_9 = A
if (!digitalRead(myPin[1])) var |= (1<<4);
if (!digitalRead(myPin[2])) var |= (1<<5);
if (!digitalRead(myPin[3])) var |= (1<<6);
if (!digitalRead(myPin[0])) var |= (1<<7);
return var;
}
void UpdatePad(int joy_code){
ExPad = CompletePad;
CompletePad = joy_code;
UPDATEPAD(HELD, CompletePad); // held
UPDATEPAD(RELEASE, (ExPad & (~CompletePad))); // released
UPDATEPAD(NEW, (CompletePad & (~ExPad))); // newpress
}
//----------------------------------------------------------------------------------
void setup() {
// Initialize Button Pins
Serial.begin(9600);
for (int index = 0; index < sizeof(myPin); index++)
{
pinMode(myPin[index], INPUT_PULLUP);
}
// Initialize Joystick Library
Joystick.begin();
Joystick.setXAxisRange(-1, 1);
Joystick.setYAxisRange(-1, 1);
}
void loop() {
// update buttons
myPad = updateButtons(myPad);
UpdatePad(myPad);
if(_C[HELD]){ // if 'autofire' then use fire1,2,up,down,left,right as extra buttons!
if(_A[HELD]){
Joystick.setButton(2, 1);
}else{
Joystick.setButton(2, 0);
}
if(_B[HELD]){
Joystick.setButton(3, 1);
}else{
Joystick.setButton(3, 0);
}
if(_Up[HELD]){
Joystick.setButton(4, 1);
}else{
Joystick.setButton(4, 0);
}
if(_Down[HELD]){
Joystick.setButton(5, 1);
}else{
Joystick.setButton(5, 0);
}
if(_Left[HELD]){
Joystick.setButton(6, 1);
}else{
Joystick.setButton(6, 0);
}
if(_Right[HELD]){
Joystick.setButton(7, 1);
}else{
Joystick.setButton(7, 0);
}
}else{ // if not autofire, then use the joystick as normal
if(_Up[HELD]){
Joystick.setYAxis(-1);
}else if(_Down[HELD]){
Joystick.setYAxis(1);
}else{
Joystick.setYAxis(0);
}
if(_Left[HELD]){
Joystick.setXAxis(-1);
}else if(_Right[HELD]){
Joystick.setXAxis(1);
}else{
Joystick.setXAxis(0);
}
if(_A[HELD]){
Joystick.setButton(0, 1);
}else{
Joystick.setButton(0, 0);
}
if(_B[HELD]){
Joystick.setButton(1, 1);
}else{
Joystick.setButton(1, 0);
}
}
}
For this to work, you need an arduino with one of the Atmega32U2 or Atmega32U4. I used an arduino leonardo clone called pro micro.Once you have the joystick wired up and the sketch uploaded, you can test it in windows if you like, just to make sure.
For the finishing touch, you need to add the joystick layout to the C64mini. The file you need to edit is - \usr\share\the64\ui\data\gamecontrollerdb.txtSimply add the following line to the end of the file.
03000000412300003680000001010000,Arduino LLC Arduino Leonardo,a:b4,b:b5,x:b3,y:b2,back:b6,start:b7,lefttrigger:b0,righttrigger:b1,leftx:a0,lefty:a1,platform:Linux,
I currently don't know how to add this directly on the c64mini, I'm using the USB boot method at the moment.
So that's it, You can use your old C64 joystick on the mini without loosing functionality.