Skip to content

Commit

Permalink
Reorganise
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacMarovitz committed Nov 14, 2023
1 parent 95c8ec8 commit 4e07010
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 51 deletions.
53 changes: 2 additions & 51 deletions src/cpu.rs
Original file line number Diff line number Diff line change
@@ -1,54 +1,5 @@
use bitflags::{bitflags};

pub struct Registers {
a: u8,
f: Flags,
b: u8,
c: u8,
d: u8,
e: u8,
h: u8,
l: u8,
pc: u16,
sp: u16,
}

bitflags! {
pub struct Flags: u8 {
const C = 0b00010000;
const H = 0b00100000;
const N = 0b01000000;
const Z = 0b10000000;
}
}

pub enum GBMode {
Classic,
Color,
ColorAsClassic,
}

impl Registers {
pub fn new(mode: GBMode) -> Registers {
match mode {
GBMode::Classic => {
Registers {
a: 0x01,
f: Flags::C | Flags::H | Flags::Z,
b: 0x00,
c: 0x13,
d: 0x00,
e: 0xD8,
h: 0x01,
l: 0x4D,
pc: 0x0100,
sp: 0xFFFE
}
},
_ => panic!("Mode not yet supported!")
}
}
}
use crate::mode::GBMode;
use crate::registers::Registers;

pub struct CPU {
reg: Registers
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use clap::{Parser};
use crate::cpu::{CPU, GBMode};

mod cpu;
mod registers;
mod mode;

#[derive(Parser)]
struct Args {
Expand Down
4 changes: 4 additions & 0 deletions src/mode.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub enum GBMode {
Classic,
Color,
}
46 changes: 46 additions & 0 deletions src/registers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use bitflags::{bitflags};
use crate::mode::GBMode;

pub struct Registers {
a: u8,
f: Flags,
b: u8,
c: u8,
d: u8,
e: u8,
h: u8,
l: u8,
pc: u16,
sp: u16,
}

bitflags! {
pub struct Flags: u8 {
const C = 0b00010000;
const H = 0b00100000;
const N = 0b01000000;
const Z = 0b10000000;
}
}

impl Registers {
pub fn new(mode: GBMode) -> Registers {
match mode {
GBMode::Classic => {
Registers {
a: 0x01,
f: Flags::C | Flags::H | Flags::Z,
b: 0x00,
c: 0x13,
d: 0x00,
e: 0xD8,
h: 0x01,
l: 0x4D,
pc: 0x0100,
sp: 0xFFFE
}
},
_ => panic!("Mode not yet supported!")
}
}
}

0 comments on commit 4e07010

Please sign in to comment.