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

chore: support for pyboy boot ROM files

Added interface to custom boot ROM loading in Python.
parent 54b278fa
No related branches found
No related tags found
1 merge request!37Improved support for PyBoy interface
Pipeline #3674 passed
from time import time
from boytacean import GameBoy, VISUAL_FREQ
from os.path import dirname, realpath, join
CURRENT_DIR = dirname(realpath(__file__))
ROM_PATH = join(CURRENT_DIR, "../../res/roms/demo/pocket.gb")
BOOT_ROM_PATH = join(CURRENT_DIR, "../../res/boot/dmg_pyboy.bin")
IMAGE_NAME = "pocket.png"
FRAME_COUNT = 12000
LOAD_GRAPHICS = True
gb = GameBoy(
apu_enabled=False, serial_enabled=False, load_graphics=LOAD_GRAPHICS, boot=False
)
gb.load_boot_path(BOOT_ROM_PATH)
gb.load_rom(ROM_PATH)
start = time()
for _ in range(FRAME_COUNT):
gb.next_frame()
total = time() - start
print(f"Time taken: {total:.2f} seconds")
print(f"Speedup: {FRAME_COUNT / total / VISUAL_FREQ:.2f}x")
gb.save_image(IMAGE_NAME)
File added
File added
use pyo3::{prelude::*, types::PyBytes};
use pyo3::{exceptions::PyException, prelude::*, types::PyBytes};
use crate::{
gb::{GameBoy as GameBoyBase, GameBoyMode},
......@@ -32,6 +32,12 @@ impl GameBoy {
self.system.load(boot);
}
pub fn load_boot_path(&mut self, path: &str) -> PyResult<()> {
self.system
.load_boot_path(path)
.map_err(|err| PyErr::new::<PyException, _>(err))
}
pub fn load_rom(&mut self, data: &[u8]) {
self.system.load_rom(data, None);
}
......
......@@ -69,8 +69,11 @@ This is a [Game Boy](https://en.wikipedia.org/wiki/Game_Boy) emulator built usin
def load(self, boot=True):
self._system.load(boot)
def load_rom(self, filename: str):
self._system.load_rom_file(filename)
def load_boot_path(self, path: str):
self._system.load_boot_path(path)
def load_rom(self, path: str):
self._system.load_rom_file(path)
def load_rom_data(self, data: bytes):
self._system.load_rom(data)
......@@ -104,9 +107,9 @@ This is a [Game Boy](https://en.wikipedia.org/wiki/Game_Boy) emulator built usin
image = frombytes("RGB", (DISPLAY_WIDTH, DISPLAY_HEIGHT), frame_buffer, "raw")
return image
def save_image(self, filename: str, format: str = "png"):
def save_image(self, path: str, format: str = "png"):
image = self.image()
image.save(filename, format=format)
image.save(path, format=format)
def video(
self,
......
from .gb import GameBoy
from .gb import GameBoy
class PyBoy(GameBoy):
def __init__(
self,
gamerom_file,
*,
bootrom_file=None,
disable_renderer=False,
sound=False,
sound_emulated=False,
cgb=None,
randomize=False,
**kwargs
):
super().__init__(apu_enabled=sound)
def __init__(self):
super().__init__()
def tick(self):
super().tick()
def load_rom(self, rom):
super().load_rom(rom)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment