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

feat: new instructions

Added boot roms to separate dir
New static boot roms
parent 972b2c90
No related branches found
No related tags found
No related merge requests found
Pipeline #855 passed
File moved
File added
File deleted
/// Static data corresponding to the DMG boot ROM
/// allows freely using the emulator without external dependency.
pub const DMB_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,
234, 16, 153, 33, 47, 153, 14, 12, 61, 40, 8, 50, 13, 32, 249, 46, 15, 24, 243, 103, 62, 100,
87, 224, 66, 62, 145, 224, 64, 4, 30, 2, 14, 12, 240, 68, 254, 144, 32, 250, 13, 32, 247, 29,
32, 242, 14, 19, 36, 124, 30, 131, 254, 98, 40, 6, 30, 193, 254, 100, 32, 6, 123, 226, 12, 62,
135, 226, 240, 66, 144, 224, 66, 21, 32, 210, 5, 32, 79, 22, 32, 24, 203, 79, 6, 4, 197, 203,
17, 23, 193, 203, 17, 23, 5, 32, 245, 34, 35, 34, 35, 201, 206, 237, 102, 102, 204, 13, 0, 11,
3, 115, 0, 131, 0, 12, 0, 13, 0, 8, 17, 31, 136, 137, 0, 14, 220, 204, 110, 230, 221, 221, 217,
153, 187, 187, 103, 99, 110, 14, 236, 204, 221, 220, 153, 159, 187, 185, 51, 62, 60, 66, 185,
165, 185, 165, 66, 60, 33, 4, 1, 17, 168, 0, 26, 19, 190, 32, 254, 35, 125, 254, 52, 32, 245,
6, 25, 120, 134, 35, 5, 32, 251, 134, 32, 254, 62, 1, 224, 80,
];
pub const SGB_BOOT: [u8; 256] = [
49, 254, 255, 62, 48, 224, 0, 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, 33, 95, 192, 14, 8,
175, 50, 13, 32, 252, 17, 79, 1, 62, 251, 14, 6, 245, 6, 0, 26, 27, 50, 128, 71, 13, 32, 248,
50, 241, 50, 14, 14, 214, 2, 254, 239, 32, 234, 17, 4, 1, 33, 16, 128, 26, 205, 211, 0, 205,
212, 0, 19, 123, 254, 52, 32, 243, 17, 230, 0, 6, 8, 26, 19, 34, 35, 5, 32, 249, 62, 25, 234,
16, 153, 33, 47, 153, 14, 12, 61, 40, 8, 50, 13, 32, 249, 46, 15, 24, 243, 62, 145, 224, 64,
33, 0, 192, 14, 0, 62, 0, 226, 62, 48, 226, 6, 16, 30, 8, 42, 87, 203, 66, 62, 16, 32, 2, 62,
32, 226, 62, 48, 226, 203, 26, 29, 32, 239, 5, 32, 232, 62, 32, 226, 62, 48, 226, 205, 194, 0,
125, 254, 96, 32, 210, 14, 19, 62, 193, 226, 12, 62, 7, 226, 24, 58, 22, 4, 240, 68, 254, 144,
32, 250, 30, 0, 29, 32, 253, 21, 32, 242, 201, 79, 6, 4, 197, 203, 17, 23, 193, 203, 17, 23, 5,
32, 245, 34, 35, 34, 35, 201, 60, 66, 185, 165, 185, 165, 66, 60, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 62, 1, 224, 80,
];
use crate::{ use crate::{
cpu::Cpu, cpu::Cpu,
data::SGB_BOOT,
mmu::Mmu, mmu::Mmu,
ppu::{Ppu, FRAME_BUFFER_SIZE}, ppu::{Ppu, FRAME_BUFFER_SIZE},
util::read_file, util::read_file,
...@@ -8,23 +9,6 @@ use crate::{ ...@@ -8,23 +9,6 @@ use crate::{
#[cfg(feature = "wasm")] #[cfg(feature = "wasm")]
use wasm_bindgen::prelude::*; use wasm_bindgen::prelude::*;
/// Static data corresponding to the DMG boot ROM
/// allows freely using the emulator without external dependency.
pub const BOOT_DATA: [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,
234, 16, 153, 33, 47, 153, 14, 12, 61, 40, 8, 50, 13, 32, 249, 46, 15, 24, 243, 103, 62, 100,
87, 224, 66, 62, 145, 224, 64, 4, 30, 2, 14, 12, 240, 68, 254, 144, 32, 250, 13, 32, 247, 29,
32, 242, 14, 19, 36, 124, 30, 131, 254, 98, 40, 6, 30, 193, 254, 100, 32, 6, 123, 226, 12, 62,
135, 226, 240, 66, 144, 224, 66, 21, 32, 210, 5, 32, 79, 22, 32, 24, 203, 79, 6, 4, 197, 203,
17, 23, 193, 203, 17, 23, 5, 32, 245, 34, 35, 34, 35, 201, 206, 237, 102, 102, 204, 13, 0, 11,
3, 115, 0, 131, 0, 12, 0, 13, 0, 8, 17, 31, 136, 137, 0, 14, 220, 204, 110, 230, 221, 221, 217,
153, 187, 187, 103, 99, 110, 14, 236, 204, 221, 220, 153, 159, 187, 185, 51, 62, 60, 66, 185,
165, 185, 165, 66, 60, 33, 4, 1, 17, 168, 0, 26, 19, 190, 32, 254, 35, 125, 254, 52, 32, 245,
6, 25, 120, 134, 35, 5, 32, 251, 134, 32, 254, 62, 1, 224, 80,
];
/// Top level structure that abstracts the usage of the /// Top level structure that abstracts the usage of the
/// Game Boy system under the Boytacean emulator. /// Game Boy system under the Boytacean emulator.
/// Should serve as the main entry-point API. /// Should serve as the main entry-point API.
...@@ -76,15 +60,16 @@ impl GameBoy { ...@@ -76,15 +60,16 @@ impl GameBoy {
pub fn load_boot_file(&mut self, path: &str) { pub fn load_boot_file(&mut self, path: &str) {
let data = read_file(path); let data = read_file(path);
println!("{:?}", data);
self.load_boot(&data); self.load_boot(&data);
} }
pub fn load_boot_default(&mut self) { pub fn load_boot_default(&mut self) {
self.load_boot_file("./res/dmg_rom.bin"); self.load_boot_file("./res/boot/dmg_boot.bin");
} }
pub fn load_boot_static(&mut self) { pub fn load_boot_static(&mut self) {
self.load_boot(&BOOT_DATA); self.load_boot(&SGB_BOOT);
} }
pub fn frame_buffer_eager(&mut self) -> Vec<u8> { pub fn frame_buffer_eager(&mut self) -> Vec<u8> {
......
...@@ -30,7 +30,7 @@ pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &'static str); 256] = [ ...@@ -30,7 +30,7 @@ pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &'static str); 256] = [
(jr_i8, 12, "JR i8"), (jr_i8, 12, "JR i8"),
(noimpl, 4, "! UNIMP !"), (noimpl, 4, "! UNIMP !"),
(ld_a_mde, 8, "LD A, [DE]"), (ld_a_mde, 8, "LD A, [DE]"),
(noimpl, 4, "! UNIMP !"), (dec_de, 8, "DEC DE"),
(inc_e, 4, "INC E"), (inc_e, 4, "INC E"),
(dec_e, 4, "DEC E"), (dec_e, 4, "DEC E"),
(ld_e_u8, 8, "LD E, u8"), (ld_e_u8, 8, "LD E, u8"),
...@@ -71,8 +71,8 @@ pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &'static str); 256] = [ ...@@ -71,8 +71,8 @@ pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &'static str); 256] = [
(noimpl, 4, "! UNIMP !"), (noimpl, 4, "! UNIMP !"),
// 0x4 opcodes // 0x4 opcodes
(ld_b_b, 4, "LD B, B"), (ld_b_b, 4, "LD B, B"),
(noimpl, 4, "! UNIMP !"), (ld_b_c, 4, "LD B, C"),
(noimpl, 4, "! UNIMP !"), (ld_b_d, 4, "LD B, D"),
(ld_b_e, 4, "LD B, E"), (ld_b_e, 4, "LD B, E"),
(ld_b_h, 4, "LD B, H"), (ld_b_h, 4, "LD B, H"),
(noimpl, 4, "! UNIMP !"), (noimpl, 4, "! UNIMP !"),
...@@ -138,7 +138,7 @@ pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &'static str); 256] = [ ...@@ -138,7 +138,7 @@ pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &'static str); 256] = [
(ld_a_mhl, 8, "LD A, [HL]"), (ld_a_mhl, 8, "LD A, [HL]"),
(noimpl, 4, "! UNIMP !"), (noimpl, 4, "! UNIMP !"),
// 0x8 opcodes // 0x8 opcodes
(noimpl, 4, "! UNIMP !"), (add_a_b, 4, "ADD A, B"),
(add_a_c, 4, "ADD A, C"), (add_a_c, 4, "ADD A, C"),
(noimpl, 4, "! UNIMP !"), (noimpl, 4, "! UNIMP !"),
(add_a_e, 4, "ADD A, E"), (add_a_e, 4, "ADD A, E"),
...@@ -347,7 +347,7 @@ pub const EXTENDED: [(fn(&mut Cpu), u8, &'static str); 256] = [ ...@@ -347,7 +347,7 @@ pub const EXTENDED: [(fn(&mut Cpu), u8, &'static str); 256] = [
// 0x4 opcodes // 0x4 opcodes
(noimpl, 4, "! UNIMP !"), (noimpl, 4, "! UNIMP !"),
(noimpl, 4, "! UNIMP !"), (noimpl, 4, "! UNIMP !"),
(noimpl, 4, "! UNIMP !"), (bit_0_d, 8, "BIT 0, D"),
(noimpl, 4, "! UNIMP !"), (noimpl, 4, "! UNIMP !"),
(noimpl, 4, "! UNIMP !"), (noimpl, 4, "! UNIMP !"),
(noimpl, 4, "! UNIMP !"), (noimpl, 4, "! UNIMP !"),
...@@ -708,6 +708,10 @@ fn ld_a_mde(cpu: &mut Cpu) { ...@@ -708,6 +708,10 @@ fn ld_a_mde(cpu: &mut Cpu) {
cpu.a = byte; cpu.a = byte;
} }
fn dec_de(cpu: &mut Cpu) {
cpu.set_de(cpu.de().wrapping_sub(1));
}
fn inc_e(cpu: &mut Cpu) { fn inc_e(cpu: &mut Cpu) {
let value = cpu.e.wrapping_add(1); let value = cpu.e.wrapping_add(1);
...@@ -919,6 +923,14 @@ fn ld_b_b(cpu: &mut Cpu) { ...@@ -919,6 +923,14 @@ fn ld_b_b(cpu: &mut Cpu) {
cpu.b = cpu.b; cpu.b = cpu.b;
} }
fn ld_b_c(cpu: &mut Cpu) {
cpu.b = cpu.c;
}
fn ld_b_d(cpu: &mut Cpu) {
cpu.b = cpu.d;
}
fn ld_b_e(cpu: &mut Cpu) { fn ld_b_e(cpu: &mut Cpu) {
cpu.b = cpu.e; cpu.b = cpu.e;
} }
...@@ -1011,6 +1023,10 @@ fn ld_a_mhl(cpu: &mut Cpu) { ...@@ -1011,6 +1023,10 @@ fn ld_a_mhl(cpu: &mut Cpu) {
cpu.a = byte; cpu.a = byte;
} }
fn add_a_b(cpu: &mut Cpu) {
cpu.a = add_set_flags(cpu, cpu.a, cpu.b);
}
fn add_a_c(cpu: &mut Cpu) { fn add_a_c(cpu: &mut Cpu) {
cpu.a = add_set_flags(cpu, cpu.a, cpu.c); cpu.a = add_set_flags(cpu, cpu.a, cpu.c);
} }
...@@ -1349,6 +1365,10 @@ fn srl_b(cpu: &mut Cpu) { ...@@ -1349,6 +1365,10 @@ fn srl_b(cpu: &mut Cpu) {
cpu.b = srl(cpu, cpu.b); cpu.b = srl(cpu, cpu.b);
} }
fn bit_0_d(cpu: &mut Cpu) {
bit_d(cpu, 0);
}
fn bit_7_h(cpu: &mut Cpu) { fn bit_7_h(cpu: &mut Cpu) {
bit_h(cpu, 7); bit_h(cpu, 7);
} }
...@@ -1414,6 +1434,12 @@ fn bit_zero(val: u8, bit: u8) -> bool { ...@@ -1414,6 +1434,12 @@ fn bit_zero(val: u8, bit: u8) -> bool {
(val & (1u8 << (bit as usize))) == 0 (val & (1u8 << (bit as usize))) == 0
} }
fn bit_d(cpu: &mut Cpu, bit: u8) {
cpu.set_sub(false);
cpu.set_zero(bit_zero(cpu.d, bit));
cpu.set_half_carry(true);
}
fn bit_h(cpu: &mut Cpu, bit: u8) { fn bit_h(cpu: &mut Cpu, bit: u8) {
cpu.set_sub(false); cpu.set_sub(false);
cpu.set_zero(bit_zero(cpu.h, bit)); cpu.set_zero(bit_zero(cpu.h, bit));
......
pub mod cpu; pub mod cpu;
pub mod data;
pub mod gb; pub mod gb;
pub mod inst; pub mod inst;
pub mod mmu; pub mod mmu;
......
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