55$ copy the file dist/core/index.untouched.wasm
66"""
77
8- import sys
9- import logging
10- import os
118import argparse
9+ import logging
10+ import sys
11+ from pathlib import Path
1212
1313import numpy as np
1414import pygame
1515from pygame .locals import QUIT
1616
17- from ppci .wasm import Module , instantiate
1817from ppci .utils import reporting
18+ from ppci .wasm import Module , instantiate
1919
20+ this_dir = Path (__file__ ).resolve ().parent
21+ default_gb_path = this_dir / "cpu_instrs.gb"
22+ wasmboy_path = this_dir / "wasmboy.wasm"
2023parser = argparse .ArgumentParser ()
21- parser .add_argument ("--rom" , default = "cpu_instrs.gb" )
24+ parser .add_argument ("--rom" , default = default_gb_path , type = Path )
2225args = parser .parse_args ()
2326logging .basicConfig (level = logging .INFO )
27+ logger = logging .getLogger ()
2428
25- with open ("wasmboy.wasm" , "rb" ) as f :
29+ logger .info (f"Loading { wasmboy_path } " )
30+ with wasmboy_path .open ("rb" ) as f :
2631 wasm_module = Module (f )
2732
2833
2934def log (a : int , b : int , c : int , d : int , e : int , f : int , g : int ) -> None :
3035 print ("Log:" , a , b , c , d , e , f , g )
3136
3237
33- this_dir = os .path .dirname (os .path .abspath (__file__ ))
34- html_report = os .path .join (this_dir , "wasmboy_report.html" )
38+ html_report = this_dir / "wasmboy_report.html"
3539with reporting .html_reporter (html_report ) as reporter :
3640 wasm_boy = instantiate (
3741 wasm_module ,
@@ -44,11 +48,10 @@ def log(a: int, b: int, c: int, d: int, e: int, f: int, g: int) -> None:
4448# https://github.com/torch2424/wasmBoy/wiki/%5BWIP%5D-Core-API
4549
4650rom_filename = args .rom
47- logging .info ("Loading %s" , rom_filename )
51+ logger .info ("Loading %s" , rom_filename )
4852# Load in a game to CARTRIDGE_ROM_LOCATION
4953rom_location = wasm_boy .exports .CARTRIDGE_ROM_LOCATION .read ()
50- with open (rom_filename , "rb" ) as f :
51- rom_data = f .read ()
54+ rom_data = rom_filename .read_bytes ()
5255rom_size = len (rom_data )
5356wasm_boy .exports .memory [rom_location : rom_location + rom_size ] = rom_data
5457
0 commit comments