diff --git a/Changelog.txt b/Changelog.txt index 531f88f..7ff7e15 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,5 +1,8 @@ --- v1.2 (May 2, 2009) -Added NES fourscore support. When a fourscore is detected in port 1, fourscore +- License changed to GPLv2 +- Implemented "Live autodetection". This allows NES and SNES controllers to be +changed at runtime. This features can be disabled by closing JP1. +- Added NES fourscore support. When a fourscore is detected in port 1, fourscore mode is entered and ports 1 and 2 are used to read up to 4 NES controllers. --- v1.1 (18 Apr 2007) diff --git a/Makefile b/Makefile index 1e02f14..721d6d6 100644 --- a/Makefile +++ b/Makefile @@ -5,13 +5,13 @@ # Tabsize: 4 # Copyright: (c) 2006 by OBJECTIVE DEVELOPMENT Software GmbH # License: Proprietary, free under certain conditions. See Documentation. -# This Revision: $Id: Makefile,v 1.4 2009-05-02 13:55:11 cvs Exp $ +# This Revision: $Id: Makefile,v 1.5 2009-05-02 14:02:52 cvs Exp $ UISP = uisp -dprog=stk500 -dpart=atmega8 -dserial=/dev/avr COMPILE = avr-gcc -Wall -Os -Iusbdrv -I. -mmcu=atmega8 -DF_CPU=12000000L #-DDEBUG_LEVEL=1 COMMON_OBJS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o -OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o snes.o devdesc.o +OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o fournsnes.o devdesc.o HEXFILE=main.hex # symbolic targets: @@ -35,7 +35,7 @@ clean: rm -f $(HEXFILE) main.lst main.obj main.cof main.list main.map main.eep.hex main.bin *.o usbdrv/*.o main.s usbdrv/oddebug.s usbdrv/usbdrv.s # file targets: -main.bin: $(COMMON_OBJS) snes.o devdesc.o +main.bin: $(COMMON_OBJS) fournsnes.o devdesc.o $(COMPILE) -o main.bin $(OBJECTS) -Wl,-Map=main.map $(HEXFILE): main.bin diff --git a/snes.c b/fournsnes.c similarity index 94% rename from snes.c rename to fournsnes.c index 250e006..2d32da5 100644 --- a/snes.c +++ b/fournsnes.c @@ -1,4 +1,4 @@ -/* Name: snes.c +/* Name: fournsnes.c * Project: Multiple NES/SNES to USB converter * Author: Raphael Assenat * Copyright: (C) 2007-2009 Raphael Assenat @@ -14,7 +14,7 @@ #include #include "gamepad.h" #include "leds.h" -#include "snes.h" +#include "fournsnes.h" #define GAMEPAD_BYTES 8 /* 2 byte per snes controller * 4 controllers */ @@ -47,10 +47,10 @@ #define SNES_GET_DATA4() (SNES_DATA_PIN & SNES_DATA_BIT4) /*********** prototypes *************/ -static void snesInit(void); -static void snesUpdate(void); -static char snesChanged(char report_id); -static char snesBuildReport(unsigned char *reportBuffer, char report_id); +static void fournsnesInit(void); +static void fournsnesUpdate(void); +static char fournsnesChanged(char report_id); +static char fournsnesBuildReport(unsigned char *reportBuffer, char report_id); // the most recent bytes we fetched from the controller @@ -107,7 +107,7 @@ static void autoDetectFourScore(void) } -static void snesInit(void) +static void fournsnesInit(void) { unsigned char sreg; sreg = SREG; @@ -130,7 +130,7 @@ static void snesInit(void) SNES_LATCH_PORT &= ~(SNES_LATCH_BIT); nesMode = 0; - snesUpdate(); + fournsnesUpdate(); if (!live_autodetect) { /* Snes controller buttons are sent in this order: @@ -188,7 +188,7 @@ static void snesInit(void) * */ -static void snesUpdate(void) +static void fournsnesUpdate(void) { int i; unsigned char tmp1=0; @@ -329,7 +329,7 @@ static void snesUpdate(void) } -static char snesChanged(char report_id) +static char fournsnesChanged(char report_id) { report_id--; // first report is 1 @@ -373,7 +373,7 @@ static unsigned char snesReorderButtons(unsigned char bytes[2]) return v; } -static char snesBuildReport(unsigned char *reportBuffer, char id) +static char fournsnesBuildReport(unsigned char *reportBuffer, char id) { int idx; @@ -441,7 +441,7 @@ static char snesBuildReport(unsigned char *reportBuffer, char id) return 4; } -const char snes_usbHidReportDescriptor[] PROGMEM = { +const char fournsnes_usbHidReportDescriptor[] PROGMEM = { /* Controller and report_id 1 */ 0x05, 0x01, // USAGE_PAGE (Generic Desktop) @@ -549,16 +549,16 @@ const char snes_usbHidReportDescriptor[] PROGMEM = { Gamepad SnesGamepad = { .num_reports = 4, - .reportDescriptorSize = sizeof(snes_usbHidReportDescriptor), - .init = snesInit, - .update = snesUpdate, - .changed = snesChanged, - .buildReport = snesBuildReport + .reportDescriptorSize = sizeof(fournsnes_usbHidReportDescriptor), + .init = fournsnesInit, + .update = fournsnesUpdate, + .changed = fournsnesChanged, + .buildReport = fournsnesBuildReport }; -Gamepad *snesGetGamepad(void) +Gamepad *fournsnesGetGamepad(void) { - SnesGamepad.reportDescriptor = (void*)snes_usbHidReportDescriptor; + SnesGamepad.reportDescriptor = (void*)fournsnes_usbHidReportDescriptor; return &SnesGamepad; } diff --git a/snes.h b/fournsnes.h similarity index 61% rename from snes.h rename to fournsnes.h index 1f19767..125370a 100644 --- a/snes.h +++ b/fournsnes.h @@ -1,5 +1,5 @@ #include "gamepad.h" void disableLiveAutodetect(void); -Gamepad *snesGetGamepad(void); +Gamepad *fournsnesGetGamepad(void); diff --git a/main.c b/main.c index b636940..3d7ab18 100644 --- a/main.c +++ b/main.c @@ -17,7 +17,7 @@ #include "oddebug.h" #include "gamepad.h" -#include "snes.h" +#include "fournsnes.h" #include "leds.h" #include "devdesc.h" @@ -212,10 +212,33 @@ int main(void) char must_report = 0; /* bitfield */ uchar idleCounters[MAX_REPORTS]; int i; + unsigned char run_mode; memset(idleCounters, 0, MAX_REPORTS); - curGamepad = snesGetGamepad(); + + DDRB |= 0x01; + DDRB &= ~0x06; + PORTB |= 0x06; /* enable pull up on DB1 and DB2 */ + PORTB &= ~0x01; /* Set DB0 to low */ + + _delay_ms(10); /* let pins settle */ + run_mode = (PINB & 0x06)>>1; + + switch(run_mode) + { + // Close JP1 to disable live auto-detect + case 2: + disableLiveAutodetect(); + break; + + case 1: + case 3: + case 4: + break; + } + + curGamepad = fournsnesGetGamepad(); // configure report descriptor according to // the current gamepad