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

feat: new instructions

parent c7564b65
No related branches found
No related tags found
No related merge requests found
Pipeline #865 passed
......@@ -80,10 +80,12 @@ fn main() {
let mut game_boy = GameBoy::new();
game_boy.load_boot_dmg();
game_boy.load_rom_file("../../res/roms.prop/tetris.gb");
//game_boy.load_rom_file("../../res/roms/firstwhite.gb");
//game_boy.load_rom_file("../../res/roms/opus5.gb");
//game_boy.load_rom_file("../../res/roms/ld_r_r.gb");
game_boy.load_rom_file("../../res/roms/special.gb");
//game_boy.load_rom_file("../../res/roms/special.gb");
//game_boy.load_rom_file("../../res/roms/firstwhite.gb");
let mut counter = 0;
......
use core::panic;
use crate::{
inst::{EXTENDED, INSTRUCTIONS},
mmu::Mmu,
......@@ -303,6 +305,11 @@ impl Cpu {
self.halted = true;
}
#[inline(always)]
pub fn stop(&mut self) {
panic!("STOP is not implemented");
}
#[inline(always)]
pub fn enable_int(&mut self) {
// @todo implement this one
......
......@@ -19,7 +19,7 @@ pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &'static str); 256] = [
(ld_c_u8, 8, "LD C, u8"),
(noimpl, 4, "! UNIMP !"),
// 0x1 opcodes
(noimpl, 4, "! UNIMP !"),
(stop, 4, "STOP"),
(ld_de_u16, 12, "LD DE, u16"),
(ld_mde_a, 8, "LD [DE], A"),
(inc_de, 8, "INC DE"),
......@@ -62,7 +62,7 @@ pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &'static str); 256] = [
(ld_mhl_u8, 12, "LD [HL], u8 "),
(scf, 4, "SCF"),
(jr_c_i8, 8, "JR C, i8"),
(noimpl, 4, "! UNIMP !"),
(add_hl_sp, 8, "ADD HL, SP"),
(noimpl, 4, "! UNIMP !"),
(noimpl, 4, "! UNIMP !"),
(inc_a, 4, "INC A"),
......@@ -656,6 +656,10 @@ fn ld_c_u8(cpu: &mut Cpu) {
cpu.c = byte;
}
fn stop(cpu: &mut Cpu) {
cpu.stop();
}
fn ld_de_u16(cpu: &mut Cpu) {
let word = cpu.read_u16();
cpu.set_de(word);
......@@ -923,6 +927,11 @@ fn jr_c_i8(cpu: &mut Cpu) {
cpu.ticks = cpu.ticks.wrapping_add(4);
}
fn add_hl_sp(cpu: &mut Cpu) {
let value = add_u16_u16(cpu, cpu.hl(), cpu.sp());
cpu.set_hl(value);
}
fn inc_a(cpu: &mut Cpu) {
let value = cpu.a.wrapping_add(1);
......
......@@ -51,9 +51,9 @@ impl Mmu {
}
self.rom[addr as usize]
}
// ROM0 (12 KB/16 KB)
// ROM 0 (12 KB/16 KB)
0x1000 | 0x2000 | 0x3000 => self.rom[addr as usize],
// ROM1 (Unbanked) (16 KB)
// ROM 1 (Unbanked) (16 KB)
0x4000 | 0x5000 | 0x6000 | 0x7000 => self.rom[addr as usize],
// Graphics: VRAM (8 KB)
0x8000 | 0x9000 => self.ppu.vram[(addr & 0x1fff) as usize],
......@@ -99,15 +99,15 @@ impl Mmu {
// BOOT (256 B) + ROM0 (4 KB/16 KB)
0x0000 => {
self.rom[addr as usize] = value;
println!("Writing to BOOT at 0x{:04x}", addr)
panic!("Writing to BOOT at 0x{:04x}", addr)
}
// ROM0 (12 KB/16 KB)
// ROM 0 (12 KB/16 KB)
0x1000 | 0x2000 | 0x3000 => {
println!("Writing to ROM 0 at 0x{:04x}", addr);
panic!("Writing to ROM 0 at 0x{:04x}", addr);
}
// ROM1 (Unbanked) (16 KB)
// ROM 1 (Unbanked) (16 KB)
0x4000 | 0x5000 | 0x6000 | 0x7000 => {
println!("Writing to ROM 1 at 0x{:04x}", addr);
panic!("Writing to ROM 1 at 0x{:04x}", addr);
}
// Graphics: VRAM (8 KB)
0x8000 | 0x9000 => {
......
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