263 lines
6.7 KiB
Plaintext
263 lines
6.7 KiB
Plaintext
' ########### start ###########
|
|
' pic:PIC16C84
|
|
' ########### end ###########
|
|
|
|
'----------------------------------------------------------------------
|
|
' Joystick adapter Nintendo SNES to AMIGA
|
|
' 2016-01-21 (c) Paolo Iocco
|
|
'
|
|
' Circuit diagram
|
|
' ---------------
|
|
' ATTiny84
|
|
' +-----+
|
|
' VCC-------->|° |<--------GND
|
|
' PB0-------->| |<--------PA0
|
|
' PB1-------->| |<--------PA1
|
|
' PB3/Reset-->| |---------PA2
|
|
' PB2---------| |---------PA3
|
|
' PA7---------| |---------PA4 SCK
|
|
' PA6 MOSI----| |---------PA5 MISO
|
|
' +-----+
|
|
'
|
|
' 16C84
|
|
' +-----+
|
|
' f1 PA2 -----|° |----- PA1
|
|
' f2 PA3 -----| |----- PA0
|
|
' PA4 -----| |<---------H
|
|
' RST ------>| |<---------H
|
|
' GND ------>| |<--------+5V
|
|
' ri PB0 -----| |----- PB7
|
|
' le PB1 -----| |----- PB6 Clock
|
|
' dn PB2 -----| |----- PB5 Latch
|
|
' up PB3 -----| |----- PB4 Dat
|
|
' +-----+
|
|
'----------------------------------------------------------------------
|
|
'
|
|
' SNES STANDARDS
|
|
' ~~~~~~~~~~~~~~
|
|
'
|
|
' Pinout for SNES gamepads and mice
|
|
'
|
|
' +-----------------------\
|
|
' 7 | o o o o | x x o | 1
|
|
' +-----------------------/
|
|
' | | | | |
|
|
' | | | | +-> Ground (brown)
|
|
' | | | +------------> Data (red)
|
|
' | | +---------------> Latch (yellow)
|
|
' | +------------------> Clock (orange)
|
|
' +---------------------> Power (white)
|
|
' ___
|
|
'LATCH _| |________________________________________________________________(Latch 12uS)_
|
|
' _______ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ____(Clock 12uS)_
|
|
'CLOCK |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_|
|
|
' _____ _____________
|
|
'DATA |B |Y |SEL|STA|UP |DN |LE |RI |A |X |L |R |? |? |? |? |(16 bit)
|
|
'
|
|
'
|
|
'----------------------------------------------------------------------
|
|
'
|
|
' DB9 STANDARDS
|
|
' ~~~~~~~~~~~~~
|
|
'
|
|
' Atari MSX
|
|
'
|
|
' +-----------> Power
|
|
' +---------> Right | +---------> Right
|
|
' | +-------> Left | | +-------> Left
|
|
' | | +-----> Down | | | +-----> Down
|
|
' | | | +---> Up | | | | +---> Up
|
|
' | | | | | | | | |
|
|
' _____________ _____________
|
|
' 5 \ x o o o o / 1 5 \ o o o o o / 1
|
|
' \ x o o o / \ o o o o /
|
|
' 9 `~~~~~~~' 6 9 `~~~~~~~' 6
|
|
' | | | | | | |
|
|
' | | +----> Button | | | +----> Button 1
|
|
' | +------> Power | | +------> Button 2
|
|
' +--------> Ground | +--------> Output 3
|
|
' +----------> Ground
|
|
'
|
|
' Commodore AMIGA
|
|
'
|
|
' +---------> Right +---------> Right
|
|
' | +-------> Left | +-------> Left
|
|
' | | +-----> Down | | +-----> Down
|
|
' | | | +---> Up | | | +---> Up
|
|
' | | | | | | | |
|
|
' _____________ _____________
|
|
' 5 \ x o o o o / 1 5 \ x o o o o / 1
|
|
' \ x o x o / \ o o o o /
|
|
' 9 `~~~~~~~' 6 9 `~~~~~~~' 6
|
|
' | | | | | |
|
|
' | +----> Button | | | +----> Button 1
|
|
' +--------> Ground | | +------> Power
|
|
' | +--------> Ground
|
|
' +----------> Button 2
|
|
'----------------------------------------------------------------------
|
|
'
|
|
' Sony Playstation
|
|
' ~~~~~~~~~~~~~~~~
|
|
'
|
|
' The PSX controller is supported by the gamecon.c. Pinout of the PSX
|
|
' controller (compatible with DirectPadPro):
|
|
'
|
|
' +---------+---------+---------+
|
|
' 9 | o o x | o o o | o x x | 1
|
|
' \________|_________|________/
|
|
' | | | | | |
|
|
' | | | | | +--------> Clock
|
|
' | | | | +------------> Select
|
|
' | | | +---------------> Power
|
|
' | | +------------------> Ground
|
|
' | +-------------------------> Command
|
|
' +----------------------------> Data
|
|
'
|
|
'----------------------------------------------------------------------
|
|
|
|
'Chip model
|
|
'#chip tiny84a, 8
|
|
#Chip 16C84, 1 ' (RC OScillator - please measure the actual frequency)
|
|
#Config OSC = RC, WDT = OFF, PWRTE = ON, CP = OFF
|
|
|
|
#define CICLO 50 us
|
|
'I/O
|
|
#define o_up PORTB.3
|
|
#define o_dn PORTB.2
|
|
#define o_le PORTB.1
|
|
#define o_ri PORTB.0
|
|
#define o_f1 PORTA.2
|
|
#define o_f2 PORTA.3
|
|
#define Dat PORTB.4
|
|
#define a_up PORTB,3
|
|
#define a_dn PORTB,2
|
|
#define a_le PORTB,1
|
|
#define a_ri PORTB,0
|
|
#define a_f1 PORTA,2
|
|
#define a_f2 PORTA,3
|
|
#define a_Dat PORTB,4
|
|
|
|
#define Latch PORTB.5
|
|
#define Clock PORTB.6
|
|
#define Test PORTB.7
|
|
#define a_Test PORTB,7
|
|
|
|
dir o_up out
|
|
dir o_dn out
|
|
dir o_le out
|
|
dir o_ri out
|
|
dir o_f1 out
|
|
dir o_f2 out
|
|
dir Dat in
|
|
dir Latch out
|
|
dir Clock out
|
|
dir Test out
|
|
'not used:
|
|
dir PORTA.0 out
|
|
dir PORTA.1 out
|
|
dir PORTA.4 out
|
|
|
|
dim Counter as word
|
|
|
|
Startup:
|
|
PORTB=0b11001111
|
|
PORTA=0b00011111
|
|
Counter = 0
|
|
|
|
'Main routine
|
|
Loop:
|
|
DO forever
|
|
'Latch Low-high = carica i dati nel registro di scorrimento, DAT è uguale al primo dato (B)
|
|
'Latch=High l'uscita è uguale al primo dato (B)
|
|
'Latch=Low, il registro scorre ad ogni rising edge del clock
|
|
|
|
' inizializza lo shift register
|
|
set Clock on
|
|
PulseOut Latch, CICLO
|
|
set Clock off
|
|
wait CICLO
|
|
|
|
PulseOut Latch, CICLO ' carica i dati nello shift register
|
|
wait CICLO
|
|
|
|
'read B
|
|
btfss a_Dat
|
|
bcf a_f2
|
|
btfsc a_Dat
|
|
bsf a_f2
|
|
PulseClock
|
|
'read Y - autofire
|
|
btfss a_Dat
|
|
bcf a_f2
|
|
btfsc a_Dat
|
|
bsf a_f2
|
|
PulseClock
|
|
'read SELECT
|
|
PulseClock
|
|
'read START
|
|
PulseClock
|
|
'read UP
|
|
btfss a_Dat
|
|
bcf a_up
|
|
btfsc a_Dat
|
|
bsf a_up
|
|
PulseClock
|
|
'read DOWN
|
|
btfss a_Dat
|
|
bcf a_dn
|
|
btfsc a_Dat
|
|
bsf a_dn
|
|
PulseClock
|
|
'read LEFT
|
|
btfss a_Dat
|
|
bcf a_le
|
|
btfsc a_Dat
|
|
bsf a_le
|
|
PulseClock
|
|
'read RIGHT
|
|
btfss a_Dat
|
|
bcf a_ri
|
|
btfsc a_Dat
|
|
bsf a_ri
|
|
PulseClock
|
|
'read A
|
|
btfss a_Dat
|
|
bcf a_f1
|
|
btfsc a_Dat
|
|
bsf a_f1
|
|
PulseClock
|
|
'read X - autofire
|
|
btfss a_Dat
|
|
bcf a_f1
|
|
btfsc a_Dat
|
|
bsf a_f1
|
|
PulseClock
|
|
'read L
|
|
btfss a_Dat
|
|
bcf a_f2
|
|
btfsc a_Dat
|
|
bsf a_f2
|
|
PulseClock
|
|
'read R
|
|
btfss a_Dat
|
|
bcf a_f1
|
|
btfsc a_Dat
|
|
bsf a_f1
|
|
PulseClock
|
|
|
|
counter++
|
|
' test = Counter_H and 0x01 - (Ciclo*12)*256
|
|
btfss counter_H,0
|
|
bcf a_Test
|
|
btfsc counter_H,0
|
|
bsf a_Test
|
|
|
|
LOOP 'Jump back to the start of the program
|
|
|
|
Sub PulseClock
|
|
set Clock on
|
|
wait CICLO
|
|
set Clock off
|
|
wait CICLO
|
|
End sub
|