Arkanoid controller: Difference between revisions

From NESdev Wiki
Jump to navigationJump to search
(→‎Test ROMs: add link to my 9-bit proof-of-concept)
(Adds a section on DPCM safety, because the Arkanoid controller has even more potential problems with DMC DMA than other controllers. Notes that a conversion should be started some time before the very first controller read to ensure valid data.)
Line 62: Line 62:
Fire button status is returned directly from the button and is not affected by the strobe. On the NES, repeated reads of this button can be used as a hint that an Arkanoid controller is being used instead of a [[Power Pad]] or [[Zapper]].
Fire button status is returned directly from the button and is not affected by the strobe. On the NES, repeated reads of this button can be used as a hint that an Arkanoid controller is being used instead of a [[Power Pad]] or [[Zapper]].


Control knob data is returned in 9 bits, most-significant-bit first. The data is also inverted. Only the first 8 bits are read by contemporary software. Because the data is latched when the conversion completes, the results of the previous conversion can be read in the period after strobing and before the new conversion completes, but they may also be read before the strobe. The 9th bit is not latched when a conversion completes, so at least one read must be performed before the strobe to latch it in the shift register. For reliability, reading the control knob data before strobing is recommended, though this may add a frame of input lag in some emulators.
Control knob data is returned in 9 bits, most-significant-bit first. The data is also inverted. Only the first 8 bits are read by contemporary software. Because the data is latched when the conversion completes, the results of the previous conversion can be read in the period after strobing and before the new conversion completes, but they may also be read before the strobe. The 9th bit is not latched when a conversion completes, so at least one read must be performed before the strobe to latch it in the shift register. For reliability, reading the control knob data before strobing is recommended, though this may add a frame of input lag in some emulators. Note that because data is not ready until some time after a strobe, care may be required after power-on to ensure the first read contains real data from a conversion rather than undefined power-on state.


The whole range is about 180 degrees and returned in approximately $140 steps (or $A0 steps for an 8-bit read), though the Arkanoid II controller's scaling pot can change the number of steps. The knob boundaries are set by plastic, so wear or additional force may result in values beyond the norm, and fast clockwise turns have been observed returning values briefly exceeding the maximum. Experimentally, the centering pot at minimum on an Arkanoid I controller allows an 8-bit range of $0D-$AD and at maximum of $5C-FC. Variations in the analog-to-digital and pot physical range can vary the result slightly.
The whole range is about 180 degrees and returned in approximately $140 steps (or $A0 steps for an 8-bit read), though the Arkanoid II controller's scaling pot can change the number of steps. The knob boundaries are set by plastic, so wear or additional force may result in values beyond the norm, and fast clockwise turns have been observed returning values briefly exceeding the maximum. Experimentally, the centering pot at minimum on an Arkanoid I controller allows an 8-bit range of $0D-$AD and at maximum of $5C-FC. Variations in the analog-to-digital and pot physical range can vary the result slightly.
Line 100: Line 100:


Although ''Arkanoid II'' uses a [[Family BASIC Keyboard]] with [[Family BASIC Data Recorder]] for saving and loading custom levels, the device cannot work correctly over the Arkanoid II controller's expansion port because OUT2, a required input, is not connected. Thus, the keyboard must be plugged directly into the console to save and load.
Although ''Arkanoid II'' uses a [[Family BASIC Keyboard]] with [[Family BASIC Data Recorder]] for saving and loading custom levels, the device cannot work correctly over the Arkanoid II controller's expansion port because OUT2, a required input, is not connected. Thus, the keyboard must be plugged directly into the console to save and load.
== DPCM safety ==
The ''Arkanoid'' controller is particularly susceptible to the bugs caused by DMC DMA when using DPCM playback (see [[DMA#Register_conflicts|DMA register conflicts]] and [[Controller_reading_code#DPCM_Safety|DPCM safety]] for details). It is not compatible with the common [[Controller_reading_code#DPCM_Safety_using_Repeated_Reads|repeated reads]] solution because reads take nearly half a frame to complete, so [[Controller_reading_code#DPCM_Safety_using_OAM_DMA|reads synced with OAM DMA]] are required. However, even when using synced reads, the controller state may still become corrupted elsewhere. This is because any CPU read in the range $4000-401F can cause DMC DMA to trigger a joypad read, deleting bits from the ''Arkanoid'' controller's latched state before the controller reading code can safely access it. These reads are commonly present in sound engines as a side effect of absolute indexed stores (e.g. STA $4000,X). This problem can be worked around in two ways:
* Ensure that only the joypad reading code ever reads from the range $4000-401F. This may require modifying the sound engine or using a different sound engine.
* Ensure that reads to $4000-401F do not occur between the time a conversion completes and when the latched data is read. This can be done by deliberately ordering the code so that these unsafe reads occur after the controller reading code, but before the strobe that starts another conversion. This requires that this unsafe code does not take so long that the conversion may not complete in time for the next controller read, something that is not a problem for most sound engines that are likely the only thing causing these unsafe reads. For most games, the ordering would be: vblank tasks, OAM DMA, synced controller reads, sound engine, controller strobe, game logic.


== Hardware ==
== Hardware ==

Revision as of 13:33, 15 January 2024

The Arkanoid controller (commonly called the Vaus controller) was included with Arkanoid and Arkanoid II, and is only used for these and Taito Chase HQ. Multiple versions of this controller were produced. The Famicom and NES versions use different joypad bits and must be handled by software separately. The Arkanoid II controller has a Famicom expansion port intended for multiplayer using another Famicom Arkanoid controller of either type. No version is compatible with four player adapters.

Layout

The controller has a single fire button and a control knob connected to a potentiometer. On the Arkanoid II and some Arkanoid versions, there is a second potentiometer under a small plastic cover that adjusts the centering of the control knob output's range. The Arkanoid II version has a third potentiometer also under this cover that adjusts the scaling of the output's range and has a Famicom expansion port next to the cord.

Arkanoid I controller:
            ,--------------------------------------.   |
            |                  %%                  |   |
            |   ,---.          %%                % |   |
            |  /     \         %%         ,-.   %% |   |
 Control  ->| |       |        %%        (   )  %% |<- Fire button
   knob     |  \     /         %%         `-'   %% |   |    
            |   `---'          %%                % |==/
Adjustment->|     ()           %%                  |
   screw    `--------------------------------------'

Interface

Input ($4016 write)

7  bit  0
---- ----
xxxx xxxC
        |
        +- Start ADC

When C goes from 0 to 1, a conversion is started. The results of this conversion are collected in a counter that is reset while C is 1, so C should be quickly returned to 0. Once the conversion is complete, the shift register is automatically loaded with the results of the counter. Additional strobes during a conversion do not restart the conversion. Keeping C at 1 or strobing again before the conversion is complete will negatively shift the result's range (shift it left) based on when during the conversion C was last set to 0.

The analog to digital conversion time depends on the control knob's position; smaller results will convert faster. Experimentally, the conversion takes up to 7 ms, so at least this amount of time should pass between strobes. Strobing again too soon will return bad data.

Arkanoid II and Taito Chase H.Q. perform a strobe of OUT1, but the controller cannot see this because the pin is not connected, so it has no effect. The reason for this strobe is not known.

Output ($4016/$4017 read)

Famicom:

$4016:
7  bit  0
---- ----
xxxx xxBx
       |
       +-- Fire button (1: pressed)

$4017:
7  bit  0
---- ----
xxxx xxDx
       |
       +-- Serial control knob data

NES:

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

Fire button status is returned directly from the button and is not affected by the strobe. On the NES, repeated reads of this button can be used as a hint that an Arkanoid controller is being used instead of a Power Pad or Zapper.

Control knob data is returned in 9 bits, most-significant-bit first. The data is also inverted. Only the first 8 bits are read by contemporary software. Because the data is latched when the conversion completes, the results of the previous conversion can be read in the period after strobing and before the new conversion completes, but they may also be read before the strobe. The 9th bit is not latched when a conversion completes, so at least one read must be performed before the strobe to latch it in the shift register. For reliability, reading the control knob data before strobing is recommended, though this may add a frame of input lag in some emulators. Note that because data is not ready until some time after a strobe, care may be required after power-on to ensure the first read contains real data from a conversion rather than undefined power-on state.

The whole range is about 180 degrees and returned in approximately $140 steps (or $A0 steps for an 8-bit read), though the Arkanoid II controller's scaling pot can change the number of steps. The knob boundaries are set by plastic, so wear or additional force may result in values beyond the norm, and fast clockwise turns have been observed returning values briefly exceeding the maximum. Experimentally, the centering pot at minimum on an Arkanoid I controller allows an 8-bit range of $0D-$AD and at maximum of $5C-FC. Variations in the analog-to-digital and pot physical range can vary the result slightly.

The expected range depends on the game. Arkanoid expects the 8-bit value range (after the inversion is undone) to be $62 to $02. Arkanoid II expects $4D-$E2 for normal gameplay and $4D-$F2 with a tiny paddle; $4D should be the minimum to allow left-side warps, so with $A0 steps, the tiny paddle will be unable to warp off the right edge. To avoid requiring adjustment of the centering pot, which is not even present on all versions, new games can attempt to find the edges programmatically. One possible approach is to accept $A0 steps from the leftmost position seen because the left edge is more reliable, and another is to track the minimum and maximum positions seen and use the middle $A0 steps.

Each read will load the current value of the lowest counter bit into the shift register, so repeatedly reading during a conversion and measuring the rate at which this bit toggles can be used to identify the size of the range. The first 8 reads should be ignored because these bits were latched before the conversion started.

Because conversions take substantial time, a function that reads the controller multiple times in a row to avoid DPCM glitches will not work. One alternative is to check for spurious accelerations, where the second difference xt - 2xt - 1 + xt - 2 exceeds about eight units. Another is to use synchronized controller reads with timed code.

Arkanoid II expansion port

Arkanoid II's controller has its own Famicom expansion port. The connected device is able to see OUT0 and Joypad 2 /OE, and its Joypad 1 and 2 D1 outputs are redirected to Joypad 2 D3 and D4. No other signals are passed through. Because of this, any additional devices daisy-chained beyond two Arkanoid II controllers will be unable to send input to the console, but will still receive OUT0 and Joypad 2 /OE.

 Arkanoid II EXP |  | Famicom EXP
-----------------+--+-----------------
         GND   1 |--| 1   GND
 Joypad 2 D1   7 |->| 4   Joypad 2 D4
Joypad 2 /OE   9 |<-| 9   Joypad 2 /OE
        OUT0  12 |<-| 12  OUT0
 Joypad 1 D1  13 |->| 5   Joypad 2 D3
          5V  15 |--| 15  5V

(All other Arkanoid II EXP pins not connected)

This port is intended to be used with another Arkanoid controller, but is not limited to this. When used with an Arkanoid controller, $4017 works as follows:

$4017 read:
7  bit  0
---- ----
xxxD BxDx
   | | |
   | | +-- Controller 1 serial control knob data
   | +---- Controller 2 fire button
   +------ Controller 2 serial control knob data

It has been observed that adjustments on one controller's control knob can cause slight changes in the result from the other controller's knob.

Although Arkanoid II uses a Family BASIC Keyboard with Family BASIC Data Recorder for saving and loading custom levels, the device cannot work correctly over the Arkanoid II controller's expansion port because OUT2, a required input, is not connected. Thus, the keyboard must be plugged directly into the console to save and load.

DPCM safety

The Arkanoid controller is particularly susceptible to the bugs caused by DMC DMA when using DPCM playback (see DMA register conflicts and DPCM safety for details). It is not compatible with the common repeated reads solution because reads take nearly half a frame to complete, so reads synced with OAM DMA are required. However, even when using synced reads, the controller state may still become corrupted elsewhere. This is because any CPU read in the range $4000-401F can cause DMC DMA to trigger a joypad read, deleting bits from the Arkanoid controller's latched state before the controller reading code can safely access it. These reads are commonly present in sound engines as a side effect of absolute indexed stores (e.g. STA $4000,X). This problem can be worked around in two ways:

  • Ensure that only the joypad reading code ever reads from the range $4000-401F. This may require modifying the sound engine or using a different sound engine.
  • Ensure that reads to $4000-401F do not occur between the time a conversion completes and when the latched data is read. This can be done by deliberately ordering the code so that these unsafe reads occur after the controller reading code, but before the strobe that starts another conversion. This requires that this unsafe code does not take so long that the conversion may not complete in time for the next controller read, something that is not a problem for most sound engines that are likely the only thing causing these unsafe reads. For most games, the ordering would be: vblank tasks, OAM DMA, synced controller reads, sound engine, controller strobe, game logic.

Hardware

The controller uses a 556 timer (containing 2 timers), a 4040B 12-bit binary counter, and an 8-bit shift register. One timer repeatedly clocks the binary counter and the other measures the control knob position. A centering pot adjusts the control knob timer and a scaling pot adjusts the counter timer. When OUT0 goes high, the counter clears and the control knob timer starts and releases the counter timer from reset, allowing it to begin incrementing the counter. When the control knob timer expires, it puts the counter timer back into reset and latches bits 9-2 of the counter into the shift register. Bit 1 of the counter connects to the shift register's serial input.

Test ROMs

  • Vaus Test shows adaptation to trimpot setting, repeated read rate, and first and second differences
  • 9-bit results shows and visualizes the 9-bit result