From ef3f39defc02967e9011cdbaf2f8c9465f05386e Mon Sep 17 00:00:00 2001 From: Michel Heily Date: Fri, 1 May 2020 18:13:00 +0300 Subject: [PATCH] Refactor rustboyadvance-core crate directory structure Former-commit-id: 1aad71d283f7ec5a0f0328f9b683f51e459ae56f Former-commit-id: 42bb30d300c17bace976d106f6da1aca8c0d7643 --- bindings/rustboyadvance-jni/src/rom_helper.rs | 2 +- platform/rustboyadvance-minifb/src/main.rs | 2 +- platform/rustboyadvance-sdl2/src/input.rs | 2 +- platform/rustboyadvance-sdl2/src/main.rs | 4 +- platform/rustboyadvance-sdl2/src/video.rs | 2 +- platform/rustboyadvance-wasm/src/emulator.rs | 2 +- platform/rustboyadvance-wasm/src/lib.rs | 2 +- .../src/{core => }/arm7tdmi/alu.rs | 0 .../src/{core => }/arm7tdmi/arm/display.rs | 2 +- .../src/{core => }/arm7tdmi/arm/exec.rs | 10 +-- .../src/{core => }/arm7tdmi/arm/mod.rs | 6 +- .../src/{core => }/arm7tdmi/cpu.rs | 4 +- .../src/{core => }/arm7tdmi/exception.rs | 0 .../src/{core => }/arm7tdmi/mod.rs | 2 +- .../src/{core => }/arm7tdmi/psr.rs | 0 .../src/{core => }/arm7tdmi/thumb/display.rs | 2 +- .../src/{core => }/arm7tdmi/thumb/exec.rs | 6 +- .../src/{core => }/arm7tdmi/thumb/mod.rs | 4 +- rustboyadvance-core/src/{core => }/bus.rs | 0 .../cartridge/backup/backup_file.rs | 0 .../src/{core => }/cartridge/backup/eeprom.rs | 0 .../src/{core => }/cartridge/backup/flash.rs | 0 .../src/{core => }/cartridge/backup/mod.rs | 0 .../src/{core => }/cartridge/builder.rs | 0 .../src/{core => }/cartridge/header.rs | 0 .../src/{core => }/cartridge/loader.rs | 0 .../src/{core => }/cartridge/mod.rs | 0 rustboyadvance-core/src/core/mod.rs | 68 ---------------- rustboyadvance-core/src/debugger/command.rs | 8 +- rustboyadvance-core/src/debugger/mod.rs | 4 +- .../src/debugger/palette_view.rs | 2 +- rustboyadvance-core/src/debugger/tile_view.rs | 4 +- rustboyadvance-core/src/disass.rs | 4 +- rustboyadvance-core/src/{core => }/dma.rs | 0 rustboyadvance-core/src/{core => }/gba.rs | 2 +- rustboyadvance-core/src/gdb.rs | 10 +-- .../src/{core => }/gpu/layer.rs | 0 rustboyadvance-core/src/{core => }/gpu/mod.rs | 2 +- .../src/{core => }/gpu/mosaic.rs | 0 .../src/{core => }/gpu/regs.rs | 0 .../src/{core => }/gpu/render.rs | 0 .../src/{core => }/gpu/render/bitmap.rs | 2 +- .../src/{core => }/gpu/render/obj.rs | 0 .../src/{core => }/gpu/render/text.rs | 2 +- .../src/{core => }/gpu/rgb15.rs | 0 rustboyadvance-core/src/{core => }/gpu/sfx.rs | 0 .../src/{core => }/gpu/window.rs | 0 .../src/{core => }/interrupt.rs | 0 rustboyadvance-core/src/{core => }/iodev.rs | 0 rustboyadvance-core/src/{core => }/keypad.rs | 0 rustboyadvance-core/src/lib.rs | 77 +++++++++++++++++-- .../src/{core => }/sound/dsp.rs | 0 .../src/{core => }/sound/fifo.rs | 0 .../src/{core => }/sound/mod.rs | 0 rustboyadvance-core/src/{core => }/sysbus.rs | 0 rustboyadvance-core/src/{core => }/timer.rs | 0 rustboyadvance-core/src/util.rs | 2 +- 57 files changed, 117 insertions(+), 122 deletions(-) rename rustboyadvance-core/src/{core => }/arm7tdmi/alu.rs (100%) rename rustboyadvance-core/src/{core => }/arm7tdmi/arm/display.rs (99%) rename rustboyadvance-core/src/{core => }/arm7tdmi/arm/exec.rs (99%) rename rustboyadvance-core/src/{core => }/arm7tdmi/arm/mod.rs (99%) rename rustboyadvance-core/src/{core => }/arm7tdmi/cpu.rs (99%) rename rustboyadvance-core/src/{core => }/arm7tdmi/exception.rs (100%) rename rustboyadvance-core/src/{core => }/arm7tdmi/mod.rs (98%) rename rustboyadvance-core/src/{core => }/arm7tdmi/psr.rs (100%) rename rustboyadvance-core/src/{core => }/arm7tdmi/thumb/display.rs (99%) rename rustboyadvance-core/src/{core => }/arm7tdmi/thumb/exec.rs (99%) rename rustboyadvance-core/src/{core => }/arm7tdmi/thumb/mod.rs (99%) rename rustboyadvance-core/src/{core => }/bus.rs (100%) rename rustboyadvance-core/src/{core => }/cartridge/backup/backup_file.rs (100%) rename rustboyadvance-core/src/{core => }/cartridge/backup/eeprom.rs (100%) rename rustboyadvance-core/src/{core => }/cartridge/backup/flash.rs (100%) rename rustboyadvance-core/src/{core => }/cartridge/backup/mod.rs (100%) rename rustboyadvance-core/src/{core => }/cartridge/builder.rs (100%) rename rustboyadvance-core/src/{core => }/cartridge/header.rs (100%) rename rustboyadvance-core/src/{core => }/cartridge/loader.rs (100%) rename rustboyadvance-core/src/{core => }/cartridge/mod.rs (100%) delete mode 100644 rustboyadvance-core/src/core/mod.rs rename rustboyadvance-core/src/{core => }/dma.rs (100%) rename rustboyadvance-core/src/{core => }/gba.rs (99%) rename rustboyadvance-core/src/{core => }/gpu/layer.rs (100%) rename rustboyadvance-core/src/{core => }/gpu/mod.rs (99%) rename rustboyadvance-core/src/{core => }/gpu/mosaic.rs (100%) rename rustboyadvance-core/src/{core => }/gpu/regs.rs (100%) rename rustboyadvance-core/src/{core => }/gpu/render.rs (100%) rename rustboyadvance-core/src/{core => }/gpu/render/bitmap.rs (98%) rename rustboyadvance-core/src/{core => }/gpu/render/obj.rs (100%) rename rustboyadvance-core/src/{core => }/gpu/render/text.rs (99%) rename rustboyadvance-core/src/{core => }/gpu/rgb15.rs (100%) rename rustboyadvance-core/src/{core => }/gpu/sfx.rs (100%) rename rustboyadvance-core/src/{core => }/gpu/window.rs (100%) rename rustboyadvance-core/src/{core => }/interrupt.rs (100%) rename rustboyadvance-core/src/{core => }/iodev.rs (100%) rename rustboyadvance-core/src/{core => }/keypad.rs (100%) rename rustboyadvance-core/src/{core => }/sound/dsp.rs (100%) rename rustboyadvance-core/src/{core => }/sound/fifo.rs (100%) rename rustboyadvance-core/src/{core => }/sound/mod.rs (100%) rename rustboyadvance-core/src/{core => }/sysbus.rs (100%) rename rustboyadvance-core/src/{core => }/timer.rs (100%) diff --git a/bindings/rustboyadvance-jni/src/rom_helper.rs b/bindings/rustboyadvance-jni/src/rom_helper.rs index f3ba62a..317737f 100644 --- a/bindings/rustboyadvance-jni/src/rom_helper.rs +++ b/bindings/rustboyadvance-jni/src/rom_helper.rs @@ -2,7 +2,7 @@ use jni::objects::*; use jni::sys::*; use jni::JNIEnv; -use rustboyadvance_core::core::cartridge; +use rustboyadvance_core::cartridge; fn parse_rom_header(env: &JNIEnv, barr: jbyteArray) -> cartridge::header::CartridgeHeader { let rom_data = env.convert_byte_array(barr).unwrap(); diff --git a/platform/rustboyadvance-minifb/src/main.rs b/platform/rustboyadvance-minifb/src/main.rs index 7f37238..7563d64 100644 --- a/platform/rustboyadvance-minifb/src/main.rs +++ b/platform/rustboyadvance-minifb/src/main.rs @@ -7,7 +7,7 @@ use std::time; #[macro_use] extern crate clap; -use rustboyadvance_core::core::keypad; +use rustboyadvance_core::keypad; use rustboyadvance_core::prelude::*; use rustboyadvance_core::util::FpsCounter; diff --git a/platform/rustboyadvance-sdl2/src/input.rs b/platform/rustboyadvance-sdl2/src/input.rs index d91513a..8a169a4 100644 --- a/platform/rustboyadvance-sdl2/src/input.rs +++ b/platform/rustboyadvance-sdl2/src/input.rs @@ -1,6 +1,6 @@ use sdl2::keyboard::Keycode; -use rustboyadvance_core::core::keypad as gba_keypad; +use rustboyadvance_core::keypad as gba_keypad; use rustboyadvance_core::InputInterface; use bit; diff --git a/platform/rustboyadvance-sdl2/src/main.rs b/platform/rustboyadvance-sdl2/src/main.rs index 8844d2f..2d14726 100644 --- a/platform/rustboyadvance-sdl2/src/main.rs +++ b/platform/rustboyadvance-sdl2/src/main.rs @@ -5,7 +5,7 @@ use sdl2::keyboard::Keycode; use sdl2::messagebox::*; use sdl2::pixels::Color; use sdl2::rect::Rect; -use sdl2::render::{Texture, WindowCanvas}; +use sdl2::render::WindowCanvas; use sdl2::EventPump; @@ -41,7 +41,7 @@ use audio::create_audio_player; use input::create_input; use video::{create_video_interface, SCREEN_HEIGHT, SCREEN_WIDTH}; -use rustboyadvance_core::core::cartridge::BackupType; +use rustboyadvance_core::cartridge::BackupType; use rustboyadvance_core::prelude::*; use rustboyadvance_core::util::spawn_and_run_gdb_server; use rustboyadvance_core::util::FpsCounter; diff --git a/platform/rustboyadvance-sdl2/src/video.rs b/platform/rustboyadvance-sdl2/src/video.rs index 26f1b0c..f901e17 100644 --- a/platform/rustboyadvance-sdl2/src/video.rs +++ b/platform/rustboyadvance-sdl2/src/video.rs @@ -3,7 +3,7 @@ use sdl2::rect::Rect; use sdl2::render::{Texture, TextureCreator, WindowCanvas}; use sdl2::video::WindowContext; -use rustboyadvance_core::core::gpu::{DISPLAY_HEIGHT, DISPLAY_WIDTH}; +use rustboyadvance_core::gpu::{DISPLAY_HEIGHT, DISPLAY_WIDTH}; use rustboyadvance_core::VideoInterface; pub const SCREEN_WIDTH: u32 = DISPLAY_WIDTH as u32; diff --git a/platform/rustboyadvance-wasm/src/emulator.rs b/platform/rustboyadvance-wasm/src/emulator.rs index a783cb0..8e95788 100644 --- a/platform/rustboyadvance-wasm/src/emulator.rs +++ b/platform/rustboyadvance-wasm/src/emulator.rs @@ -9,7 +9,7 @@ use js_sys::Float32Array; use web_sys::AudioContext; use web_sys::CanvasRenderingContext2d; -use rustboyadvance_core::core::keypad as gba_keypad; +use rustboyadvance_core::keypad as gba_keypad; use rustboyadvance_core::prelude::*; use rustboyadvance_core::util::audio::AudioRingBuffer; diff --git a/platform/rustboyadvance-wasm/src/lib.rs b/platform/rustboyadvance-wasm/src/lib.rs index 9c43eb6..5f4d616 100644 --- a/platform/rustboyadvance-wasm/src/lib.rs +++ b/platform/rustboyadvance-wasm/src/lib.rs @@ -7,7 +7,7 @@ extern crate log; use wasm_bindgen_console_logger::DEFAULT_LOGGER; -use rustboyadvance_core::core::cartridge; +use rustboyadvance_core::cartridge; pub mod emulator; diff --git a/rustboyadvance-core/src/core/arm7tdmi/alu.rs b/rustboyadvance-core/src/arm7tdmi/alu.rs similarity index 100% rename from rustboyadvance-core/src/core/arm7tdmi/alu.rs rename to rustboyadvance-core/src/arm7tdmi/alu.rs diff --git a/rustboyadvance-core/src/core/arm7tdmi/arm/display.rs b/rustboyadvance-core/src/arm7tdmi/arm/display.rs similarity index 99% rename from rustboyadvance-core/src/core/arm7tdmi/arm/display.rs rename to rustboyadvance-core/src/arm7tdmi/arm/display.rs index c72d9da..89bfa98 100644 --- a/rustboyadvance-core/src/core/arm7tdmi/arm/display.rs +++ b/rustboyadvance-core/src/arm7tdmi/arm/display.rs @@ -7,7 +7,7 @@ use crate::bit::BitIndex; use super::{ArmFormat, ArmInstruction}; use super::{AluOpCode, ArmCond, ArmHalfwordTransferType}; -use crate::core::arm7tdmi::*; +use crate::arm7tdmi::*; impl fmt::Display for ArmCond { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/rustboyadvance-core/src/core/arm7tdmi/arm/exec.rs b/rustboyadvance-core/src/arm7tdmi/arm/exec.rs similarity index 99% rename from rustboyadvance-core/src/core/arm7tdmi/arm/exec.rs rename to rustboyadvance-core/src/arm7tdmi/arm/exec.rs index d36e285..92fe2ee 100644 --- a/rustboyadvance-core/src/core/arm7tdmi/arm/exec.rs +++ b/rustboyadvance-core/src/arm7tdmi/arm/exec.rs @@ -1,11 +1,11 @@ use crate::bit::BitIndex; use super::super::alu::*; -use crate::core::arm7tdmi::psr::RegPSR; -use crate::core::arm7tdmi::CpuAction; -use crate::core::arm7tdmi::{Addr, Core, CpuMode, CpuState, REG_LR, REG_PC}; -use crate::core::sysbus::SysBus; -use crate::core::Bus; +use crate::arm7tdmi::psr::RegPSR; +use crate::arm7tdmi::CpuAction; +use crate::arm7tdmi::{Addr, Core, CpuMode, CpuState, REG_LR, REG_PC}; +use crate::sysbus::SysBus; +use crate::Bus; use super::*; diff --git a/rustboyadvance-core/src/core/arm7tdmi/arm/mod.rs b/rustboyadvance-core/src/arm7tdmi/arm/mod.rs similarity index 99% rename from rustboyadvance-core/src/core/arm7tdmi/arm/mod.rs rename to rustboyadvance-core/src/arm7tdmi/arm/mod.rs index 51b68eb..34e4d38 100644 --- a/rustboyadvance-core/src/core/arm7tdmi/arm/mod.rs +++ b/rustboyadvance-core/src/arm7tdmi/arm/mod.rs @@ -4,7 +4,7 @@ pub mod exec; use serde::{Deserialize, Serialize}; use super::alu::*; -use crate::core::arm7tdmi::{Addr, InstructionDecoder}; +use crate::arm7tdmi::{Addr, InstructionDecoder}; use crate::bit::BitIndex; use crate::byteorder::{LittleEndian, ReadBytesExt}; @@ -367,8 +367,8 @@ impl ArmInstruction { // /// All instructions constants were generated using an ARM assembler. // mod tests { // use super::*; -// use crate::core::arm7tdmi::*; -// use crate::core::sysbus::BoxedMemory; +// use crate::arm7tdmi::*; +// use crate::sysbus::BoxedMemory; // #[test] // fn swi() { diff --git a/rustboyadvance-core/src/core/arm7tdmi/cpu.rs b/rustboyadvance-core/src/arm7tdmi/cpu.rs similarity index 99% rename from rustboyadvance-core/src/core/arm7tdmi/cpu.rs rename to rustboyadvance-core/src/arm7tdmi/cpu.rs index 3f120c2..a6883ce 100644 --- a/rustboyadvance-core/src/core/arm7tdmi/cpu.rs +++ b/rustboyadvance-core/src/arm7tdmi/cpu.rs @@ -25,8 +25,8 @@ use super::CpuAction; use super::DecodedInstruction; use super::{arm::*, psr::RegPSR, thumb::ThumbInstruction, Addr, CpuMode, CpuState}; -use crate::core::bus::Bus; -use crate::core::sysbus::{MemoryAccessType::*, MemoryAccessWidth::*, SysBus}; +use crate::bus::Bus; +use crate::sysbus::{MemoryAccessType::*, MemoryAccessWidth::*, SysBus}; use bit::BitIndex; use num::FromPrimitive; diff --git a/rustboyadvance-core/src/core/arm7tdmi/exception.rs b/rustboyadvance-core/src/arm7tdmi/exception.rs similarity index 100% rename from rustboyadvance-core/src/core/arm7tdmi/exception.rs rename to rustboyadvance-core/src/arm7tdmi/exception.rs diff --git a/rustboyadvance-core/src/core/arm7tdmi/mod.rs b/rustboyadvance-core/src/arm7tdmi/mod.rs similarity index 98% rename from rustboyadvance-core/src/core/arm7tdmi/mod.rs rename to rustboyadvance-core/src/arm7tdmi/mod.rs index 076b8e3..2a33af6 100644 --- a/rustboyadvance-core/src/core/arm7tdmi/mod.rs +++ b/rustboyadvance-core/src/arm7tdmi/mod.rs @@ -21,7 +21,7 @@ pub const REG_PC: usize = 15; pub const REG_LR: usize = 14; pub const REG_SP: usize = 13; -pub(self) use crate::core::Addr; +pub(self) use crate::Addr; pub enum CpuAction { AdvancePC, diff --git a/rustboyadvance-core/src/core/arm7tdmi/psr.rs b/rustboyadvance-core/src/arm7tdmi/psr.rs similarity index 100% rename from rustboyadvance-core/src/core/arm7tdmi/psr.rs rename to rustboyadvance-core/src/arm7tdmi/psr.rs diff --git a/rustboyadvance-core/src/core/arm7tdmi/thumb/display.rs b/rustboyadvance-core/src/arm7tdmi/thumb/display.rs similarity index 99% rename from rustboyadvance-core/src/core/arm7tdmi/thumb/display.rs rename to rustboyadvance-core/src/arm7tdmi/thumb/display.rs index f4f37f7..c167e28 100644 --- a/rustboyadvance-core/src/core/arm7tdmi/thumb/display.rs +++ b/rustboyadvance-core/src/arm7tdmi/thumb/display.rs @@ -5,7 +5,7 @@ use crate::bit::BitIndex; use super::*; #[cfg(feature = "debugger")] -use crate::core::arm7tdmi::*; +use crate::arm7tdmi::*; #[cfg(feature = "debugger")] impl ThumbInstruction { diff --git a/rustboyadvance-core/src/core/arm7tdmi/thumb/exec.rs b/rustboyadvance-core/src/arm7tdmi/thumb/exec.rs similarity index 99% rename from rustboyadvance-core/src/core/arm7tdmi/thumb/exec.rs rename to rustboyadvance-core/src/arm7tdmi/thumb/exec.rs index 8ab2d54..bf8859a 100644 --- a/rustboyadvance-core/src/core/arm7tdmi/thumb/exec.rs +++ b/rustboyadvance-core/src/arm7tdmi/thumb/exec.rs @@ -1,6 +1,6 @@ -use crate::core::arm7tdmi::*; -use crate::core::sysbus::SysBus; -use crate::core::Bus; +use crate::arm7tdmi::*; +use crate::sysbus::SysBus; +use crate::Bus; use crate::bit::BitIndex; diff --git a/rustboyadvance-core/src/core/arm7tdmi/thumb/mod.rs b/rustboyadvance-core/src/arm7tdmi/thumb/mod.rs similarity index 99% rename from rustboyadvance-core/src/core/arm7tdmi/thumb/mod.rs rename to rustboyadvance-core/src/arm7tdmi/thumb/mod.rs index a8cb70f..d006cd8 100644 --- a/rustboyadvance-core/src/core/arm7tdmi/thumb/mod.rs +++ b/rustboyadvance-core/src/arm7tdmi/thumb/mod.rs @@ -321,8 +321,8 @@ impl ThumbInstruction { // mod tests { // use super::super::Core; // use super::*; -// use crate::core::sysbus::BoxedMemory; -// use crate::core::Bus; +// use crate::sysbus::BoxedMemory; +// use crate::Bus; // #[test] // fn mov_low_reg() { diff --git a/rustboyadvance-core/src/core/bus.rs b/rustboyadvance-core/src/bus.rs similarity index 100% rename from rustboyadvance-core/src/core/bus.rs rename to rustboyadvance-core/src/bus.rs diff --git a/rustboyadvance-core/src/core/cartridge/backup/backup_file.rs b/rustboyadvance-core/src/cartridge/backup/backup_file.rs similarity index 100% rename from rustboyadvance-core/src/core/cartridge/backup/backup_file.rs rename to rustboyadvance-core/src/cartridge/backup/backup_file.rs diff --git a/rustboyadvance-core/src/core/cartridge/backup/eeprom.rs b/rustboyadvance-core/src/cartridge/backup/eeprom.rs similarity index 100% rename from rustboyadvance-core/src/core/cartridge/backup/eeprom.rs rename to rustboyadvance-core/src/cartridge/backup/eeprom.rs diff --git a/rustboyadvance-core/src/core/cartridge/backup/flash.rs b/rustboyadvance-core/src/cartridge/backup/flash.rs similarity index 100% rename from rustboyadvance-core/src/core/cartridge/backup/flash.rs rename to rustboyadvance-core/src/cartridge/backup/flash.rs diff --git a/rustboyadvance-core/src/core/cartridge/backup/mod.rs b/rustboyadvance-core/src/cartridge/backup/mod.rs similarity index 100% rename from rustboyadvance-core/src/core/cartridge/backup/mod.rs rename to rustboyadvance-core/src/cartridge/backup/mod.rs diff --git a/rustboyadvance-core/src/core/cartridge/builder.rs b/rustboyadvance-core/src/cartridge/builder.rs similarity index 100% rename from rustboyadvance-core/src/core/cartridge/builder.rs rename to rustboyadvance-core/src/cartridge/builder.rs diff --git a/rustboyadvance-core/src/core/cartridge/header.rs b/rustboyadvance-core/src/cartridge/header.rs similarity index 100% rename from rustboyadvance-core/src/core/cartridge/header.rs rename to rustboyadvance-core/src/cartridge/header.rs diff --git a/rustboyadvance-core/src/core/cartridge/loader.rs b/rustboyadvance-core/src/cartridge/loader.rs similarity index 100% rename from rustboyadvance-core/src/core/cartridge/loader.rs rename to rustboyadvance-core/src/cartridge/loader.rs diff --git a/rustboyadvance-core/src/core/cartridge/mod.rs b/rustboyadvance-core/src/cartridge/mod.rs similarity index 100% rename from rustboyadvance-core/src/core/cartridge/mod.rs rename to rustboyadvance-core/src/cartridge/mod.rs diff --git a/rustboyadvance-core/src/core/mod.rs b/rustboyadvance-core/src/core/mod.rs deleted file mode 100644 index 3a74278..0000000 --- a/rustboyadvance-core/src/core/mod.rs +++ /dev/null @@ -1,68 +0,0 @@ -pub mod arm7tdmi; -pub mod cartridge; -pub mod gpu; -pub mod sound; -pub mod sysbus; -pub use sysbus::SysBus; -pub mod interrupt; -pub mod iodev; -pub use interrupt::Interrupt; -pub use interrupt::IrqBitmask; -pub mod gba; -pub use gba::GameBoyAdvance; -pub mod bus; -pub mod dma; -pub mod keypad; -pub mod timer; -pub use bus::*; - -pub use super::{AudioInterface, InputInterface, VideoInterface}; - -#[cfg(feature = "debugger")] -use crate::debugger; - -use zip; - -use std::error::Error; -use std::fmt; - -#[derive(Debug)] -pub enum GBAError { - IO(::std::io::Error), - CartridgeLoadError(String), - #[cfg(feature = "debugger")] - DebuggerError(debugger::DebuggerError), -} - -impl fmt::Display for GBAError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "error: {:?}", self) - } -} - -impl Error for GBAError { - fn description(&self) -> &str { - "emulator error" - } -} - -pub type GBAResult = Result; - -impl From<::std::io::Error> for GBAError { - fn from(err: ::std::io::Error) -> GBAError { - GBAError::IO(err) - } -} - -#[cfg(feature = "debugger")] -impl From for GBAError { - fn from(err: debugger::DebuggerError) -> GBAError { - GBAError::DebuggerError(err) - } -} - -impl From for GBAError { - fn from(_err: zip::result::ZipError) -> GBAError { - GBAError::IO(::std::io::Error::from(::std::io::ErrorKind::InvalidInput)) - } -} diff --git a/rustboyadvance-core/src/debugger/command.rs b/rustboyadvance-core/src/debugger/command.rs index 694ccb9..c99570e 100644 --- a/rustboyadvance-core/src/debugger/command.rs +++ b/rustboyadvance-core/src/debugger/command.rs @@ -2,12 +2,12 @@ use std::path::Path; use std::sync::atomic::Ordering; use std::time; -use crate::core::arm7tdmi::arm::ArmInstruction; -use crate::core::arm7tdmi::thumb::ThumbInstruction; -use crate::core::arm7tdmi::CpuState; -use crate::core::{Addr, Bus}; +use crate::arm7tdmi::arm::ArmInstruction; +use crate::arm7tdmi::thumb::ThumbInstruction; +use crate::arm7tdmi::CpuState; use crate::disass::Disassembler; use crate::util::{read_bin_file, write_bin_file}; +use crate::{Addr, Bus}; // use super::palette_view::create_palette_view; // use super::tile_view::create_tile_view; diff --git a/rustboyadvance-core/src/debugger/mod.rs b/rustboyadvance-core/src/debugger/mod.rs index 0e1fe84..ab8766c 100644 --- a/rustboyadvance-core/src/debugger/mod.rs +++ b/rustboyadvance-core/src/debugger/mod.rs @@ -6,8 +6,8 @@ use rustyline::Editor; use colored::*; -use super::core::GameBoyAdvance; -use super::core::{Addr, Bus}; +use super::GameBoyAdvance; +use super::{Addr, Bus}; mod parser; use parser::{parse_expr, DerefType, Expr, Value}; diff --git a/rustboyadvance-core/src/debugger/palette_view.rs b/rustboyadvance-core/src/debugger/palette_view.rs index efc0221..aaf4bbf 100644 --- a/rustboyadvance-core/src/debugger/palette_view.rs +++ b/rustboyadvance-core/src/debugger/palette_view.rs @@ -3,7 +3,7 @@ // use sdl2::rect::{Point, Rect}; // use sdl2::render::Canvas; -// use crate::core::palette::{Palette, Rgb15}; +// use crate::palette::{Palette, Rgb15}; // const PALETTE_RECT_WIDTH: u32 = 20; diff --git a/rustboyadvance-core/src/debugger/tile_view.rs b/rustboyadvance-core/src/debugger/tile_view.rs index e561e11..9abc753 100644 --- a/rustboyadvance-core/src/debugger/tile_view.rs +++ b/rustboyadvance-core/src/debugger/tile_view.rs @@ -5,8 +5,8 @@ // use sdl2::rect::{Point, Rect}; // use sdl2::render::Canvas; -// use crate::core::gba::GameBoyAdvance; -// use crate::core::gpu::PixelFormat; +// use crate::gba::GameBoyAdvance; +// use crate::gpu::PixelFormat; // fn draw_tile( // gba: &GameBoyAdvance, diff --git a/rustboyadvance-core/src/disass.rs b/rustboyadvance-core/src/disass.rs index 9dbc919..fba3178 100644 --- a/rustboyadvance-core/src/disass.rs +++ b/rustboyadvance-core/src/disass.rs @@ -1,8 +1,8 @@ use std::fmt; use std::marker::PhantomData; -use super::core::arm7tdmi::InstructionDecoder; -use super::core::Addr; +use super::arm7tdmi::InstructionDecoder; +use super::Addr; pub struct Disassembler<'a, D> where diff --git a/rustboyadvance-core/src/core/dma.rs b/rustboyadvance-core/src/dma.rs similarity index 100% rename from rustboyadvance-core/src/core/dma.rs rename to rustboyadvance-core/src/dma.rs diff --git a/rustboyadvance-core/src/core/gba.rs b/rustboyadvance-core/src/gba.rs similarity index 99% rename from rustboyadvance-core/src/core/gba.rs rename to rustboyadvance-core/src/gba.rs index 1c2ac8a..b510cde 100644 --- a/rustboyadvance-core/src/core/gba.rs +++ b/rustboyadvance-core/src/gba.rs @@ -13,7 +13,7 @@ use super::iodev::*; use super::sound::SoundController; use super::sysbus::SysBus; -use super::super::{AudioInterface, InputInterface, VideoInterface}; +use super::{AudioInterface, InputInterface, VideoInterface}; pub struct GameBoyAdvance { pub sysbus: Box, diff --git a/rustboyadvance-core/src/gdb.rs b/rustboyadvance-core/src/gdb.rs index 7525f5c..4274d40 100644 --- a/rustboyadvance-core/src/gdb.rs +++ b/rustboyadvance-core/src/gdb.rs @@ -1,9 +1,9 @@ -use super::core::arm7tdmi::CpuState; -use super::core::interrupt::*; -use super::core::iodev::IoDevices; -use super::core::sysbus::SysBus; -use super::core::Bus; +use super::arm7tdmi::CpuState; use super::core::GameBoyAdvance; +use super::interrupt::*; +use super::iodev::IoDevices; +use super::sysbus::SysBus; +use super::Bus; use byteorder::{LittleEndian, ReadBytesExt}; use gdbstub::{Access, Target, TargetState}; diff --git a/rustboyadvance-core/src/core/gpu/layer.rs b/rustboyadvance-core/src/gpu/layer.rs similarity index 100% rename from rustboyadvance-core/src/core/gpu/layer.rs rename to rustboyadvance-core/src/gpu/layer.rs diff --git a/rustboyadvance-core/src/core/gpu/mod.rs b/rustboyadvance-core/src/gpu/mod.rs similarity index 99% rename from rustboyadvance-core/src/core/gpu/mod.rs rename to rustboyadvance-core/src/gpu/mod.rs index 835b64c..65fa079 100644 --- a/rustboyadvance-core/src/core/gpu/mod.rs +++ b/rustboyadvance-core/src/gpu/mod.rs @@ -4,10 +4,10 @@ use std::rc::Rc; use serde::{Deserialize, Serialize}; -use super::super::VideoInterface; use super::interrupt::IrqBitmask; use super::sysbus::{BoxedMemory, SysBus}; use super::Bus; +use super::VideoInterface; use crate::bitfield::Bit; use crate::num::FromPrimitive; diff --git a/rustboyadvance-core/src/core/gpu/mosaic.rs b/rustboyadvance-core/src/gpu/mosaic.rs similarity index 100% rename from rustboyadvance-core/src/core/gpu/mosaic.rs rename to rustboyadvance-core/src/gpu/mosaic.rs diff --git a/rustboyadvance-core/src/core/gpu/regs.rs b/rustboyadvance-core/src/gpu/regs.rs similarity index 100% rename from rustboyadvance-core/src/core/gpu/regs.rs rename to rustboyadvance-core/src/gpu/regs.rs diff --git a/rustboyadvance-core/src/core/gpu/render.rs b/rustboyadvance-core/src/gpu/render.rs similarity index 100% rename from rustboyadvance-core/src/core/gpu/render.rs rename to rustboyadvance-core/src/gpu/render.rs diff --git a/rustboyadvance-core/src/core/gpu/render/bitmap.rs b/rustboyadvance-core/src/gpu/render/bitmap.rs similarity index 98% rename from rustboyadvance-core/src/core/gpu/render/bitmap.rs rename to rustboyadvance-core/src/gpu/render/bitmap.rs index 479d7e7..641679f 100644 --- a/rustboyadvance-core/src/core/gpu/render/bitmap.rs +++ b/rustboyadvance-core/src/gpu/render/bitmap.rs @@ -6,7 +6,7 @@ use super::super::Rgb15; use super::{utils, SCREEN_VIEWPORT}; -use crate::core::Bus; +use crate::Bus; impl Gpu { pub(in super::super) fn render_mode3(&mut self, bg: usize) { diff --git a/rustboyadvance-core/src/core/gpu/render/obj.rs b/rustboyadvance-core/src/gpu/render/obj.rs similarity index 100% rename from rustboyadvance-core/src/core/gpu/render/obj.rs rename to rustboyadvance-core/src/gpu/render/obj.rs diff --git a/rustboyadvance-core/src/core/gpu/render/text.rs b/rustboyadvance-core/src/gpu/render/text.rs similarity index 99% rename from rustboyadvance-core/src/core/gpu/render/text.rs rename to rustboyadvance-core/src/gpu/render/text.rs index 6a395b3..3864b92 100644 --- a/rustboyadvance-core/src/core/gpu/render/text.rs +++ b/rustboyadvance-core/src/gpu/render/text.rs @@ -5,7 +5,7 @@ use super::super::Rgb15; use super::super::{Gpu, PixelFormat, SCREEN_BLOCK_SIZE}; use super::{utils, ViewPort}; -use crate::core::Bus; +use crate::Bus; impl Gpu { pub(in super::super) fn render_reg_bg(&mut self, bg: usize) { diff --git a/rustboyadvance-core/src/core/gpu/rgb15.rs b/rustboyadvance-core/src/gpu/rgb15.rs similarity index 100% rename from rustboyadvance-core/src/core/gpu/rgb15.rs rename to rustboyadvance-core/src/gpu/rgb15.rs diff --git a/rustboyadvance-core/src/core/gpu/sfx.rs b/rustboyadvance-core/src/gpu/sfx.rs similarity index 100% rename from rustboyadvance-core/src/core/gpu/sfx.rs rename to rustboyadvance-core/src/gpu/sfx.rs diff --git a/rustboyadvance-core/src/core/gpu/window.rs b/rustboyadvance-core/src/gpu/window.rs similarity index 100% rename from rustboyadvance-core/src/core/gpu/window.rs rename to rustboyadvance-core/src/gpu/window.rs diff --git a/rustboyadvance-core/src/core/interrupt.rs b/rustboyadvance-core/src/interrupt.rs similarity index 100% rename from rustboyadvance-core/src/core/interrupt.rs rename to rustboyadvance-core/src/interrupt.rs diff --git a/rustboyadvance-core/src/core/iodev.rs b/rustboyadvance-core/src/iodev.rs similarity index 100% rename from rustboyadvance-core/src/core/iodev.rs rename to rustboyadvance-core/src/iodev.rs diff --git a/rustboyadvance-core/src/core/keypad.rs b/rustboyadvance-core/src/keypad.rs similarity index 100% rename from rustboyadvance-core/src/core/keypad.rs rename to rustboyadvance-core/src/keypad.rs diff --git a/rustboyadvance-core/src/lib.rs b/rustboyadvance-core/src/lib.rs index 7fd0027..74a137b 100644 --- a/rustboyadvance-core/src/lib.rs +++ b/rustboyadvance-core/src/lib.rs @@ -23,10 +23,31 @@ extern crate log; #[macro_use] extern crate hex_literal; +use zip; + +use std::error::Error; +use std::fmt; + #[macro_use] pub mod util; -pub mod core; +pub mod arm7tdmi; +pub mod cartridge; pub mod disass; +pub mod gpu; +pub mod sound; +pub mod sysbus; +pub use sysbus::SysBus; +pub mod interrupt; +pub mod iodev; +pub use interrupt::Interrupt; +pub use interrupt::IrqBitmask; +pub mod gba; +pub use gba::GameBoyAdvance; +pub mod bus; +pub mod dma; +pub mod keypad; +pub mod timer; +pub use bus::*; #[cfg(feature = "gdb")] pub mod gdb; @@ -55,18 +76,60 @@ pub trait AudioInterface { pub trait InputInterface { fn poll(&mut self) -> u16 { - core::keypad::KEYINPUT_ALL_RELEASED + keypad::KEYINPUT_ALL_RELEASED + } +} + +#[cfg(feature = "debugger")] +#[derive(Debug)] +pub enum GBAError { + IO(::std::io::Error), + CartridgeLoadError(String), + #[cfg(feature = "debugger")] + DebuggerError(debugger::DebuggerError), +} + +impl fmt::Display for GBAError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "error: {:?}", self) + } +} + +impl Error for GBAError { + fn description(&self) -> &str { + "emulator error" + } +} + +pub type GBAResult = Result; + +impl From<::std::io::Error> for GBAError { + fn from(err: ::std::io::Error) -> GBAError { + GBAError::IO(err) + } +} + +#[cfg(feature = "debugger")] +impl From for GBAError { + fn from(err: debugger::DebuggerError) -> GBAError { + GBAError::DebuggerError(err) + } +} + +impl From for GBAError { + fn from(_err: zip::result::ZipError) -> GBAError { + GBAError::IO(::std::io::Error::from(::std::io::ErrorKind::InvalidInput)) } } pub mod prelude { - pub use super::core::arm7tdmi; - pub use super::core::cartridge::{Cartridge, GamepakBuilder}; - pub use super::core::gpu::{DISPLAY_HEIGHT, DISPLAY_WIDTH}; - pub use super::core::Bus; - pub use super::core::{GBAError, GBAResult, GameBoyAdvance}; + pub use super::arm7tdmi; + pub use super::cartridge::{Cartridge, GamepakBuilder}; #[cfg(feature = "debugger")] pub use super::debugger::Debugger; + pub use super::gpu::{DISPLAY_HEIGHT, DISPLAY_WIDTH}; pub use super::util::{read_bin_file, write_bin_file}; + pub use super::Bus; pub use super::{AudioInterface, InputInterface, StereoSample, VideoInterface}; + pub use super::{GBAError, GBAResult, GameBoyAdvance}; } diff --git a/rustboyadvance-core/src/core/sound/dsp.rs b/rustboyadvance-core/src/sound/dsp.rs similarity index 100% rename from rustboyadvance-core/src/core/sound/dsp.rs rename to rustboyadvance-core/src/sound/dsp.rs diff --git a/rustboyadvance-core/src/core/sound/fifo.rs b/rustboyadvance-core/src/sound/fifo.rs similarity index 100% rename from rustboyadvance-core/src/core/sound/fifo.rs rename to rustboyadvance-core/src/sound/fifo.rs diff --git a/rustboyadvance-core/src/core/sound/mod.rs b/rustboyadvance-core/src/sound/mod.rs similarity index 100% rename from rustboyadvance-core/src/core/sound/mod.rs rename to rustboyadvance-core/src/sound/mod.rs diff --git a/rustboyadvance-core/src/core/sysbus.rs b/rustboyadvance-core/src/sysbus.rs similarity index 100% rename from rustboyadvance-core/src/core/sysbus.rs rename to rustboyadvance-core/src/sysbus.rs diff --git a/rustboyadvance-core/src/core/timer.rs b/rustboyadvance-core/src/timer.rs similarity index 100% rename from rustboyadvance-core/src/core/timer.rs rename to rustboyadvance-core/src/timer.rs diff --git a/rustboyadvance-core/src/util.rs b/rustboyadvance-core/src/util.rs index 15675ff..b48521d 100644 --- a/rustboyadvance-core/src/util.rs +++ b/rustboyadvance-core/src/util.rs @@ -21,7 +21,7 @@ fn now() -> Instant { instant::Instant::now() } -use crate::core::GameBoyAdvance; +use crate::GameBoyAdvance; #[cfg(feature = "gdb")] use gdbstub; #[cfg(feature = "gdb")]