QuadTari Development Guide
==========================

# Overview

The QuadTari adapter lets you multiplex between 2 controllers/devices on the same
physical port. Although the entire device maps 4 ports to 2 physical ports, each half of
the QuadTari functions completely separately, and can be used independently.

Player 1 and 3 share the first Atari port (QuadTari output A)
Player 2 and 4 share the second Atari port (QuadTari output B)

This allows for various configurations of controllers 
(ie 2 players on the first port, using QuadTari output A, and an AtariVox on the 2nd port,
not using the QuadTari)

When using the QuadTari, you generally read the joysticks as usual, but you can select which 
input joystick to use (1 & 2 or 3 & 4) by setting or clearing bit 7 of VBLANK
(ie register $01. By setting bit 7, it drags INPT0-3 to ground). 
Changing this bit will toggle the inputs for both halves of the QuadTari.

After changing bit 7, the QuadTari will need some time to stabilize with the new input.
It is safest to wait at least one scanline (76 cycles) before reading the new joystick ports.

Example:
    ; to acivate ports 1 and 2:
    lda #$00|$02     ;0 for bit 7, 2 to continue blanking. (ie DISABLE_TIA)
    sta VBLANK
    sta WSYNC        ;wait a scanline to stabilize (you could do other things here instead)
    sta WSYNC        ;make sure it's a full scanline of wait time

    ; to activate ports 3 and 4
    lda #%10000000|$02 ;set bit 7, continue blanking
    sta VBLANK
    sta WSYNC        ;
    sta WSYNC        ;wait a full scanline


# Detecting Quadtari

Your game can detect the presence of the QuadTari at startup by checking bit 7 of INPT0-INPT3
You can test each port (A and B) separately:

         port A
           INPT0           INPT1
               0               0       regular joystick connected
               0               1       multi-tap connected to port A
               1               0       Genesis pad in joystick mode
               1               1       Genesis pad (or paddles) connected
         port B
           INPT2           INPT3
               0               0       regular joystick connected
               0               1       multi-tap connected
               1               0       Genesis pad in joystick mode
               1               1       Genesis pad (or paddles) connected


# Batari Basic

For Batari Basic users, by default, controllers 1 & 2 will automatically be selected
after calling drawscreen.
Developers can manually toggle to reading controllers 3 & 4 with something like the following:

        asm
        lda #$80|%10
        sta VBLANK
        sta WSYNC
    end


# Stella auto-detection

The Stella emulator will check for the following strings anywhere in the ROM to indicate support for the QuadTari:

  -  full QuadTari: 'QUADTARI'
  -  left port only QuadTari: 'QUADL'
  -  right port only QuadTari: 'QUADR'

# Compatibility

The QuadTari has been tested with standard joysticks, Genesis pads, and the driving controller.
Other controllers are untested, but should be compatible if they don't use pins 5 or 9.

# Notes/Suggestions

Because a significant delay is required before toggling controllers, there are a few options 
available for handling multiple players and multiple joysticks.

One option is to read one half of the controllers at the end of vblank, and the other
half at the beginning of overscan, and save their values. Then player updates can happen
during vblank as usual. This works well for a 2-player game that can optionally use the
QuadTari to allow for 2 joysticks plus an AtariVox.

For a 4-player game, an option is to have each player effectively run at 30fps, and only update 2 players per frame.
Run one frame with one half of the QuadTari, and update 2 players. Then on the next frame, select the
other half of the QuadTari, and run the logic for the other 2 players.  This method might be
slightly unfair in some action games (a missile might hit one player a frame earlier even if both are
players are in the exact same spot), but most players will never notice.
