[][src]Struct virt_ic::chip::cpu::SimpleCPU

pub struct SimpleCPU { /* fields omitted */ }

A simple example CPU

  • 4M of address space (12 ADDR pins)
  • 8-bit IO Pins
  • 3 data register (Accumulator, B and C)
  • 2 address registers (H and L forming the full address HL)

Instructions

On startup or RESET, the CPU will fetch the boot address at 0xFFD and 0xFFE.
The Addresses are stored in this order : MSD, LSD, so 0x0F and 0x12 will create address 0xF12.

The stack pointer will be initialized in the bank specified at 0xFFF.
If 0xFFF contains 0x0E, the CPU will use 0x0E00 to 0x0EFF for his stack.
Note that the bank can't go beyond 0x0F since the CPU only has a 12-bit address space.

TODO: Implement IRQ
On IRQ, the CPU will fetch the Interrupt code address at 0xFFB and 0xFFC.
When IRQ is triggered, the Address at 0xFFC and 0xFFD will be used as a JSR opcode.
To return to the main code, you'll just need to execute a RTN opcode.

Opcodes

MSD\LSDx0x1x2x3x4x5x6x7x8x9xAxBxCxDxExF
0xHLTINADEAINLDELCLCADBADCTABTBATACTCATAHTHATALTLA0x
1xPHAPLAPHLPLLCPBCPCSUBSUCSALSAR1x
2xJMLJSLRTN2x
3x3x
4xSTASTBSTCLDBLDCLDALDALDA4x
5xLDALDALDALDALDBLDBLDCLDCSTASTASTASTBSTC5x
6xCMPCPBCPC6x
7x7x
8x8x
9x9x
AxAx
BxJMPJSRBCFBNFBZFBx
CxLDASTACx
DxDx
ExEx
FxFx
-x0x1x2x3x4x5x6x7x8x9xAxBxCxDxExF
OpcodeParametersDescription
HLT (0x00)-Halts the CPU
INA (0x01)-Increments the accumulator
DEA (0x02)-Decrements the accumulator
INL (0x03)-Increments the HL register
DEL (0x04)-Decrements the HL register
CLC (0x05)-Clear the Carry flag
ADB (0x06)-Add B to Accumulator
ADC (0x07)-Add C to Accumulator
TAB (0x08)-Transfer Accumulator into B register
TBA (0x09)-Transfer B register into Accumulator
TAC (0x0A)-Transfer Accumulator into C register
TCA (0x0B)-Transfer C register into Accumulator
TAH (0x0C)-Transfer Accumulator into H register
THA (0x0D)-Transfer H register into Accumulator
TAL (0x0E)-Transfer Accumulator into L register
TLA (0x0F)-Transfer L register into Accumulator
PHA (0x10)-Push the accumulator's value in the stack
PLA (0x11)-Pull the stack value in the accumulator
PHL (0x12)-Push the HL's value in the stack
PLL (0x13)-Pull two bytes from the stack in the HL register
CPB (0x14)-Compare B with the Accumulator
CPC (0x15)-Compare C with the Accumulator
SUB (0x16)-Substract B to accumulator
SUC (0x17)-Substract C to accumulator
SAL (0x18)-Shift Accumulator Left
SAR (0x19)-Shift Accumulator Right
INB (0x1A)-Increments the B register
DEB (0x1B)-Decrements the B register
INC (0x1C)-Increments the C register
DEC (0x1D)-Decrements the C register
---
JML (0x20)-Jumps to the address HL
JSL (0x21)-Jumps to subroutine at address HL
RTN (0x22)-Return from SubRoutine
---
STA (0x48)-Stores the value of accumulator into address [HL]
STB (0x49)-Stores the value of B register into address [HL]
STC (0x4A)-Stores the value of C register into address [HL]
LDB (0x4B)-Loads the value of address [HL] into the B register
LDC (0x4C)-Loads the value of address [HL] into the C register
LDA (0x4D)-Loads the value of address [HL] into the accumulator
LDA (0x4E)-Loads the value of address [HL]+B into the accumulator
LDA (0x4F)-Loads the value of address [HL]+C into the accumulator
LDA (0x50)$1: numberLoads $1 into the accumulator
LDA (0x51)[$1]: zero page addressLoads the value of address 0x0$1 into the accumulator
LDA (0x52)$1: numberLoads the value of address H0 + $1 into the accumulator
LDA (0x53)$1: numberLoads the value of address HL + $1 into the accumulator
LDB (0x54)$1: numberLoads $1 into the B register
LDB (0x55)[$1]: zero page addressLoads the value of address 0x0$1 into the B register
LDC (0x56)$1: numberLoads $1 into the C register
LDC (0x57)[$1]: zero page addressLoads the value of address 0x0$1 into the C register
STA (0x58)[$1]: zero page addressStores the value of Accumulator into address 0x0$1
STA (0x59)$1: numberStores the value of Accumulator into address H0 + $1
STA (0x5A)$1: numberStores the value of Accumulator into address HL + $1
STB (0x5B)[$1]: zero page addressStores the value of B register into address 0x0$1
STC (0x5C)[$1]: zero page addressStores the value of C register into address 0x0$1
---
CMP (0x60)$1: numberCompares the accumulator with $1
CPB (0x61)$1: numberCompares the B register with $1
CPC (0x62)$1: numberCompares the C register with $1
---
JMP (0xB0)$1$2: addressJumps to the address $1$2
JSR (0xB1)$1$2: addressJumps to subroutine at address $1$2
BCF (0xB2)$1$2: addressBranch on Carry flag
BNF (0xB3)$1$2: addressBranch on Negative flag
BZF (0xB4)$1$2: addressBranch on Zero flag
---
LDA (0xC0)$1$2: addressLoad the value of address $1$2 in the accumulator
STA (0xC1)$1$2: addressStore the value of accumulator into address $1$2

diagram

IRQ: Interrupt Request (active low) RESET: Reset (active low) R/!W: Read Write mode CLOCK: Clock pin A0-9: Addresses IO0-7: Input/Output

       ---__---
  A0 --|1   26|-- VCC
  A1 --|2   25|-- R/!W
  A2 --|3   24|-- IO7
  A3 --|4   23|-- IO6
  A4 --|5   22|-- IO5
  A5 --|6   21|-- IO4
  A6 --|7   20|-- IO3
  A7 --|8   19|-- IO2
  A8 --|9   18|-- IO1
  A9 --|10  17|-- IO0
 A10 --|11  16|-- !IRQ
 A11 --|12  15|-- !RESET
 GND --|13  14|-- CLOCK
       --------

Implementations

impl SimpleCPU[src]

pub const A0: u8[src]

pub const A1: u8[src]

pub const A2: u8[src]

pub const A3: u8[src]

pub const A4: u8[src]

pub const A5: u8[src]

pub const A6: u8[src]

pub const A7: u8[src]

pub const A8: u8[src]

pub const A9: u8[src]

pub const A10: u8[src]

pub const A11: u8[src]

pub const CLOCK: u8[src]

pub const RESET: u8[src]

pub const IRQ: u8[src]

pub const IO0: u8[src]

pub const IO1: u8[src]

pub const IO2: u8[src]

pub const IO3: u8[src]

pub const IO4: u8[src]

pub const IO5: u8[src]

pub const IO6: u8[src]

pub const IO7: u8[src]

pub const RW: u8[src]

pub const VCC: u8[src]

pub const GND: u8[src]

pub fn new() -> Self[src]

Trait Implementations

impl Chip for SimpleCPU[src]

impl Debug for SimpleCPU[src]

impl Default for SimpleCPU[src]

Auto Trait Implementations

impl !RefUnwindSafe for SimpleCPU

impl !Send for SimpleCPU

impl !Sync for SimpleCPU

impl Unpin for SimpleCPU

impl !UnwindSafe for SimpleCPU

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,