tests: Wrap gba-suite by jsmolka

Former-commit-id: 511f08470520c712b3b5a5bd9e33ac590939c315
This commit is contained in:
Michel Heily 2020-01-17 01:28:11 +02:00
parent 1d7035b600
commit 8755013ec6
6 changed files with 89 additions and 7 deletions

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "external/gba-suite"]
path = external/gba-suite
url = https://github.com/jsmolka/gba-suite.git

View file

@ -58,12 +58,12 @@ crashes when entering in-game menu, other than that works fine.
![Pokemon Emerald](media/screenshot1.png) ![Kirby - Nightmare in Dreamland](media/screenshot2.png) ![Dragon Ball - Legacy of Goku 2](media/screenshot3.png) ![Pokemon Emerald](media/screenshot1.png) ![Kirby - Nightmare in Dreamland](media/screenshot2.png) ![Dragon Ball - Legacy of Goku 2](media/screenshot3.png)
# Links # Links and attribution
- [ARM7TDMI Technical Reference Manual](http://infocenter.arm.com/help/topic/com.arm.doc.ddi0210c/DDI0210B.pdf) - [ARM7TDMI Technical Reference Manual](http://infocenter.arm.com/help/topic/com.arm.doc.ddi0210c/DDI0210B.pdf)
Technical Reference Manuals are **fun**. Technical Reference Manuals are **fun**.
- [GBATEK](http://problemkaputt.de/gbatek.htm) - [GBATEK](http://problemkaputt.de/gbatek.htm)
A single webpage written by *no$gba* developer Martin Korth. A single webpage written by *no$gba* developer Martin Korth.
This page has pretty much everything. Seriously, it's the best. This page has pretty much everything. Seriously, it's the best.
- [TONC](https://www.coranac.com/tonc/text/) - [TONC](https://www.coranac.com/tonc/text/)
A comprehensive GBA dev guide that I used a-lot in order to understand the GBA system. A comprehensive GBA dev guide that I used a-lot in order to understand the GBA system.
@ -71,5 +71,5 @@ crashes when entering in-game menu, other than that works fine.
- [NanoboyAdvance](https://github.com/fleroviux/NanoboyAdvance) - [NanoboyAdvance](https://github.com/fleroviux/NanoboyAdvance)
A GameBoy Advance emulator written in C++17 by a nice person called fleroviux. A GameBoy Advance emulator written in C++17 by a nice person called fleroviux.
I've used this for debugging. I've used this for debugging.
- [Eggvance](https://github.com/jsmolka/eggvance/tree/master/tests) - [Eggvance gba-suite](https://github.com/jsmolka/gba-suite)
A GameBoy Advance emulator written in C++, with really useful CPU test roms. Incredible test suite for the arm7tdmi interpreter that I'm using, written by Julian Smolka.

1
external/gba-suite vendored Submodule

@ -0,0 +1 @@
Subproject commit 854c1fb3a02fc8d94d04041b2948826708d81011

View file

@ -122,6 +122,15 @@ impl Cartridge {
bytes: rom_bin.into_boxed_slice(), bytes: rom_bin.into_boxed_slice(),
}) })
} }
pub fn from_bytes(bytes: &[u8]) -> Cartridge {
let header = CartridgeHeader::parse(&bytes);
Cartridge {
header: header,
bytes: bytes.into(),
}
}
} }
impl Bus for Cartridge { impl Bus for Cartridge {

View file

@ -182,3 +182,67 @@ impl GameBoyAdvance {
io.intc.request_irqs(irqs); io.intc.request_irqs(irqs);
} }
} }
#[cfg(test)]
mod tests {
use super::*;
use std::cell::RefCell;
use std::rc::Rc;
use super::super::arm7tdmi;
use super::super::cartridge::Cartridge;
struct DummyInterface {}
impl DummyInterface {
fn new() -> DummyInterface {
DummyInterface {}
}
}
impl VideoInterface for DummyInterface {}
impl AudioInterface for DummyInterface {}
impl InputInterface for DummyInterface {}
fn make_mock_gba(rom: &[u8]) -> GameBoyAdvance {
let bios = vec![0; 0x4000];
let cpu = arm7tdmi::Core::new();
let cartridge = Cartridge::from_bytes(rom);
let dummy = Rc::new(RefCell::new(DummyInterface::new()));
let mut gba = GameBoyAdvance::new(
cpu,
bios,
cartridge,
dummy.clone(),
dummy.clone(),
dummy.clone(),
);
gba.skip_bios();
gba
}
#[test]
fn test_arm7tdmi_arm_eggvance() {
let mut gba = make_mock_gba(include_bytes!("../../external/gba-suite/arm/arm.gba"));
for _ in 0..10 {
gba.frame();
}
assert_eq!(0x080019e0, gba.cpu.pc);
assert_eq!(0, gba.cpu.gpr[12]);
}
#[test]
fn test_arm7tdmi_thumb_eggvance() {
let mut gba = make_mock_gba(include_bytes!("../../external/gba-suite/thumb/thumb.gba"));
for _ in 0..10 {
gba.frame();
}
assert_eq!(0x800091a, gba.cpu.pc);
assert_eq!(0, gba.cpu.gpr[7]);
}
}

View file

@ -43,20 +43,25 @@ pub mod disass;
pub mod debugger; pub mod debugger;
pub trait VideoInterface { pub trait VideoInterface {
fn render(&mut self, buffer: &[u32]); #[allow(unused_variables)]
fn render(&mut self, buffer: &[u32]) {}
} }
pub type StereoSample = (i16, i16); pub type StereoSample = (i16, i16);
pub trait AudioInterface { pub trait AudioInterface {
fn get_sample_rate(&self) -> i32; fn get_sample_rate(&self) -> i32 {
44100
}
#[allow(unused_variables)] #[allow(unused_variables)]
fn push_sample(&mut self, samples: StereoSample) {} fn push_sample(&mut self, samples: StereoSample) {}
} }
pub trait InputInterface { pub trait InputInterface {
fn poll(&mut self) -> u16; fn poll(&mut self) -> u16 {
core::keypad::KEYINPUT_ALL_RELEASED
}
} }
pub mod prelude { pub mod prelude {