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

chore: more constants exported

parent 6fb6446d
No related branches found
No related tags found
1 merge request!36Support for Python
Pipeline #3597 passed
......@@ -4,4 +4,4 @@ gb = boytacean.GameBoy()
gb.load()
gb.load_rom("../../res/roms/demo/pocket.gb")
gb.clocks(10000000)
gb.save_image("tobias.png")
gb.save_image("pocket.png")
use pyo3::{prelude::*, types::PyBytes};
use crate::{gb::GameBoy as GameBoyBase, ppu::FRAME_BUFFER_SIZE};
use crate::{
gb::GameBoy as GameBoyBase,
ppu::{DISPLAY_HEIGHT, DISPLAY_WIDTH},
};
#[pyclass]
struct GameBoy {
......@@ -49,5 +52,7 @@ impl GameBoy {
#[pymodule]
fn boytacean(_py: Python, module: &PyModule) -> PyResult<()> {
module.add_class::<GameBoy>()?;
module.add("DISPLAY_WIDTH", DISPLAY_WIDTH)?;
module.add("DISPLAY_HEIGHT", DISPLAY_HEIGHT)?;
Ok(())
}
from PIL import Image
from .boytacean import GameBoy as GameBoyRust
from .boytacean import DISPLAY_WIDTH, DISPLAY_HEIGHT, GameBoy as GameBoyRust
class GameBoy:
......@@ -26,7 +26,9 @@ class GameBoy:
def frame_buffer(self):
return self._system.frame_buffer()
def save_image(self, filename: str):
def save_image(self, filename: str, format: str = "PNG"):
frame_buffer = self._system.frame_buffer()
image = Image.frombytes("RGB", (160, 144), frame_buffer, "raw")
image.save(filename, "PNG")
image = Image.frombytes(
"RGB", (DISPLAY_WIDTH, DISPLAY_HEIGHT), frame_buffer, "raw"
)
image.save(filename, format=format)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment