Skip to content

Commit

Permalink
Start of implementing BRK instruction in emulator
Browse files Browse the repository at this point in the history
  • Loading branch information
Granddave committed Dec 23, 2023
1 parent ece32a3 commit c1cab75
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions src/emulator/cpu.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::{
assembler::compiler::opcode::OPCODE_MAPPING,
ast::{ASTAddressingMode, ASTInstructionNode, ASTOperand},
ast::{ASTAddressingMode, ASTInstructionNode, ASTMnemonic, ASTOperand},
emulator::memory::Bus,
};

#[derive(Debug)]
#[derive(Debug, Default)]
struct Status {
carry: bool,
zero: bool,
Expand All @@ -15,7 +15,7 @@ struct Status {
negative: bool,
}

#[derive(Debug)]
#[derive(Debug, Default)]
pub struct Cpu {
a: u8,
x: u8,
Expand All @@ -25,12 +25,6 @@ pub struct Cpu {
status: Status,
}

impl Default for Cpu {
fn default() -> Self {
Self::new()
}
}

impl Cpu {
pub fn new() -> Self {
Self::default()
Expand Down Expand Up @@ -67,13 +61,26 @@ impl Cpu {
instruction
}

pub fn run(&mut self, _memory: &mut dyn Bus, _cycles: usize) {
todo!();
// while cycles > 0 {
// let instruction = self.fetch_and_decode(memory)
//
// println!("{:?}", instruction);
// }
fn execute_instruction(
&mut self,
ins: ASTInstructionNode,
_memory: &mut dyn Bus,
_cycles: &mut usize,
) {
match ins.ins.mnemonic {
ASTMnemonic::BRK => {
self.pc += 1;
panic!("BRK");
}
_ => panic!("Invalid instruction: '{:#?}'", ins.ins.mnemonic),
}
}

pub fn run(&mut self, memory: &mut dyn Bus, mut cycles: usize) {
while cycles > 0 {
let instruction = self.fetch_and_decode(memory);
self.execute_instruction(instruction, memory, &mut cycles);
}
}
}

Expand Down

0 comments on commit c1cab75

Please sign in to comment.