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

chore: added step_to operation

parent b5b17094
No related branches found
No related tags found
1 merge request!37Improved support for PyBoy interface
Pipeline #3691 passed
...@@ -499,6 +499,17 @@ impl GameBoy { ...@@ -499,6 +499,17 @@ impl GameBoy {
cycles cycles
} }
pub fn step_to(&mut self, addr: u16) -> u32 {
let mut cycles = 0u32;
loop {
cycles += self.clock() as u32;
if self.cpu_i().pc() == addr {
break;
}
}
cycles
}
pub fn key_press(&mut self, key: PadKey) { pub fn key_press(&mut self, key: PadKey) {
self.pad().key_press(key); self.pad().key_press(key);
} }
......
...@@ -76,6 +76,10 @@ impl GameBoy { ...@@ -76,6 +76,10 @@ impl GameBoy {
self.system.next_frame() self.system.next_frame()
} }
pub fn step_to(&mut self, addr: u16) -> u32 {
self.system.step_to(addr)
}
pub fn key_press(&mut self, key: u8) { pub fn key_press(&mut self, key: u8) {
self.system.key_press(PadKey::from_u8(key)) self.system.key_press(PadKey::from_u8(key))
} }
......
...@@ -19,6 +19,7 @@ class GameBoy: ...@@ -19,6 +19,7 @@ class GameBoy:
def clock_m(self, count: int) -> int: ... def clock_m(self, count: int) -> int: ...
def clocks(self, count: int) -> int: ... def clocks(self, count: int) -> int: ...
def next_frame(self) -> int: ... def next_frame(self) -> int: ...
def step_to(self, addr: int) -> int: ...
def key_press(self, key: int): ... def key_press(self, key: int): ...
def key_lift(self, key: int): ... def key_lift(self, key: int): ...
def frame_buffer(self) -> bytes: ... def frame_buffer(self) -> bytes: ...
......
...@@ -110,6 +110,9 @@ This is a [Game Boy](https://en.wikipedia.org/wiki/Game_Boy) emulator built usin ...@@ -110,6 +110,9 @@ This is a [Game Boy](https://en.wikipedia.org/wiki/Game_Boy) emulator built usin
self._on_next_frame() self._on_next_frame()
return cycles return cycles
def step_to(self, addr: int) -> int:
return self._system.step_to(addr)
def skip_frames(self, count: int) -> int: def skip_frames(self, count: int) -> int:
cycles = 0 cycles = 0
for _ in range(count): for _ in range(count):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment