class

CPU

Inherits Reference < Object

Constants

ADD = StaticArray[F1, F2, MC::IO | MC::MI, MC::RO | MC::BI, (MC::EO | MC::AI) | MC::FI]
ADI = StaticArray[F1, F2, MC::IO | MC::BI, (MC::EO | MC::AI) | MC::FI, MC::None]
CMP = StaticArray[F1, F2, MC::IO | MC::MI, ((MC::RO | MC::BI) | MC::SU) | MC::FI, MC::None]
F1 = MC::CO | MC::MI

Fetch instruction microcode

F2 = (MC::RO | MC::II) | MC::CE
HLT = StaticArray[F1, F2, MC::HLT, MC::None, MC::None]
JC = StaticArray[F1, F2, MC::IO | MC::JC, MC::None, MC::None]
JMP = StaticArray[F1, F2, MC::IO | MC::J, MC::None, MC::None]
JPA = StaticArray[F1, F2, MC::AO | MC::J, MC::None, MC::None]
JZ = StaticArray[F1, F2, MC::IO | MC::JZ, MC::None, MC::None]
LABEL_REGEX = /^(?<label>[a-z\_\d]+)\:/i
LDA = StaticArray[F1, F2, MC::IO | MC::MI, MC::RO | MC::AI, MC::None]
LDI = StaticArray[F1, F2, MC::IO | MC::AI, MC::None, MC::None]
LSR = StaticArray[F1, F2, MC::SR | MC::FI, MC::None, MC::None]
NOP = StaticArray[F1, F2, MC::None, MC::None, MC::None]

Opcodes

OUT = StaticArray[F1, F2, MC::AO | MC::OI, MC::None, MC::None]
ROM = Slice[NOP, LDA, ADD, SUB, STA, LDI, JMP, JC, JZ, ADI, JPA, CMP, LSR, SBI, OUT, HLT]

Set opcodes in micro-code ROM

SBI = StaticArray[F1, F2, MC::IO | MC::BI, ((MC::EO | MC::SU) | MC::AI) | MC::FI, MC::None]
STA = StaticArray[F1, F2, MC::IO | MC::MI, MC::AO | MC::RI, MC::None]
SUB = StaticArray[F1, F2, MC::IO | MC::MI, MC::RO | MC::BI, ((MC::EO | MC::AI) | MC::SU) | MC::FI]
SYM_REGEX = /\:(?<label>[a-z\_\d]+)/i

Constructors

new(prog : String, options : Options | Nil = nil)

Initialize from un-assembled program

Source
new(ram : Bytes, options : Options | Nil = nil)

Initialize from assembled program

Source

Class methods

asm(line : String)

Assemble instruction

Source
assemble(prog : String)

Assemble a program

Source
dasm(instr : UInt8)

Disassemble instruction

Source

Instance methods

address
Source
address=(address : UInt8)
Source
bus_receive
Source
bus_transfer

Based on the control word, transfer data onto the bus

Source
control
Source
flags

Get the current state of the flags Note: this is latched to @reg_f on MC::FI

Source
mc_step
Source
options
Source
options=(options : Options)
Source
program_counter
Source
ram=(ram : Bytes)
Source
reg_a
Source
reg_b
Source
reg_e

ALU

Source
reg_f
Source
reg_i
Source
reg_o
Source
run

Run the main loop

Source
set_instruction

Fetch an instruction and increment the micro-code step

Source
step
Source

Nested types