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

feat: better display of information

parent 45b6f484
No related branches found
No related tags found
No related merge requests found
Pipeline #949 passed
...@@ -87,9 +87,10 @@ fn main() { ...@@ -87,9 +87,10 @@ fn main() {
//game_boy.load_rom_file("../../res/roms.prop/tetris.gb"); //game_boy.load_rom_file("../../res/roms.prop/tetris.gb");
//game_boy.load_rom_file("../../res/roms.prop/dr_mario.gb"); //game_boy.load_rom_file("../../res/roms.prop/dr_mario.gb");
//game_boy.load_rom_file("../../res/roms.prop/alleyway.gb"); //game_boy.load_rom_file("../../res/roms.prop/alleyway.gb");
game_boy.load_rom_file("../../res/roms.prop/super_mario.gb");
//game_boy.load_rom_file("../../res/roms/firstwhite.gb"); //game_boy.load_rom_file("../../res/roms/firstwhite.gb");
game_boy.load_rom_file("../../res/roms/opus5.gb"); //game_boy.load_rom_file("../../res/roms/opus5.gb");
//game_boy.load_rom_file("../../res/roms/paradius/cpu/01-special.gb"); // PASSED //game_boy.load_rom_file("../../res/roms/paradius/cpu/01-special.gb"); // PASSED
//game_boy.load_rom_file("../../res/roms/paradius/cpu/02-interrupts.gb"); // PASSED //game_boy.load_rom_file("../../res/roms/paradius/cpu/02-interrupts.gb"); // PASSED
......
...@@ -4,6 +4,7 @@ use crate::{ ...@@ -4,6 +4,7 @@ use crate::{
mmu::Mmu, mmu::Mmu,
pad::{Pad, PadKey}, pad::{Pad, PadKey},
ppu::{Ppu, Tile, FRAME_BUFFER_SIZE}, ppu::{Ppu, Tile, FRAME_BUFFER_SIZE},
rom::Rom,
timer::Timer, timer::Timer,
util::read_file, util::read_file,
}; };
...@@ -69,6 +70,8 @@ impl GameBoy { ...@@ -69,6 +70,8 @@ impl GameBoy {
} }
pub fn load_rom(&mut self, data: &[u8]) { pub fn load_rom(&mut self, data: &[u8]) {
let rom = Rom::from_data(data);
println!("{}", rom);
self.cpu.mmu().write_rom(0x0000, data); self.cpu.mmu().write_rom(0x0000, data);
} }
......
...@@ -113,7 +113,7 @@ impl Display for ObjectData { ...@@ -113,7 +113,7 @@ impl Display for ObjectData {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!( write!(
f, f,
"Index => {} X => {} Y => {} Tile => {}", "Index => {}\nX => {}\nY => {}\nTile => {}",
self.index, self.x, self.y, self.tile self.index, self.x, self.y, self.tile
) )
} }
......
use core::fmt;
use std::fmt::{Display, Formatter};
pub struct Rom { pub struct Rom {
data: Vec<u8>, data: Vec<u8>,
} }
pub enum RomType { pub enum RomType {
RomOnly = 0x00, RomOnly = 0x00,
Mbc1 = 0x01, Mbc1 = 0x01,
...@@ -12,12 +14,58 @@ pub enum RomType { ...@@ -12,12 +14,58 @@ pub enum RomType {
Unknown = 0xff, Unknown = 0xff,
} }
pub enum RomSize {
Size32K = 32,
Size64K = 64,
Size128K = 128,
SizeUnknown = 0,
}
impl Rom { impl Rom {
pub fn title() -> &'static str { pub fn from_data(data: &[u8]) -> Self {
"asdas" Self {
data: data.to_vec(),
}
} }
pub fn rom_type() -> RomType { pub fn data(&self) -> &Vec<u8> {
RomType::RomOnly &self.data
}
pub fn title(&self) -> &str {
std::str::from_utf8(&self.data[0x0134..0x0143]).unwrap()
}
pub fn rom_type(&self) -> RomType {
match self.data[0x0147] {
0x00 => RomType::RomOnly,
0x01 => RomType::Mbc1,
0x02 => RomType::Mbc1Ram,
0x03 => RomType::Mbc1RamBattery,
0x05 => RomType::Mbc2,
0x06 => RomType::Mbc2Battery,
_ => RomType::Unknown,
}
}
pub fn size(&self) -> RomSize {
match self.data[0x0148] {
0x00 => RomSize::Size32K,
0x01 => RomSize::Size64K,
0x02 => RomSize::Size128K,
_ => RomSize::SizeUnknown,
}
}
}
impl Display for Rom {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(
f,
"Name => {}\nType => {}\nSize => {}",
self.title(),
self.rom_type() as u8,
self.size() as u32
)
} }
} }
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