2020-01-16 17:49:13 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate serde;
|
|
|
|
|
2020-05-20 23:01:23 +01:00
|
|
|
#[macro_use]
|
|
|
|
extern crate lazy_static;
|
|
|
|
|
2019-12-28 13:59:35 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate debug_stub_derive;
|
|
|
|
|
2019-06-30 20:31:16 +01:00
|
|
|
#[macro_use]
|
|
|
|
extern crate enum_primitive_derive;
|
2020-02-14 12:01:48 +00:00
|
|
|
use num;
|
|
|
|
use num_traits;
|
2019-06-30 20:31:16 +01:00
|
|
|
|
2020-02-14 12:01:48 +00:00
|
|
|
use bit;
|
2019-08-02 22:18:59 +01:00
|
|
|
#[macro_use]
|
|
|
|
extern crate bitfield;
|
2019-08-13 19:57:45 +01:00
|
|
|
#[macro_use]
|
|
|
|
extern crate bitflags;
|
2019-06-30 20:31:16 +01:00
|
|
|
|
2020-02-14 12:01:48 +00:00
|
|
|
use byteorder;
|
2020-01-17 14:08:23 +00:00
|
|
|
|
2020-01-30 23:47:52 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate log;
|
|
|
|
|
2020-05-01 15:58:15 +01:00
|
|
|
#[macro_use]
|
|
|
|
extern crate hex_literal;
|
|
|
|
|
2020-11-06 10:38:41 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate smart_default;
|
|
|
|
|
2020-10-06 07:46:14 +01:00
|
|
|
extern crate cfg_if;
|
|
|
|
|
2020-05-01 16:13:00 +01:00
|
|
|
use zip;
|
|
|
|
|
|
|
|
use std::error::Error;
|
|
|
|
use std::fmt;
|
|
|
|
|
2019-07-30 22:52:46 +01:00
|
|
|
#[macro_use]
|
|
|
|
pub mod util;
|
2020-05-01 16:13:00 +01:00
|
|
|
pub mod arm7tdmi;
|
2020-11-23 22:45:07 +00:00
|
|
|
pub use arm7tdmi::disass;
|
2020-10-18 01:00:02 +01:00
|
|
|
mod bios;
|
2020-05-01 16:13:00 +01:00
|
|
|
pub mod cartridge;
|
|
|
|
pub mod gpu;
|
2020-10-03 20:09:38 +01:00
|
|
|
mod sched;
|
2020-05-01 16:13:00 +01:00
|
|
|
pub mod sound;
|
|
|
|
pub mod sysbus;
|
|
|
|
pub use sysbus::SysBus;
|
|
|
|
pub mod interrupt;
|
|
|
|
pub mod iodev;
|
|
|
|
pub use interrupt::Interrupt;
|
2020-05-25 23:46:05 +01:00
|
|
|
pub use interrupt::SharedInterruptFlags;
|
2020-05-01 16:13:00 +01:00
|
|
|
pub mod gba;
|
|
|
|
pub use gba::GameBoyAdvance;
|
|
|
|
pub mod bus;
|
|
|
|
pub mod dma;
|
|
|
|
pub mod keypad;
|
|
|
|
pub mod timer;
|
|
|
|
pub use bus::*;
|
2020-10-24 13:54:31 +01:00
|
|
|
mod mgba_debug;
|
2020-05-20 23:01:23 +01:00
|
|
|
pub(crate) mod overrides;
|
2019-12-04 23:15:49 +00:00
|
|
|
|
2020-02-21 12:04:39 +00:00
|
|
|
#[cfg(feature = "gdb")]
|
|
|
|
pub mod gdb;
|
|
|
|
|
2020-01-12 23:11:58 +00:00
|
|
|
#[cfg(feature = "debugger")]
|
2019-12-29 21:37:23 +00:00
|
|
|
pub mod debugger;
|
|
|
|
|
2020-09-29 22:10:47 +01:00
|
|
|
#[cfg(not(feature = "no_video_interface"))]
|
2019-12-04 23:15:49 +00:00
|
|
|
pub trait VideoInterface {
|
2020-01-16 23:28:11 +00:00
|
|
|
#[allow(unused_variables)]
|
|
|
|
fn render(&mut self, buffer: &[u32]) {}
|
2019-12-04 23:15:49 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 23:18:47 +00:00
|
|
|
pub type StereoSample<T> = (T, T);
|
2019-12-28 13:59:35 +00:00
|
|
|
|
2019-12-04 23:15:49 +00:00
|
|
|
pub trait AudioInterface {
|
2020-01-16 23:28:11 +00:00
|
|
|
fn get_sample_rate(&self) -> i32 {
|
|
|
|
44100
|
|
|
|
}
|
2019-12-21 22:58:18 +00:00
|
|
|
|
2020-01-20 23:18:47 +00:00
|
|
|
/// Pushes a stereo sample into the audio device
|
|
|
|
/// Sample should be normilized to siged 16bit values
|
|
|
|
/// Note: It is not guarentied that the sample will be played
|
2019-12-21 22:58:18 +00:00
|
|
|
#[allow(unused_variables)]
|
2020-09-29 22:27:00 +01:00
|
|
|
fn push_sample(&mut self, samples: &[i16]) {}
|
2019-12-04 23:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub trait InputInterface {
|
2020-01-16 23:28:11 +00:00
|
|
|
fn poll(&mut self) -> u16 {
|
2020-05-01 16:13:00 +01:00
|
|
|
keypad::KEYINPUT_ALL_RELEASED
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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<T> = Result<T, GBAError>;
|
|
|
|
|
|
|
|
impl From<::std::io::Error> for GBAError {
|
|
|
|
fn from(err: ::std::io::Error) -> GBAError {
|
|
|
|
GBAError::IO(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "debugger")]
|
|
|
|
impl From<debugger::DebuggerError> for GBAError {
|
|
|
|
fn from(err: debugger::DebuggerError) -> GBAError {
|
|
|
|
GBAError::DebuggerError(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<zip::result::ZipError> for GBAError {
|
|
|
|
fn from(_err: zip::result::ZipError) -> GBAError {
|
|
|
|
GBAError::IO(::std::io::Error::from(::std::io::ErrorKind::InvalidInput))
|
2020-01-16 23:28:11 +00:00
|
|
|
}
|
2019-12-04 23:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub mod prelude {
|
2020-05-01 16:13:00 +01:00
|
|
|
pub use super::arm7tdmi;
|
|
|
|
pub use super::cartridge::{Cartridge, GamepakBuilder};
|
2020-01-12 23:11:58 +00:00
|
|
|
#[cfg(feature = "debugger")]
|
2019-12-04 23:15:49 +00:00
|
|
|
pub use super::debugger::Debugger;
|
2020-05-01 16:13:00 +01:00
|
|
|
pub use super::gpu::{DISPLAY_HEIGHT, DISPLAY_WIDTH};
|
2020-01-16 17:49:43 +00:00
|
|
|
pub use super::util::{read_bin_file, write_bin_file};
|
2020-05-01 16:13:00 +01:00
|
|
|
pub use super::Bus;
|
2020-09-29 22:10:47 +01:00
|
|
|
#[cfg(not(feature = "no_video_interface"))]
|
|
|
|
pub use super::VideoInterface;
|
2020-10-10 19:06:11 +01:00
|
|
|
pub use super::{AudioInterface, InputInterface, StereoSample};
|
2020-05-01 16:13:00 +01:00
|
|
|
pub use super::{GBAError, GBAResult, GameBoyAdvance};
|
2019-12-04 23:15:49 +00:00
|
|
|
}
|