diff --git a/src/bin/main.rs b/src/bin/main.rs index c85a1f0..a1c193c 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -5,11 +5,11 @@ use clap::{App, ArgMatches}; extern crate rustboyadvance_ng; -use rustboyadvance_ng::arm7tdmi::Core; -use rustboyadvance_ng::cartridge::Cartridge; -use rustboyadvance_ng::debugger::Debugger; +use rustboyadvance_ng::core::arm7tdmi::Core; +use rustboyadvance_ng::core::cartridge::Cartridge; +use rustboyadvance_ng::core::{GBAResult, GameBoyAdvance}; use rustboyadvance_ng::util::read_bin_file; -use rustboyadvance_ng::{GBAResult, GameBoyAdvance}; +use rustboyadvance_ng::debugger::Debugger; fn run_debug(matches: &ArgMatches) -> GBAResult<()> { let skip_bios = match matches.occurrences_of("skip_bios") { diff --git a/src/arm7tdmi/alu.rs b/src/core/arm7tdmi/alu.rs similarity index 100% rename from src/arm7tdmi/alu.rs rename to src/core/arm7tdmi/alu.rs diff --git a/src/arm7tdmi/arm/display.rs b/src/core/arm7tdmi/arm/display.rs similarity index 99% rename from src/arm7tdmi/arm/display.rs rename to src/core/arm7tdmi/arm/display.rs index 371bb90..eb843f3 100644 --- a/src/arm7tdmi/arm/display.rs +++ b/src/core/arm7tdmi/arm/display.rs @@ -3,7 +3,7 @@ use std::fmt; use crate::bit::BitIndex; use super::{AluOpCode, ArmCond, ArmFormat, ArmHalfwordTransferType, ArmInstruction}; -use crate::arm7tdmi::{ +use crate::core::arm7tdmi::{ psr::RegPSR, reg_string, Addr, BarrelShiftOpCode, BarrelShifterValue, ShiftedRegister, REG_PC, }; diff --git a/src/arm7tdmi/arm/exec.rs b/src/core/arm7tdmi/arm/exec.rs similarity index 97% rename from src/arm7tdmi/arm/exec.rs rename to src/core/arm7tdmi/arm/exec.rs index 58eaddb..a5267a1 100644 --- a/src/arm7tdmi/arm/exec.rs +++ b/src/core/arm7tdmi/arm/exec.rs @@ -1,11 +1,13 @@ use crate::bit::BitIndex; -use crate::arm7tdmi::alu::*; -use crate::arm7tdmi::bus::Bus; -use crate::arm7tdmi::cpu::{Core, CpuExecResult}; -use crate::arm7tdmi::exception::Exception; -use crate::arm7tdmi::psr::RegPSR; -use crate::arm7tdmi::{Addr, CpuError, CpuMode, CpuResult, CpuState, DecodedInstruction, REG_PC}; +use crate::core::arm7tdmi::alu::*; +use crate::core::arm7tdmi::bus::Bus; +use crate::core::arm7tdmi::cpu::{Core, CpuExecResult}; +use crate::core::arm7tdmi::exception::Exception; +use crate::core::arm7tdmi::psr::RegPSR; +use crate::core::arm7tdmi::{ + Addr, CpuError, CpuMode, CpuResult, CpuState, DecodedInstruction, REG_PC, +}; use super::*; diff --git a/src/arm7tdmi/arm/mod.rs b/src/core/arm7tdmi/arm/mod.rs similarity index 99% rename from src/arm7tdmi/arm/mod.rs rename to src/core/arm7tdmi/arm/mod.rs index 9eafb4e..09652fd 100644 --- a/src/arm7tdmi/arm/mod.rs +++ b/src/core/arm7tdmi/arm/mod.rs @@ -2,7 +2,7 @@ pub mod display; pub mod exec; use super::alu::*; -use crate::arm7tdmi::{Addr, InstructionDecoder, InstructionDecoderError}; +use crate::core::arm7tdmi::{Addr, InstructionDecoder, InstructionDecoderError}; use crate::bit::BitIndex; use crate::byteorder::{LittleEndian, ReadBytesExt}; @@ -351,7 +351,7 @@ impl ArmInstruction { /// All instructions constants were generated using an ARM assembler. mod tests { use super::*; - use crate::arm7tdmi::*; + use crate::core::arm7tdmi::*; use crate::sysbus::BoxedMemory; #[test] diff --git a/src/arm7tdmi/bus.rs b/src/core/arm7tdmi/bus.rs similarity index 100% rename from src/arm7tdmi/bus.rs rename to src/core/arm7tdmi/bus.rs diff --git a/src/arm7tdmi/cpu.rs b/src/core/arm7tdmi/cpu.rs similarity index 100% rename from src/arm7tdmi/cpu.rs rename to src/core/arm7tdmi/cpu.rs diff --git a/src/arm7tdmi/exception.rs b/src/core/arm7tdmi/exception.rs similarity index 100% rename from src/arm7tdmi/exception.rs rename to src/core/arm7tdmi/exception.rs diff --git a/src/arm7tdmi/mod.rs b/src/core/arm7tdmi/mod.rs similarity index 100% rename from src/arm7tdmi/mod.rs rename to src/core/arm7tdmi/mod.rs diff --git a/src/arm7tdmi/psr.rs b/src/core/arm7tdmi/psr.rs similarity index 100% rename from src/arm7tdmi/psr.rs rename to src/core/arm7tdmi/psr.rs diff --git a/src/arm7tdmi/thumb/display.rs b/src/core/arm7tdmi/thumb/display.rs similarity index 99% rename from src/arm7tdmi/thumb/display.rs rename to src/core/arm7tdmi/thumb/display.rs index ba59cc9..79c6134 100644 --- a/src/arm7tdmi/thumb/display.rs +++ b/src/core/arm7tdmi/thumb/display.rs @@ -3,7 +3,7 @@ use std::fmt; use crate::bit::BitIndex; use super::*; -use crate::arm7tdmi::*; +use crate::core::arm7tdmi::*; impl ThumbInstruction { fn fmt_thumb_move_shifted_reg(&self, f: &mut fmt::Formatter) -> fmt::Result { diff --git a/src/arm7tdmi/thumb/exec.rs b/src/core/arm7tdmi/thumb/exec.rs similarity index 99% rename from src/arm7tdmi/thumb/exec.rs rename to src/core/arm7tdmi/thumb/exec.rs index dcbf722..6937ce3 100644 --- a/src/arm7tdmi/thumb/exec.rs +++ b/src/core/arm7tdmi/thumb/exec.rs @@ -1,6 +1,6 @@ -use crate::arm7tdmi::bus::Bus; -use crate::arm7tdmi::cpu::{Core, CpuExecResult}; -use crate::arm7tdmi::*; +use crate::core::arm7tdmi::bus::Bus; +use crate::core::arm7tdmi::cpu::{Core, CpuExecResult}; +use crate::core::arm7tdmi::*; use super::*; fn push(cpu: &mut Core, bus: &mut Bus, r: usize) { diff --git a/src/arm7tdmi/thumb/mod.rs b/src/core/arm7tdmi/thumb/mod.rs similarity index 99% rename from src/arm7tdmi/thumb/mod.rs rename to src/core/arm7tdmi/thumb/mod.rs index ed5a167..a7c94c1 100644 --- a/src/arm7tdmi/thumb/mod.rs +++ b/src/core/arm7tdmi/thumb/mod.rs @@ -348,7 +348,7 @@ impl ThumbInstruction { /// All instructions constants were generated using an ARM assembler. mod tests { use super::*; - use crate::arm7tdmi::{Core, Bus}; + use crate::core::arm7tdmi::{Bus, Core}; use crate::sysbus::BoxedMemory; #[test] diff --git a/src/cartridge.rs b/src/core/cartridge.rs similarity index 97% rename from src/cartridge.rs rename to src/core/cartridge.rs index 7ec350f..b3a5fd9 100644 --- a/src/cartridge.rs +++ b/src/core/cartridge.rs @@ -2,13 +2,12 @@ use std::str::from_utf8; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; -use crate::arm7tdmi::{ +use super::arm7tdmi::{ bus::{Bus, MemoryAccess, MemoryAccessWidth}, Addr, }; -use crate::sysbus::WaitState; +use super::sysbus::WaitState; use crate::util::read_bin_file; -use crate::GBAError; /// From GBATEK /// @@ -79,7 +78,7 @@ pub struct Cartridge { impl Cartridge { const MIN_SIZE: usize = 4 * 1024 * 1024; - pub fn load(path: &str) -> Result { + pub fn load(path: &str) -> Result { let mut rom_bin = read_bin_file(path)?; if rom_bin.len() < Cartridge::MIN_SIZE { rom_bin.resize_with(Cartridge::MIN_SIZE, Default::default); diff --git a/src/dma.rs b/src/core/dma.rs similarity index 100% rename from src/dma.rs rename to src/core/dma.rs diff --git a/src/gba.rs b/src/core/gba.rs similarity index 98% rename from src/gba.rs rename to src/core/gba.rs index e5fcbaf..57175cb 100644 --- a/src/gba.rs +++ b/src/core/gba.rs @@ -7,8 +7,8 @@ use super::gpu::*; use super::interrupt::*; use super::ioregs::consts::*; use super::sysbus::SysBus; - -use super::{EmuIoDev, GBAError, GBAResult}; +use super::EmuIoDev; +use super::{GBAError, GBAResult}; pub struct GameBoyAdvance { pub cpu: Core, diff --git a/src/gpu.rs b/src/core/gpu.rs similarity index 98% rename from src/gpu.rs rename to src/core/gpu.rs index 2be5edb..0c115d1 100644 --- a/src/gpu.rs +++ b/src/core/gpu.rs @@ -145,7 +145,7 @@ use GpuState::*; pub struct Gpu { cycles: usize, - pub pixeldata: [Rgb15; 256 * 256], + pub pixeldata: [Rgb15; 512 * 512], pub state: GpuState, pub current_scanline: usize, // VCOUNT } @@ -168,7 +168,7 @@ impl Gpu { state: HDraw, current_scanline: 0, cycles: 0, - pixeldata: [Rgb15::from(0); 256 * 256], + pixeldata: [Rgb15::from(0); 512 * 512], } } @@ -300,7 +300,7 @@ impl Gpu { self.get_palette_color(sysbus, index as u32, 0) } }; - self.pixeldata[((px + tile_x) as usize) + py * 256] = color; + self.pixeldata[((px + tile_x) as usize) + py * 512] = color; } px += 8; if px == bgcnt.screen_width as u32 { @@ -313,7 +313,7 @@ impl Gpu { let page: u32 = match dispcnt.display_frame { 0 => 0x0600_0000, 1 => 0x0600_a000, - _ => unreachable!() + _ => unreachable!(), }; let y = self.current_scanline; @@ -322,7 +322,7 @@ impl Gpu { let bitmap_index = x + y * Self::DISPLAY_WIDTH; let bitmap_addr = page + (bitmap_index as u32); let index = sysbus.read_8(bitmap_addr as Addr) as u32; - self.pixeldata[x + y * 256] = self.get_palette_color(sysbus, index, 0); + self.pixeldata[x + y * 512] = self.get_palette_color(sysbus, index, 0); } } diff --git a/src/interrupt.rs b/src/core/interrupt.rs similarity index 100% rename from src/interrupt.rs rename to src/core/interrupt.rs diff --git a/src/ioregs.rs b/src/core/ioregs.rs similarity index 99% rename from src/ioregs.rs rename to src/core/ioregs.rs index a2e8cfd..3a4faa0 100644 --- a/src/ioregs.rs +++ b/src/core/ioregs.rs @@ -2,7 +2,7 @@ use std::io; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; -use crate::arm7tdmi::{Addr, Bus, MemoryAccess}; +use crate::core::arm7tdmi::{Addr, Bus, MemoryAccess}; pub mod consts { use super::*; diff --git a/src/core/mod.rs b/src/core/mod.rs new file mode 100644 index 0000000..b117412 --- /dev/null +++ b/src/core/mod.rs @@ -0,0 +1,45 @@ +pub mod arm7tdmi; +pub mod cartridge; +pub mod gpu; +pub mod sysbus; +pub use sysbus::SysBus; +pub mod interrupt; +pub mod ioregs; +pub use interrupt::Interrupt; +pub mod gba; +pub use gba::GameBoyAdvance; +pub mod dma; +pub mod palette; + +use crate::debugger; + +pub trait EmuIoDev { + fn step(&mut self, cycles: usize, sysbus: &mut SysBus) -> (usize, Option); +} + +#[derive(Debug)] +pub enum GBAError { + IO(::std::io::Error), + CpuError(arm7tdmi::CpuError), + DebuggerError(debugger::DebuggerError), +} + +pub type GBAResult = Result; + +impl From<::std::io::Error> for GBAError { + fn from(err: ::std::io::Error) -> GBAError { + GBAError::IO(err) + } +} + +impl From for GBAError { + fn from(err: arm7tdmi::CpuError) -> GBAError { + GBAError::CpuError(err) + } +} + +impl From for GBAError { + fn from(err: debugger::DebuggerError) -> GBAError { + GBAError::DebuggerError(err) + } +} diff --git a/src/palette.rs b/src/core/palette.rs similarity index 100% rename from src/palette.rs rename to src/core/palette.rs diff --git a/src/sysbus.rs b/src/core/sysbus.rs similarity index 100% rename from src/sysbus.rs rename to src/core/sysbus.rs diff --git a/src/debugger/command.rs b/src/debugger/command.rs index 7facecb..49c4e98 100644 --- a/src/debugger/command.rs +++ b/src/debugger/command.rs @@ -1,9 +1,11 @@ -use crate::arm7tdmi::bus::Bus; -use crate::arm7tdmi::{Addr, CpuState}; +use crate::core::arm7tdmi::arm::ArmInstruction; +use crate::core::arm7tdmi::bus::Bus; +use crate::core::arm7tdmi::thumb::ThumbInstruction; +use crate::core::arm7tdmi::{Addr, CpuState}; +use crate::core::gpu::*; +use crate::core::ioregs::consts::*; +use crate::core::GBAError; use crate::disass::Disassembler; -use crate::ioregs::consts::*; -use crate::gpu::*; -use crate::GBAError; use super::palette_view::create_palette_view; use super::render_view::create_render_view; @@ -137,9 +139,6 @@ impl Command { hexdump::hexdump(&bytes[0..nbytes]); } Disass(mode, addr, n) => { - use crate::arm7tdmi::arm::ArmInstruction; - use crate::arm7tdmi::thumb::ThumbInstruction; - let bytes = debugger.gba.sysbus.get_bytes(addr); match mode { DisassMode::ModeArm => { diff --git a/src/debugger/mod.rs b/src/debugger/mod.rs index 3f81feb..5068e7d 100644 --- a/src/debugger/mod.rs +++ b/src/debugger/mod.rs @@ -3,8 +3,8 @@ use rustyline::Editor; use colored::*; -use super::arm7tdmi::{Addr, Bus, CpuError}; -use super::GameBoyAdvance; +use super::core::arm7tdmi::{Addr, Bus, CpuError}; +use super::core::GameBoyAdvance; mod parser; use parser::{parse_expr, DerefType, Expr, Value}; diff --git a/src/debugger/palette_view.rs b/src/debugger/palette_view.rs index c037573..f1deb62 100644 --- a/src/debugger/palette_view.rs +++ b/src/debugger/palette_view.rs @@ -3,7 +3,7 @@ use sdl2::pixels::Color; use sdl2::rect::{Point, Rect}; use sdl2::render::Canvas; -use super::super::palette::{Palette, Rgb15}; +use crate::core::palette::{Palette, Rgb15}; const PALETTE_RECT_WIDTH: u32 = 20; diff --git a/src/debugger/render_view.rs b/src/debugger/render_view.rs index 854cdc4..2bc0e5e 100644 --- a/src/debugger/render_view.rs +++ b/src/debugger/render_view.rs @@ -4,8 +4,8 @@ use sdl2::event::Event; use sdl2::pixels::Color; use sdl2::rect::Point; -use crate::gba::GameBoyAdvance; -use crate::gpu::Gpu; +use crate::core::gba::GameBoyAdvance; +use crate::core::gpu::Gpu; const SCREEN_WIDTH: u32 = Gpu::DISPLAY_WIDTH as u32; const SCREEN_HEIGHT: u32 = Gpu::DISPLAY_HEIGHT as u32; @@ -39,7 +39,7 @@ pub fn create_render_view(gba: &GameBoyAdvance) { for y in 0..Gpu::DISPLAY_HEIGHT { for x in 0..Gpu::DISPLAY_WIDTH { - let index = (x as usize) + (y as usize) * (256 as usize); + let index = (x as usize) + (y as usize) * (512 as usize); let color = gba.gpu.pixeldata[index]; let rgb24: Color = color.into(); canvas.set_draw_color(rgb24); diff --git a/src/debugger/tile_view.rs b/src/debugger/tile_view.rs index 2b09bde..56277fb 100644 --- a/src/debugger/tile_view.rs +++ b/src/debugger/tile_view.rs @@ -5,12 +5,12 @@ use sdl2::pixels::Color; use sdl2::rect::{Point, Rect}; use sdl2::render::Canvas; -use crate::arm7tdmi::bus::Bus; -use crate::gba::GameBoyAdvance; -use crate::ioregs::consts::*; -use crate::gpu::*; -use crate::palette::*; -use crate::sysbus::SysBus; +use crate::core::arm7tdmi::bus::Bus; +use crate::core::gba::GameBoyAdvance; +use crate::core::gpu::*; +use crate::core::ioregs::consts::*; +use crate::core::palette::*; +use crate::core::sysbus::SysBus; impl Into for Rgb15 { fn into(self) -> Color { @@ -100,7 +100,6 @@ pub fn create_tile_view(bg: u32, gba: &GameBoyAdvance) { } } - canvas.set_draw_color(Color::RGB(00, 00, 00)); canvas.clear(); diff --git a/src/disass.rs b/src/disass.rs index eef3477..11b8c8c 100644 --- a/src/disass.rs +++ b/src/disass.rs @@ -1,6 +1,6 @@ use std::marker::PhantomData; -use super::arm7tdmi::{Addr, InstructionDecoder, InstructionDecoderError}; +use super::core::arm7tdmi::{Addr, InstructionDecoder, InstructionDecoderError}; use std::io::ErrorKind; pub struct Disassembler<'a, D> diff --git a/src/lib.rs b/src/lib.rs index ab58e7d..22eade4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,49 +14,7 @@ extern crate nom; extern crate ansi_term; extern crate colored; // not needed in Rust 2018 -pub mod arm7tdmi; -pub mod cartridge; +pub mod core; pub mod debugger; pub mod disass; -pub mod gpu; -pub mod sysbus; -pub use sysbus::SysBus; -pub mod interrupt; -pub mod ioregs; -pub use interrupt::Interrupt; -pub mod gba; -pub use gba::GameBoyAdvance; -pub mod dma; -pub mod palette; pub mod util; - -pub trait EmuIoDev { - fn step(&mut self, cycles: usize, sysbus: &mut SysBus) -> (usize, Option); -} - -#[derive(Debug)] -pub enum GBAError { - IO(::std::io::Error), - CpuError(arm7tdmi::CpuError), - DebuggerError(debugger::DebuggerError), -} - -pub type GBAResult = Result; - -impl From<::std::io::Error> for GBAError { - fn from(err: ::std::io::Error) -> GBAError { - GBAError::IO(err) - } -} - -impl From for GBAError { - fn from(err: arm7tdmi::CpuError) -> GBAError { - GBAError::CpuError(err) - } -} - -impl From for GBAError { - fn from(err: debugger::DebuggerError) -> GBAError { - GBAError::DebuggerError(err) - } -}