NES controller to DC... without opening both

Discuss modifications you have done or plan to do to your Dreamcast or any other hardware, or discuss devices you want to build. If your console does not work or is acting up, ask about fixing it in here.
Post Reply
Synlor
Official DCEMU Stalker
Official DCEMU Stalker
Posts: 1604
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Tue Apr 23, 2002 6:26 pm
Location: South Dakota
Has thanked: 0
Been thanked: 0
Contact:

NES controller to DC... without opening both

Post by Synlor »

I have finally done it :). I have written a program for a pic mcu (a 16f628a to be specific) that will decode the output of an NES controller without modification. The NES controller has 5 connections needed to operate:
+5 volts
ground
clock
strobe
serial out
You can read more on how the nes controller works at http://www.gamesx.com

My program provides the necessary clock and strobe signals so that the controller will output the serial information on which buttons have been pressed. The program will then read this serial information and decode it into individual signals. So basically when I press the A button on the controller the RB0 pin outputs 5 volts. If I press the B button it will output 5 volts on pin RB1.

It took a long time, and I had to deal with a bunch of programming issues, but I finally got it done. I will have more to come later, especially on how to interface it with the dreamcast easily. For now I'll only post the code, but I won't explain anything further until I get a tutorial posted just for the sake of my sanity :)

Here it is:

Code: Select all

;-----------
; NES to decoded outputs
; Written by Kevin Ahrendt based on original code by Tennessee Carmel-Veilleux
; Copyright Notice: Neither Tennessee Carmel-Veilleux nor Kevin Ahrendt is responsible for
; any damage this firmware software may cause.
;----------Assembler Directives-----------------------------------------
	list P=16F628A, F=INHX8M, C=80, N=80, ST=OFF, MM=ON, R=DEC
	include "p16f628a.inc"
        __config (_CP_OFF & _PWRTE_ON & _LVP_OFF & _BODEN_OFF & _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_ON )

;----------Equates------------------------------------------------------
Bank0Ram 	equ	h'0c'
PortAMask	equ	b'11111001'	; Port a has Inputs for NES pad and control for pad's shift regs
PortBMask	equ	b'00000000'	; Five LSBs of portb control the atari port shift reg (4094) and fire buttons

Ctrl1D0		equ	0
CtrlClk		equ	1
CtrlStrb	equ	2

CtrlB		equ	0
CtrlA		equ	1
CtrlSl		equ	2
CtrlSt		equ	3
CtrlUp		equ	4
CtrlDo		equ	5
CtrlLe		equ	6
CtrlRi		equ	7

;----------Variables----------------------------------------------------
	CBLOCK 0x20

CTRLDATA	;We read the NES controller serial data in this var
LOOPCNT
	ENDC

;----------Controller Data Format---------------------------------------
;B0		B1		B2		B3		B4		B5		B6		B7
;[A]	[B]		[SEL]	[START]	[UP]	[DOWN]	[LEFT]	[RIGHT]

;----------Mainline program---------------------------------------------
	org h'000'
	movlw	0x07
	movwf	CMCON	
	goto Main
	nop

Main	
	movlw	PortAMask	; Set PortA/B to their inital TRIS masks and port output values
	banksel TRISA
	movwf	TRISA         
	movlw	PortBMask
	movwf	TRISB
	banksel PORTA
	clrf	PORTA

; Here starts the main work loop

Loop
	movlw h'8'		; Loop 8 times
	movwf LOOPCNT
	bsf PORTA,CtrlStrb	; Strobe the controllers
	nop
	nop
	bcf PORTA,CtrlStrb
	nop

ReadLoop 

	nop
	nop
				 		; Reading starts here
	bsf STATUS,C		; Preset Carry to 1
	btfss PORTA,Ctrl1D0	; If data bit is 0, reset carry to 0
	bcf STATUS,C		
	rlf CTRLDATA,F		; Shift-in the carry in the controller information

	bsf PORTA,CtrlClk	; Clock the port for next bit
	nop
	nop
	bcf PORTA,CtrlClk
	
	decfsz LOOPCNT,F
	goto ReadLoop

; Test if B is pressed
	rlf		CTRLDATA,F	; Moves data so first bit is in carry bit
	btfsc	STATUS,C	; Carry Bit is checked
	goto	BOn		; If on go to BOn, if off
	bsf		PORTB,CtrlB	; turn line low
	goto	BDone		; Check next button
; B is on
BOn
	bcf	PORTB,CtrlB	; Sets pin on high

BDone
	rlf 	CTRLDATA,F
	btfsc	STATUS,C
	goto	AOn
	bsf		PORTB,CtrlA
	goto	ADone
; A is on
AOn
	bcf	PORTB,CtrlA

; Test Select
ADone
	rlf		CTRLDATA,F
	btfsc	STATUS,C
	goto	SlOn
	bsf	PORTB,CtrlSl
	goto	SlDone
; Select is on
SlOn
	bcf	PORTB,CtrlSl

; Test Start
SlDone
	rlf 	CTRLDATA,F
	btfsc	STATUS,C
	goto	StOn
	bsf	PORTB,CtrlSt
	goto	StDone
; Start is on
StOn
	bcf	PORTB,CtrlSt

; Test Up
StDone
	rlf 	CTRLDATA,F
	btfsc	STATUS,C
	goto	UpOn
	bsf	PORTB,CtrlUp
	goto	UpDone
; Up is on
UpOn
	bcf	PORTB,CtrlUp

; Test Down
UpDone
	rlf 	CTRLDATA,F
	btfsc	STATUS,C
	goto	DoOn
	bsf	PORTB,CtrlDo
	goto	DoDone
; Down is on
DoOn
	bcf	PORTB,CtrlDo

; Test Left
DoDone
	rlf 	CTRLDATA,F
	btfsc	STATUS,C
	goto	LeOn
	bsf	PORTB,CtrlLe
	goto	LeDone
; Left is on
LeOn
	bcf	PORTB,CtrlLe

; Test Right
LeDone
	rlf 	CTRLDATA,F
	btfsc	STATUS,C
	goto	RiOn
	bsf	PORTB,CtrlRi
	goto	RiDone
; Right is on
RiOn
	bcf	PORTB,CtrlRi

RiDone
	goto	Loop		; Loop the main loop

;-----------
	END
Image
Thanks to Digital Chaos, GoldbergWWE, and ace for the avatar, sig, and badge!
http://devcast.dcemulation.com
sixteen-bit
Hardware Freak
Hardware Freak
Posts: 3246
Joined: Sat Dec 29, 2001 3:45 pm
Has thanked: 0
Been thanked: 0

Post by sixteen-bit »

:thumbsup:
Are you encoding it directly for the DC or using a PSX-DC pad adapter to do the hard work for you?


I know which method I was going to use but never got round to :lol:
Synlor
Official DCEMU Stalker
Official DCEMU Stalker
Posts: 1604
Joined: Tue Apr 23, 2002 6:26 pm
Location: South Dakota
Has thanked: 0
Been thanked: 0
Contact:

Post by Synlor »

Right now I'm planning on just doing it the "old fashioned" way, so you only have to modify the dreamcast controller. I was briefly looking over the maple bus protocol, and first off I think the PIC's internal clock of 4 mhz (I'm too cheap to buy a crystal) is too slow. Secondly, it is way to complicated for me to even write the code for it. I don't own a psx convertor either, so unless I get some money to get one, I'm too cheap to interface with that.
Image
Thanks to Digital Chaos, GoldbergWWE, and ace for the avatar, sig, and badge!
http://devcast.dcemulation.com
Matt
Soul Sold for DCEmu
Soul Sold for DCEmu
Posts: 4235
Joined: Fri Jan 24, 2003 4:48 pm
Location: By my PC Hair:Bad
Has thanked: 0
Been thanked: 0
Contact:

Post by Matt »

Wow that is cool very nice work dude
Strapping Scherzo
DC Developer
DC Developer
Posts: 2285
Joined: Fri Feb 21, 2003 7:37 am
Location: Chicago, IL
Has thanked: 0
Been thanked: 1 time
Contact:

Post by Strapping Scherzo »

That's great!

Could you give me some links to some specs on that micro controller, please? I have little hardware knowledge. I just want to brainstorm on how else a component like that could be used.
Image
Synlor
Official DCEMU Stalker
Official DCEMU Stalker
Posts: 1604
Joined: Tue Apr 23, 2002 6:26 pm
Location: South Dakota
Has thanked: 0
Been thanked: 0
Contact:

Post by Synlor »

scherzo, the whole pic microcontroller family is very popular among hobbyist. Check out microchip.com for deep technical data, but a simple google search reveals quite a lot. Here is a link to a tutorial on how to get started :)
http://www.winpicprog.co.uk/pic_tutorial.htm Overal there are many differant things you can use them for, as they are quite powerful.

I'm thinking of adding psx and snes support. SNES should be fairly trivial because it is the same protocol as the nes, just 8 bits more need to be read. PSX decoding is already been done, but looks quite complex and it wouldn't allow use of analog (or the other 2 shoulder buttons) due to a limited number if I/O pins on the PIC itself. I'm thinking of possibly using a PIC with more I/O pins to make it all easier on my head.

I also have a nice controller (3rd party, don't remember brand off my head) for the dreamcast that has a very small main board itself (the buttons are off all on their own boards). It looks very easy to modify buttonwise, and the small compact shape will make it ideal. My goal is to end with a nice box with just 2 VMU connectors sticking out and NES/SNES/PSX/anything else connectors. Now just need a good source for controller extension cables to make it all look nice and such... any ideas? Cheap if not free is always preferable ;)
Image
Thanks to Digital Chaos, GoldbergWWE, and ace for the avatar, sig, and badge!
http://devcast.dcemulation.com
Alexvrb
DCEmu Ultra Poster
DCEmu Ultra Poster
Posts: 1754
Joined: Wed Jul 17, 2002 11:25 am
Has thanked: 0
Been thanked: 0

Post by Alexvrb »

What about Saturn pads? ;)
If you have twenty monkeys,
banging randomly on typewriters,
they will in twenty minutes produce the complete source code to World of Warcraft.
Synlor
Official DCEMU Stalker
Official DCEMU Stalker
Posts: 1604
Joined: Tue Apr 23, 2002 6:26 pm
Location: South Dakota
Has thanked: 0
Been thanked: 0
Contact:

Post by Synlor »

SNES is completed, though I must wait for some new PICs to arrive that have more I/O ports. I have decoded all the buttons on a 16f628, but do to some limits on a few of the I/O ports I wasn't able to show 1 button being pressed, but the program itself will work. Just needs to be put on a differant PIC :)

I'm going to look at genesis, saturn and psx in the next few days. Thanks to pixel for lending me the snes, genesis, and saturn controllers. Hopefully the whole device will be built in about a week, and a tutorial soon following that. :)
Image
Thanks to Digital Chaos, GoldbergWWE, and ace for the avatar, sig, and badge!
http://devcast.dcemulation.com
Sir Savant
Somewhat Dumb Knight
Posts: 3653
Joined: Tue Oct 12, 2004 2:26 pm
Has thanked: 0
Been thanked: 0

Post by Sir Savant »

Synlor, you are a god.

I wonder..... could the same thing be used to make a pc controll from the dc?
Synlor
Official DCEMU Stalker
Official DCEMU Stalker
Posts: 1604
Joined: Tue Apr 23, 2002 6:26 pm
Location: South Dakota
Has thanked: 0
Been thanked: 0
Contact:

Post by Synlor »

Alrighty, I got genesis 3 button controller working, still a bit puzzled with the 6 button controller. If anyone has info on how it works could you please link it to me? Thanks.

I'll work on saturn tomorrow... it is fairly similar to the genesis protocol, except with a second status line. Hopefully the PICs I ordered with more I/O ports will come soon so I can integrate them all into a single program.

Dark Savant0, do you mean making a dreamcast controller work on a PC? In theory yes, but I am definatly not capable of it because the maple bus is so complicated.
Image
Thanks to Digital Chaos, GoldbergWWE, and ace for the avatar, sig, and badge!
http://devcast.dcemulation.com
Synlor
Official DCEMU Stalker
Official DCEMU Stalker
Posts: 1604
Joined: Tue Apr 23, 2002 6:26 pm
Location: South Dakota
Has thanked: 0
Been thanked: 0
Contact:

Post by Synlor »

Alright I got 6 button genesis controllers down, but due once again to a limited amount of I/O ports on the 16f628, I can't have every single one being decoded... But atleast I know how to do it, so its all good :)

The goals for the project thus far:
NES decoding - Completed
SNES decoding - Completed
Genesis decoding (3 button) - Completed
Genesis decoding (6 button) - Completed
Saturn decoding - In progress
Playstation 1 (digital) decoding - In progess
Playstation 1 (analog) decoding - In progress
Integrating all into 1 chip - In progress

Hopefully the last few will go well. In the meantime I'm hoping to post some guides on devcast, for just individual controllers. So I'll make a page on the NES program for example, and how all of it should be hooked up and such. I'll put those up on devcast, so keep checking their for them :).
Image
Thanks to Digital Chaos, GoldbergWWE, and ace for the avatar, sig, and badge!
http://devcast.dcemulation.com
User avatar
MetaFox
Adventure Gamer
Adventure Gamer
Posts: 2818
Joined: Wed Oct 17, 2001 7:44 pm
Has thanked: 0
Been thanked: 12 times
Contact:

Post by MetaFox »

Any chance of adding Nintendo 64 controller support? :P
Synlor
Official DCEMU Stalker
Official DCEMU Stalker
Posts: 1604
Joined: Tue Apr 23, 2002 6:26 pm
Location: South Dakota
Has thanked: 0
Been thanked: 0
Contact:

Post by Synlor »

MetaFox, a quick search reveals that the PIC's internal clock probably is too slow, but overall it seems quite simple. I'll have a go at it if I have some free time after I figure out these other ones.

I'm still waiting for the new PICs to come, but that should be any day now. In the meantime I've put the nes code on devcast with a explanation. I'm either gonna put up the genesis or snes stuff next.
Image
Thanks to Digital Chaos, GoldbergWWE, and ace for the avatar, sig, and badge!
http://devcast.dcemulation.com
Synlor
Official DCEMU Stalker
Official DCEMU Stalker
Posts: 1604
Joined: Tue Apr 23, 2002 6:26 pm
Location: South Dakota
Has thanked: 0
Been thanked: 0
Contact:

Post by Synlor »

I added the genesis info onto devcast, so check it out if interested. I also got more PICs yesterday, so now I'll be able to play with more I/O lines. I've been trying to get PSX decoding towork, but no luck yet. Hopefully I can have all the programs combined into 1 soon, and then finally interface it with the Dreamcast.
Image
Thanks to Digital Chaos, GoldbergWWE, and ace for the avatar, sig, and badge!
http://devcast.dcemulation.com
Synlor
Official DCEMU Stalker
Official DCEMU Stalker
Posts: 1604
Joined: Tue Apr 23, 2002 6:26 pm
Location: South Dakota
Has thanked: 0
Been thanked: 0
Contact:

Post by Synlor »

Woo hoo! PSX decoding is working. Heh... stupid me.... first problem was my lack of understanding of electronics. I needed to add a pull-up resistor to make it work. The other problem was I sorta put a command on the wrong side of a loop.... so the clock wouldn't strobe.

All I have left to do is get genesis 6 button working (I know how, I just haven't gotten *all* 6 buttons at once.. 4, not 6 :)) and saturn. Saturn I have presumably working code, and I could fix any error pretty quickly with it if there were any. The problem is hooking up the connector.. its sorta hard to interface. Then of course putting it all togethor into one..... but thats almost trivial. Though I still need a source of connectors (extension cables maybe?) to make it all look nice. :D
Image
Thanks to Digital Chaos, GoldbergWWE, and ace for the avatar, sig, and badge!
http://devcast.dcemulation.com
User avatar
Ominous 0nionfrog
Insane DCEmu
Insane DCEmu
Posts: 156
Joined: Thu Feb 24, 2005 8:33 pm
Has thanked: 0
Been thanked: 0

Post by Ominous 0nionfrog »

you pwn! Once you post it i'll do the genesis controller... :D
jaredfogle wrote: Every time you jack off, you kill thousands of "people."
xinixke
DCEmu Newbie
DCEmu Newbie
Posts: 2
Joined: Wed Jul 14, 2010 12:34 pm
Has thanked: 0
Been thanked: 0

Re: NES controller to DC... without opening both

Post by xinixke »

wow, a 5 year old bump :wink:

I was looking for a way to connect an original NES controller to my softmodded xbox and this seems EXACTLY what I need.
But since I'm not that good with electronics and IC's I could use a little help. I tried searching for the page at devcast (I believe it was: http://devcast.dcemulation.com/mods/unicont/nes.php) but it can't be found.

Could someone please get me a scheme on how to connect the NES port to the PIC?
All other tips are welcome too :wink:

kind regards
Ayla
DC Developer
DC Developer
Posts: 142
Joined: Thu Apr 03, 2008 7:01 am
Has thanked: 0
Been thanked: 4 times
Contact:

Re: NES controller to DC... without opening both

Post by Ayla »

xinixke
DCEmu Newbie
DCEmu Newbie
Posts: 2
Joined: Wed Jul 14, 2010 12:34 pm
Has thanked: 0
Been thanked: 0

Re: NES controller to DC... without opening both

Post by xinixke »

Thank you, kind sir Image
baigos
DCEmu Newbie
DCEmu Newbie
Posts: 2
Joined: Wed Oct 20, 2010 1:09 pm
Has thanked: 0
Been thanked: 0

Re: NES controller to DC... without opening both

Post by baigos »

why not use the source of retrotap's firmware?
http://denki.world3.net/retro_v2.html

seems it can be ported to maple bus, yes, it can be ported "for the king, for the land, for the moountains"
Post Reply