From f39ceff511431778cc6e151ce39a981378fe4215 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= <joamag@gmail.com> Date: Sun, 3 Jul 2022 23:59:58 +0100 Subject: [PATCH] feat: more instructions --- examples/sdl/src/main.rs | 1 + src/inst.rs | 31 ++++++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/examples/sdl/src/main.rs b/examples/sdl/src/main.rs index 6d00e8f0..576485d5 100644 --- a/examples/sdl/src/main.rs +++ b/examples/sdl/src/main.rs @@ -83,6 +83,7 @@ fn main() { //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/opus5.gb"); let mut counter = 0; diff --git a/src/inst.rs b/src/inst.rs index 0eeacf64..02d8d580 100644 --- a/src/inst.rs +++ b/src/inst.rs @@ -45,7 +45,7 @@ pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &'static str); 256] = [ (ld_h_u8, 8, "LD H, u8"), (noimpl, 4, "! UNIMP !"), (jr_z_i8, 8, "JR Z, i8"), - (noimpl, 4, "! UNIMP !"), + (add_hl_hl, 8, "ADD HL, HL"), (ld_a_mhli, 8, "LD A, [HL+] "), (noimpl, 4, "! UNIMP !"), (inc_l, 4, "INC L"), @@ -100,7 +100,7 @@ pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &'static str); 256] = [ (noimpl, 4, "! UNIMP !"), (noimpl, 4, "! UNIMP !"), (noimpl, 4, "! UNIMP !"), - (noimpl, 4, "! UNIMP !"), + (ld_e_l, 4, "LD E, L"), (noimpl, 4, "! UNIMP !"), (ld_e_a, 4, "LD E, A"), // 0x6 opcodes @@ -119,7 +119,7 @@ pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &'static str); 256] = [ (noimpl, 4, "! UNIMP !"), (noimpl, 4, "! UNIMP !"), (ld_l_mhl, 8, "LD L, [HL]"), - (noimpl, 4, "! UNIMP !"), + (ld_l_a, 4, "LD L, A"), // 0x7 opcodes (ld_mhl_b, 8, "LD [HL], B"), (ld_mhl_c, 8, "LD [HL], C"), @@ -249,7 +249,7 @@ pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &'static str); 256] = [ (and_a_u8, 8, "AND A, u8"), (noimpl, 4, "! UNIMP !"), (noimpl, 4, "! UNIMP !"), - (noimpl, 4, "! UNIMP !"), + (jp_hl, 4, "JP HL"), (ld_mu16_a, 16, "LD [u16], A"), (illegal, 4, "ILLEGAL"), (illegal, 4, "ILLEGAL"), @@ -305,7 +305,7 @@ pub const EXTENDED: [(fn(&mut Cpu), u8, &'static str); 256] = [ (noimpl, 4, "! UNIMP !"), (rr_c, 8, "RR C"), (rr_d, 8, "RR D"), - (noimpl, 4, "! UNIMP !"), + (rr_e, 8, "RR E"), (noimpl, 4, "! UNIMP !"), (noimpl, 4, "! UNIMP !"), (noimpl, 4, "! UNIMP !"), @@ -826,6 +826,11 @@ fn jr_z_i8(cpu: &mut Cpu) { cpu.ticks = cpu.ticks.wrapping_add(4); } +fn add_hl_hl(cpu: &mut Cpu) { + let value = add_u16_u16(cpu, cpu.hl(), cpu.hl()); + cpu.set_hl(value); +} + fn ld_a_mhli(cpu: &mut Cpu) { let byte = cpu.mmu.read(cpu.hl()); cpu.a = byte; @@ -1015,6 +1020,10 @@ fn ld_d_a(cpu: &mut Cpu) { cpu.d = cpu.a; } +fn ld_e_l(cpu: &mut Cpu) { + cpu.e = cpu.l; +} + fn ld_e_a(cpu: &mut Cpu) { cpu.e = cpu.a; } @@ -1028,6 +1037,10 @@ fn ld_l_mhl(cpu: &mut Cpu) { cpu.l = byte; } +fn ld_l_a(cpu: &mut Cpu) { + cpu.l = cpu.a; +} + fn ld_mhl_b(cpu: &mut Cpu) { cpu.mmu.write(cpu.hl(), cpu.b); } @@ -1363,6 +1376,10 @@ fn and_a_u8(cpu: &mut Cpu) { cpu.set_carry(false); } +fn jp_hl(cpu: &mut Cpu) { + cpu.pc = cpu.hl(); +} + fn ld_mu16_a(cpu: &mut Cpu) { let word = cpu.read_u16(); cpu.mmu.write(word, cpu.a); @@ -1431,6 +1448,10 @@ fn rr_d(cpu: &mut Cpu) { cpu.d = rr(cpu, cpu.d); } +fn rr_e(cpu: &mut Cpu) { + cpu.e = rr(cpu, cpu.e); +} + fn sla_b(cpu: &mut Cpu) { cpu.b = sla(cpu, cpu.b); } -- GitLab