Unterstützung für NES gamecontroller
This commit is contained in:
parent
6f1f03dc63
commit
11aa8c9f37
|
@ -150,6 +150,9 @@ SIGNAL(SIG_OUTPUT_COMPARE0)
|
|||
//Watchdog zurücksetzen
|
||||
wdt_reset();
|
||||
|
||||
//Tasten für joystick einlesen
|
||||
readButtons();
|
||||
|
||||
for(row=0; row < 8; row++){
|
||||
pd1165_write(row, pixmap[plane][row][0]);
|
||||
CTRLPORT &= ~((1<<BIT_CS3)|(1<<BIT_RW));
|
||||
|
@ -243,7 +246,7 @@ void timer2_on(){
|
|||
|
||||
*/
|
||||
TCCR2 = (1<<WGM21) | (1<<COM20) | 1 ; //CTC, OC2 toggle, clk/1
|
||||
OCR2 = 100; //80kHz clock on OC2
|
||||
OCR2 = 92; //80kHz clock on OC2
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -6,4 +6,9 @@ include $(TOPDIR)/defaults.mk
|
|||
SRC = joystick.c
|
||||
SRC_SIM =
|
||||
|
||||
ifeq ($(JOYSTICK_TYPE), JOYSTICK_NES)
|
||||
SRC = nes_pad.c
|
||||
endif
|
||||
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
dep_bool_menu "joystick support" JOYSTICK_SUPPORT y
|
||||
|
||||
choice 'Joystick type' \
|
||||
"NES-Pad JOYSTICK_NES \
|
||||
Parallel JOYSTICK_PARALLEL" \
|
||||
'JOYSTICK_PARALLEL' JOYSTICK_TYPE
|
||||
|
||||
|
||||
###################### Parallel joystick menu #################################
|
||||
dep_bool_menu "parallel joystick support" PARALLEL_JOYSTICK_SUPPORT y
|
||||
|
||||
|
@ -96,6 +102,67 @@ choice 'Bit fire' \
|
|||
endmenu
|
||||
###############################################################################
|
||||
|
||||
###################### NES-Pad menu #################################
|
||||
dep_bool_menu "nes-pad support" NES_PAD_SUPPORT y
|
||||
|
||||
choice 'Port clk' \
|
||||
"PORTA PORTA \
|
||||
PORTB PORTB \
|
||||
PORTC PORTC \
|
||||
PORTD PORTD" \
|
||||
'PORTB' NES_PAD_PORT_CLK
|
||||
|
||||
choice 'Port ds' \
|
||||
"PORTA PORTA \
|
||||
PORTB PORTB \
|
||||
PORTC PORTC \
|
||||
PORTD PORTD" \
|
||||
'PORTB' NES_PAD_PORT_PL
|
||||
|
||||
choice 'Pin pl' \
|
||||
"PINA PINA \
|
||||
PINB PINB \
|
||||
PINC PINC \
|
||||
PIND PIND" \
|
||||
'PINB' NES_PAD_PIN_DS
|
||||
|
||||
|
||||
choice 'Bit clk' \
|
||||
"Bit0 0 \
|
||||
Bit1 1 \
|
||||
Bit2 2 \
|
||||
Bit3 3 \
|
||||
Bit4 4 \
|
||||
Bit5 5 \
|
||||
Bit6 6 \
|
||||
Bit7 7" \
|
||||
'Bit0' NES_PAD_BIT_CLK
|
||||
|
||||
choice 'Bit pl' \
|
||||
"Bit0 0 \
|
||||
Bit1 1 \
|
||||
Bit2 2 \
|
||||
Bit3 3 \
|
||||
Bit4 4 \
|
||||
Bit5 5 \
|
||||
Bit6 6 \
|
||||
Bit7 7" \
|
||||
'Bit0' NES_PAD_BIT_PL
|
||||
|
||||
choice 'Bit ds' \
|
||||
"Bit0 0 \
|
||||
Bit1 1 \
|
||||
Bit2 2 \
|
||||
Bit3 3 \
|
||||
Bit4 4 \
|
||||
Bit5 5 \
|
||||
Bit6 6 \
|
||||
Bit7 7" \
|
||||
'Bit0' NES_PAD_BIT_DS
|
||||
|
||||
|
||||
endmenu
|
||||
###############################################################################
|
||||
|
||||
|
||||
endmenu
|
|
@ -8,6 +8,7 @@ unsigned char waitForFire;
|
|||
|
||||
|
||||
inline void joy_init(){
|
||||
|
||||
PORT_FROM_PIN(JOYSTICK_PIN_UP ) |= (1<<JOYSTICK_BIT_UP );
|
||||
PORT_FROM_PIN(JOYSTICK_PIN_DOWN ) |= (1<<JOYSTICK_BIT_DOWN );
|
||||
PORT_FROM_PIN(JOYSTICK_PIN_LEFT ) |= (1<<JOYSTICK_BIT_LEFT );
|
||||
|
|
|
@ -4,9 +4,22 @@
|
|||
extern unsigned char waitForFire;
|
||||
void joy_init();
|
||||
|
||||
|
||||
#ifdef AVR
|
||||
|
||||
# include <avr/io.h>
|
||||
# ifdef NES_PAD_SUPPORT
|
||||
|
||||
extern volatile unsigned char fakeport;
|
||||
|
||||
# define JOYISUP (!! ((1<<4) & fakeport))
|
||||
# define JOYISDOWN (!! ((1<<5) & fakeport))
|
||||
# define JOYISLEFT (!! ((1<<6) & fakeport))
|
||||
# define JOYISRIGHT (!! ((1<<7) & fakeport))
|
||||
# define JOYISFIRE (!! ((1<<0) & fakeport))
|
||||
|
||||
|
||||
# else
|
||||
|
||||
# define JOYISUP (!(JOYSTICK_PIN_UP & (1<<JOYSTICK_BIT_UP )))
|
||||
# define JOYISDOWN (!(JOYSTICK_PIN_DOWN & (1<<JOYSTICK_BIT_DOWN )))
|
||||
|
@ -14,9 +27,10 @@ void joy_init();
|
|||
# define JOYISRIGHT (!(JOYSTICK_PIN_RIGHT & (1<<JOYSTICK_BIT_RIGHT)))
|
||||
# define JOYISFIRE (!(JOYSTICK_PIN_FIRE & (1<<JOYSTICK_BIT_FIRE )))
|
||||
|
||||
# endif
|
||||
#else
|
||||
|
||||
extern unsigned char fakeport;
|
||||
extern volatile unsigned char fakeport;
|
||||
|
||||
# define JOYISUP (0x10 & fakeport)
|
||||
# define JOYISDOWN (0x08 & fakeport)
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
#include <avr/io.h>
|
||||
#include <util/delay.h>
|
||||
#include "../makros.h"
|
||||
#include "../config.h"
|
||||
|
||||
#define NES_PAD_DDR_PL DDR(NES_PAD_PORT_PL)
|
||||
#define NES_PAD_DDR_CLK DDR(NES_PAD_PORT_CLK)
|
||||
#define NES_PAD_DDR_DS DDR(NES_PAD_PIN_DS)
|
||||
volatile unsigned char fakeport;
|
||||
unsigned char waitForFire;
|
||||
|
||||
|
||||
void joy_init(){
|
||||
|
||||
NES_PAD_DDR_PL |= 1<<NES_PAD_BIT_PL;
|
||||
NES_PAD_DDR_CLK |= 1<<NES_PAD_BIT_CLK;
|
||||
NES_PAD_DDR_DS &= ~(1<<NES_PAD_BIT_DS);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void readButtons(){
|
||||
|
||||
NES_PAD_PORT_PL |= 1<<NES_PAD_BIT_PL;
|
||||
asm volatile("nop\r\t");
|
||||
asm volatile("nop\r\t");
|
||||
asm volatile("nop\r\t");
|
||||
|
||||
NES_PAD_PORT_PL &= ~ (1<<NES_PAD_BIT_PL);
|
||||
|
||||
uint8_t i, port=0;
|
||||
for(i=0; i<8; i++){
|
||||
|
||||
port >>= 1;
|
||||
_delay_us(1);
|
||||
if(NES_PAD_PIN_DS & (1 << NES_PAD_BIT_DS))
|
||||
port |=0x80;
|
||||
|
||||
NES_PAD_PORT_CLK |= 1<<NES_PAD_BIT_CLK;
|
||||
asm volatile("nop\r\t");
|
||||
asm volatile("nop\r\t");
|
||||
NES_PAD_PORT_CLK &= ~(1<<NES_PAD_BIT_CLK);
|
||||
}
|
||||
fakeport= ~port;
|
||||
}
|
Loading…
Reference in New Issue