Skip to content
Snippets Groups Projects
Verified Commit 56ce6bc5 authored by João Magalhães's avatar João Magalhães :rocket:
Browse files

feat: initial registers support

parent 7387c805
No related branches found
No related tags found
No related merge requests found
const RAM_SIZE: usize = 8192;
pub struct Cpu { pub struct Cpu {
pc: u16, pc: u16,
sp: u16, sp: u16,
...@@ -9,9 +11,40 @@ pub struct Cpu { ...@@ -9,9 +11,40 @@ pub struct Cpu {
reg_f: u8, reg_f: u8,
reg_h: u8, reg_h: u8,
reg_l: u8, reg_l: u8,
ram: [u8; RAM_SIZE],
} }
impl Cpu { impl Cpu {
pub fn new() -> Cpu {
Cpu {
pc: 0x0,
sp: 0x0,
reg_a: 0x0,
reg_b: 0x0,
reg_c: 0x0,
reg_d: 0x0,
reg_e: 0x0,
reg_f: 0x0,
reg_h: 0x0,
reg_l: 0x0,
ram: [0u8; RAM_SIZE],
}
}
pub fn clock(&mut self) {
// fetches the current instruction and increments
// the PC (program counter) accordingly
let instruction = self.ram[self.pc as usize];
self.pc += 1;
let opcode = instruction & 0xf000;
let address = instruction & 0x0fff;
let x = ((instruction & 0x0f00) >> 8) as usize;
let y = ((instruction & 0x00f0) >> 4) as usize;
let nibble = (instruction & 0x000f) as u8;
let byte = (instruction & 0x00ff) as u8;
}
#[inline(always)] #[inline(always)]
fn reg_af(&self) -> u16 { fn reg_af(&self) -> u16 {
(self.reg_a as u16) << 8 | self.reg_f as u16 (self.reg_a as u16) << 8 | self.reg_f as u16
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment