Skip to content

Commit

Permalink
rename rom module to cartridge
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanballs committed Sep 9, 2024
1 parent 27ba2ac commit 90c1e05
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/gameboy/debugger.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use core::fmt;
use std::io::{self, Write};

use crate::{instructions::parse, mmu::rom::GBCHeader};
use crate::{instructions::parse, mmu::cartridge::CartridgeHeader};

use super::GameBoy;
use colored::*;
Expand All @@ -19,6 +19,7 @@ fn parse_number(s: &str) -> Option<u16> {
impl GameBoy {
pub fn debugger_cli(&mut self) {
println!("{}", self.format_instruction());

loop {
print!("{}", ">>> ".cyan());
let _ = io::stdout().flush();
Expand Down Expand Up @@ -52,7 +53,7 @@ impl GameBoy {
println!("UNSUPPORTED")
}

"ro" | "rom" => println!("{:#?}", &GBCHeader::new(&self.mmu.rom)),
"ro" | "rom" => println!("{:#?}", &CartridgeHeader::new(&self.mmu.rom)),

"r" | "registers" => println!("{:#?}", self.cpu.registers),

Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub mod mmu;
mod renderer;

use colored::*;
use mmu::rom::GBCHeader;
use mmu::cartridge::CartridgeHeader;
use std::fs::File;
use std::io::Read;
use std::process::exit;
Expand All @@ -23,7 +23,7 @@ fn main() {
let (tx, rx) = mpsc::channel::<PPU>();
let (tx_key, rx_key) = mpsc::channel::<(bool, Key)>();
let rom = read_file_to_bytes("roms/tetris.gb").unwrap();
let game_title = GBCHeader::new(&rom).unwrap().title();
let game_title = CartridgeHeader::new(&rom).unwrap().title();

let _ = thread::spawn(move || emulator_loop(rom, tx, rx_key));
window_loop(rx, tx_key, &game_title);
Expand Down
8 changes: 4 additions & 4 deletions src/mmu/rom.rs → src/mmu/cartridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::fmt;
use std::slice;

#[repr(C, packed)]
pub struct GBCHeader {
pub struct CartridgeHeader {
padding: [u8; 0x100],
entry_point: [u8; 4],
nintendo_logo: [u8; 48],
Expand All @@ -21,13 +21,13 @@ pub struct GBCHeader {
global_checksum: [u8; 2],
}

impl GBCHeader {
impl CartridgeHeader {
pub fn new(data: &[u8]) -> Result<Self, &'static str> {
if data.len() < 0x150 {
return Err("Data is too short for a valid GBC header");
}

Ok(unsafe { std::ptr::read(data.as_ptr() as *const GBCHeader) })
Ok(unsafe { std::ptr::read(data.as_ptr() as *const CartridgeHeader) })
}

pub fn title(&self) -> String {
Expand Down Expand Up @@ -76,7 +76,7 @@ impl GBCHeader {
}
}

impl fmt::Debug for GBCHeader {
impl fmt::Debug for CartridgeHeader {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("GBCHeader")
.field("title", &self.title())
Expand Down
2 changes: 1 addition & 1 deletion src/mmu/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub mod bootrom;
pub mod cartridge;
pub mod joypad;
pub mod ppu;
pub mod rom;
pub mod timer;

use bootrom::BOOT_ROM;
Expand Down

0 comments on commit 90c1e05

Please sign in to comment.