Education – Breadboard

A breadboard is a convenient way to prototype electronics projects.  It’s essentially a plastic board with a ton of holes in it.  You stick electronic components into those holes to build circuits without the need for soldering things together (most of the time).  On a breadboard, the holes are also interconnected in a couple of different ways, and that helps to make electrical connections without having to run a wire for every little thing.

Basic Layout

Sometimes they are taller (more rows), other times they are wider (more center groups), but they almost always look something like what is shown here.  In general though, a breadboard looks a bit like this.

Sometimes there are letters or numbers to identify the rows and columns a lot like a chessboard, but I haven’t bothered putting those labels on my diagram.  Some very small breadboards do not have the vertical power rails.

Connection Patterns

A breadboard wouldn’t be much use if they just had holes in a plastic board with nothing else going on.  After all it would be impossible to make a circuit if there were no electrical connections being made.  Nearly all breadboards, regardless of what color, size or shape they are, have the same basic connection layout.  Along the sides of the board you have the power rails.  These connect the whole way from the top to the bottom and are typically used to provide easy access to power and ground no matter where you are on the breadboard.  In the middle you have groups of connected holes.  These are usually two groups of five holes per row.  Large breadboards can have several groups of five holes.  Here is a diagram to explain how the holes are connected inside the breadboard.

Sample Circuit.

Here is a simple example circuit where an LED has a power switch to turn it on and off.  In this case, the power comes from a battery that we’re pretending has enough voltage for what we are trying to do.  The battery is plugged into the power rails on the breadboard, which means we now have a way to get positive and ground any where we want.  Next, positive power goes through a switch that straddles the gap down the middle.  We get the positive from the output side of the switch and run it over to an LED.  On the other side, we use a resistor to get ground over to the LED.  Now when we turn on the switch, the LED comes on and when we flip the switch again the LED turns back off.

While this may be one of the easiest ways to make a circuit, and it may be a simple device to use, if you didn’t know how the holes are connected together, well, it could be a bit like some crazy magic and not terribly useful for you.  Hopefully now you know what’s going on and are already imagining all the things you can do with them.  If you want to buy one or six, head over to the Shopping Recommendations page for my suggestion.

Education – NES and SNES Joypads

If you haven’t already, I recommend you start with the education article on the 4021 Chip to learn how they work.  Once you are done with that, you can come back here to learn how they are used in the NES and SNES joypads.

NES and SNES Joypad Connectors

Even though the plugs for NES and SNES joypads look very different, they actually house the exact same number of wires with the same purposes.  Oddly enough, both connectors have 7 holes and only 5 wires in use.  I guess they left the other 2 spots for some sort of future expansion that never happened.  Here is a diagram to explain how the wires are arranged and what they all do:

NES and SNES Joypad Buttons

Joypad buttons in both the NES and the SNES are set up in a “pull down” arrangement.  That means that when you aren’t pressing a button it is represented by a “1” bit instead of the “0” you might expect.  When you press a button it pulls the value down to a “0” to indicate that it is pressed.

At first glance, this is backwards from the way that makes sense, but they had an ulterior motive when they did it this way.  They wanted to be able to tell when a joystick is plugged into the NES or SNES.  If you think about it for a moment, you will probably realize that if the buttons sent back in “0” when they aren’t pressed, and a “1” when pressed, then there is no way to know that a joystick is plugged in because there would be no difference between not being plugged in (which would result in a ton of “0”s) and simply not pressing anything on it.  That means you’d only be able to tell that something is connected if the player was actually pressing something.

By flipping it around, all the buttons are suddenly sending “1”s even when the player isn’t pressing anything, just by having the joystick plugged in.  Viola, you can tell that it’s plugged in whether or not a player is pressing anything.

NES Joypad 4021 Layout

There is a single 4021 chip in a NES joypad.  It has its buttons connected to pins in the following arrangement:

  • Input 1 – Pin 7 – D-Pad Right
  • Input 2 – Pin 6 – D-Pad Left
  • Input 3 – Pin 5 – D-Pad Down
  • Input 4 – Pin 4 – D-Pad Up
  • Input 5 – Pin 13 – Start Button
  • Input 6 – Pin 14 – Select Button
  • Input 7 – Pin 15 – B Button
  • Input 8 – Pin 1 – A Button

SNES Joypad 4021 Layout

There are two 4021 chips chained together in a SNES joypad.  One of them is the primary chip and has its data output (pin 3) connected to the SNES console.  The other is the secondary chip and has its data output (pin 3) connected to the data input (pin 11) on the primary chip.  The buttons connected to pins in the following arrangement:

Primary Chip

  • Input 1 – Pin 7 – D-Pad Right
  • Input 2 – Pin 6 – D-Pad Left
  • Input 3 – Pin 5 – D-Pad Down
  • Input 4 – Pin 4 – D-Pad Up
  • Input 5 – Pin 13 – Start Button
  • Input 6 – Pin 14 – Select Button
  • Input 7 – Pin 15 – Y Button
  • Input 8 – Pin 1 – B Button

Secondary Chip

  • Input 1 – Pin 7 – No Joypad Button (see note below)
  • Input 2 – Pin 6 – No Joypad Button (see note below)
  • Input 3 – Pin 5 – No Joypad Button (see note below)
  • Input 4 – Pin 4 – No Joypad Button (see note below)
  • Input 5 – Pin 13 – Right Shoulder Button
  • Input 6 – Pin 14 – Left Shoulder Button
  • Input 7 – Pin 15 – X Button
  • Input 8 – Pin 1 – A Button

Note:  Pins on the secondary 4021 chip that are not connected to any button on the joypad (Pins 4, 5, 6, and 7) are instead connected to +5V DC through a 10K ohm resistor.

NES Joypad Wiring Diagram

This diagram looks worse than it really is, honest.  When a lot of the wires are inside a breadboard or some other prototype perfboard, it’s vastly less complicated to build.  All of the resistors are 10K ohm 1/4 watt resistors.  The buttons are any momentary switch you like.

(You can click on this image to view it larger.)

SNES Joypad Wiring Diagram

This diagram is a bit worse than the NES one above, but it still isn’t really evil.  There is a second 4021, four extra buttons and eight extra resistors.  Once again, when a lot of the wires are inside a breadboard or some other prototype perfboard, it’s less complicated to build than it seems.  All of the resistors are 10K ohm 1/4 watt resistors.  The buttons are any momentary switch you like.

(You can click on this image to view it larger.)

Education – 4021 Chip

The 4021 chip is a parallel in, serial out, 8-bit shift register.  That’s a lot of words to describe a single chip, so we’ll take them a little at a time.

Parallel In

This means that the chip connects to some number sources of information in parallel.  In most cases, these sources are switches or buttons of some sort.   That should make it fairly obvious why these chips are often found in joysticks.  A joystick is just a device full of buttons that you want to know the individual states of while someone is playing a game.

Serial Out

This means that the information collected from lots of buttons is transmitted out of the chip in single file.  This is handy because it means that the information from all of those buttons doesn’t need a lot of wires to send it to a video game console.


This is the amount of storage in the chip for holding the data that came from all the buttons.  The data is arranged as one bit per parallel input on the chip and has nothing to do with how many bits the console system CPU has.

Shift Register

This describes how the data is moved inside the chip as it is requested by the connected system.  In this case, each time the data is requested the front bit is sent on its way and the remaining bits all shift one spot over toward the front.  The back is filled in with zeros.  Eventually all of the data space inside is filled with zeros and there is nothing else to retrieve.

Chaining Chips Together

In most situations, 8 bits isn’t enough.  The original NES controller has 8 buttons, so it will work perfectly, but a SNES controller has 12 buttons.  You can’t connect 12 parallel inputs (buttons) to a chip that only knows how to deal with 8, there just aren’t enough places to solder things to.  Fortunately the folks that designed this chip knew that might be a problem and made sure there was a way to chain more than one of them together.  There is a pin on the chip that can be connected to the output on another chip.  When data is read from the chip and normally the register would fill in the back of the data with zeros, it uses the output data from the next chip in line instead.  There is theoretically no limit to how many you can chain together in this way, but I’ve never tried more than two.

Latch Signal

Buttons are being pressed and released all the time on the joystick when someone is playing a game.  Logically that could have a very confusing effect on the data coming out of the register unless there is a way to prevent button state changes from screwing things up.  The way this is achieved is what is called a latch.  Essentially when a latch signal gets to the chip, it means “remember everything as it is right now, and ignore all other button presses until we are done reading all the data.”

Data Output

There is a single pin on the chip that is used to send data out from the chip.  First a latch signal is received, and then data is sent out once per clock pulse received on the clock pin.

Pin Layout

We have now covered the basic flow of information for this chip and we’ve talked about a lot of inputs and outputs, so it will now be helpful to know how they are laid out on the chip itself.  The best way to do that is with a diagram.

I consider it to be a somewhat unfortunate layout for the pins due to the inputs being all over the place, but as long as you have a map handy like the one above, you shouldn’t have any trouble connecting things to the right places.  The two pins without labels (2 and 12) don’t have anything connected to them, and in situations where you are not chaining multiple chips together, Data Input (pin 11) should be connected to ground.

This concludes our discussion about the 4021 chip and how it works, hopefully you now understand their uses and why they are often found in joysticks.

Button Press Values

In an effort to keep the NerdTAS file format relatively concise, the information about which buttons are pressed is done in a bit mask style value.  This value places the buttons in a specific order.  The buttons represent the binary value after assigning each button to a bit.

The simple way to come up with the value that represents the buttons that are pressed is to add up the values shown below for all buttons that are NOT pressed. This may seem backwards, but the way the NES and SNES work is that buttons are represented by a “1” when they are not pressed, and by a “0” when they are.  For that reason, the NerdTAS file format treats them the same way.

NES Button Data Values:

  • Up = 128
  • Down = 64
  • Left = 32
  • Right = 16
  • B = 8
  • A = 4
  • Select = 2
  • Start = 1

SNES Button Data Values:

  • Up = 2048
  • Down = 1024
  • Left = 512
  • Right = 256
  • B = 128
  • A = 64
  • Y = 32
  • X = 16
  • L = 8
  • R = 4
  • Select = 2
  • Start = 1

NerdTAS File Example

Example of a NerdTAS file that enters the Konami Code after waiting roughly 5 seconds.

ver 1
sys nes
# Konami Code: Up, Up, Down, Down
# Left, Right, Left Right, B, A, Start
dup 1
del 300
but 127
but 127
but 191
but 191
but 223
but 239
but 223
but 239
but 247
but 251
but 254

NerdTAS File Format

First things first.  Button data needs to be stored somewhere for playback by a NerdTAS robot.  The way I’ve chosen to do that is to invent a simple line-by-line style format that is readable and editable by people with tools no more complex than a text editor.  Due in part to a fair amount of work in the past with 6502 assembly (the CPU in the NES), I chose to make this file format use (mostly) three character tags.

For the format details below, ## represents an integer value and XX represents text value.  All commands appear only one per line.

These are the parts of a .nerdtas file:

NerdTAS Header
This line is required to be the first line in a .nerdtas file and is used to indicate that the file is a NerdTAS file. This tag is case sensitive and must be capitalized as shown.
Syntax: NerdTAS
Options: n/a
Example: NerdTAS
Version Tag
This line is required to be the second line in a .nerdtas file and is used to indicate what version of the NerdTas format the file is in.
Syntax: ver ##
Options: 1 (only 1 version so far)
Example: ver 1
System Tag
This line is required to be the third line in a .nerdtas file and is used to indicate which system the button data is for.
Syntax: sys XX
Options: nes, snes
Example: sys snes
Comment Tag
This command is used to indicate that this is a line of content to be ignored. A comment is a full line only and must start with a # and a space. In other words, a comment is not valid on the same line after another tag.
Syntax: # XX
Options: any text
Example: # Hello World
Frame Duplicator Tag
This command is used to indicate how many frames each button should last. Some games only accept input when they receive the same input multiple consecutive times. This allows those games to work correctly without having to manually duplicate the button data yourself. Note: This value only applies to button data that does NOT have a run length specified. Run length button data is assumed to already be the correct number of frames.
Syntax: dup ##
Options: 1 to 255
Example: dup 2
Frame Delay Tag
This command is used to cause a delay of some number of frames. During this delay, no buttons are pressed. Typical frame rates are around 60 FPS, so multiply the number of seconds you would like to delay by 60.
Syntax: del ##
Options: 1 to 216,000 (roughly 1 hour)
Example: del 300
Button Data (Single Frame)
This command is made up of a number that represent all of the buttons pressed for a single frame. The values allowed for the buttons depend on the system specified. Single frame button data may take more than one frame if a Frame Duplicator value is specified. The values used for buttons are explained below.
Syntax: but ##
Options: NES: 0 to 255, SNES: 0 to 4095
Example: but 240
Button Data (Run Length)
This command is made up of a number that represent all of the buttons pressed for a single frame, and how many frames this button configuration should be held. The values allowed for the buttons depend on the system specified. Run Length button data is not affected by Frame Duplicator values, with the exception of when run length is specified as a single frame.  The values used for buttons are explained below.
Syntax: but ## ##
Button Value (parameter 1): NES: 0 to 255, SNES: 0 to 4095
Run Length (parameter 2): 1 to 255
Example: but 240 17

Welcome to NerdTAS

This site is all about how to build, configure and use your own home made TAS robot from scratch.  A TAS is a Tool Assisted Speedrun of a video game.  That means that either a player is using a tool to stitch together all of the best segments of tons of attempts at a speedrun, or that an actual tool is playing the game itself, typically with a recorded set of joystick inputs that is being played back.   In general, it is supposed to be a machine playing a game better than a person can because it can be very entertaining to see a game played as close to “perfectly” as possible.

Tool Assisted Speedruns used to have a bit of a negative image that is only recently starting to be removed.  Some shady folks used to use tools to make amazing speedruns, and then try to pass them off as though they played them without help.  This gave TAS a very bad name in the speedrunning community.  Somewhere in the fairly recent past however, people realized that these speedruns were wildly fun to watch, and that as long as they were called out for what they are, they may just not be so bad.

If you build your own NerdTAS robot and make speedruns with it, be sure to tell everyone that it’s a TAS so we don’t end up back in the place where TAS has a bad name again.

Thanks for stopping by, and good luck if you try to do this.