diff --git a/examples/sdl/src/main.rs b/examples/sdl/src/main.rs index 50af56f892bf24ea07c23a6463d9d155910c058e..6d2b89900698951b1d640eb84a4829427095563f 100644 --- a/examples/sdl/src/main.rs +++ b/examples/sdl/src/main.rs @@ -79,9 +79,9 @@ fn main() { .unwrap(); let mut game_boy = GameBoy::new(); - game_boy.load_boot_static(); - game_boy.load_rom_file("../../res/roms/firstwhite.gb"); - //game_boy.load_rom_file("../../res/roms/opus5.gb"); + game_boy.load_boot_dmg(); + //game_boy.load_rom_file("../../res/roms/firstwhite.gb"); + game_boy.load_rom_file("../../res/roms/opus5.gb"); let mut counter = 0; diff --git a/src/data.rs b/src/data.rs index 244483f55b30c6dd69dbdce442aee099fc3a8deb..c86c3e34e7b278756548c11dcf35dba949039363 100644 --- a/src/data.rs +++ b/src/data.rs @@ -1,6 +1,6 @@ /// Static data corresponding to the DMG boot ROM /// allows freely using the emulator without external dependency. -pub const DMB_BOOT: [u8; 256] = [ +pub const DMG_BOOT: [u8; 256] = [ 49, 254, 255, 175, 33, 255, 159, 50, 203, 124, 32, 251, 33, 38, 255, 14, 17, 62, 128, 50, 226, 12, 62, 243, 226, 50, 62, 119, 119, 62, 252, 224, 71, 17, 4, 1, 33, 16, 128, 26, 205, 149, 0, 205, 150, 0, 19, 123, 254, 52, 32, 243, 17, 216, 0, 6, 8, 26, 19, 34, 35, 5, 32, 249, 62, 25, diff --git a/src/gb.rs b/src/gb.rs index 7a0ac812abd5e3c27bf674521427375f061bd349..026f6ce6f2e83a86b8900501d86eff452735dac0 100644 --- a/src/gb.rs +++ b/src/gb.rs @@ -1,6 +1,6 @@ use crate::{ cpu::Cpu, - data::SGB_BOOT, + data::{SGB_BOOT, DMG_BOOT}, mmu::Mmu, ppu::{Ppu, FRAME_BUFFER_SIZE}, util::read_file, @@ -68,7 +68,11 @@ impl GameBoy { self.load_boot_file("./res/boot/dmg_boot.bin"); } - pub fn load_boot_static(&mut self) { + pub fn load_boot_dmg(&mut self) { + self.load_boot(&DMG_BOOT); + } + + pub fn load_boot_sgb(&mut self) { self.load_boot(&SGB_BOOT); } diff --git a/src/inst.rs b/src/inst.rs index 401d3e40f201f32fd7702a0af9afb2d9dcc316e6..0cdeff6a681c3457a89149af37679bd28e5fa359 100644 --- a/src/inst.rs +++ b/src/inst.rs @@ -12,7 +12,7 @@ pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &'static str); 256] = [ (rlca, 4, "RLCA"), (ld_mu16_sp, 20, "LD [u16], SP"), (add_hl_bc, 8, "ADD HL, BC"), - (noimpl, 4, "! UNIMP !"), + (ld_a_mbc, 8, "LD A, [BC]"), (dec_bc, 8, "DEC BC"), (inc_c, 4, "INC C"), (dec_c, 4, "DEC C"), @@ -78,12 +78,12 @@ pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &'static str); 256] = [ (noimpl, 4, "! UNIMP !"), (ld_b_mhl, 8, "LD B, [HL]"), (ld_b_a, 4, "LD B, A"), - (noimpl, 4, "! UNIMP !"), - (noimpl, 4, "! UNIMP !"), - (noimpl, 4, "! UNIMP !"), - (noimpl, 4, "! UNIMP !"), - (noimpl, 4, "! UNIMP !"), - (noimpl, 4, "! UNIMP !"), + (ld_c_b, 4, "LD C, B"), + (ld_c_c, 4, "LD C, C"), + (ld_c_d, 4, "LD C, D"), + (ld_c_e, 4, "LD C, E"), + (ld_c_h, 4, "LD C, H"), + (ld_c_l, 4, "LD C, L"), (ld_c_mhl, 8, "LD C, [HL]"), (ld_c_a, 4, "LD C, A"), // 0x5 opcodes @@ -617,6 +617,11 @@ fn add_hl_bc(cpu: &mut Cpu) { cpu.set_hl(value); } +fn ld_a_mbc(cpu: &mut Cpu) { + let byte = cpu.mmu.read(cpu.bc()); + cpu.a = byte; +} + fn dec_bc(cpu: &mut Cpu) { cpu.set_bc(cpu.bc().wrapping_sub(1)); } @@ -948,6 +953,30 @@ fn ld_b_a(cpu: &mut Cpu) { cpu.b = cpu.a; } +fn ld_c_b(cpu: &mut Cpu) { + cpu.c = cpu.b; +} + +fn ld_c_c(cpu: &mut Cpu) { + cpu.c = cpu.c; +} + +fn ld_c_d(cpu: &mut Cpu) { + cpu.c = cpu.d; +} + +fn ld_c_e(cpu: &mut Cpu) { + cpu.c = cpu.e; +} + +fn ld_c_h(cpu: &mut Cpu) { + cpu.c = cpu.h; +} + +fn ld_c_l(cpu: &mut Cpu) { + cpu.c = cpu.l; +} + fn ld_c_mhl(cpu: &mut Cpu) { let byte = cpu.mmu.read(cpu.hl()); cpu.c = byte;