more code fixes

This commit is contained in:
Kevin Hamacher 2020-02-14 11:45:37 +01:00
parent 93e38d49ef
commit 99dc3210d6
9 changed files with 33 additions and 32 deletions

View File

@ -2,6 +2,7 @@
name = "gbc"
version = "0.1.0"
authors = ["Kevin Hamacher <kevin.hamacher@rub.de>"]
edition = '2018'
[dependencies]
sdl2 = "*"

View File

@ -1,4 +1,4 @@
use super::mbc::mbc::MBC;
use crate::mbc::{mbc, mbc1, mbc2, mbc3};
#[derive(Debug, PartialEq)]
enum MemoryBankControllerType {
@ -18,7 +18,7 @@ enum RamSize {
}
pub struct Cartridge {
mbc: Box<dyn super::mbc::mbc::MBC>,
mbc: Box<dyn mbc::MBC>,
savefile: Option<String>,
}
@ -57,11 +57,11 @@ impl Cartridge {
let ram = Cartridge::load_savefile(&save_file, ram_size);
let mbc: Box<dyn super::mbc::mbc::MBC> = match mbc_type {
MemoryBankControllerType::None => Box::new(super::mbc::mbc::NoMBC::new(rom, ram)),
MemoryBankControllerType::MBC1 => Box::new(super::mbc::mbc1::MBC1::new(rom, ram)),
MemoryBankControllerType::MBC2 => Box::new(super::mbc::mbc2::MBC2::new(rom, ram)),
MemoryBankControllerType::MBC3 => Box::new(super::mbc::mbc3::MBC3::new(rom, ram)),
let mbc: Box<dyn mbc::MBC> = match mbc_type {
MemoryBankControllerType::None => Box::new(mbc::NoMBC::new(rom, ram)),
MemoryBankControllerType::MBC1 => Box::new(mbc1::MBC1::new(rom, ram)),
MemoryBankControllerType::MBC2 => Box::new(mbc2::MBC2::new(rom, ram)),
MemoryBankControllerType::MBC3 => Box::new(mbc3::MBC3::new(rom, ram)),
};
Cartridge {

View File

@ -289,9 +289,9 @@ impl Interconnect {
// println!("Reading IF: {:02X}", self.interrupt_request_flags);
self.interrupt_request_flags
}
0xFF10...0xFF26 => self.sound.sound_object.lock().unwrap().read_byte(addr),
0xFF30...0xFF3F => self.sound.sound_object.lock().unwrap().read_byte(addr),
0xFF40...0xFF4B => self.display.read_byte(addr),
0xFF10..=0xFF26 => self.sound.sound_object.lock().unwrap().read_byte(addr),
0xFF30..=0xFF3F => self.sound.sound_object.lock().unwrap().read_byte(addr),
0xFF40..=0xFF4B => self.display.read_byte(addr),
0xFF50 => self.disable_bootrom,
0xFF51 => self.vram_dma_source_high,
0xFF52 => self.vram_dma_source_low,
@ -345,14 +345,14 @@ impl Interconnect {
0xFF0F => {
self.interrupt_request_flags = val;
}
0xFF10...0xFF26 => {
0xFF10..=0xFF26 => {
self.sound
.sound_object
.lock()
.unwrap()
.write_byte(addr, val);
}
0xFF30...0xFF3F => self
0xFF30..=0xFF3F => self
.sound
.sound_object
.lock()

View File

@ -43,14 +43,14 @@ fn main() {
}
pub fn read_file<P: AsRef<Path>>(rom_path: P) -> Result<Box<[u8]>, io::Error> {
let mut file = r#try!(fs::File::open(rom_path));
let mut file = fs::File::open(rom_path)?;
let mut buf = Vec::new();
r#try!(file.read_to_end(&mut buf));
file.read_to_end(&mut buf)?;
Ok(buf.into_boxed_slice())
}
pub fn write_file<P: AsRef<Path>>(path: P, data: &Box<[u8]>) -> Result<(), io::Error> {
let mut file = r#try!(fs::File::create(path));
r#try!(file.write(&data));
let mut file = fs::File::create(path)?;
file.write(&data)?;
Ok(())
}

View File

@ -1,5 +1,5 @@
// Implements the envelopes
use sound::{AudioComponent, AudioModule};
use crate::sound::{AudioComponent, AudioModule};
#[derive(Clone, Debug)]
pub enum EnvelopeDirection {

View File

@ -1,5 +1,5 @@
// Implement the length counter
use sound::{AudioComponent, AudioModule};
use crate::sound::{AudioComponent, AudioModule};
use std::fmt::Debug;
#[derive(Default, Debug)]

View File

@ -72,7 +72,7 @@ impl Channel1 {
pub fn read_byte(&self, addr: u16) -> u8 {
match addr {
0xFF10...0xFF14 => self.stored_regs[(addr - 0xFF10) as usize],
0xFF10..=0xFF14 => self.stored_regs[(addr - 0xFF10) as usize],
_ => {
println!("Channel1 does not support reading ({:04X})", addr);
0
@ -228,7 +228,7 @@ impl Channel3 {
self.length_counter.set_enabled(val & 1 << 6);
}
0xFF30...0xFF3F => {
0xFF30..=0xFF3F => {
self.wave_gen.set_sample_pair((addr - 0xFF30) as usize, val);
}
_ => panic!("Channel3: Write not supported: {:04X} = {:02X}", addr, val),
@ -414,14 +414,14 @@ impl Sound {
pub fn write_byte(&mut self, addr: u16, val: u8) {
// println!("Snd: {:04X} = {:02X} ({:08b})", addr, val, val);
match addr {
0xFF10...0xFF14 => self.channel1.write_byte(addr, val),
0xFF16...0xFF19 => self.channel2.write_byte(addr, val),
0xFF1A...0xFF1E => self.channel3.write_byte(addr, val),
0xFF10..=0xFF14 => self.channel1.write_byte(addr, val),
0xFF16..=0xFF19 => self.channel2.write_byte(addr, val),
0xFF1A..=0xFF1E => self.channel3.write_byte(addr, val),
0xFF24 => self.sound_channel_volume_control = val,
0xFF25 => self.sound_output_terminal_selector = val,
0xFF26 => self.enabled = val,
0xFF30...0xFF3F => self.channel3.write_byte(addr, val),
0xFF30..=0xFF3F => self.channel3.write_byte(addr, val),
_ => {
// panic!("Sound: Write {:02X} to {:04X} unsupported", val, addr);
@ -433,14 +433,14 @@ impl Sound {
pub fn read_byte(&self, addr: u16) -> u8 {
// println!("RD {:04X}", addr);
match addr {
0xFF10...0xFF14 => self.channel1.read_byte(addr),
0xFF16...0xFF19 => self.channel2.read_byte(addr),
0xFF1A...0xFF1E => self.channel3.read_byte(addr),
0xFF10..=0xFF14 => self.channel1.read_byte(addr),
0xFF16..=0xFF19 => self.channel2.read_byte(addr),
0xFF1A..=0xFF1E => self.channel3.read_byte(addr),
0xFF24 => self.sound_channel_volume_control,
0xFF25 => self.sound_output_terminal_selector,
0xFF26 => self.enabled,
0xFF30...0xFF3F => self.channel3.read_byte(addr),
0xFF30..=0xFF3F => self.channel3.read_byte(addr),
_ => panic!("Sound: Read from {:04X} unsupported", addr),
}

View File

@ -1,6 +1,6 @@
// Square wave generator
use sound::AudioComponent;
use sound::OUTPUT_SAMPLE_RATE;
use crate::sound::AudioComponent;
use crate::sound::OUTPUT_SAMPLE_RATE;
#[derive(Debug)]
pub enum DutyCycle {

View File

@ -1,6 +1,6 @@
// Square wave generator
use sound::AudioComponent;
use sound::OUTPUT_SAMPLE_RATE;
use crate::sound::AudioComponent;
use crate::sound::OUTPUT_SAMPLE_RATE;
#[derive(Debug, Default)]
struct SamplePair(u8);