Skip to content

Commit

Permalink
Fix Saturn Controller support
Browse files Browse the repository at this point in the history
  • Loading branch information
rsn8887 committed Dec 9, 2023
1 parent a9664c6 commit 698ff1e
Show file tree
Hide file tree
Showing 28 changed files with 6,399 additions and 7,659 deletions.
1,249 changes: 567 additions & 682 deletions RetroAdapterV2_Arcade.hex

Large diffs are not rendered by default.

1,241 changes: 565 additions & 676 deletions RetroAdapterV2_Arcade_16MHz.hex

Large diffs are not rendered by default.

1,223 changes: 555 additions & 668 deletions RetroAdapterV2_MiSTer.hex

Large diffs are not rendered by default.

1,215 changes: 553 additions & 662 deletions RetroAdapterV2_MiSTer_16MHz.hex

Large diffs are not rendered by default.

1,248 changes: 567 additions & 681 deletions RetroAdapterV2_Normal.hex

Large diffs are not rendered by default.

1,240 changes: 565 additions & 675 deletions RetroAdapterV2_Normal_16MHz.hex

Large diffs are not rendered by default.

982 changes: 439 additions & 543 deletions RetroAdapterV2_Switch.hex

Large diffs are not rendered by default.

974 changes: 437 additions & 537 deletions RetroAdapterV2_Switch_16MHz.hex

Large diffs are not rendered by default.

1,213 changes: 549 additions & 664 deletions RetroAdapterV2_Undamned.hex

Large diffs are not rendered by default.

1,205 changes: 547 additions & 658 deletions RetroAdapterV2_Undamned_16MHz.hex

Large diffs are not rendered by default.

1,084 changes: 494 additions & 590 deletions RetroAdapterV2_XBox.hex

Large diffs are not rendered by default.

1,074 changes: 490 additions & 584 deletions RetroAdapterV2_XBox_16MHz.hex

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions make_all.sh
Expand Up @@ -64,3 +64,35 @@ cp *.hex ../
make -f Makefile16MHz clean

cd ..

# MiSTer
cd src_MiSTerMode

make clean
make -f Makefile16MHz clean

make
cp *.hex ../
make clean

make -f Makefile16MHz
cp *.hex ../
make -f Makefile16MHz clean

cd ..

# Undamned
cd src_UndamnedMode

make clean
make -f Makefile16MHz clean

make
cp *.hex ../
make clean

make -f Makefile16MHz
cp *.hex ../
make -f Makefile16MHz clean

cd ..
10 changes: 5 additions & 5 deletions src_MiSTerMode/saturn.c
Expand Up @@ -62,10 +62,10 @@ void ReadSaturn(report_t *reportBuffer)

_delay_us(2);

if (!(PINB & SAT_UP)) reportBuffer->b1 |= (1<<5); // Z
if (!(PINB & SAT_DN)) reportBuffer->b1 |= (1<<4); // Y
if (!(PINB & SAT_UP)) reportBuffer->b1 |= (1<<7); // Z
if (!(PINB & SAT_DN)) reportBuffer->b1 |= (1<<6); // Y
if (!(PIND & SAT_LF)) reportBuffer->b1 |= (1<<3); // X
if (!(PIND & SAT_RT)) reportBuffer->b1 |= (1<<7); // R
if (!(PIND & SAT_RT)) reportBuffer->b1 |= (1<<5); // R
}

else if (PINB & SAT_UP) // Analogue pad
Expand Down Expand Up @@ -192,7 +192,7 @@ void ReadSaturn(report_t *reportBuffer)
if (!(PIND & SAT_LF)) temp |= (1<<2); // Left
if (!(PIND & SAT_RT)) temp |= (1<<3); // Right

if (satmode == 1) reportBuffer->ry = temp - 128;
if (satmode == 1) reportBuffer->ry = (temp >> 1);

/* --- Left shoulder ----------------------------------------------------------------*/

Expand All @@ -215,7 +215,7 @@ void ReadSaturn(report_t *reportBuffer)
if (!(PIND & SAT_LF)) temp |= (1<<2); // Left
if (!(PIND & SAT_RT)) temp |= (1<<3); // Right

if (satmode == 1) reportBuffer->rx = temp - 128;
if (satmode == 1) reportBuffer->rx = (temp >> 1);

/* --- End of data transfer ---------------------------------------------------------*/

Expand Down
2 changes: 1 addition & 1 deletion src_NormalAndArcadeMode/ArcadeMode/Makefile
Expand Up @@ -6,7 +6,7 @@
PROJECT = RetroAdapterV2_Arcade
MCU = atmega168
TARGET = $(PROJECT).elf
CC = avr-gcc.exe
CC = avr-gcc

## Options common to compile, link and assembly rules
COMMON = -mmcu=$(MCU)
Expand Down
2 changes: 1 addition & 1 deletion src_NormalAndArcadeMode/ArcadeMode/Makefile16MHz
Expand Up @@ -6,7 +6,7 @@
PROJECT = RetroAdapterV2_Arcade_16MHz
MCU = atmega168
TARGET = $(PROJECT).elf
CC = avr-gcc.exe
CC = avr-gcc

## Options common to compile, link and assembly rules
COMMON = -mmcu=$(MCU)
Expand Down
2 changes: 1 addition & 1 deletion src_NormalAndArcadeMode/Makefile
Expand Up @@ -6,7 +6,7 @@
PROJECT = RetroAdapterV2_Normal
MCU = atmega168
TARGET = $(PROJECT).elf
CC = avr-gcc.exe
CC = avr-gcc

## Options common to compile, link and assembly rules
COMMON = -mmcu=$(MCU)
Expand Down
2 changes: 1 addition & 1 deletion src_NormalAndArcadeMode/Makefile16MHz
Expand Up @@ -6,7 +6,7 @@
PROJECT = RetroAdapterV2_Normal_16MHz
MCU = atmega168
TARGET = $(PROJECT).elf
CC = avr-gcc.exe
CC = avr-gcc

## Options common to compile, link and assembly rules
COMMON = -mmcu=$(MCU)
Expand Down
10 changes: 5 additions & 5 deletions src_NormalAndArcadeMode/saturn.c
Expand Up @@ -62,10 +62,10 @@ void ReadSaturn(report_t *reportBuffer)

_delay_us(2);

if (!(PINB & SAT_UP)) reportBuffer->b1 |= (1<<5); // Z
if (!(PINB & SAT_DN)) reportBuffer->b1 |= (1<<4); // Y
if (!(PINB & SAT_UP)) reportBuffer->b1 |= (1<<7); // Z
if (!(PINB & SAT_DN)) reportBuffer->b1 |= (1<<6); // Y
if (!(PIND & SAT_LF)) reportBuffer->b1 |= (1<<3); // X
if (!(PIND & SAT_RT)) reportBuffer->b1 |= (1<<7); // R
if (!(PIND & SAT_RT)) reportBuffer->b1 |= (1<<5); // R
}

else if (PINB & SAT_UP) // Analogue pad
Expand Down Expand Up @@ -192,7 +192,7 @@ void ReadSaturn(report_t *reportBuffer)
if (!(PIND & SAT_LF)) temp |= (1<<2); // Left
if (!(PIND & SAT_RT)) temp |= (1<<3); // Right

if (satmode == 1) reportBuffer->ry = temp - 128;
if (satmode == 1) reportBuffer->ry = (temp >> 1);

/* --- Left shoulder ----------------------------------------------------------------*/

Expand All @@ -215,7 +215,7 @@ void ReadSaturn(report_t *reportBuffer)
if (!(PIND & SAT_LF)) temp |= (1<<2); // Left
if (!(PIND & SAT_RT)) temp |= (1<<3); // Right

if (satmode == 1) reportBuffer->rx = temp - 128;
if (satmode == 1) reportBuffer->rx = (temp >> 1);

/* --- End of data transfer ---------------------------------------------------------*/

Expand Down
2 changes: 1 addition & 1 deletion src_SwitchMode/Makefile
Expand Up @@ -6,7 +6,7 @@
PROJECT = RetroAdapterV2_Switch
MCU = atmega168
TARGET = $(PROJECT).elf
CC = avr-gcc.exe
CC = avr-gcc

## Options common to compile, link and assembly rules
COMMON = -mmcu=$(MCU)
Expand Down
2 changes: 1 addition & 1 deletion src_SwitchMode/Makefile16MHz
Expand Up @@ -6,7 +6,7 @@
PROJECT = RetroAdapterV2_Switch_16MHz
MCU = atmega168
TARGET = $(PROJECT).elf
CC = avr-gcc.exe
CC = avr-gcc

## Options common to compile, link and assembly rules
COMMON = -mmcu=$(MCU)
Expand Down
14 changes: 7 additions & 7 deletions src_SwitchMode/saturn.c
Expand Up @@ -35,7 +35,7 @@ void ReadSaturn(report_t *reportBuffer)
// TH = 1, TR = 1
if (PIND & SAT_LF) // Standard digital pad
{
if (!(PIND & SAT_RT)) reportBuffer->b1 |= (1<<6); // L
if (!(PIND & SAT_RT)) reportBuffer->b1 |= (1<<4); // L

// TH = 0, TR = 1
PORTB &= ~(SAT_TH);
Expand All @@ -60,17 +60,17 @@ void ReadSaturn(report_t *reportBuffer)
if (!(PINB & SAT_UP)) reportBuffer->b1 |= (1<<1); // B
if (!(PINB & SAT_DN)) reportBuffer->b1 |= (1<<2); // C
if (!(PIND & SAT_LF)) reportBuffer->b1 |= (1<<0); // A
if (!(PIND & SAT_RT)) reportBuffer->b2 |= (1<<3); // Start
if (!(PIND & SAT_RT)) reportBuffer->b2 |= (1<<1); // Start

// TH = 0, TR = 0
PORTB &= ~(SAT_TH|SAT_TR);

_delay_us(2);

if (!(PINB & SAT_UP)) reportBuffer->b1 |= (1<<5); // Z
if (!(PINB & SAT_DN)) reportBuffer->b1 |= (1<<4); // Y
if (!(PINB & SAT_UP)) reportBuffer->b1 |= (1<<7); // Z
if (!(PINB & SAT_DN)) reportBuffer->b1 |= (1<<6); // Y
if (!(PIND & SAT_LF)) reportBuffer->b1 |= (1<<3); // X
if (!(PIND & SAT_RT)) reportBuffer->b1 |= (1<<7); // R
if (!(PIND & SAT_RT)) reportBuffer->b1 |= (1<<5); // R
}

else if (PINB & SAT_UP) // Analogue pad
Expand Down Expand Up @@ -208,7 +208,7 @@ void ReadSaturn(report_t *reportBuffer)
if (!(PIND & SAT_LF)) temp |= (1<<2); // Left
if (!(PIND & SAT_RT)) temp |= (1<<3); // Right

if (satmode == 1) reportBuffer->ry = temp - 128;
if (satmode == 1) reportBuffer->ry = temp >> 1;

/* --- Left shoulder ----------------------------------------------------------------*/

Expand All @@ -231,7 +231,7 @@ void ReadSaturn(report_t *reportBuffer)
if (!(PIND & SAT_LF)) temp |= (1<<2); // Left
if (!(PIND & SAT_RT)) temp |= (1<<3); // Right

if (satmode == 1) reportBuffer->rx = temp - 128;
if (satmode == 1) reportBuffer->rx = temp >> 1;

/* --- End of data transfer ---------------------------------------------------------*/

Expand Down
2 changes: 1 addition & 1 deletion src_UndamnedMode/Makefile
Expand Up @@ -6,7 +6,7 @@
PROJECT = RetroAdapterV2_Undamned
MCU = atmega168
TARGET = $(PROJECT).elf
CC = avr-gcc.exe
CC = avr-gcc

## Options common to compile, link and assembly rules
COMMON = -mmcu=$(MCU)
Expand Down
2 changes: 1 addition & 1 deletion src_UndamnedMode/Makefile16MHz
Expand Up @@ -6,7 +6,7 @@
PROJECT = RetroAdapterV2_Undamned_16MHz
MCU = atmega168
TARGET = $(PROJECT).elf
CC = avr-gcc.exe
CC = avr-gcc

## Options common to compile, link and assembly rules
COMMON = -mmcu=$(MCU)
Expand Down
10 changes: 5 additions & 5 deletions src_UndamnedMode/saturn.c
Expand Up @@ -62,10 +62,10 @@ void ReadSaturn(report_t *reportBuffer)

_delay_us(2);

if (!(PINB & SAT_UP)) reportBuffer->b1 |= (1<<5); // Z
if (!(PINB & SAT_DN)) reportBuffer->b1 |= (1<<4); // Y
if (!(PINB & SAT_UP)) reportBuffer->b1 |= (1<<7); // Z
if (!(PINB & SAT_DN)) reportBuffer->b1 |= (1<<6); // Y
if (!(PIND & SAT_LF)) reportBuffer->b1 |= (1<<3); // X
if (!(PIND & SAT_RT)) reportBuffer->b1 |= (1<<7); // R
if (!(PIND & SAT_RT)) reportBuffer->b1 |= (1<<5); // R
}

else if (PINB & SAT_UP) // Analogue pad
Expand Down Expand Up @@ -192,7 +192,7 @@ void ReadSaturn(report_t *reportBuffer)
if (!(PIND & SAT_LF)) temp |= (1<<2); // Left
if (!(PIND & SAT_RT)) temp |= (1<<3); // Right

if (satmode == 1) reportBuffer->ry = temp - 128;
if (satmode == 1) reportBuffer->ry = (temp >> 1);

/* --- Left shoulder ----------------------------------------------------------------*/

Expand All @@ -215,7 +215,7 @@ void ReadSaturn(report_t *reportBuffer)
if (!(PIND & SAT_LF)) temp |= (1<<2); // Left
if (!(PIND & SAT_RT)) temp |= (1<<3); // Right

if (satmode == 1) reportBuffer->rx = temp - 128;
if (satmode == 1) reportBuffer->rx = (temp >> 1);

/* --- End of data transfer ---------------------------------------------------------*/

Expand Down
2 changes: 1 addition & 1 deletion src_XboxMode/Makefile
Expand Up @@ -6,7 +6,7 @@
PROJECT = RetroAdapterV2_XBox
MCU = atmega168
TARGET = $(PROJECT).elf
CC = avr-gcc.exe
CC = avr-gcc

## Options common to compile, link and assembly rules
COMMON = -mmcu=$(MCU)
Expand Down
2 changes: 1 addition & 1 deletion src_XboxMode/Makefile16MHz
Expand Up @@ -6,7 +6,7 @@
PROJECT = RetroAdapterV2_XBox_16MHz
MCU = atmega168
TARGET = $(PROJECT).elf
CC = avr-gcc.exe
CC = avr-gcc

## Options common to compile, link and assembly rules
COMMON = -mmcu=$(MCU)
Expand Down
14 changes: 7 additions & 7 deletions src_XboxMode/saturn.c
Expand Up @@ -35,7 +35,7 @@ void ReadSaturn(report_t *reportBuffer)
// TH = 1, TR = 1
if (PIND & SAT_LF) // Standard digital pad
{
if (!(PIND & SAT_RT)) reportBuffer->b1 |= (1<<6); // L
if (!(PIND & SAT_RT)) reportBuffer->b1 |= (1<<4); // L

// TH = 0, TR = 1
PORTB &= ~(SAT_TH);
Expand All @@ -60,17 +60,17 @@ void ReadSaturn(report_t *reportBuffer)
if (!(PINB & SAT_UP)) reportBuffer->b1 |= (1<<1); // B
if (!(PINB & SAT_DN)) reportBuffer->b1 |= (1<<2); // C
if (!(PIND & SAT_LF)) reportBuffer->b1 |= (1<<0); // A
if (!(PIND & SAT_RT)) reportBuffer->b2 |= (1<<3); // Start
if (!(PIND & SAT_RT)) reportBuffer->b2 |= (1<<1); // Start

// TH = 0, TR = 0
PORTB &= ~(SAT_TH|SAT_TR);

_delay_us(2);

if (!(PINB & SAT_UP)) reportBuffer->b1 |= (1<<5); // Z
if (!(PINB & SAT_DN)) reportBuffer->b1 |= (1<<4); // Y
if (!(PINB & SAT_UP)) reportBuffer->b1 |= (1<<7); // Z
if (!(PINB & SAT_DN)) reportBuffer->b1 |= (1<<6); // Y
if (!(PIND & SAT_LF)) reportBuffer->b1 |= (1<<3); // X
if (!(PIND & SAT_RT)) reportBuffer->b1 |= (1<<7); // R
if (!(PIND & SAT_RT)) reportBuffer->b1 |= (1<<5); // R
}

else if (PINB & SAT_UP) // Analogue pad
Expand Down Expand Up @@ -208,7 +208,7 @@ void ReadSaturn(report_t *reportBuffer)
if (!(PIND & SAT_LF)) temp |= (1<<2); // Left
if (!(PIND & SAT_RT)) temp |= (1<<3); // Right

if (satmode == 1) reportBuffer->ry = temp - 128;
if (satmode == 1) reportBuffer->ry = (temp >> 1);

/* --- Left shoulder ----------------------------------------------------------------*/

Expand All @@ -231,7 +231,7 @@ void ReadSaturn(report_t *reportBuffer)
if (!(PIND & SAT_LF)) temp |= (1<<2); // Left
if (!(PIND & SAT_RT)) temp |= (1<<3); // Right

if (satmode == 1) reportBuffer->rx = temp - 128;
if (satmode == 1) reportBuffer->rx = (temp >> 1);

/* --- End of data transfer ---------------------------------------------------------*/

Expand Down

0 comments on commit 698ff1e

Please sign in to comment.