Jump to content
  • Advertisement
Sign in to follow this  
  • entries
    11
  • comments
    11
  • views
    13051

More Hardware

Sign in to follow this  
Monder

663 views

I haven't really progressed much since my last post due to lack of time. However I have done some stuff. I've hooked up a composite video connector so I can display stuff on my TV, connected a SNES pad I got off eBay (decided I didn't need the ps/2 connector for a keyboard, I may add one at a later date) and my sample order arrived from Microchip so I have a 256k EEPROM as well.

Here's a labeled picture of what the setup is now:



What I need to do now is actually write a game for the thing [grin]. What I currently have running is a (highly unimpressive) test program that just draws a rectangle on the TV you can move around with the SNES pad. It's horribly flickery but at least it works. Here's a picture of the output on my TV:



Here's a little test program that comes with the Propeller dev environment:



The SNES Pad

The SNES pad is a very simple device to interface with, it basically consists of two 4021 shift registers (The 4021 datasheet is here). A shift register is a very simple device that basically holds a load of binary digits, then on a clock pulse every bit shifts along by 1 (You can look at like this, if the contents of the register were a variable x, every clock pulse x = x << 1). The 4021 has parallel load and serial input. The parallel load allows you to set every bit in the shift register at once, the serial input is read from when you shift everything along one and is used as the new bit 0 (When you shift every along 1 there's nothing to the right of bit 0 so it's read from the serial input instead). The 4021 also has 3 parallel outputs which just output the current state of bits 7, 6 and 5. In the SNES pad there are two 4021s with the parallel output of bit 7 of one of them connected to the serial input of the other, so basically it acts like a single 16-bit shift register.

Every button in the SNES pad is just a simple switch, and each button is connected directly to a parallel load input of a shift register. So to read the current button state you pull the parallel load line of the pad high, then read the first bit from the output line, pulse the clock line then read the next bit from the output line and so on. This gives you a 16 bit number where 1 signifies the button is up and 0 signifies the button is down. There are only 12 buttons on the pad so the last 4 bits are always high.

I decided as a little side-project I'd build something to connect the SNES pad to my PC. This is really rather simple, I just programmed a PIC to read the state of the pad and send it over the serial when it received a lowercase s. Here's a picture of the hardware setup:



Here's the complete C code for the PIC program:


#include
#include
#include

#pragma config WDT=OFF, OSC=INTIO2

char Read(void)
{
int i;
int f;
unsigned char ret;

//A4 Is the parallel load line
//A1 Is the clock line
//A0 Is the output line

//Pulse parallel load to load button state
//Into shift registers
PORTAbits.RA4 = 1;
PORTAbits.RA4 = 0;
//Set clock low
PORTAbits.RA1 = 0;

//Set parallel load and clock lines as outputs and pad output line as an input
TRISAbits.TRISA4 = 0;
TRISAbits.TRISA1 = 0;
TRISAbits.TRISA0 = 1;

for(f = 0; f < 2; ++f)
{
ret = 0;

for(i = 0; i < 8; ++i)
{
unsigned char b = 0;

//Read a bit from the output line
b = PORTAbits.RA0;
//Pulse the clock
PORTAbits.RA1 = 1;
PORTAbits.RA1 = 0;

ret |= (b << i);
}

printf("%c", ret);
}

return ret;
}

void main()
{
OSCCON=0x73;

//Setup serial comms
OpenUSART( USART_TX_INT_OFF &
USART_RX_INT_OFF &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH,
25 );

while(1)
{
//If we receive an 's'
if(DataRdyUSART() && getcUSART() == 's')
{
Read();
}
}
}



I then wrote a little program which sends an s to com1 and reads back the returned 2-byte number. It then prints the names of the buttons that are currently down. Here's a screenshot of it in action:



The next step is to write a driver so I can use the pad as a gamepad in games. I'm not entirely sure how I'm gonna go about that though, writing a driver for windows is probably a fair amount of work (I've never written any drivers for windows, though I have dabbled with drivers in linux, it would probably be pretty easy in linux actually so prehaps it might be easy in windows). It would be nice if there was a way I could get it to work as a generic game pad without needing to write a full-blown driver (If anyone knows how, please tell me).
Sign in to follow this  


3 Comments


Recommended Comments

Nice, my current breadboard is tad messy though I think I'll be doing a PCB at some point, rather than using a Tortilla.

Share this comment


Link to comment
I want to get the $130 Propeller demo kit: it's all in one board, which is good as I'm pretty dire at electronics. It's got jacks for everything!

Andre LaMothe is apparently using his to write 3D games for his "Hydra" system based around it.

I was also thinking of an Arduino because it's cheap and works well with my Mac.

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!