diff --git a/src/cpu.rs b/src/cpu.rs index 1376fa8..c2e49ea 100644 --- a/src/cpu.rs +++ b/src/cpu.rs @@ -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 diff --git a/src/main.rs b/src/main.rs index fd4e778..8a7a6dd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,8 @@ use clap::{Parser}; use crate::cpu::{CPU, GBMode}; mod cpu; +mod registers; +mod mode; #[derive(Parser)] struct Args { diff --git a/src/mode.rs b/src/mode.rs new file mode 100644 index 0000000..00de0a3 --- /dev/null +++ b/src/mode.rs @@ -0,0 +1,4 @@ +pub enum GBMode { + Classic, + Color, +} \ No newline at end of file diff --git a/src/registers.rs b/src/registers.rs new file mode 100644 index 0000000..57cb35f --- /dev/null +++ b/src/registers.rs @@ -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!") + } + } +} \ No newline at end of file