From 7d2727d2962e8483f5b7082b42f607ecf973a991 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= <joamag@gmail.com> Date: Tue, 5 Jul 2022 16:36:11 +0100 Subject: [PATCH] feat: more instructions --- examples/sdl/src/main.rs | 8 ++++---- src/inst.rs | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/examples/sdl/src/main.rs b/examples/sdl/src/main.rs index 44e078fa..879ac9f4 100644 --- a/examples/sdl/src/main.rs +++ b/examples/sdl/src/main.rs @@ -81,24 +81,24 @@ fn main() { // creates a new Game Boy instance and loads both the boot ROM // and the initial game ROM to "start the engine" let mut game_boy = GameBoy::new(); - game_boy.load_boot_mgb_bootix(); + game_boy.load_boot_dmg_bootix(); //game_boy.load_rom_file("../../res/roms.prop/tetris.gb"); //game_boy.load_rom_file("../../res/roms.prop/alleyway.gb"); //game_boy.load_rom_file("../../res/roms/firstwhite.gb"); - game_boy.load_rom_file("../../res/roms/opus5.gb"); + //game_boy.load_rom_file("../../res/roms/opus5.gb"); //game_boy.load_rom_file("../../res/roms/special.gb"); //game_boy.load_rom_file("../../res/roms/paradius/cpu/01-special.gb"); // PASSED //game_boy.load_rom_file("../../res/roms/paradius/cpu/02-interrupts.gb"); // NO FINISH - //game_boy.load_rom_file("../../res/roms/paradius/cpu/03-op sp,hl.gb"); // NO FINISH + //game_boy.load_rom_file("../../res/roms/paradius/cpu/03-op sp,hl.gb"); // PASSED //game_boy.load_rom_file("../../res/roms/paradius/cpu/04-op r,imm.gb"); // PASSED //game_boy.load_rom_file("../../res/roms/paradius/cpu/05-op rp.gb"); // PASSED //game_boy.load_rom_file("../../res/roms/paradius/cpu/06-ld r,r.gb"); // PASSED //game_boy.load_rom_file("../../res/roms/paradius/cpu/07-jr,jp,call,ret,rst.gb"); // PASSED //game_boy.load_rom_file("../../res/roms/paradius/cpu/08-misc instrs.gb"); // PASSED - //game_boy.load_rom_file("../../res/roms/paradius/cpu/09-op r,r.gb"); // NO FINISH + game_boy.load_rom_file("../../res/roms/paradius/cpu/09-op r,r.gb"); // NO FINISH //game_boy.load_rom_file("../../res/roms/paradius/cpu/11-op a,(hl).gb"); // NO FINISH 'main: loop { diff --git a/src/inst.rs b/src/inst.rs index cdcceb6f..04a8bd7e 100644 --- a/src/inst.rs +++ b/src/inst.rs @@ -220,7 +220,7 @@ pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &'static str); 256] = [ (ret_z, 8, "RET Z"), (ret, 16, "RET"), (jp_z_u16, 12, "JP Z, u16"), - (noimpl, 4, "! UNIMP !"), + (illegal, 4, "ILLEGAL"), (call_z_u16, 12, "CALL Z, u16"), (call_u16, 24, "CALL u16"), (adc_a_u8, 8, "ADC A, u8 "), @@ -268,7 +268,7 @@ pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &'static str); 256] = [ (push_af, 16, "PUSH AF"), (or_a_u8, 8, "OR A, u8"), (rst_30h, 16, "RST 30h"), - (noimpl, 4, "! UNIMP !"), + (ld_hl_spi8, 12, "LD HL, SP+i8"), (ld_sp_hl, 8, "LD SP, HL"), (ld_a_mu16, 16, "LD A [u16]"), (ei, 4, "EI"), @@ -2005,6 +2005,21 @@ fn rst_30h(cpu: &mut Cpu) { rst(cpu, 0x0030); } +fn ld_hl_spi8(cpu: &mut Cpu) { + let sp = cpu.sp as i32; + let byte = cpu.read_u8() as i8; + let byte_i32 = byte as i32; + + let result = sp.wrapping_add(byte_i32); + + cpu.set_sub(false); + cpu.set_zero(false); + cpu.set_half_carry((sp ^ byte_i32 ^ result) & 0x10 == 0x10); + cpu.set_carry((sp ^ byte_i32 ^ result) & 0x100 == 0x100); + + cpu.set_hl(result as u16); +} + fn ld_sp_hl(cpu: &mut Cpu) { cpu.sp = cpu.hl(); } -- GitLab