Skip to content

Commit

Permalink
chore: extract core emulator to own crate, add actions for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
EliseZeroTwo committed Jan 2, 2024
1 parent dff765a commit 984ead0
Show file tree
Hide file tree
Showing 31 changed files with 85 additions and 26 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
on:
push:
branches:
- main

jobs:
main_test:
name: Test changes to main
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install toolchain
run: curl https://sh.rustup.rs -sSf | sh -s -- --profile minimal --default-toolchain stable -y && echo "$HOME/.cargo/bin" >> $GITHUB_PATH

- name: Run cargo tests (meowgb-core)
run: cargo test -p meowgb-core

- name: Run test ROM (blargg cpu_instrs)
if: always()
run: cargo run --bin meowgb-tests --release -- test-roms/blargg/roms/cpu_instrs.gb test -m 100000000 -s meowgb-tests/expected_output/cpu_instrs.bin

- name: Run test ROM (blargg instr_timing)
if: always()
run: cargo run --bin meowgb-tests --release -- test-roms/blargg/roms/instr_timing.gb test -m 100000000 -s meowgb-tests/expected_output/instr_timing.bin

- name: Run test ROM (mealybug-tearoom-tests intr_1_2_timing)
if: always()
run: cargo run --bin meowgb-tests --release -- test-roms/mealybug-tearoom-tests/roms/intr_1_2_timing-GS.gb test -m 100000000 -s meowgb-tests/expected_output/intr_1_2_timing-GS.bin

- name: Run test ROM (mealybug-tearoom-tests intr_2_0_timing)
if: always()
run: cargo run --bin meowgb-tests --release -- test-roms/mealybug-tearoom-tests/roms/intr_2_0_timing.gb test -m 100000000 -s meowgb-tests/expected_output/intr_2_0_timing.bin

- name: Run test ROM (mealybug-tearoom-tests stat_lyc_onoff)
if: always()
run: cargo run --bin meowgb-tests --release -- test-roms/mealybug-tearoom-tests/roms/stat_lyc_onoff.gb test -m 100000000 -s meowgb-tests/expected_output/stat_lyc_onoff.bin

- name: Run test ROM (mealybug-tearoom-tests stat_irq_blocking)
if: always()
run: cargo run --bin meowgb-tests --release -- test-roms/mealybug-tearoom-tests/roms/stat_irq_blocking.gb test -m 100000000 -s meowgb-tests/expected_output/stat_irq_blocking.bin
20 changes: 15 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[workspace]
resolver = "2"
members = ["meowgb", "meowgb-opcode", "meowgb-tests"]
members = ["meowgb", "meowgb-core", "meowgb-opcode", "meowgb-tests"]
15 changes: 15 additions & 0 deletions meowgb-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "meowgb-core"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
log = "0.4.14"
paste = "1.0.6"
meowgb-opcode = { path = "../meowgb-opcode" }
bmp = "0.5.0"
chrono = "0.4.19"
thiserror = "1.0.30"
sha1 = { version = "0.10.6", features = ["std"] }
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 1 addition & 5 deletions meowgb/src/lib.rs → meowgb-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
use std::io::Stdout;

pub mod gameboy;
#[allow(unused)]
mod settings;

pub fn setup_test_emulator<const ROM_LENGTH: usize>(
test_opcodes: [u8; ROM_LENGTH],
) -> gameboy::Gameboy<Stdout> {
) -> gameboy::Gameboy<std::io::Stdout> {
let mut gameboy = gameboy::Gameboy::new(None, std::io::stdout());

let mut cartridge = gameboy::mapper::NoMBC { rom: [0u8; 0x8000], ram: None };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use meowgb::setup_test_emulator;
use meowgb_core::setup_test_emulator;

macro_rules! conditional_jump_relative_testgen {
($flag:ident, $not_opcode:literal, $opcode:literal) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use meowgb::setup_test_emulator;
use meowgb_core::setup_test_emulator;

macro_rules! ld_reg_imm_u16_testgen {
($hireg:ident, $loreg:ident, $opcode:literal) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use meowgb::setup_test_emulator;
use meowgb_core::setup_test_emulator;

#[test]
fn test_nop() {
Expand Down
2 changes: 1 addition & 1 deletion meowgb-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ edition = "2021"

[dependencies]
clap = { version = "4.4.12", features = ["derive"] }
meowgb = { path = "../meowgb" }
meowgb-core = { path = "../meowgb-core" }
thiserror = "1.0.56"
2 changes: 1 addition & 1 deletion meowgb-tests/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{path::{PathBuf, Path}, sync::{RwLock, Arc}, time::{Duration, Instant}};

use clap::{Parser, Subcommand};
use meowgb::gameboy::{Gameboy, serial::SerialWriter};
use meowgb_core::gameboy::{Gameboy, serial::SerialWriter};

#[derive(Debug, Parser)]
/// DMG Emulator
Expand Down
9 changes: 3 additions & 6 deletions meowgb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bmp = "0.5.0"
chrono = "0.4.19"
meowgb-core = { path = "../meowgb-core" }
clap = { version = "4.4.12", features = ["derive"] }
config = "0.13.4"
meowgb-opcode = { path = "../meowgb-opcode" }
env_logger = "0.10.1"
log = "0.4.14"
paste = "1.0.6"
pixels = "0.13.0"
serde = { version = "1.0.130", features = ["derive"] }
sha1 = { version = "0.10.6", features = ["std"] }
thiserror = "1.0.30"
winit = { version = "0.29.7", default-features = false, features = ["serde", "rwh_05"] }
winit_input_helper = "0.15.1"
chrono = "0.4.31"
log = "0.4.20"
3 changes: 1 addition & 2 deletions meowgb/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
mod gameboy;
mod settings;
mod window;

Expand All @@ -10,7 +9,7 @@ use std::{

use chrono::{Duration, Utc};
use clap::Parser;
use gameboy::{Gameboy, bootrom::{BootromParseError, verify_parse_bootrom}};
use meowgb_core::gameboy::{Gameboy, bootrom::{BootromParseError, verify_parse_bootrom}};
use settings::DeemgeeConfig;
use window::EmulatorWindowEvent;

Expand Down
4 changes: 2 additions & 2 deletions meowgb/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ pub fn run_window(
let window_size = window.inner_size();
let surface_texture = SurfaceTexture::new(window_size.width, window_size.height, &window);
Pixels::new(
crate::gameboy::ppu::FB_WIDTH,
crate::gameboy::ppu::FB_HEIGHT,
meowgb_core::gameboy::ppu::FB_WIDTH,
meowgb_core::gameboy::ppu::FB_HEIGHT,
surface_texture,
)
.unwrap()
Expand Down

0 comments on commit 984ead0

Please sign in to comment.