Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vs
*.elf
*.o
*.map
Expand Down
3 changes: 2 additions & 1 deletion Makefile.atmega168
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are those changes necessary? I'm pretty sure code compiled for atmega168 vs. atmega168a is the same.
And why add a commented CFLAGS line?

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ LD=$(CC)

PROGNAME=atmega168_extenmote
OBJDIR=objs-$(PROGNAME)
CPU=atmega168a
CPU=atmega168
CFLAGS=-Wall -mmcu=$(CPU) -DF_CPU=12000000L -Os -DWITH_SNES -DWITH_N64 -DWITH_GAMECUBE -DWITH_EEPROM -DWITH_DB9
#CFLAGS=-Wall -mmcu=$(CPU) -DF_CPU=12000000L -Os -DWITH_SNES -DWITH_EEPROM
LDFLAGS=-mmcu=$(CPU) -Wl,-Map=$(PROGNAME).map
HEXFILE=$(PROGNAME).hex
AVRDUDE=avrdude -p m168 -P usb -c avrispmkII
Expand Down
63 changes: 63 additions & 0 deletions Makefile.atmega328p
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
CC=avr-gcc
AS=$(CC)
LD=$(CC)

PROGNAME=atmega328p_extenmote
OBJDIR=objs-$(PROGNAME)
CPU=atmega328p
CFLAGS=-Wall -mmcu=$(CPU) -DF_CPU=16000000L -Os -DWITH_SNES -DWITH_N64 -DWITH_GAMECUBE -DWITH_EEPROM -DWITH_DB9
LDFLAGS=-mmcu=$(CPU) -Wl,-Map=$(PROGNAME).map
HEXFILE=$(PROGNAME).hex
AVRDUDE=avrdude -p m328p -P com5 -c avrisp -b 19200

# - - - - - BOOTSZ1 BOOTSZ0 BOOTRST
# 0 0 0 0 0 0 0 1
# 1 1 1 1 1 0 0 1
#EFUSE=0x01
EFUSE=0xF9

# RSTDISBL DWEN SPIEN WDTON EESAVE BODLEVEL2 BODLEVEL1 BODLEVEL0
# 1 1 0 1 1 1 1 1
HFUSE=0xdf
#
# CKDIV8 CKOUT SUT1 SUT0 CKSEL3 CKSEL2 CKSEL1 CKSEL0
# 1 1 0 1 1 1 1 1
#
# 8mhz internal RC oscillator (Ok for NES/SNES only mode)
LFUSE=0xDF

OBJS=$(addprefix $(OBJDIR)/, main.o wiimote.o snes.o rlut.o n64.o gcn64_protocol.o gamecube.o eeprom.o classic.o analog.o tripleclick.o db9.o)

all: $(HEXFILE)

clean:
rm -f $(PROGNAME).elf $(PROGNAME).hex $(PROGNAME).map $(OBJS)

$(OBJDIR)/%.o: %.S
$(CC) $(CFLAGS) -c $< -o $@

$(OBJDIR)/%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@

$(OBJDIR)/%.o: %.c %.h
$(CC) $(CFLAGS) -c $< -o $@

$(PROGNAME).elf: $(OBJS)
$(LD) $(OBJS) $(LDFLAGS) -o $(PROGNAME).elf

$(PROGNAME).hex: $(PROGNAME).elf
avr-objcopy -j .data -j .text -O ihex $(PROGNAME).elf $(PROGNAME).hex
avr-size $(PROGNAME).elf

fuse:
$(AVRDUDE) -e -Uefuse:w:$(EFUSE):m -Uhfuse:w:$(HFUSE):m -Ulfuse:w:$(LFUSE):m -B 20.0 -v

flash: $(HEXFILE)
$(AVRDUDE) -Uflash:w:$(HEXFILE) -B 1.0 -F

chip_erase:
$(AVRDUDE) -e -B 1.0 -F

reset:
$(AVRDUDE) -B 1.0 -F

27 changes: 27 additions & 0 deletions classic.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Changes pertaining to SNES Mouse and NES lightgun Copyright (C) 2023 Akerasoft
* The author may be contacted at robert.kolski@akerasoft.com
*/
#include <string.h>

Expand Down Expand Up @@ -55,6 +58,10 @@
* 'G' | 'C' Gamecube controller
* 'S' | 'F' SNES
* 'F' | 'C' NES
* (C) Akerasoft 2023 -- BEGIN --
* 'G' | 'N' NES Lightgun / Zapper
* 'M' | 'S' SNES Mouse
* (C) Akerasoft 2023 -- END --
*
* Writing at byte 6 might one day control the rumble motor. Rumbles on when non-zero.
*/
Expand Down Expand Up @@ -289,6 +296,26 @@ void dataToClassic(const gamepad_data *src, classic_pad_data *dst, char first_re
}
break;

// (C) Akerasoft 2023 -- BEGIN --
case PAD_TYPE_MOUSE:
dst->controller_id[0] = 'M';
dst->controller_id[1] = 'S';
memcpy(dst->controller_raw_data, src->snes.raw_data, MOUSE_RAW_SIZE);

if (src->snes.buttons & MOUSE_BTN_L) { dst->buttons |= CPAD_BTN_X; }
if (src->snes.buttons & MOUSE_BTN_R) { dst->buttons |= CPAD_BTN_A; }
break;

case PAD_TYPE_GUN:
dst->controller_id[0] = 'G';
dst->controller_id[1] = 'N';
memcpy(dst->controller_raw_data, src->gun.raw_data, GUN_RAW_SIZE);

if (src->snes.buttons & GUN_BTN_TRIGGER) { dst->buttons |= CPAD_BTN_B; }
if (src->snes.buttons & GUN_BTN_SENSOR) { dst->buttons |= CPAD_BTN_A; }
break;
// (C) Akerasoft 2023 -- END --

case PAD_TYPE_NES:
// if (first_read && src->nes.buttons & NES_BTN_START) {
// disable_config = 1;
Expand Down
36 changes: 36 additions & 0 deletions gamepads.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Changes pertaining to SNES Mouse and NES lightgun Copyright (C) 2023 Akerasoft
* The author may be contacted at robert.kolski@akerasoft.com
*
*/
#ifndef _gamepad_h__
#define _gamepad_h__
Expand All @@ -25,9 +29,17 @@
#define PAD_TYPE_GAMECUBE 5
#define PAD_TYPE_MD 6
#define PAD_TYPE_SMS 7
// (C) Akerasoft 2023 -- BEGIN --
#define PAD_TYPE_GUN 8
#define PAD_TYPE_MOUSE 9
// (C) Akerasoft 2023 -- END --

#define NES_RAW_SIZE 1
#define SNES_RAW_SIZE 2
// (C) Akerasoft 2023 -- BEGIN --
#define MOUSE_RAW_SIZE 4
#define GUN_RAW_SIZE 1
// (C) Akerasoft 2023 -- END --
#define N64_RAW_SIZE 4
#define GC_RAW_SIZE 8
#define DB9_RAW_SIZE 2
Expand Down Expand Up @@ -90,6 +102,26 @@ typedef struct _snes_pad_data {
#define SNES_BTN_L 0x2000
#define SNES_BTN_R 0x1000

// (C) Akerasoft 2023 -- BEGIN --
typedef struct _mouse_pad_data {
unsigned char pad_type; // PAD_TYPE_MOUSE
unsigned short buttons;
unsigned char raw_data[MOUSE_RAW_SIZE];
} mouse_pad_data;

#define MOUSE_BTN_R 0x8000
#define MOUSE_BTN_L 0x4000
#define MOUSE_SENSITIVITY 0x3000

typedef struct _gun_pad_data {
unsigned char pad_type; // PAD_TYPE_GUN
unsigned short buttons;
unsigned char raw_data[GUN_RAW_SIZE];
} gun_pad_data;

#define GUN_BTN_TRIGGER 0x0080
#define GUN_BTN_SENSOR 0x0040
// (C) Akerasoft 2023 -- END --

typedef struct _nes_pad_data {
unsigned char pad_type; // PAD_TYPE_NES
Expand Down Expand Up @@ -190,6 +222,10 @@ typedef struct _gamepad_data {
unsigned char pad_type; // PAD_TYPE_*
classic_pad_data classic;
snes_pad_data snes;
// (C) Akerasoft 2023 -- BEGIN --
mouse_pad_data mouse;
gun_pad_data gun;
// (C) Akerasoft 2023 -- END --
nes_pad_data nes;
n64_pad_data n64;
gc_pad_data gc;
Expand Down
28 changes: 25 additions & 3 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Changes pertaining to SNES Mouse and NES lightgun Copyright (C) 2023 Akerasoft
* The author may be contacted at robert.kolski@akerasoft.com
*
*/

#include <avr/io.h>
Expand Down Expand Up @@ -66,14 +70,20 @@ static void hwInit(void)
/* PORTD
* 0: out0
* 1: out0
* 2: out0
* 3: out0
// (C) Akerasoft 2023 - proposal PORT D2 and D3 are for NES Zapper. When no other controller found
// use NES Zapper / lightgun in the SNES.c file.
* 2: in
* 3: in
// (C) Akerasoft 2023 - END
* 4: out1 // Tied to VCC on Multiuse PCB2 for routing reasons
* 5: out0
* 6: in-pu // Pulled to GND on mutluse db9 v3. Wired to VCC on multiuse PCB2.
* 7: out0
*/
PORTD = 0x60;
// (C) Akerasoft 2023 - proposal PORT D2 and D3 are for NES Zapper.
PORTD = 0x6C;
// (C) Akerasoft 2023 - END

DDRD = 0xbf;

_delay_ms(1);
Expand Down Expand Up @@ -393,6 +403,18 @@ int main(void)
memcpy(raw, lastReadData.nes.raw_data, sizeof(lastReadData.nes.raw_data));
wm_newaction(raw, sizeof(lastReadData.nes.raw_data));
break;

// (C) Akerasoft 2023 - BEGIN
case PAD_TYPE_GUN:
memcpy(raw, lastReadData.gun.raw_data, sizeof(lastReadData.gun.raw_data));
wm_newaction(raw, sizeof(lastReadData.gun.raw_data));
break;

case PAD_TYPE_MOUSE:
memcpy(raw, lastReadData.mouse.raw_data, sizeof(lastReadData.mouse.raw_data));
wm_newaction(raw, sizeof(lastReadData.mouse.raw_data));
break;
// (C) Akerasoft 2023 - END
}

// TODO : Controller specific report format
Expand Down
Loading