Skip to content
Snippets Groups Projects
Verified Commit 28bf8179 authored by João Magalhães's avatar João Magalhães :rocket:
Browse files

feat: new instructions

parent 593a20cb
No related branches found
No related tags found
No related merge requests found
......@@ -6,5 +6,8 @@ fn main() {
for _ in 0..40000 {
game_boy.clock();
if game_boy.cpu().pc() >= 0x0016 {
break;
}
}
}
......@@ -2,7 +2,7 @@ use crate::mmu::Mmu;
pub const PREFIX: u8 = 0xcb;
pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &'static str); 208] = [
pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &'static str); 256] = [
// 0x0 opcodes
(nop, 4, "NOP"),
(ld_bc_u16, 12, "LD BC, u16"),
......@@ -16,7 +16,7 @@ pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &'static str); 208] = [
(add_hl_bc, 8, "ADD HL, BC"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(inc_c, 4, "INC C"),
(nop, 4, "NOP"),
(ld_c_u8, 8, "LD C, u8"),
(nop, 4, "NOP"),
......@@ -224,6 +224,57 @@ pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &'static str); 208] = [
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
// 0xd opcodes
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
// 0xe opcodes
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(ld_mff00c_a, 8, "LD [FF00+C], A"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
// 0xf opcodes
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
(nop, 4, "NOP"),
];
pub const BITWISE: [(fn(&mut Cpu), u8, &'static str); 176] = [
......@@ -486,6 +537,11 @@ impl Cpu {
&mut self.mmu
}
#[inline(always)]
pub fn pc(&self) -> u16 {
self.pc
}
#[inline(always)]
fn af(&self) -> u16 {
(self.a as u16) << 8 | self.f() as u16
......@@ -660,6 +716,16 @@ fn add_hl_bc(cpu: &mut Cpu) {
cpu.set_hl(value);
}
fn inc_c(cpu: &mut Cpu) {
let value = cpu.c.wrapping_add(1);
cpu.set_sub(false);
cpu.set_zero(value == 0);
cpu.set_half_carry((value & 0xf) == 0xf);
cpu.c = value;
}
fn ld_c_u8(cpu: &mut Cpu) {
let byte = cpu.read_u8();
cpu.c = byte;
......@@ -704,6 +770,10 @@ fn xor_a_a(cpu: &mut Cpu) {
cpu.set_carry(false);
}
fn ld_mff00c_a(cpu: &mut Cpu) {
cpu.mmu.write((0xff0c + cpu.c as u16), cpu.a);
}
fn bit_7_h(cpu: &mut Cpu) {
bit_h(cpu, 7);
}
......
......@@ -20,6 +20,10 @@ impl GameBoy {
self.cpu.clock()
}
pub fn cpu(&self) -> &Cpu {
&self.cpu
}
pub fn load_boot(&mut self, path: &str) {
let data = read_file(path);
self.cpu.mmu().write_buffer(0x0000, &data);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment