diff --git a/examples/sdl/src/main.rs b/examples/sdl/src/main.rs index c6881f53687569f6f121272ba95c08e6046a3dbb..198494db5ffee3b536a45d0c941c68244316ac40 100644 --- a/examples/sdl/src/main.rs +++ b/examples/sdl/src/main.rs @@ -80,10 +80,12 @@ fn main() { let mut game_boy = GameBoy::new(); game_boy.load_boot_dmg(); + game_boy.load_rom_file("../../res/roms.prop/tetris.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/ld_r_r.gb"); - game_boy.load_rom_file("../../res/roms/special.gb"); + //game_boy.load_rom_file("../../res/roms/special.gb"); + //game_boy.load_rom_file("../../res/roms/firstwhite.gb"); let mut counter = 0; diff --git a/src/cpu.rs b/src/cpu.rs index dab920c8e61e1b2350531f2ee093ac72358c3627..da9b50488a6fd925a4aaaa656e58fd58885c58a3 100644 --- a/src/cpu.rs +++ b/src/cpu.rs @@ -1,3 +1,5 @@ +use core::panic; + use crate::{ inst::{EXTENDED, INSTRUCTIONS}, mmu::Mmu, @@ -303,6 +305,11 @@ impl Cpu { self.halted = true; } + #[inline(always)] + pub fn stop(&mut self) { + panic!("STOP is not implemented"); + } + #[inline(always)] pub fn enable_int(&mut self) { // @todo implement this one diff --git a/src/inst.rs b/src/inst.rs index b4109886c133087a19d584cbc3bb95e9d0c7d039..726225ea1c65d8f7ce76c21e7def40a78876d213 100644 --- a/src/inst.rs +++ b/src/inst.rs @@ -19,7 +19,7 @@ pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &'static str); 256] = [ (ld_c_u8, 8, "LD C, u8"), (noimpl, 4, "! UNIMP !"), // 0x1 opcodes - (noimpl, 4, "! UNIMP !"), + (stop, 4, "STOP"), (ld_de_u16, 12, "LD DE, u16"), (ld_mde_a, 8, "LD [DE], A"), (inc_de, 8, "INC DE"), @@ -62,7 +62,7 @@ pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &'static str); 256] = [ (ld_mhl_u8, 12, "LD [HL], u8 "), (scf, 4, "SCF"), (jr_c_i8, 8, "JR C, i8"), - (noimpl, 4, "! UNIMP !"), + (add_hl_sp, 8, "ADD HL, SP"), (noimpl, 4, "! UNIMP !"), (noimpl, 4, "! UNIMP !"), (inc_a, 4, "INC A"), @@ -656,6 +656,10 @@ fn ld_c_u8(cpu: &mut Cpu) { cpu.c = byte; } +fn stop(cpu: &mut Cpu) { + cpu.stop(); +} + fn ld_de_u16(cpu: &mut Cpu) { let word = cpu.read_u16(); cpu.set_de(word); @@ -923,6 +927,11 @@ fn jr_c_i8(cpu: &mut Cpu) { cpu.ticks = cpu.ticks.wrapping_add(4); } +fn add_hl_sp(cpu: &mut Cpu) { + let value = add_u16_u16(cpu, cpu.hl(), cpu.sp()); + cpu.set_hl(value); +} + fn inc_a(cpu: &mut Cpu) { let value = cpu.a.wrapping_add(1); diff --git a/src/mmu.rs b/src/mmu.rs index 13e8a564dfdfdd254f531b609f9b46e142538ed3..7126ba780e6ceefad33aacd098ea3134086cbf70 100644 --- a/src/mmu.rs +++ b/src/mmu.rs @@ -51,9 +51,9 @@ impl Mmu { } self.rom[addr as usize] } - // ROM0 (12 KB/16 KB) + // ROM 0 (12 KB/16 KB) 0x1000 | 0x2000 | 0x3000 => self.rom[addr as usize], - // ROM1 (Unbanked) (16 KB) + // ROM 1 (Unbanked) (16 KB) 0x4000 | 0x5000 | 0x6000 | 0x7000 => self.rom[addr as usize], // Graphics: VRAM (8 KB) 0x8000 | 0x9000 => self.ppu.vram[(addr & 0x1fff) as usize], @@ -99,15 +99,15 @@ impl Mmu { // BOOT (256 B) + ROM0 (4 KB/16 KB) 0x0000 => { self.rom[addr as usize] = value; - println!("Writing to BOOT at 0x{:04x}", addr) + panic!("Writing to BOOT at 0x{:04x}", addr) } - // ROM0 (12 KB/16 KB) + // ROM 0 (12 KB/16 KB) 0x1000 | 0x2000 | 0x3000 => { - println!("Writing to ROM 0 at 0x{:04x}", addr); + panic!("Writing to ROM 0 at 0x{:04x}", addr); } - // ROM1 (Unbanked) (16 KB) + // ROM 1 (Unbanked) (16 KB) 0x4000 | 0x5000 | 0x6000 | 0x7000 => { - println!("Writing to ROM 1 at 0x{:04x}", addr); + panic!("Writing to ROM 1 at 0x{:04x}", addr); } // Graphics: VRAM (8 KB) 0x8000 | 0x9000 => {