Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arrange the log handling #105

Merged
merged 1 commit into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ Coming soon!

### Optional flags

* `--log` - Print logs in debug mode to a file
* `--file-audio` - Saves the audio to a file
* `--full-screen` - Full screen mode
* `--no-vsync` - Disable vsync
Expand Down
2 changes: 1 addition & 1 deletion gb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ path = "src/main.rs"
lib_gb = {path = "../lib_gb/"}
image_inter = {path = "../image_inter", optional = true}
bcm_host = {path = "../bcm_host", optional = true}
log = "0.4"
log = {version = "0.4", features = ["max_level_debug", "release_max_level_info"]}
fern = "0.6"
chrono = "0.4"
sdl2 = {version = "0.35", optional = true}
Expand Down
19 changes: 5 additions & 14 deletions gb/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,8 @@ cfg_if::cfg_if!{
}
}

fn init_logger(debug:bool)->Result<(), fern::InitError>{
let level = if debug {log::LevelFilter::Debug} else {log::LevelFilter::Info};
let mut fern_logger = fern::Dispatch::new()
fn init_logger()->Result<(), fern::InitError>{
let fern_logger = fern::Dispatch::new()
.format(|out, message, record| {
out.finish(format_args!(
"{}[{}] {}",
Expand All @@ -106,14 +105,8 @@ fn init_logger(debug:bool)->Result<(), fern::InitError>{
message
))
})
.level(level);

if !debug{
fern_logger = fern_logger.chain(std::io::stdout());
}
else{
fern_logger = fern_logger.chain(fern::log_file("output.log")?);
}
.chain(std::io::stdout())
.chain(fern::log_file("output.log")?);

fern_logger.apply()?;

Expand Down Expand Up @@ -162,10 +155,8 @@ static mut RUNNING:bool = true;

fn main() {
let args: Vec<String> = env::args().collect();

let debug_level = check_for_terminal_feature_flag(&args, "--log");

match init_logger(debug_level){
match init_logger(){
Result::Ok(())=>{},
Result::Err(error)=>std::panic!("error initing logger: {}", error)
}
Expand Down
24 changes: 9 additions & 15 deletions lib_gb/src/machine/gameboy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::{
ppu::gfx_device::GfxDevice, keypad::joypad_provider::JoypadProvider
};
use std::boxed::Box;
use log::debug;

//CPU frequrncy: 4,194,304 / 59.727~ / 4 == 70224 / 4
pub const CYCLES_PER_FRAME:u32 = 17556;
Expand Down Expand Up @@ -67,20 +66,15 @@ impl<'a, JP:JoypadProvider, AD:AudioDevice, GFX:GfxDevice> GameBoy<'a, JP, AD, G
fn execute_opcode(&mut self)->u8{
let pc = self.cpu.program_counter;

//debug
if self.mmu.io_bus.finished_boot{
let a = *self.cpu.af.high();
let b = *self.cpu.bc.high();
let c = *self.cpu.bc.low();
let d = *self.cpu.de.high();
let e = *self.cpu.de.low();
let f = *self.cpu.af.low();
let h = *self.cpu.hl.high();
let l = *self.cpu.hl.low();
debug!("A: {:02X} F: {:02X} B: {:02X} C: {:02X} D: {:02X} E: {:02X} H: {:02X} L: {:02X} SP: {:04X} PC: 00:{:04X} ({:02X} {:02X} {:02X} {:02X})",
a,f,b,c,d,e,h,l, self.cpu.stack_pointer, pc, self.mmu.read(pc,0), self.mmu.read(pc+1,0), self.mmu.read(pc+2,0), self.mmu.read(pc+3,0));
}

log::trace!("A: {:02X} F: {:02X} B: {:02X} C: {:02X} D: {:02X} E: {:02X} H: {:02X} L: {:02X} SP: {:04X} PC: 00:{:04X} ({:02X} {:02X} {:02X} {:02X})",
{*self.cpu.af.high()}, *self.cpu.af.low(),
{*self.cpu.bc.high()}, *self.cpu.bc.low(),
{*self.cpu.de.high()}, *self.cpu.de.low(),
{*self.cpu.hl.high()}, *self.cpu.hl.low(),
self.cpu.stack_pointer, pc,
self.mmu.read(pc,0), self.mmu.read(pc+1,0), self.mmu.read(pc+2,0), self.mmu.read(pc+3,0)
);

self.cpu.run_opcode(&mut self.mmu)
}
}
Expand Down