From fc710000a4017dd8060b9d88db5ac50e4204e58c Mon Sep 17 00:00:00 2001 From: Nick Krichevsky Date: Fri, 1 Apr 2022 18:10:56 -0400 Subject: [PATCH] Initial commit. Add registers --- .gitignore | 1 + Cargo.lock | 7 +++++++ Cargo.toml | 8 ++++++++ src/lib.rs | 3 +++ src/main.rs | 3 +++ src/register.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 68 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 src/lib.rs create mode 100644 src/main.rs create mode 100644 src/register.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..12e2cc3 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ferris-boi" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..f874040 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "ferris-boi" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..ef1a3bf --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,3 @@ +#![warn(clippy::all, clippy::pedantic)] + +mod register; diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/src/register.rs b/src/register.rs new file mode 100644 index 0000000..b57be83 --- /dev/null +++ b/src/register.rs @@ -0,0 +1,46 @@ +//! The register module Holds the basic [`Registers`] type and functions needed +//! to access/manipulate them + +const INITIAL_PROGRAM_COUNTER_VALUE: u16 = 0x100; + +/// Registers holds all of the registers for the Gameboy +#[derive(Debug, Clone)] +pub struct Registers { + pub a: u8, + pub b: u8, + pub c: u8, + pub d: u8, + pub e: u8, + pub f: u8, + pub h: u8, + pub l: u8, + pub stack_pointer: u16, + pub program_counter: u16, + flags: u8, +} + +impl Registers { + pub fn new() -> Self { + Self::default() + } +} + +impl Default for Registers { + fn default() -> Self { + // TODO: verify that these 0 values are correct. I feel like they must + // be, but I haven't read enough of the manual + Registers { + a: 0, + b: 0, + c: 0, + d: 0, + e: 0, + f: 0, + h: 0, + l: 0, + stack_pointer: 0, + program_counter: INITIAL_PROGRAM_COUNTER_VALUE, + flags: 0, + } + } +}