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

feat: more instructions

parent 30e2a631
No related branches found
No related tags found
No related merge requests found
Pipeline #858 passed
......@@ -81,7 +81,8 @@ fn main() {
let mut game_boy = GameBoy::new();
game_boy.load_boot_dmg();
//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/opus5.gb");
game_boy.load_rom_file("../../res/roms/ld_r_r.gb");
let mut counter = 0;
......
use crate::{
cpu::Cpu,
data::{SGB_BOOT, DMG_BOOT},
data::{DMG_BOOT, SGB_BOOT},
mmu::Mmu,
ppu::{Ppu, FRAME_BUFFER_SIZE},
util::read_file,
......
......@@ -214,13 +214,13 @@ pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &'static str); 256] = [
(push_bc, 16, "PUSH BC"),
(add_a_u8, 8, "ADD A, u8"),
(noimpl, 4, "! UNIMP !"),
(noimpl, 4, "! UNIMP !"),
(ret_z, 8, "RET Z"),
(ret, 16, "RET"),
(jp_z_u16, 12, "JP Z, u16"),
(noimpl, 4, "! UNIMP !"),
(call_z_u16, 12, "CALL Z, u16"),
(call_u16, 24, "CALL u16"),
(noimpl, 4, "! UNIMP !"),
(adc_a_u8, 8, "ADC A, u8 "),
(rst_08h, 16, "RST 08h"),
// 0xd opcodes
(ret_nc, 8, "RET NC"),
......@@ -1206,6 +1206,15 @@ fn add_a_u8(cpu: &mut Cpu) {
cpu.a = add_set_flags(cpu, cpu.a, byte);
}
fn ret_z(cpu: &mut Cpu) {
if !cpu.get_zero() {
return;
}
cpu.pc = cpu.pop_word();
cpu.ticks = cpu.ticks.wrapping_add(12);
}
fn ret(cpu: &mut Cpu) {
cpu.pc = cpu.pop_word();
}
......@@ -1239,6 +1248,11 @@ fn call_u16(cpu: &mut Cpu) {
cpu.pc = word;
}
fn adc_a_u8(cpu: &mut Cpu) {
let byte = cpu.read_u8();
cpu.a = add_carry_set_flags(cpu, cpu.a, byte);
}
fn rst_08h(cpu: &mut Cpu) {
rst(cpu, 0x0008);
}
......@@ -1499,6 +1513,22 @@ fn add_set_flags(cpu: &mut Cpu, first: u8, second: u8) -> u8 {
result_b
}
fn add_carry_set_flags(cpu: &mut Cpu, first: u8, second: u8) -> u8 {
let first = first as u32;
let second = second as u32;
let carry = cpu.get_carry() as u32;
let result = first.wrapping_add(second).wrapping_add(carry);
let result_b = result as u8;
cpu.set_sub(false);
cpu.set_zero(result_b == 0);
cpu.set_half_carry((first ^ second ^ result) & 0x10 == 0x10);
cpu.set_carry(result & 0x100 == 0x100);
result_b
}
fn sub_set_flags(cpu: &mut Cpu, first: u8, second: u8) -> u8 {
let first = first as u32;
let second = second as u32;
......
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