# Signetics 2650 & 2636 programming/2650 processor

The 2650 was first released by Signetics in 1975. These video game consoles use the 2650A, a redesigned version that was smaller, cheaper to manufacture and had improved operating margins. The 2650A was released in 1977. A later version, the 2650B, had a few design changes and additional features, but we aren't concerned with those here. The 2650 was fabricated in NMOS, was TTL compatible, and its many control signals made it simple to interface to. It was described by Adam Osborne as being a very minicomputer-like device having been closely based on the IBM 1130. It has a number of distinguishing features:
* 32k byte address range, organised as four 8k byte pages.
* Variable-length instructions of 1, 2 or 3 bytes.
* Single bit I/O path (flag and sense pins).
* Multiple addressing modes including indirect and indexed.
* Vectored interrupt.
* Eight-level return address stack.
* Seven 8-bit registers.
* Two program status bytes.
* Powerful instruction set.

## Registers

The 2650 has seven general purpose 8-bit registers. R0 is always available, whereas there are two banks of R1, R2 and R3 which are selected by the RS bit in the Program Status Word.

## Program Status Word

The Program Status Word (PSW) is a special purpose register that contains status and control bits. It is divided into two bytes, the Program Status Upper (PSU) and Program Status Lower (PSL). The PSW bits may be tested, loaded, stored, preset or cleared using the instructions tpsu, tpsl, lpsu, lpsl, spsu, spsl, ppsu, ppsl, cpsu or cpsl.
PSU :
| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| S | F | II | - | - | SP2 | SP1 | SP0 |
PSL :
| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| CC1 | CC0 | IDC | RS | WC | OVF | COM | C |
| S | Sense input pin | Pin 1 of the 2650, connected to the Vertical Reset signal. |
| F | Flag output pin | Pin 40 of the 2650, determines if vertical or horizontal joystick potentiometers are read. |
| II | Interrupt Inhibit | Inhibits recognition of interrupt signals. |
| SP2,SP1,SP0 | Stack Pointer | Pointer to the internal Return Address Stack of 8 words. |
| CC1,CC0 | Condition code | Set by most operations except branches. |
| IDC | Inter Digit Carry | Stores the bit 3 to bit 4 carry in arithmetic and rotate instructions. |
| RS | Register bank Select | Determines which of the two banks of registers (r1,r2,r3) is being used. |
| WC | With/without Carry | Determines if the carry bit is used in arithmetic and rotate instructions. |
| OVF | Overflow | Set if a two's complement overflow occurs. |
| COM | Logical/arithmetic Compare | Determines how comparisons are made. |
| C | Carry | Stores any carry from the high order bit during arithmetic and rotate instructions. |

## Reset

When a Reset pulse is applied to the 2650A, program execution is forced to begin at memory address 0. The only other thing we know for sure about the state of the processor after reset is that the Interrupt Inhibit bit in the Program Status Word is cleared. As we very much don’t want spontaneous interrupts to happen, one of the first things our program should do is set it to disable them until we ready for them. The “Signetics 2650 Initialization Application Memo” also suggests that we may set the Stack Pointer to zero, and that we should set the Register Select bit to a known state.
The With Carry bit and the Compare bit may be set to whatever condition you will need them in first. In a simple program which has them in the same state throughout, this is a straightforward decision. In more complex programs it is generally best to set them to the most used condition initially, and then switch them back and forth whenever the opposite condition is needed. If the With Carry bit is on, then the Carry bit should be initialised appropriately before the first arithmetic instruction. Otherwise there is no need to initialise Carry or any of the other bits (Condition Code, Interdigit Carry, or Overflow).

## Interrupts

Certain events occurring in the PVI cause it to signal the 2650 that it needs attention by setting the interrupt line low. If the Interrupt Inhibit bit in the Program Status Word is not set, (in other words interrupts are enabled), the processor will finish the current instruction and then set the Interrupt Inhibit bit. The PVI then outputs its interrupt vector, 3, to the data bus and the processor executes a ZBSR (branch to subroutine on page zero) to address $0003.
When the interrupt service subroutine has finished, it should be exited with either a RETC or RETE instruction. The latter will re-enable interrupts.

## Instruction set

All mnemonics in the 2650A instruction set are 3 or 4 characters long. The first two or three characters specify the operation, and if present, a final character indicates an addressing mode to use (see the next section, Addressing modes for more detail). Assembly code for the 2650 generally looks something like this:
There are 34 basic instructions:
2650A basic instruction set :
| Transfer | LOD | Z,I,R,A | Load register |
| Transfer | STR | Z,R,A | Store register |
| Arithmetic | ADD | Z,I,R,A | Add to register |
| Arithmetic | SUB | Z,I,R,A | Subtract from register |
| Arithmetic | DAR | | Decimal adjust register |
| Logical | AND | Z,I,R,A | Bitwise AND to register |
| Logical | IOR | Z,I,R,A | Bitwise OR to register |
| Logical | EOR | Z,I,R,A | Bitwise EXCLUSIVE-OR to register |
| Test | COM | Z,I,R,A | Compare value to register |
| Test | TM | I | Test masked bits of register |
| Rotate | RRR | | Rotate register right by one bit |
| Rotate | RRL | | Rotate register left by one bit |
| Branch | BCT | R,A | Branch on condition true |
| Branch | BCF | R,A | Branch on condition false |
| Branch | BRN | R,A | Branch if register not-zero |
| Branch | BIR | R,A | Increment the register and branch if it is not zero |
| Branch | BDR | R,A | Decrement the register and branch if it is not zero |
| Branch | ZBR | R | Branch, relative to address $0000 |
| Branch | BX | A | Branch, indexed |
| Call / Return | BST | R,A | Branch to subroutine on condition true |
| Call / Return | BSF | R,A | Branch to subroutine on condition false |
| Call / Return | BSN | R,A | Branch to subroutine if register not-zero |
| Call / Return | ZBS | R | Branch to subroutine, relative to address $0000 |
| Call / Return | BSX | A | Branch to subroutine, indexed |
| Call / Return | RET | C,E | Conditionally return from subroutine. RETE also enables interrupts |
| Input / Output | WRT | C,D,E | Input/output hardware is not implemented on these consoles |
| Input / Output | RED | C,D,E | Input/output hardware is not implemented on these consoles |
| Miscellaneous | HALT | | Enter WAIT state until processor is reset or interrupted |
| Miscellaneous | NOP | | Do nothing except fetch and execute this instruction |
| Program status word | LPS | U,L | Load the PSW |
| Program status word | SPS | U,L | Store the PSW |
| Program status word | CPS | U,L | Clear specified bits in the the PSW |
| Program status word | PPS | U,L | Preset specified bits in the the PSW |
| Program status word | TPS | U,L | Test specified bits in the the PSW |

## Addressing modes

The Signetics 2650 has four main addressing modes: Register, Immediate, Relative and Absolute. In addition Indirect and Indexing may be combined with some of these.

### Register addressing

All register-to-register instructions are 1 byte in length and use R0 as the first operand, while the other can be any of R0, R1, R2, R3.

### Immediate addressing

In immediate addressing the first operand, which can be any register, is specified next to the instruction; followed by the value of the other operand, which implicitly must be a constant. All immediate addressing instructions are two bytes in length.

### Absolute addressing

In absolute addressing the first operand, which can be any register$^{(butseeexceptioninIndexedaddressingbelow)}$, is specified next to the instruction. The second argument designates the absolute address of the memory location where the other operand is located.

### Relative addressing

In relative addressing the first operand, which can be any register, is specified next to the instruction. The second argument designates a memory location where the other operand is located. This second argument is a relative displacement from the current address and can be any value from -64 to +63. In practice we don't specify this value as a number. It generally takes the form of a label and the assembler does the calculation for us. If the label is too far away the assembler will generate an error message. Relative addressing is also used in branch instructions to jump to a memory location close by.

### Indexed addressing

When indexed addressing is used, the effective address is calculated by adding the contents of the specified index register to the address field. The addition uses the value in the index register as an 8-bit positive number.
Note that the first argument is always r0. Some assemblers may allow this to be omitted from the code, but for the sake of readability it should be included if possible.
Two other options allow for the index register to be auto-decremented or auto-incremented before it is added to the base address:
Indexing may only be used with absolute addressing. It may not be used with branch instructions, but two special instructions exist for this purpose. They are BXA (branch indexed, absolute) and BSXA (branch to subroutine indexed, absolute). Auto-increment and auto-decrement cannot be used with them, and register R3 must be specified as the index register.

### Indirect addressing

Indirect addressing means that the argument address of an instruction is not specified by the instruction itself, but rather the argument address will be found in the two bytes pointed to by the instruction. The indirect addressing mode is indicated by an asterisk.
Indirection may be used with relative addressing as well, but since code in these consoles is operating out of ROM, and RAM addresses are generally too far away for a relative address, there is no apparent use. One exception does occur when space for code is at a premium:
The last two instructions both load a register from bar, but the last instruction only uses two bytes rather than three.

### Indexed Indirect addressing

When indexing and indirect are used together, the value of the index register is added to the indirect address, not to the value in the address field of the instruction.

## Further reading

For more detailed information consult the Signetics 2650 User Manual, available as a full pdf or abridged for programmers as html.

## References

* ↑ Microcomputer Digest (PDF). Cupertino, CA: Microcomputer Associates Inc. 2 (1): 1–3. July 1975 http://bitsavers.trailing-edge.com/magazines/Microcomputer_Digest/Microcomputer_Digest_v02n01_Jul75.pdf. Archived (PDF) from the original on 1 February 2014. Retrieved 4 December 2021. {{cite journal}}: Cite has empty unknown parameter: |1= (help); Invalid |url-access=4 December 2021 (help); Missing or empty |title= (help)
* ↑ "Signetics 2650: An IBM on a Chip". The CPUshack museum. October 16th, 2016. Retrieved 5 December 2021. {{cite web}}: Check date values in: |date= (help)
* ↑ Osborne, Adam (1978). An introduction to microcomputers (PDF). Berkeley, Calif.: Osborne & Associates. p. 736. ISBN 0-931988-15-2. Retrieved 4 November 2021.
* ↑ 2650 Series Microprocessor datasheet (PDF). Philips. Retrieved 4 November 2021.
* 1 2 Signetics Applications Memo MP51 - 2650 initialization (PDF). Philips. Retrieved 4 November 2021.