From 079926e2034cee800ea8155081e4dbc8cd4da09f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= <joamag@gmail.com>
Date: Wed, 29 Jun 2022 10:23:57 +0100
Subject: [PATCH] feat: new instruction and better code

---
 src/cpu.rs | 10 +++++++---
 src/gb.rs  | 12 +-----------
 2 files changed, 8 insertions(+), 14 deletions(-)

diff --git a/src/cpu.rs b/src/cpu.rs
index b16002dd..e9da5993 100644
--- a/src/cpu.rs
+++ b/src/cpu.rs
@@ -40,7 +40,7 @@ pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &'static str); 256] = [
     // 0x2 opcodes
     (jr_nz_i8, 8, "JR NZ, i8"),
     (ld_hl_u16, 12, "LD HL, u16"),
-    (ld_mhli_a, 8, "LD [HL]+, A"),
+    (ld_mhli_a, 8, "LD [HL+], A"),
     (inc_hl, 8, "INC HL"),
     (nop, 4, "! UNIMP !"),
     (nop, 4, "! UNIMP !"),
@@ -57,7 +57,7 @@ pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &'static str); 256] = [
     // 0x3 opcodes
     (nop, 4, "! UNIMP !"),
     (ld_sp_u16, 12, "LD SP, u16"),
-    (ld_mhld_a, 8, "LD [HL]-, A"),
+    (ld_mhld_a, 8, "LD [HL-], A"),
     (nop, 4, "! UNIMP !"),
     (nop, 4, "! UNIMP !"),
     (nop, 4, "! UNIMP !"),
@@ -134,7 +134,7 @@ pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &'static str); 256] = [
     (nop, 4, "! UNIMP !"),
     (nop, 4, "! UNIMP !"),
     (nop, 4, "! UNIMP !"),
-    (nop, 4, "! UNIMP !"),
+    (ld_a_e, 4, "LD A, E"),
     (nop, 4, "! UNIMP !"),
     (nop, 4, "! UNIMP !"),
     (nop, 4, "! UNIMP !"),
@@ -829,6 +829,10 @@ fn ld_c_a(cpu: &mut Cpu) {
     cpu.c = cpu.a;
 }
 
+fn ld_a_e(cpu: &mut Cpu) {
+    cpu.a = cpu.e;
+}
+
 fn xor_a_a(cpu: &mut Cpu) {
     cpu.a ^= cpu.a;
 
diff --git a/src/gb.rs b/src/gb.rs
index cf4dd195..6d6739c0 100644
--- a/src/gb.rs
+++ b/src/gb.rs
@@ -1,14 +1,4 @@
-use std::{
-    cell::RefCell,
-    rc::{Rc, Weak},
-};
-
-use crate::{
-    cpu::Cpu,
-    mmu::Mmu,
-    ppu::Ppu,
-    util::{read_file, SharedMut},
-};
+use crate::{cpu::Cpu, mmu::Mmu, ppu::Ppu, util::read_file};
 
 pub struct GameBoy {
     cpu: Cpu,
-- 
GitLab