The executor is coming along.

Graphics and sound related instructions are gonna remain unimplemented for a while as I focus on getting the generic CPU up, then a ROM buffer and eventually working out how to graphics.
This commit is contained in:
abbie 2022-02-18 17:21:01 +00:00
parent fd3a499b52
commit 668d938097
No known key found for this signature in database
GPG key ID: 04DDE463F9200F87
2 changed files with 38 additions and 2 deletions

View file

@ -1,6 +1,6 @@
[package]
name = "celc8"
version = "0.1.0"
version = "0.1.1"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View file

@ -28,6 +28,9 @@ impl Cpu {
fn indwrite(&mut self, value: u16) {
self.i = value;
}
fn incrementpc(&mut self) {
self.pc = self.pc + 2
}
}
struct Instruction {
@ -198,11 +201,44 @@ fn decodetest(opcode: u16, expected: &str) {
}
}
fn execute(opcode: u16, instruction: Instruction, mut cpu: Cpu) -> Cpu {
let mut args: Vec<u16> = vec![];
let mut i = 0;
if instruction.masks.len() != 0 {
for mask in instruction.masks {
let shift = instruction.shifts[i];
args.push((opcode & mask) >> shift);
i = i + 1;
}
}
if instruction.name == "LD_VX_BYTE" {
cpu.regwrite(args[0] as usize, args[1] as u8);
cpu.incrementpc();
}
else { println!("Unimplemented instruction {}. Skipping.", instruction.name) }
return cpu;
}
fn main() {
let mut cpu = Cpu { memory: vec![0; 4096], pc: 0x200, registers: vec![0;16], i: 0, stack: vec![0; 16], sp: -1, dt: 0, st: 0 };
let mut cpu = Cpu { memory: vec![0; 4096], pc: 0x200, registers: vec![0; 16], i: 0, stack: vec![0; 16], sp: -1, dt: 0, st: 0 };
println!("CPU initialised!");
torture();
println!("If you see messages above that are about opcodes, there's a bug!");
println!("Executing LD_VX_BYTE with opcode 0x6010, register 0 should be 16.");
let mut opcode = 0x6010;
let mut instruction = disassemble(opcode);
cpu = execute(opcode, instruction, cpu);
println!("Register 0 is {}!", cpu.registers[0]);
println!("Executing CLS which is not implemented. There should be an unimplemented error.");
opcode = 0x00e0;
instruction = disassemble(opcode);
cpu = execute(opcode, instruction, cpu);
}
fn torture() {