Controller input - Falmouth-Games-Academy/comp310-wiki GitHub Wiki

Introduction

The controller for the NES had a unique style to it. The design was simple, a four-button layout: two round buttons labelled “A” and “B”, a “START” and a “SELECT” button. The controller also used a “Directional Pad” (“D-Pad”) which we now see on most controllers. A Nintendo employee[1] designed the ‘D-pad’ in order to replace the bulkier joysticks that had been used on earlier gaming consoles, thus bringing a new look at how movement can be put into a gaming console. The NES controller (4021) is an iconic piece of gaming hardware, its look and colour scheme makes it easily recognisable. Although the controller is simple compared to those of the present gaming generation, its layout confined games to have simple yet clever mechanics. 'Retro games' aren't as complex as the 'cinematic masterpieces' we have today but they can be more enjoyable and inclusive as the casual players don't need a road map of the different buttons to use at certain times, it's just a directional-pad and two buttons, making any player feel comfortable no matter their skill.

Controller Input

Controller 1 has the address $4016

Controller 2 has the address $4017

NES Controllers have 8 buttons each of which corresponds to a different bit. Each time LDA $4016 or LDA $4017 is called it will cycle through the different buttons, the first time it will correspond to the ‘A’ button and then the next time it will be the ‘B’ button and so on. This means it will have to be called 7 times before getting to the ‘left’ button. This is the only way to call the different buttons; there is no other way to reference the buttons.

(1) A
(2) B
(3) Select
(4) Start
(5) Up
(6) Down
(7) Left
(8) Right

NES Controller [1]

The following section of code shows how to check if the 'A' button has been pressed. [2]

LatchController:
  LDA #$01
  STA $4016
  LDA #$00
  STA $4016       ; tell both the controllers to latch buttons

ReadA: 
  LDA $4016       ; player 1 - A
  AND #%00000001  ; only look at bit 0
  BEQ ReadADone   ; branch to ReadADone if button is NOT pressed (0)
                  ; add instructions here to do something when button IS pressed (1)

ReadADone:        ; handling this button is done

Button Flags

To make programming easier it can be a good idea to define buttons as a series of flags

BUTTON_A		= 1 << 7
BUTTON_B		= 1 << 6
BUTTON_SELECT	        = 1 << 5
BUTTON_START		= 1 << 4
BUTTON_UP		= 1 << 3
BUTTON_DOWN	        = 1 << 2
BUTTON_LEFT		= 1 << 1
BUTTON_RIGHT		= 1 << 0

Code from 3(https://wiki.nesdev.com/w/index.php/Controller_Reading)

Then buttons can be checked as follows;

LDA buttons
and #BUTTON_A | BUTTON_B
beq notPressingAorB
;Handle Presses.
notPressingAorB

Code from 3(https://wiki.nesdev.com/w/index.php/Controller_Reading)

NES 4021 Hardware

The 4021 controller for the NES is an 8-bit parallel to serial-shift register. ‘Serial input’ is the pin for the controller, this pin is ordinarily used to chain the output of one shift register into the next one as seen in the Four Score. The ‘Serial Input’ on the tail end of such a chain can be tied to ground or ‘Vcc’, which determines the state of the output after all bits have been shifted out. If the Serial input’ is grounded, the register produces a 0. If it tied to ‘Vcc’ then it produces a 1. In the NES’ case, the controller input is grounded. But because the signals from the controllers pass through an inverter before reaching the CPU, the register produces a 1 for all the reads after the first eight are done.[9]

Optional controllers for the NES

There were many controllers made for the NES by both Nintendo and third party companies. Most third party made controllers were created with specific games in mind. Below are a few examples of these optional controllers.

NES Zapper

The NES Zapper is awesome:

Awesome!

The zapper communicates with the NES in a similar way to that of an ordinary control pad. As the zapper is plugged into a controller port in the same way; it is read by a program after being strobed from either $4016 or $4017 (note that many games only allow it's use in controller port #2 to allow standard menu navigation with a control pad used in controller port #1), and returns an 8-bit report. Unlike the standard control pad where every bit corresponds to a control pad action, we are only interested in bit 3 and 4 [4].

7  bit  0
---- ----
xxxT Wxxx
   | |
   | |
   | +---- Light sense (0: detected; 1: not detected)
   +------ Trigger (0: released; 1: pulled)

The process of detection as declared in Nintendo's 1985 patent [6] reads:

  • In brief, the invention resides in producing a trigger signal in response to a manual operation, displaying a black picture on a television monitor screen for a predetermined short period of time in response to said trigger signal, displaying a white picture as a mock target in a position where a target was displayed just before or around the periphery thereof upon the lapse of said time, detecting the light from the white picture upon the lapse of the black picture display period after the trigger signal has been produced, extracting the signal which is related to the television synchronizing signal from among the detection signals, and using said signal as a detection signal from the target.

Implementation would require a check on each frame on whether the trigger button has been pressed (bit 4), and upon success, checking whether a target has been hit (some games such as Wild Gunman rely only upon the timing, not the direction the Zapper is pointing). The screen then goes entirely black. A check can be done here that the Zapper's light sensor sees the same black to counter cheating methods where a user would simply hold the Zapper to a light emitter flooding the sensor with light). After the black screen, a light coloured box can sequentially appear over each potential target then the light sensor checked. If the light sensor responds that it can see the light, then the program infers that the Zapper is pointing its light at that particular target. By timing, the light target specific hit-boxes the program can effectively deduce which target the Zapper was pointing at when the trigger was pulled [4] [5] [6].

The Arkanoid/ Vaus Controller

The Arkanoid/ Vaus controller created by Taito was made to be used with the game of the same name. More specifically it was supposed to make it easier to play the game7(https://www.revolvy.com/page/Arkanoid-Controller).

Arkanoid Controller

8(https://www.retrogames.co.uk/003327/Nintendo/NES-Arkanoid-Controller-by-Taito)

The controller consists of a black button at the top and a knob that could be spun a maximum of 180 degrees at the bottom.

---- ----
xxxD Bxxx
   | |
   | +---- Fire button (1: pressed)
   +------ Serial control knob data

The Arkanoid Controller can be read from both $4016 and $4017 controller ports.

NES Satellite

The NES Satellite wasn't actually a controller instead its function was to extend the number of controllers available for use. It came as two separate parts, with the smaller part being a receiver which was plugged into the NES controller port and then the main body allowing for multiple users (Up to four) to play wirelessly up to fifteen feet away. 10(https://en.wikipedia.org/wiki/NES_Satellite)

NES Satellite Image

R.O.B (Robotic Operating Buddy)

R.O.B is probably the best known NES peripheral as it's made cameos in a slew of Nintendo titles, including Super Smash Bros and Mario Kart, even though he only ever had 2 games of his own released at the time[11].

R.O.B operates on the exact same principles as the NES Zapper[4][5], but instead of having the light sensor in the end of the gun, it was placed in his eyes, in the game Gyromite[12], the player must give commands to R.O.B by hitting the Start button, which then turns the screen blue, putting R.O.B into "receive" mode as it were and the next button press would trigger another screen flash cause R.O.B to move the "Gyros" (Heavy spinning tops) that correspond to the colored doors in the game that needed to be opened in order for the player to advance through the level[11], when the "Gyro" was moved onto the corresponding Red or Blue trays (As visible in the below image), either the A or B button would be pressed on the second NES controller, which would open the door in game.

R.O.B caused quite the stir when it was released 2 years after the games crash of 1983[13], Nintendo created him to make the NES seem more of a "advanced and novel toy and" and most importantly to push the "Entertainment System" that the NES was sold as, rather than a regular games console[11] As this would have more mass market appeal and was the key to their later market success,with the NES being the best selling home console of the 80s[14][15].

R.O.B set up for Gyromite

References