[[Category:CP1610]] The CPU used in the Intellivision [[Category:Master Component]] is a [[General Instruments]] CP1610. The CP1610 is a general purpose microprocessor capable of supporting 16-bit addresses and 10-bit instructions.

==Overview==
Clock Speed894,886.25 Hz (NTSC)
1MHz (PAL/SECAM)
Address Width16-bit
Instruction Opcode Width10-bit
Reset Address$1000
Interrupt Address$1004
[[#Flags|Flags]]S, Z, O, C, I, D
[[#Registers|Registers]]Eight 16-bit Registers, R0-R7

==General Behavior== The R7 register behaves as program counter for the CP1610. On the Intellivision, the CP1610 initializes R7 to the value $1000. The CP1610 then reads, decodes, and executes the opcode at the location reference by R7 and the increments R7 to the next instruction. Although most opcodes are only one memory location in length (one 10-bit value or "decle"), a few opcodes stretch to two or three memory locations, causing R7 to increment by more than a single value in order to find the next instruction to execute. The CP1610 repeats this behavior indefinitely, or until a HLT instruction is read.

The processor also receives hardware interrupts from the [[STIC]] which occur once per screen refresh and cause the CP1610 to jump to the interrupt subroutine located at $1004 in the [[Executive ROM]]. The STIC may also request the CP1610 temporarily halt processing to allow the [[STIC]] to perform direct memory accesses.

==Flags==
S[[Sign Flag]]If set, indicates that the previous operation resulted in negative value, which is determined by a one (1) in bit 15 of the result.
C[[Carry Flag]]If set, indicates that the previous operation resulted in unsigned integer overflow.
Z[[Zero Flag]]If set, indicates that the previous operation resulted in zero.
O[[Overflow Flag]]If set, indicates that the previous operation gave a signed result that is inconsistent with the signs of the source operands. (Signed overflow.)
I[[Interrupt Enable Flag]]If set, allows the INTRM line to trigger an interrupt, causing the CPU to jump to the interrupt subroutine located in the Executive ROM at $1004.
D[[Double Byte Data Flag]]If set, it causes the next instruction to read a 16-bit operand with two 8-bit memory accesses, if it supports it.

Special notes: * The S, C, Z, and O flags are directly visible to the programmer via the [[GSWD]] instruction. The I and D flags are internal to the CPU, and not visible directly visible to the programmer. * The C and O flags serve a secondary purpose for the shift and rotate instructions. The [[SLLC]], [[SARC]], [[RLC]] and [[RRC]] use the C and O flags to store bits that get "shifted away." Also, the [[RLC]] and [[RRC]] instructions "shift in" the bits stored in C and O. * The S flag takes on a special role also with the shift instructions. The [[SWAP]], [[SLR]], [[SAR]], [[SARC]] and [[RRC]] instructions set the S flag based on bit 7 of the result, rather than bit 15.

==Signal Pins==
SignalNameDirectionPurposeUse on Intellivision
INTRMINTerrupt Request, Masked.Input A high-to-low transition on this pin causes the CPU to take an interrupt if interrupts are enabled. If the signal transitions back to the "high" state prior to taking the interrupt, the CPU will ignore the interrupt.Connects to the SR1 output pin on the STIC. The STIC signals [[VBlank Interrupt]] to the CP1610 on this pin, and the CP1610 jumps to the interrupt vector at $1004 after the next interruptible instruction.
INTRINTerrupt Request.Input A high-to-low transition on this pin causes the CPU to take an interrupt, regardless of whether interrupts are enabled.The Intellivision leaves this signal tied to +5v (deasserted).
BUSRQBUS ReQuest.Input A high-to-low transition on this pin requests that the CPU halt so that something else may access the bus. Connects to the SR2 output pin on the STIC. The STIC signals the CP1610 on this pin at points during active display when it needs to access [[System RAM]]. The CP1610 halts after the next interruptible instruction, regardless of whether interrupts are enabled.
BUSAKBUS AcKnowledge.Output Asserted (active-low output) when the CPU has yielded the bus. Connects to the SST input pins on the System RAM and the [[Graphics ROM|GROM]]. The CP1610 acknowledges the STIC's bus request by signaling to the System RAM and GROM that it halted by request of the STIC.
MSYNCMaster SYNC.Input Asserting this signal (active low) resets the CPU and synchronizes it to its clocks. Connects to the MSYNC output of the STIC. The STIC generates this signal shortly after powerup after the clock stabilizes, or whenever someone releases the reset button or asserts RESET on the cartridge port.
EBCA0 - EBCA3External Branch Condition Address.Output The four outputs EBCA0 through EBCA3, along with the single input ECBI provide a mechanism for external hardware to generate branch control inputs to the CPU. The BEXT instruction includes a 4-bit field that the CP1610 asserts on EBCA0 - EBCA3. External hardware then asserts a 0 or 1 on EBCI to indicate whether to take the branch. This allows up to 16 different branch conditions to be asserted to the CPU. These pins are not connected in the Intellivision, so the BEXT instruction is typically never used.
EBCIExternal Branch Condition Input.Input
TCITerminate Current Interrupt.Output TCI is both an instruction as well as a pin on the device. The TCI instruction pulses the TCI pin on the CP1610. The Intellivision leaves this signal unconnected, and so the TCI instruction is effectively a NOP.
PCITProgram Counter Inhibit/Trap.Bidirectional. External hardware can prevent the CPU from incrementing the program counter by asserting this signal. The SIN instruction generates a pulse on this line. The Intellivision leaves this signal tied to +5v (deasserted) through a resistor.
STPSTSToP-STart.InputStops or starts the execution of the CPU whenever it sees a high-to-low transition. Can restart the CPU after a [[HLT]] instruction.The Intellivision leaves this signal tied to +5v.
HALTHALTed.OutputIndicates the CPU halted, either due to STPST or a [[HLT]] instruction.The Intellivision leaves this signal unconnected.
BDRDYBus Data ReaDY.InputWhen deasserted, it causes the CPU to wait for data to become available on the bus, effectively inserting wait states.The Intellivision leaves this signal unconnected, and thus has no notion of wait states.


==Interruptibility== Each CP1610 opcode is considered either "interruptible" or "not interruptible". The interruptibility of an opcode determines whether or not the CP1610 checks the status of INTRM and BUSRQ after executing that instruction, and prior to executing the next. The CP1610 will check for an interrupt request signaled via INTRM only if both the [[Interrupt Enable Flag]] flag is set and previous instruction was an interruptible instruction. It is important to understand that the [[Interrupt Enable Flag]] and the interruptibility of each opcode are completely separate functions and both work together to control when the CP1610 accepts interrupts on the INTRM line. For more information on interrupts, see the [[VBlank Interrupt]] topic.

Similarly, the [[STIC]] only asserts BUSRQ to the CP1610 for 114 CP1610 clock cycles (on NTSC systems). The [[Interrupt Enable Flag]] does not affect the CPU's ability to respond to this bus request. Non-interruptible instructions, however, do. Thus, if a program contains an extended sequence of non-interruptible instructions, the CPU will not halt in time for the [[System RAM]] to prepare the next row of display cards. Instead, the machine will duplicate the previous row and push the rest of the display down. It appears that the CPU must halt within about 57 cycles of BUSRQ first being asserted in order to prevent display glitches.

==Registers== There are eight 16-bit registers available in the CP1610, labelled R0-R7.

Register NameDescription
R0General Purpose.
R1General Purpose.
R2General Purpose.
R3General Purpose.
R4General Purpose. Auto-increments on indirect reads and writes.
R5General Purpose. Auto-increments on indirect reads and writes.
R6SPStack Pointer. Auto-increments on indirect reads. Auto-decrements on indirect writes.
R7PCProgram Counter. Auto-increments on indirect reads and writes.

The names "SP" and "PC" are assembler aliases for "R6" and "R7," respectively. They may be used interchangeably. ==Addressing Modes== The CP1610 supports several addressing modes. Click on any of the addressing modes below for more information.
[[Implied Mode|Implied]]The opcode's inputs or outputs are implied by the opcode itself.
[[Register Mode|Register]]The value to be read or written is contained in one or more registers. No memory access are required to execute Register-mode opcodes.
[[Direct Mode|Direct]]The address of the value to be read or written is specified by the value immediately following the address of the opcode.
[[Immediate Mode|Immediate]]The address of the value to be read or written is the address immediately following the opcode. Note that immediate mode addressing is really just Indirect addressing using the R7 register.
[[Indirect Mode|Indirect]]The address of the value to be read or written is contained in one of the registers.
[[Stack Mode|Stack]]This [[Indirect Mode]] through R6, the stack pointer.


==Instruction Set== Below is a detailed breakdown of all the opcodes available as a part of the CP1610 instruction set. Click on each opcode for more information. Also, you might look at the original [[GI Instruction Set Reference]], which is a handy (if occasionally incomplete or inaccurate) guide.

RangeInstructionMnemonic(s)CyclesInterruptibleInput FlagsOutput Flags
SZOCDSZOCID
$0000[[HLT|Halt]][[HLT]]NANo
$0001[[SDBD|Set Double Byte Data]][[SDBD]]4NoD
$0002[[EIS|Enable Interrupt System]][[EIS]]4NoI
$0003[[DIS|Disable Interrupt System]][[DIS]]4NoI
$0004[[Jump]][[J]]12Yes
[[JE]]12YesI
[[JD]]12YesI
[[JSR]]12Yes
[[JSRE]]12YesI
[[JSRD]]12YesI
$0005[[TCI|Terminate Current Interrupt]][[TCI]]4No
$0006[[CLRC|Clear Carry]][[CLRC]]4NoC
$0007[[SETC|Set Carry]][[SETC]]4NoC
$0008-$000F[[INCR|Increment Register]][[INCR]]6YesSZ
$0010-$0017[[DECR|Decrement Register]][[DECR]]6YesSZ
$0018-$001F[[COMR|Complement Register]][[COMR]]6YesSZ
$0020-$0027[[NEGR|Negate Register]][[NEGR]]6YesSZOC
$0028-$002F[[ADCR|Add Carry to Register]][[ADCR]]6YesCSZOC
$0030-$0033[[GSWD|Get the Status Word]][[GSWD]]6YesSZOC
$0034-$0035[[NOP|No Operation]][[NOP]]6Yes
$0036-$0037[[SIN|Software Interrupt]][[SIN]]6Yes
$0038-$003F[[RSWD|Return Status Word]][[RSWD]]6YesSZOC
$0040-$0047[[SWAP|Swap Bytes]][[SWAP]]6/8NoSZ
$0048-$004F[[SLL|Shift Logical Left]][[SLL]]6/8NoSZ
$0050-$0057[[RLC|Rotate Left through Carry]][[RLC]]6/8NoOCSZOC
$0058-$005F[[SLLC|Shift Logical Left through Carry]][[SLLC]]6/8NoOCSZOC
$0060-$0067[[SLR|Shift Logical Right]][[SLR]]6/8NoSZ
$0068-$006F[[SAR|Shift Arithmetic Right]][[SAR]]6/8NoSZ
$0070-$0077[[RRC|Rotate Right through Carry]][[RRC]]6/8NoOCSZOC
$0078-$007F[[SARC|Shift Arithmetic Right through Carry]][[SARC]]6/8NoOCSZOC
$0080-$00BF[[MOVR|Move Register]][[MOVR]]6/7YesSZ
$00C0-$00FF[[ADDR|Add Registers]][[ADDR]]6YesSZOC
$0100-$013F[[SUBR|Subtract Registers]][[SUBR]]6YesSZOC
$0140-$017F[[CMPR|Compare Registers]][[CMPR]]6YesSZOC
$0180-$01BF[[ANDR|And Registers]][[ANDR]]6YesSZ
$01C0-$01FF[[XORR|Xor Registers]][[XORR]]6YesSZ
$0200-$023F[[Branch]][[B]]9Yes
[[BC]]7/9YesC
[[BOV]]7/9YesO
[[BPL]]7/9YesS
[[BEQ]]7/9YesZ
[[BLT]]7/9YesSO
[[BLE]]7/9YesSZO
[[BUSC]]7/9YesSC
[[NOPP]]7Yes
[[BNC]]7/9YesC
[[BNOV]]7/9YesO
[[BMI]]7/9YesS
[[BNEQ]]7/9YesZ
[[BGE]]7/9YesSO
[[BGT]]7/9YesSZO
[[BESC]]7/9YesSC
[[BEXT]]7/9Yes
$0240-$0247[[MVO|Move Out]][[MVO]]11No
$0248-$026F[[MVO@|Move Out Indirect]][[MVO@]]9NoD
$0270-$027F[[MVOI|Move Out Immediate]][[MVOI]]9NoD
$0280-$0287[[MVI|Move In]][[MVI]]10Yes
$0288-$02AF[[MVI@|Move In Indirect]][[MVI@]]8/10/11YesD
$02B0-$02BF[[MVII|Move In Immediate]][[MVII]]8/10YesD
$02C0-$02C7[[ADD|Add]][[ADD]]10YesSZOC
$02C8-$02EF[[ADD@|Add Indirect]][[ADD@]]8/10/11YesDSZOC
$02F0-$02FF[[ADDI|Add Immediate]][[ADDI]]8/10YesDSZOC
$0300-$0307[[SUB|Subtract]][[SUB]]10YesSZOC
$0308-$032F[[SUB@|Subtract Indirect]][[SUB@]]8/10/11YesDSZOC
$0330-$033F[[SUBI|Subtract Immediate]][[SUBI]]8/10YesDSZOC
$0340-$0347[[CMP|Compare]][[CMP]]10YesSZOC
$0348-$036F[[CMP@|Compare Indirect]][[CMP@]]8/10/11YesDSZOC
$0370-$037F[[CMPI|Compare Immediate]][[CMPI]]8/10YesDSZOC
$0380-$0387[[AND|And]][[AND]]10YesSZ
$0388-$03AF[[AND@|And Indirect]][[AND@]]8/10/11YesDSZ
$03B0-$03BF[[ANDI|And Immediate]][[ANDI]]8/10YesDSZ
$03C0-$03C7[[XOR|Xor]][[XOR]]10YesSZ
$03C8-$03EF[[XOR@|Xor Indirect]][[XOR@]]8/10/11YesDSZ
$03F0-$03FF[[XORI|Xor Immediate]][[XORI]]8/10YesDSZ