From b1b7aaad96c3c9b980a2657b9899a7bc2b00a7ff Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= <joamag@gmail.com>
Date: Sat, 2 Jul 2022 10:19:44 +0100
Subject: [PATCH] feat: more instructions

---
 src/cpu.rs  |  4 ++--
 src/inst.rs | 19 ++++++++++++++++---
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/src/cpu.rs b/src/cpu.rs
index 160d07bb..ae088c04 100644
--- a/src/cpu.rs
+++ b/src/cpu.rs
@@ -77,8 +77,8 @@ impl Cpu {
             println!("GOING TO PLAY BOOT SOUND");
         }
 
-        if pc == 0x00e0 {
-            println!("GOING TO PLAY BOOT 0x00e0");
+        if pc == 0x00e9 {
+            println!("GOING TO PLAY BOOT 0x00ef");
         }
 
         // calls the current instruction and increments the number of
diff --git a/src/inst.rs b/src/inst.rs
index 1e722377..49746b90 100644
--- a/src/inst.rs
+++ b/src/inst.rs
@@ -129,12 +129,12 @@ pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &'static str); 256] = [
     (noimpl, 4, "! UNIMP !"),
     (noimpl, 4, "! UNIMP !"),
     (ld_mhl_a, 8, "LD [HL], A"),
-    (noimpl, 4, "! UNIMP !"),
+    (ld_a_b, 4, "LD A, B"),
     (noimpl, 4, "! UNIMP !"),
     (noimpl, 4, "! UNIMP !"),
     (ld_a_e, 4, "LD A, E"),
     (ld_a_h, 4, "LD A, H"),
-    (noimpl, 4, "! UNIMP !"),
+    (ld_a_l, 4, "LD A, L"),
     (noimpl, 4, "! UNIMP !"),
     (noimpl, 4, "! UNIMP !"),
     // 0x8 opcodes
@@ -203,7 +203,7 @@ pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &'static str); 256] = [
     (noimpl, 4, "! UNIMP !"),
     (noimpl, 4, "! UNIMP !"),
     (noimpl, 4, "! UNIMP !"),
-    (noimpl, 4, "! UNIMP !"),
+    (cp_a_mhl, 8, "CP A, [HL]"),
     (noimpl, 4, "! UNIMP !"),
     // 0xc opcodes
     (ret_nz, 8, "RET NZ"),
@@ -717,6 +717,10 @@ fn ld_mhl_a(cpu: &mut Cpu) {
     cpu.mmu.write(cpu.hl(), cpu.a);
 }
 
+fn ld_a_b(cpu: &mut Cpu) {
+    cpu.a = cpu.b;
+}
+
 fn ld_a_e(cpu: &mut Cpu) {
     cpu.a = cpu.e;
 }
@@ -725,6 +729,10 @@ fn ld_a_h(cpu: &mut Cpu) {
     cpu.a = cpu.h;
 }
 
+fn ld_a_l(cpu: &mut Cpu) {
+    cpu.a = cpu.l;
+}
+
 fn sub_a_b(cpu: &mut Cpu) {
     cpu.a = sub_set_flags(cpu, cpu.a, cpu.b);
 }
@@ -738,6 +746,11 @@ fn xor_a_a(cpu: &mut Cpu) {
     cpu.set_carry(false);
 }
 
+fn cp_a_mhl(cpu: &mut Cpu) {
+    let byte = cpu.mmu.read(cpu.hl());
+    sub_set_flags(cpu, cpu.a, byte);
+}
+
 fn ret_nz(cpu: &mut Cpu) {
     if cpu.get_zero() {
         return;
-- 
GitLab