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

feat: new instructions

parent 2473aa8f
No related branches found
No related tags found
No related merge requests found
Pipeline #856 passed
......@@ -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;
......
/// 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,
......
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);
}
......
......@@ -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;
......
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