Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Console + code viewer + fixes #41

Merged
merged 25 commits into from
May 22, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
move register write triggers to set_mem8
pineman committed May 22, 2024
commit cb5a3c460cd757e2a719b17282c717cb46e55037
19 changes: 12 additions & 7 deletions fpt/src/lr35902.rs
Original file line number Diff line number Diff line change
@@ -196,7 +196,7 @@ impl LR35902 {
self.af = bw::set_bit16::<4>(self.af, value);
}

// other
// other getters/setters
pub fn pc(&self) -> u16 {
self.pc
}
@@ -241,7 +241,7 @@ impl LR35902 {
self.inst_cycle_count = inst_cycle_count;
}

// helpers
// Memory
pub fn mem8(&self, index: u16) -> u8 {
self.mem.read(index)
}
@@ -251,6 +251,7 @@ impl LR35902 {
}

pub fn set_mem8(&mut self, index: u16, value: u8) {
self.register_write_triggers(index, value);
self.mem.write(index, value);
}

@@ -259,6 +260,13 @@ impl LR35902 {
self.set_mem8(index, bw::get_byte16::<0>(value));
}

fn register_write_triggers(&mut self, index: u16, value: u8) {
if index == memory::map::BANK as u16 && value != 0 {
self.mem.unload_bootrom();
}
}

// Decoding
/// get 8 bit immediate at position pc + 1 + pos
fn get_d8(&self, pos: u8) -> u8 {
self.mem8(self.pc + pos as u16 + 1)
@@ -283,6 +291,7 @@ impl LR35902 {
self.set_mem8(self.hl(), value);
}

// Instruction logic
fn half_carry8(&self, x: u8, y: u8) -> bool {
((x & 0x0f) + (y & 0x0f)) > 0x0f
}
@@ -1659,11 +1668,7 @@ impl LR35902 {
}
0xE0 => {
// LDH (a8),A
let mem = 0xFF00 | self.get_d8(0) as u16;
if mem as usize == memory::map::BANK && self.a() != 0 {
self.mem.unload_bootrom();
}
self.set_mem8(mem, self.a());
self.set_mem8(0xFF00 | self.get_d8(0) as u16, self.a());
}
0xE1 => {
// POP HL