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

feat: new game boy API

parent b2087d21
No related branches found
No related tags found
No related merge requests found
......@@ -5,7 +5,14 @@ fn main() {
game_boy.load_boot_default();
for i in 0..37000 {
game_boy.clock();
// runs the CPU clock and determines the number of
// cycles that have advanced for that clock tick
let cycles = game_boy.clock();
// calls the clock in the PPU to update its own
// execution lifecycle by one set of ticks
game_boy.ppu_clock(cycles);
if game_boy.cpu().pc() >= 0x6032 {
println!("{}", i);
break;
......
......@@ -506,7 +506,7 @@ impl Cpu {
}
}
pub fn clock(&mut self) {
pub fn clock(&mut self) -> u8 {
let pc = self.pc;
// fetches the current instruction and increments
......@@ -535,9 +535,9 @@ impl Cpu {
instruction_fn(self);
self.ticks = self.ticks.wrapping_add(*instruction_time as u32);
// calls the clock in the PPU to update its own
// execution lifecycle by one set of ticks
self.ppu().clock(*instruction_time);
// returns the number of cycles that the operation
// that has been executed has taken
*instruction_time
}
#[inline(always)]
......
......@@ -12,10 +12,14 @@ impl GameBoy {
GameBoy { cpu: cpu }
}
pub fn clock(&mut self) {
pub fn clock(&mut self) -> u8 {
self.cpu.clock()
}
pub fn ppu_clock(&mut self, cycles: u8) {
self.ppu().clock(cycles)
}
pub fn cpu(&mut self) -> &mut Cpu {
&mut self.cpu
}
......
......@@ -88,8 +88,8 @@ impl Ppu {
}
}
pub fn clock(&mut self, ticks: u8) {
self.mode_clock += ticks as u16;
pub fn clock(&mut self, cycles: u8) {
self.mode_clock += cycles as u16;
match self.mode {
PpuMode::OamRead => {
if self.mode_clock >= 204 {
......
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