Skip to content

Commit 4c035a1

Browse files
committed
Add enum for load flags
1 parent 17217c9 commit 4c035a1

3 files changed

Lines changed: 25 additions & 4 deletions

File tree

gambaterm/console.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,10 @@ def __init__(
158158
self.gb.set_save_directory(tempfile.mkdtemp())
159159

160160
# Load the rom
161-
return_code = self.gb.load(self.romfile, 0 if self.force_gameboy else 1)
161+
flags = self.gb.LoadFlag.NO_BIOS
162+
if not self.force_gameboy:
163+
flags |= self.gb.LoadFlag.CGB_MODE
164+
return_code = self.gb.load(self.romfile, flags)
162165
if return_code != 0:
163166
# Make sure it exists
164167
open(self.romfile).close()

gambaterm/libgambatte.pyi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1+
from enum import IntFlag
12
import numpy as np
23
import numpy.typing as npt
34

45
class GB:
6+
class LoadFlag(IntFlag):
7+
CGB_MODE = ...
8+
GBA_FLAG = ...
9+
RESERVED_FLAG = ...
10+
SGB_MODE = ...
11+
READONLY_SAV = ...
12+
NO_BIOS = ...
513
def load(self, rom_file: str, flags: int = 0) -> int: ...
614
def run_for(
715
self,

libgambatte_ext/libgambatte.pyx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,19 @@
22
# distutils: libraries = gambatte
33
# cython: language_level=3
44

5+
from enum import IntFlag
56
from libcpp.string cimport string
67
from libc.stdint cimport uint32_t, int16_t
78
from _libgambatte cimport GB as C_GB
89

10+
class LoadFlag(IntFlag):
11+
CGB_MODE = 1 # Treat the ROM as having CGB support regardless of what its header advertises.
12+
GBA_FLAG = 2 # Use GBA intial CPU register values when in CGB mode.
13+
RESERVED_FLAG = 4 # Previously a multicart heuristics enable. Reserved for future use.
14+
SGB_MODE = 8 # Treat the ROM as having SGB support regardless of what its header advertises.
15+
READONLY_SAV = 16 # Prevent implicit saveSavedata calls for the ROM.
16+
NO_BIOS = 32 # Use heuristics to boot without a BIOS.
17+
918

1019
cdef unsigned c_getinput(void *context) noexcept nogil:
1120
cdef unsigned int* value_ptr = <unsigned int*>context
@@ -15,12 +24,13 @@ cdef class GB:
1524
cdef C_GB c_gb
1625
cdef unsigned int c_input
1726

27+
LoadFlag = LoadFlag
28+
1829
def __cinit__(self):
1930
self.c_gb.setInputGetter(&c_getinput, &self.c_input)
2031

21-
def load(self, str rom_file, unsigned flags=0):
22-
no_bios_flags = 32
23-
return self.c_gb.load(rom_file.encode(), flags | no_bios_flags)
32+
def load(self, str rom_file, unsigned int flags=0):
33+
return self.c_gb.load(rom_file.encode(), flags)
2434

2535
def run_for(
2636
self,

0 commit comments

Comments
 (0)