Cpu.Processorprocessor.ml - CPU logic
type processor = {regs : Registers.registers;mem : Memory.Vmem.mem_ctrl;ih : Interrupts.interrupt_handler;halted : bool Stdlib.ref;}Emulates CPU state
val _init_processor : Memory.Vmem.mem_ctrl -> processorReturns an initialized CPU state
val read_byte : processor -> charRead the next byte at position (PC) and increment PC
val read_word : processor -> intRead the next word (2 bytes) at position (PC) and increment PC twice
val is_flag_set : processor -> int -> boolCheck if a specific flag is set in the F register
val is_flag_set_b : processor -> int -> intCheck if a specific flag is set in the F register - returns an int
val set_flag : processor -> int -> bool -> unitSet a flag in the F register
val rp_table_read : int -> Registers.registers -> Utils.U16.u16Get the register read function corresponding to rpn
val rp_table_write : int -> Registers.registers -> int -> unitGet the register write function corresponding to rpn
val r_table_read :
processor ->
int ->
int * (Registers.registers -> Utils.U8.u8)Get the register read function corresponding to r[n]
val r_table_write : processor -> int -> char -> unitGet the register write function corresponding to rn
val push : processor -> int -> unitPush 16 bits onto the stack
val push_rp2 : processor -> int -> unitPush 16 bits onto the stack from a set register in the RP2 table
val pop : processor -> intPop 16 bits from the stack
val pop_rp2 : processor -> int -> unitPop 16 bits from the stack and load them into a set register in the RP2 table
val halt : processor -> intHalts the CPU
val jp : processor -> int -> unitUnconditional jump
val jr : processor -> int -> unitUnconditional relative jump
val jp_cond : processor -> int -> int -> intConditional jump
jp_cond cpu cond address
val jr_cond : processor -> int -> int -> intConditional relative jump
jr_cond cpu cond offset
val call : processor -> int -> unitCall
call cpu new_pc
val call_cond : processor -> int -> int -> intConditional call
call cpu new_pc cond
val ret : processor -> unitReturn
val ret_cond : processor -> int -> intConditional return
val rst : processor -> int -> intRestart
val alu : processor -> int -> Utils.U8.u8 -> intALU table
alu cpu table_idx operand
val rotate_left : processor -> char -> bool -> bool -> charLeftward bit-rotation operation
rotate_left cpu to_rotate include_carry update_zero
val rotate_right : processor -> char -> bool -> bool -> charRightward bit-rotation operation
rotate_right cpu to_rotate include_carry update_zero
val shift_left : processor -> char -> charLeft bitshift
shift_left cpu to_shift
val shift_right : processor -> char -> bool -> charRight bitshift
shift_left cpu to_shift keep_msb
val swap : processor -> char -> charSwaps the highest MSBs and lowest MSBs
swap cpu to_swap
val bit : processor -> char -> int -> unitTest a bit bit cpu value bit_to_test
val rot : processor -> int -> int -> intRotation table ROT
val decode_execute : processor -> char -> intGeneral decoder
Layout is based on this table
Returns the number of cycles taken to execute the provided instruction
val de_step : processor -> intPerforms one step of the decode-execute cycle