1
0
mirror of https://github.com/raphnet/4nes4snes synced 2024-12-21 22:48:51 -05:00

live autodetect can be disabled by JP1

This commit is contained in:
Raphaël Assénat 2009-05-02 14:02:52 +00:00
parent ad7a037a7c
commit 0bc7c8ff68
5 changed files with 52 additions and 26 deletions

View File

@ -1,5 +1,8 @@
--- v1.2 (May 2, 2009) --- 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. mode is entered and ports 1 and 2 are used to read up to 4 NES controllers.
--- v1.1 (18 Apr 2007) --- v1.1 (18 Apr 2007)

View File

@ -5,13 +5,13 @@
# Tabsize: 4 # Tabsize: 4
# Copyright: (c) 2006 by OBJECTIVE DEVELOPMENT Software GmbH # Copyright: (c) 2006 by OBJECTIVE DEVELOPMENT Software GmbH
# License: Proprietary, free under certain conditions. See Documentation. # 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 UISP = uisp -dprog=stk500 -dpart=atmega8 -dserial=/dev/avr
COMPILE = avr-gcc -Wall -Os -Iusbdrv -I. -mmcu=atmega8 -DF_CPU=12000000L #-DDEBUG_LEVEL=1 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 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 HEXFILE=main.hex
# symbolic targets: # 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 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: # 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 $(COMPILE) -o main.bin $(OBJECTS) -Wl,-Map=main.map
$(HEXFILE): main.bin $(HEXFILE): main.bin

View File

@ -1,4 +1,4 @@
/* Name: snes.c /* Name: fournsnes.c
* Project: Multiple NES/SNES to USB converter * Project: Multiple NES/SNES to USB converter
* Author: Raphael Assenat <raph@raphnet.net> * Author: Raphael Assenat <raph@raphnet.net>
* Copyright: (C) 2007-2009 Raphael Assenat <raph@raphnet.net> * Copyright: (C) 2007-2009 Raphael Assenat <raph@raphnet.net>
@ -14,7 +14,7 @@
#include <string.h> #include <string.h>
#include "gamepad.h" #include "gamepad.h"
#include "leds.h" #include "leds.h"
#include "snes.h" #include "fournsnes.h"
#define GAMEPAD_BYTES 8 /* 2 byte per snes controller * 4 controllers */ #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) #define SNES_GET_DATA4() (SNES_DATA_PIN & SNES_DATA_BIT4)
/*********** prototypes *************/ /*********** prototypes *************/
static void snesInit(void); static void fournsnesInit(void);
static void snesUpdate(void); static void fournsnesUpdate(void);
static char snesChanged(char report_id); static char fournsnesChanged(char report_id);
static char snesBuildReport(unsigned char *reportBuffer, char report_id); static char fournsnesBuildReport(unsigned char *reportBuffer, char report_id);
// the most recent bytes we fetched from the controller // 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; unsigned char sreg;
sreg = SREG; sreg = SREG;
@ -130,7 +130,7 @@ static void snesInit(void)
SNES_LATCH_PORT &= ~(SNES_LATCH_BIT); SNES_LATCH_PORT &= ~(SNES_LATCH_BIT);
nesMode = 0; nesMode = 0;
snesUpdate(); fournsnesUpdate();
if (!live_autodetect) { if (!live_autodetect) {
/* Snes controller buttons are sent in this order: /* 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; int i;
unsigned char tmp1=0; 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 report_id--; // first report is 1
@ -373,7 +373,7 @@ static unsigned char snesReorderButtons(unsigned char bytes[2])
return v; return v;
} }
static char snesBuildReport(unsigned char *reportBuffer, char id) static char fournsnesBuildReport(unsigned char *reportBuffer, char id)
{ {
int idx; int idx;
@ -441,7 +441,7 @@ static char snesBuildReport(unsigned char *reportBuffer, char id)
return 4; return 4;
} }
const char snes_usbHidReportDescriptor[] PROGMEM = { const char fournsnes_usbHidReportDescriptor[] PROGMEM = {
/* Controller and report_id 1 */ /* Controller and report_id 1 */
0x05, 0x01, // USAGE_PAGE (Generic Desktop) 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
@ -549,16 +549,16 @@ const char snes_usbHidReportDescriptor[] PROGMEM = {
Gamepad SnesGamepad = { Gamepad SnesGamepad = {
.num_reports = 4, .num_reports = 4,
.reportDescriptorSize = sizeof(snes_usbHidReportDescriptor), .reportDescriptorSize = sizeof(fournsnes_usbHidReportDescriptor),
.init = snesInit, .init = fournsnesInit,
.update = snesUpdate, .update = fournsnesUpdate,
.changed = snesChanged, .changed = fournsnesChanged,
.buildReport = snesBuildReport .buildReport = fournsnesBuildReport
}; };
Gamepad *snesGetGamepad(void) Gamepad *fournsnesGetGamepad(void)
{ {
SnesGamepad.reportDescriptor = (void*)snes_usbHidReportDescriptor; SnesGamepad.reportDescriptor = (void*)fournsnes_usbHidReportDescriptor;
return &SnesGamepad; return &SnesGamepad;
} }

View File

@ -1,5 +1,5 @@
#include "gamepad.h" #include "gamepad.h"
void disableLiveAutodetect(void); void disableLiveAutodetect(void);
Gamepad *snesGetGamepad(void); Gamepad *fournsnesGetGamepad(void);

27
main.c
View File

@ -17,7 +17,7 @@
#include "oddebug.h" #include "oddebug.h"
#include "gamepad.h" #include "gamepad.h"
#include "snes.h" #include "fournsnes.h"
#include "leds.h" #include "leds.h"
#include "devdesc.h" #include "devdesc.h"
@ -212,10 +212,33 @@ int main(void)
char must_report = 0; /* bitfield */ char must_report = 0; /* bitfield */
uchar idleCounters[MAX_REPORTS]; uchar idleCounters[MAX_REPORTS];
int i; int i;
unsigned char run_mode;
memset(idleCounters, 0, MAX_REPORTS); 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 // configure report descriptor according to
// the current gamepad // the current gamepad