From 984ead01ebdebd4806fa0a1a403c6d36c1a3b2fb Mon Sep 17 00:00:00 2001 From: EliseZeroTwo Date: Tue, 2 Jan 2024 13:42:56 -0700 Subject: [PATCH] chore: extract core emulator to own crate, add actions for testing --- .github/workflows/action.yml | 42 +++++++++++++++++++ Cargo.lock | 20 ++++++--- Cargo.toml | 2 +- meowgb-core/Cargo.toml | 15 +++++++ {meowgb => meowgb-core}/src/gameboy.rs | 0 .../src/gameboy/bootrom.rs | 0 {meowgb => meowgb-core}/src/gameboy/cpu.rs | 0 .../src/gameboy/cpu/alu.rs | 0 .../src/gameboy/cpu/flow.rs | 0 .../src/gameboy/cpu/load_store_move.rs | 0 .../src/gameboy/cpu/misc.rs | 0 .../src/gameboy/cpu/prefixed.rs | 0 .../src/gameboy/interrupts.rs | 0 {meowgb => meowgb-core}/src/gameboy/joypad.rs | 0 {meowgb => meowgb-core}/src/gameboy/mapper.rs | 0 .../src/gameboy/mapper/mbc1.rs | 0 {meowgb => meowgb-core}/src/gameboy/memory.rs | 0 {meowgb => meowgb-core}/src/gameboy/ppu.rs | 0 {meowgb => meowgb-core}/src/gameboy/serial.rs | 0 {meowgb => meowgb-core}/src/gameboy/sound.rs | 0 {meowgb => meowgb-core}/src/gameboy/timer.rs | 0 {meowgb => meowgb-core}/src/lib.rs | 6 +-- {meowgb => meowgb-core}/tests/flow_opcodes.rs | 2 +- .../tests/load_store_move_opcodes.rs | 2 +- {meowgb => meowgb-core}/tests/misc_opcodes.rs | 2 +- meowgb-tests/Cargo.toml | 2 +- .../{intr_lyc_onoff.gb => stat_lyc_onoff.bin} | 0 meowgb-tests/src/main.rs | 2 +- meowgb/Cargo.toml | 9 ++-- meowgb/src/main.rs | 3 +- meowgb/src/window.rs | 4 +- 31 files changed, 85 insertions(+), 26 deletions(-) create mode 100644 .github/workflows/action.yml create mode 100644 meowgb-core/Cargo.toml rename {meowgb => meowgb-core}/src/gameboy.rs (100%) rename {meowgb => meowgb-core}/src/gameboy/bootrom.rs (100%) rename {meowgb => meowgb-core}/src/gameboy/cpu.rs (100%) rename {meowgb => meowgb-core}/src/gameboy/cpu/alu.rs (100%) rename {meowgb => meowgb-core}/src/gameboy/cpu/flow.rs (100%) rename {meowgb => meowgb-core}/src/gameboy/cpu/load_store_move.rs (100%) rename {meowgb => meowgb-core}/src/gameboy/cpu/misc.rs (100%) rename {meowgb => meowgb-core}/src/gameboy/cpu/prefixed.rs (100%) rename {meowgb => meowgb-core}/src/gameboy/interrupts.rs (100%) rename {meowgb => meowgb-core}/src/gameboy/joypad.rs (100%) rename {meowgb => meowgb-core}/src/gameboy/mapper.rs (100%) rename {meowgb => meowgb-core}/src/gameboy/mapper/mbc1.rs (100%) rename {meowgb => meowgb-core}/src/gameboy/memory.rs (100%) rename {meowgb => meowgb-core}/src/gameboy/ppu.rs (100%) rename {meowgb => meowgb-core}/src/gameboy/serial.rs (100%) rename {meowgb => meowgb-core}/src/gameboy/sound.rs (100%) rename {meowgb => meowgb-core}/src/gameboy/timer.rs (100%) rename {meowgb => meowgb-core}/src/lib.rs (89%) rename {meowgb => meowgb-core}/tests/flow_opcodes.rs (99%) rename {meowgb => meowgb-core}/tests/load_store_move_opcodes.rs (97%) rename {meowgb => meowgb-core}/tests/misc_opcodes.rs (97%) rename meowgb-tests/expected_output/{intr_lyc_onoff.gb => stat_lyc_onoff.bin} (100%) diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml new file mode 100644 index 0000000..dea2a50 --- /dev/null +++ b/.github/workflows/action.yml @@ -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 diff --git a/Cargo.lock b/Cargo.lock index b223dae..c141340 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1063,22 +1063,32 @@ checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" name = "meowgb" version = "0.1.0" dependencies = [ - "bmp", "chrono", "clap", "config", "env_logger", "log", - "meowgb-opcode", - "paste", + "meowgb-core", "pixels", "serde", - "sha1", "thiserror", "winit", "winit_input_helper", ] +[[package]] +name = "meowgb-core" +version = "0.1.0" +dependencies = [ + "bmp", + "chrono", + "log", + "meowgb-opcode", + "paste", + "sha1", + "thiserror", +] + [[package]] name = "meowgb-opcode" version = "0.1.0" @@ -1094,7 +1104,7 @@ name = "meowgb-tests" version = "0.1.0" dependencies = [ "clap", - "meowgb", + "meowgb-core", "thiserror", ] diff --git a/Cargo.toml b/Cargo.toml index 9a4b189..0f5d33a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,3 @@ [workspace] resolver = "2" -members = ["meowgb", "meowgb-opcode", "meowgb-tests"] \ No newline at end of file +members = ["meowgb", "meowgb-core", "meowgb-opcode", "meowgb-tests"] diff --git a/meowgb-core/Cargo.toml b/meowgb-core/Cargo.toml new file mode 100644 index 0000000..b1475b5 --- /dev/null +++ b/meowgb-core/Cargo.toml @@ -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"] } \ No newline at end of file diff --git a/meowgb/src/gameboy.rs b/meowgb-core/src/gameboy.rs similarity index 100% rename from meowgb/src/gameboy.rs rename to meowgb-core/src/gameboy.rs diff --git a/meowgb/src/gameboy/bootrom.rs b/meowgb-core/src/gameboy/bootrom.rs similarity index 100% rename from meowgb/src/gameboy/bootrom.rs rename to meowgb-core/src/gameboy/bootrom.rs diff --git a/meowgb/src/gameboy/cpu.rs b/meowgb-core/src/gameboy/cpu.rs similarity index 100% rename from meowgb/src/gameboy/cpu.rs rename to meowgb-core/src/gameboy/cpu.rs diff --git a/meowgb/src/gameboy/cpu/alu.rs b/meowgb-core/src/gameboy/cpu/alu.rs similarity index 100% rename from meowgb/src/gameboy/cpu/alu.rs rename to meowgb-core/src/gameboy/cpu/alu.rs diff --git a/meowgb/src/gameboy/cpu/flow.rs b/meowgb-core/src/gameboy/cpu/flow.rs similarity index 100% rename from meowgb/src/gameboy/cpu/flow.rs rename to meowgb-core/src/gameboy/cpu/flow.rs diff --git a/meowgb/src/gameboy/cpu/load_store_move.rs b/meowgb-core/src/gameboy/cpu/load_store_move.rs similarity index 100% rename from meowgb/src/gameboy/cpu/load_store_move.rs rename to meowgb-core/src/gameboy/cpu/load_store_move.rs diff --git a/meowgb/src/gameboy/cpu/misc.rs b/meowgb-core/src/gameboy/cpu/misc.rs similarity index 100% rename from meowgb/src/gameboy/cpu/misc.rs rename to meowgb-core/src/gameboy/cpu/misc.rs diff --git a/meowgb/src/gameboy/cpu/prefixed.rs b/meowgb-core/src/gameboy/cpu/prefixed.rs similarity index 100% rename from meowgb/src/gameboy/cpu/prefixed.rs rename to meowgb-core/src/gameboy/cpu/prefixed.rs diff --git a/meowgb/src/gameboy/interrupts.rs b/meowgb-core/src/gameboy/interrupts.rs similarity index 100% rename from meowgb/src/gameboy/interrupts.rs rename to meowgb-core/src/gameboy/interrupts.rs diff --git a/meowgb/src/gameboy/joypad.rs b/meowgb-core/src/gameboy/joypad.rs similarity index 100% rename from meowgb/src/gameboy/joypad.rs rename to meowgb-core/src/gameboy/joypad.rs diff --git a/meowgb/src/gameboy/mapper.rs b/meowgb-core/src/gameboy/mapper.rs similarity index 100% rename from meowgb/src/gameboy/mapper.rs rename to meowgb-core/src/gameboy/mapper.rs diff --git a/meowgb/src/gameboy/mapper/mbc1.rs b/meowgb-core/src/gameboy/mapper/mbc1.rs similarity index 100% rename from meowgb/src/gameboy/mapper/mbc1.rs rename to meowgb-core/src/gameboy/mapper/mbc1.rs diff --git a/meowgb/src/gameboy/memory.rs b/meowgb-core/src/gameboy/memory.rs similarity index 100% rename from meowgb/src/gameboy/memory.rs rename to meowgb-core/src/gameboy/memory.rs diff --git a/meowgb/src/gameboy/ppu.rs b/meowgb-core/src/gameboy/ppu.rs similarity index 100% rename from meowgb/src/gameboy/ppu.rs rename to meowgb-core/src/gameboy/ppu.rs diff --git a/meowgb/src/gameboy/serial.rs b/meowgb-core/src/gameboy/serial.rs similarity index 100% rename from meowgb/src/gameboy/serial.rs rename to meowgb-core/src/gameboy/serial.rs diff --git a/meowgb/src/gameboy/sound.rs b/meowgb-core/src/gameboy/sound.rs similarity index 100% rename from meowgb/src/gameboy/sound.rs rename to meowgb-core/src/gameboy/sound.rs diff --git a/meowgb/src/gameboy/timer.rs b/meowgb-core/src/gameboy/timer.rs similarity index 100% rename from meowgb/src/gameboy/timer.rs rename to meowgb-core/src/gameboy/timer.rs diff --git a/meowgb/src/lib.rs b/meowgb-core/src/lib.rs similarity index 89% rename from meowgb/src/lib.rs rename to meowgb-core/src/lib.rs index c067f8c..9e0a2bb 100644 --- a/meowgb/src/lib.rs +++ b/meowgb-core/src/lib.rs @@ -1,12 +1,8 @@ -use std::io::Stdout; - pub mod gameboy; -#[allow(unused)] -mod settings; pub fn setup_test_emulator( test_opcodes: [u8; ROM_LENGTH], -) -> gameboy::Gameboy { +) -> gameboy::Gameboy { let mut gameboy = gameboy::Gameboy::new(None, std::io::stdout()); let mut cartridge = gameboy::mapper::NoMBC { rom: [0u8; 0x8000], ram: None }; diff --git a/meowgb/tests/flow_opcodes.rs b/meowgb-core/tests/flow_opcodes.rs similarity index 99% rename from meowgb/tests/flow_opcodes.rs rename to meowgb-core/tests/flow_opcodes.rs index cd84faa..c143332 100644 --- a/meowgb/tests/flow_opcodes.rs +++ b/meowgb-core/tests/flow_opcodes.rs @@ -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) => { diff --git a/meowgb/tests/load_store_move_opcodes.rs b/meowgb-core/tests/load_store_move_opcodes.rs similarity index 97% rename from meowgb/tests/load_store_move_opcodes.rs rename to meowgb-core/tests/load_store_move_opcodes.rs index caabcfc..fdeceed 100644 --- a/meowgb/tests/load_store_move_opcodes.rs +++ b/meowgb-core/tests/load_store_move_opcodes.rs @@ -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) => { diff --git a/meowgb/tests/misc_opcodes.rs b/meowgb-core/tests/misc_opcodes.rs similarity index 97% rename from meowgb/tests/misc_opcodes.rs rename to meowgb-core/tests/misc_opcodes.rs index 8aac8a6..030725a 100644 --- a/meowgb/tests/misc_opcodes.rs +++ b/meowgb-core/tests/misc_opcodes.rs @@ -1,4 +1,4 @@ -use meowgb::setup_test_emulator; +use meowgb_core::setup_test_emulator; #[test] fn test_nop() { diff --git a/meowgb-tests/Cargo.toml b/meowgb-tests/Cargo.toml index 4532d24..cbb6f82 100644 --- a/meowgb-tests/Cargo.toml +++ b/meowgb-tests/Cargo.toml @@ -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" diff --git a/meowgb-tests/expected_output/intr_lyc_onoff.gb b/meowgb-tests/expected_output/stat_lyc_onoff.bin similarity index 100% rename from meowgb-tests/expected_output/intr_lyc_onoff.gb rename to meowgb-tests/expected_output/stat_lyc_onoff.bin diff --git a/meowgb-tests/src/main.rs b/meowgb-tests/src/main.rs index f56c5a1..54c1f34 100644 --- a/meowgb-tests/src/main.rs +++ b/meowgb-tests/src/main.rs @@ -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 diff --git a/meowgb/Cargo.toml b/meowgb/Cargo.toml index abb98ed..972c030 100644 --- a/meowgb/Cargo.toml +++ b/meowgb/Cargo.toml @@ -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" diff --git a/meowgb/src/main.rs b/meowgb/src/main.rs index eb5166c..90b87da 100644 --- a/meowgb/src/main.rs +++ b/meowgb/src/main.rs @@ -1,4 +1,3 @@ -mod gameboy; mod settings; mod window; @@ -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; diff --git a/meowgb/src/window.rs b/meowgb/src/window.rs index a750b69..c1b5985 100644 --- a/meowgb/src/window.rs +++ b/meowgb/src/window.rs @@ -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()