Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import sys
import cv2
import struct
import numpy as np
import socket
from pyboy import PyBoy
pyboy = PyBoy(sys.argv[1],debugging=False,disable_input=False,hide_window="--quiet" in sys.argv)
pyboy.set_emulation_speed(1)
tick = 0
pixelBuffer = []
rgbMode = struct.pack("<?", 0)
versionBit = struct.pack("<B", 1)
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
while True:
screen_dimensions = pyboy.get_raw_screen_buffer_dims()
frame = np.frombuffer(pyboy.get_raw_screen_buffer(), dtype=np.uint8).reshape(screen_dimensions[1], screen_dimensions[0], 4)
frame = cv2.resize(frame, dsize=(64, 32), interpolation=cv2.INTER_CUBIC)
rows, cols, _ = frame.shape
for r in range(rows):
for c in range(cols):
pixelBuffer.append(bytes(struct.pack("<2H4B", c, r, *frame[r,c])))
if len(pixelBuffer) > 256: # Update screen every 256 pixels
sock.sendto(versionBit + rgbMode + b"".join(pixelBuffer), ("10.208.42.159", 5004))
pixelBuffer = []
pyboy.tick()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment