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

chore: better printing support for specs

Will allow much better debug.
parent 71a51c80
No related branches found
No related tags found
1 merge request!16Support for Game Boy Color (CGB) 😎🖍️
Pipeline #2591 failed
......@@ -8,7 +8,6 @@ use audio::Audio;
use boytacean::{
devices::printer::PrinterDevice,
gb::{AudioProvider, GameBoy, GameBoyMode},
gen::VERSION,
pad::PadKey,
ppu::{PaletteInfo, PpuMode, DISPLAY_HEIGHT, DISPLAY_WIDTH},
};
......@@ -472,15 +471,6 @@ fn main() {
let args = Args::parse();
let mode = GameBoyMode::from_str(&args.mode);
// prints the current version of the emulator (informational message)
println!("========= Boytacean =========");
println!("Version {}", VERSION);
println!("Mode {}", mode);
println!("CPU Freq. 4.34 Mhz");
println!("RAM Size 32 KB");
println!("ROM Size 32 KB");
println!("VRAM Size 32 KB");
// creates a new Game Boy instance and loads both the boot ROM
// and the initial game ROM to "start the engine"
let mut game_boy = GameBoy::new(mode);
......@@ -499,6 +489,9 @@ fn main() {
game_boy.attach_serial(printer);
game_boy.load(true);
// prints the current version of the emulator (informational message)
println!("========= Boytacean =========\n{}", game_boy);
// creates a new generic emulator structure then starts
// both the video and audio sub-systems, loads default
// ROM file and starts running it
......
......@@ -3,11 +3,11 @@ use crate::{
cpu::Cpu,
data::{BootRom, CGB_BOOT, DMG_BOOT, DMG_BOOTIX, MGB_BOOTIX, SGB_BOOT},
devices::{printer::PrinterDevice, stdout::StdoutDevice},
gen::{COMPILATION_DATE, COMPILATION_TIME, COMPILER, COMPILER_VERSION},
gen::{COMPILATION_DATE, COMPILATION_TIME, COMPILER, COMPILER_VERSION, VERSION},
mmu::Mmu,
pad::{Pad, PadKey},
ppu::{Ppu, PpuMode, Tile, FRAME_BUFFER_SIZE},
rom::Cartridge,
rom::{Cartridge, RamSize},
serial::{NullDevice, Serial, SerialDevice},
timer::Timer,
util::read_file,
......@@ -591,6 +591,36 @@ impl GameBoy {
pub fn attach_printer_serial(&mut self) {
self.attach_serial(Box::<PrinterDevice>::default());
}
pub fn ram_size(&self) -> RamSize {
match self.mode {
GameBoyMode::Dmg => RamSize::Size8K,
GameBoyMode::Cgb => RamSize::Size32K,
GameBoyMode::Sgb => RamSize::Size8K,
}
}
pub fn vram_size(&self) -> RamSize {
match self.mode {
GameBoyMode::Dmg => RamSize::Size8K,
GameBoyMode::Cgb => RamSize::Size16K,
GameBoyMode::Sgb => RamSize::Size8K,
}
}
pub fn description(&self, column_length: usize) -> String {
format!(
"{} {}\n{} {}\n{} {}\n{} {}",
format!("{:width$}", "Version", width = column_length),
VERSION,
format!("{:width$}", "Mode", width = column_length),
self.mode(),
format!("{:width$}", "RAM Size", width = column_length),
self.ram_size(),
format!("{:width$}", "VRAM Size", width = column_length),
self.vram_size(),
)
}
}
/// Gameboy implementations that are meant with performance
......@@ -801,3 +831,9 @@ impl Default for GameBoy {
Self::new(GameBoyMode::Dmg)
}
}
impl Display for GameBoy {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.description(9))
}
}
use core::fmt;
use std::{
any::Any,
cmp::max,
fmt::{Display, Formatter},
};
......@@ -144,6 +145,7 @@ pub enum RamSize {
NoRam,
Unused,
Size8K,
Size16K,
Size32K,
Size64K,
Size128K,
......@@ -156,6 +158,7 @@ impl RamSize {
RamSize::NoRam => "No RAM",
RamSize::Unused => "Unused",
RamSize::Size8K => "8 KB",
RamSize::Size16K => "16 KB",
RamSize::Size32K => "32 KB",
RamSize::Size128K => "128 KB",
RamSize::Size64K => "64 KB",
......@@ -168,6 +171,7 @@ impl RamSize {
RamSize::NoRam => 0,
RamSize::Unused => 0,
RamSize::Size8K => 1,
RamSize::Size16K => 2,
RamSize::Size32K => 4,
RamSize::Size64K => 8,
RamSize::Size128K => 16,
......@@ -498,6 +502,22 @@ impl Cartridge {
pub fn set_ram_data(&mut self, ram_data: Vec<u8>) {
self.ram_data = ram_data;
}
pub fn description(&self, column_length: usize) -> String {
format!(
"{} {}\n{} {}\n{} {}\n{} {}\n{} {}",
format!("{:width$}", "Name", width = column_length),
self.title(),
format!("{:width$}", "Type", width = column_length),
self.rom_type(),
format!("{:width$}", "ROM Size", width = column_length),
self.rom_size(),
format!("{:width$}", "RAM Size", width = column_length),
self.ram_size(),
format!("{:width$}", "CGB Mode", width = column_length),
self.cgb_flag()
)
}
}
impl Default for Cartridge {
......@@ -508,15 +528,7 @@ impl Default for Cartridge {
impl Display for Cartridge {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(
f,
"Name {}\nType {}\nROM Size {}\nRAM Size {}\nCGB Mode {}",
self.title(),
self.rom_type(),
self.rom_size(),
self.ram_size(),
self.cgb_flag()
)
write!(f, "{}", self.description(9))
}
}
......
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