This is Port B, the second of the I/O Ports. It is 8 bits wide, and is generally used for reading the status of the Stella console switches.
SWCHB (Port B, Console Switches)
Name | D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0
| |
$282 | SWCHB | P1 DIFF | P0 DIFF | · | · | COL/B&W | · | SELECT | RESET |
Normally, Port B is only used for read-only access to the console switches, and the data direction register SWBCNT is set to all-input (0). The Stella Programmer's Guide advises that the port is "hardwired" as input, but this is not quite the case. While it is true that the hardware switches (left and right difficulty, colour/B&W, select and reset) are tied to the bits as shown, it is possible to configure the port for input or output individually for all of the pins.
Buffer/RAM
The register acts as a one-byte buffer, holding any bits written to it (in output mode), and will return these bits when read (in input mode). The consequences of this is that the register can be used as a RAM storage location (in particular, the three unused bits D5, D4, and D2). The reliability of using the hardwired bits (those connected to physical switches) as storage is unknown, but has been reported to work.
To use them, in your code initialisation set SWBCNT to 'output' for those bits. Then you can read and write to SWCHB like a normal register. The writes only affect pins you set to one. If you don't use some of the switches in your program (like the player difficulties) then you can make them 1's as well.
; set DDR bits to output (write access) on pins D5, D4, and D2 lda #%00110100 sta SWBCNT ;
The attached demo from Omegamatrix demonstrates use of these bits as RAM.
Console Switches
By default, the port is wired to the console switches. They can be read according to the following table.
Switch | Use | ||||||||
P1 DIFF D7 | P1 difficulty | 0 = Beginner (B) 1 = Advanced (A) | |||||||
P0 DIFF D6 | P0 difficulty | 0 = Beginner (B) 1 = Advanced (A) | |||||||
D5 | (not used) | RAM1 | |||||||
D4 | (not used) | RAM1 | |||||||
COL/B&W D3 | Colour / B&W switch | 0 = Black and White 1 = colour | |||||||
D2 | (not used) | RAM1 | |||||||
SELECT D1 | SELECT | 0 = switch pressed 1 = switch not pressed | |||||||
RESET D0 | RESET | 0 = switch pressed 1 = switch not pressed |
1. For further details on use of these bits as RAM, see the above notes.