cool stuff for memory

This commit is contained in:
abbie 2022-02-18 18:53:07 +00:00
parent 668d938097
commit afdc8c458d
No known key found for this signature in database
GPG key ID: 04DDE463F9200F87
2 changed files with 10 additions and 9 deletions

2
Cargo.lock generated
View file

@ -4,4 +4,4 @@ version = 3
[[package]] [[package]]
name = "celc8" name = "celc8"
version = "0.1.0" version = "0.1.1"

View file

@ -22,15 +22,18 @@ impl Cpu {
fn regwrite(&mut self, index: usize, value: u8) { fn regwrite(&mut self, index: usize, value: u8) {
self.registers[index] = value; self.registers[index] = value;
} }
fn indread(&self) -> &u16 { fn iread(&self) -> &u16 {
&self.i &self.i
} }
fn indwrite(&mut self, value: u16) { fn iwrite(&mut self, value: u16) {
self.i = value; self.i = value;
} }
fn incrementpc(&mut self) { fn incrementpc(&mut self) {
self.pc = self.pc + 2 self.pc = self.pc + 2
} }
fn fetch(&mut self) -> u16 {
return ((self.memory[self.pc as usize] as u16) << 8 | self.memory[self.pc as usize + 1 as usize] as u16)
}
} }
struct Instruction { struct Instruction {
@ -229,16 +232,14 @@ fn main() {
torture(); torture();
println!("If you see messages above that are about opcodes, there's a bug!"); 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."); println!("Executing LD_VX_BYTE with opcode 0x6010 through memory.");
let mut opcode = 0x6010; cpu.memory[0x200] = 0x60;
cpu.memory[0x201] = 0x10;
let mut opcode = cpu.fetch();
let mut instruction = disassemble(opcode); let mut instruction = disassemble(opcode);
cpu = execute(opcode, instruction, cpu); cpu = execute(opcode, instruction, cpu);
println!("Register 0 is {}!", cpu.registers[0]); 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() { fn torture() {