Skip to content

Commit 105a33e

Browse files
authored
Update dependencies and add ZIP support for linux and macos
2 parents ec7cc5c + afd348d commit 105a33e

7 files changed

Lines changed: 125 additions & 103 deletions

File tree

gambaterm/run.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ def run(
5757
assert color_mode > 0
5858

5959
# Prepare buffers with invalid data
60-
video = np.full((console.HEIGHT, console.WIDTH), -1, np.uint32)
61-
audio = np.full((2 * console.TICKS_IN_FRAME, 2), -1, np.int16)
60+
video = np.full((console.HEIGHT, console.WIDTH), 0xFFFFFFFF, np.uint32)
61+
audio = np.full((2 * console.TICKS_IN_FRAME, 2), -0x7FFF, np.int16)
6262
last_frame = video.copy()
6363

6464
# Print area
@@ -133,7 +133,7 @@ def run(
133133
app_session.output.flush()
134134
height, width = new_size
135135
refx, refy = get_ref(width, height, console)
136-
last_frame.fill(-1)
136+
last_frame.fill(0xFFFFFFFF)
137137
# Render frame
138138
video_data = blit(
139139
video, last_frame, refx, refy, width - 1, height, color_mode

libgambatte/src/file/unzip/unzip.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password)
11751175
if (password != NULL)
11761176
{
11771177
int i;
1178-
s->pcrc_32_tab = get_crc_table();
1178+
s->pcrc_32_tab = (const unsigned long*)get_crc_table();
11791179
init_keys(password,s->keys,s->pcrc_32_tab);
11801180
if (ZSEEK(s->z_filefunc, s->filestream,
11811181
s->pfile_in_zip_read->pos_in_zipfile +

libgambatte_ext/_libgambatte.pxd

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
from libcpp.string cimport string
2+
from libc.stdint cimport uint32_t
23

34
cdef extern from "gambatte.h" namespace "gambatte":
45
cdef cppclass GB:
56
GB() except +;
67
int load(string& romfile, unsigned flags);
78
ptrdiff_t runFor(
8-
unsigned int *videoBuf,
9+
uint32_t *videoBuf,
910
ptrdiff_t pitch,
10-
unsigned int *audioBuf,
11+
uint32_t *audioBuf,
1112
size_t& samples,
1213
);
1314
void setInputGetter(GetInput *getInput);
@@ -17,7 +18,7 @@ cdef extern from "gambatte.h" namespace "gambatte":
1718
void selectState(int state);
1819
int currentState();
1920
int loadState();
20-
int saveState(unsigned int *videoBuf, ptrdiff_t pitch);
21+
int saveState(uint32_t *videoBuf, ptrdiff_t pitch);
2122

2223

2324
cdef extern from "input.h" namespace "gambatte":

libgambatte_ext/libgambatte.pyx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# distutils: language = c++
22
# distutils: libraries = gambatte
3+
# cython: language_level=3
34

4-
cimport numpy as np
55
from libcpp.string cimport string
6+
from libc.stdint cimport uint32_t, int16_t
67
from _libgambatte cimport GB as C_GB
78
from _libgambatte cimport GetInput as C_GetInput
89

@@ -19,13 +20,13 @@ cdef class GB:
1920

2021
def run_for(
2122
self,
22-
np.ndarray[np.uint32_t, ndim=2] video,
23+
uint32_t[:, ::1] video,
2324
ptrdiff_t pitch,
24-
np.ndarray[np.int16_t, ndim=2] audio,
25+
int16_t[:, ::1] audio,
2526
size_t samples,
2627
):
27-
cdef unsigned int* video_buffer = <unsigned int*> video.data
28-
cdef unsigned int* audio_buffer = <unsigned int*> audio.data
28+
cdef uint32_t* video_buffer = &video[0, 0]
29+
cdef uint32_t* audio_buffer = <uint32_t*>&audio[0, 0]
2930
result = self.c_gb.runFor(video_buffer, pitch, audio_buffer, samples)
3031
return result, samples
3132

@@ -46,10 +47,10 @@ cdef class GB:
4647

4748
def save_state(
4849
self,
49-
np.ndarray[np.uint32_t, ndim=2] video,
50+
uint32_t[:, ::1] video,
5051
ptrdiff_t pitch,
5152
):
5253
if video is None:
5354
return self.c_gb.saveState(NULL, 0)
54-
cdef unsigned int* video_buffer = <unsigned int*> video.data
55+
cdef uint32_t* video_buffer = &video[0, 0]
5556
return self.c_gb.saveState(video_buffer, pitch)

pyproject.toml

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,58 @@
11
[build-system]
22
requires = [
3-
"setuptools>=42",
3+
"setuptools>=61.0",
44
"wheel",
5-
"Cython>=0.29.13,<3.0",
5+
"Cython>=3.2.1",
66
"oldest-supported-numpy",
77
]
88
build-backend = "setuptools.build_meta"
99

10+
[project]
11+
name = "gambaterm"
12+
version = "0.12.7"
13+
description = "A terminal frontend for gambatte game boy color emulator"
14+
readme = "README.md"
15+
requires-python = ">=3.7"
16+
license = "GPL-3.0-only"
17+
authors = [
18+
{name = "Vincent Michel", email = "vxgmichel@gmail.com"}
19+
]
20+
classifiers = [
21+
"Programming Language :: Python",
22+
"Programming Language :: Python :: 3",
23+
"Programming Language :: Python :: 3.9",
24+
"Programming Language :: Python :: 3.10",
25+
"Programming Language :: Python :: 3.11",
26+
"Programming Language :: Python :: 3.12",
27+
"Programming Language :: Python :: 3.13",
28+
"Programming Language :: Python :: 3.14",
29+
]
30+
dependencies = [
31+
"numpy>=2.0.0,<3.0.0",
32+
"asyncssh>=2.9,<3.0.0",
33+
"prompt_toolkit>=3.0.29,<4.0.0",
34+
"sounddevice>=0.4,<1.0",
35+
"samplerate>=0.1.0,<0.2.0",
36+
"python-xlib; sys_platform == 'linux'",
37+
"pynput; sys_platform != 'linux'",
38+
]
39+
40+
[project.optional-dependencies]
41+
controller-support = ["pygame>=1.9.5,<2.0.0"]
42+
43+
[project.urls]
44+
Homepage = "https://github.com/vxgmichel/gambatte-terminal"
45+
46+
[project.scripts]
47+
gambaterm = "gambaterm:main"
48+
gambaterm-ssh = "gambaterm.ssh:main"
49+
50+
[tool.setuptools]
51+
packages = ["gambaterm"]
52+
53+
[tool.setuptools.package-data]
54+
gambaterm = ["py.typed", "*.pyi"]
55+
1056
[tool.mypy]
1157
strict = true
1258
show_error_codes = true
@@ -23,6 +69,7 @@ ignore_missing_imports = true
2369

2470
[tool.cibuildwheel]
2571
build = "cp*-win_amd64 cp*-manylinux_x86_64 cp*-macosx_x86_64 cp*-macosx_arm64"
72+
skip = ["cp38-*", "cp3??t-*"]
2673

2774
[tool.cibuildwheel.windows]
2875
test-command = "gambaterm --help"

setup.py

Lines changed: 52 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,66 @@
11
from __future__ import annotations
22

33
import glob
4+
import platform
45
from pathlib import Path
56
from setuptools import Extension, setup
67

7-
import numpy
8+
# No ZIP support for windows, building with zlib is a pain
9+
ZIP_SUPPORT = platform.system() != "Windows"
810

9-
# Read the contents of the README file
10-
LONG_DESCRIPTION = (Path(__file__).parent / "README.md").read_text()
1111

12-
# List libgambatte sources, excluding `file_zip.cpp`
13-
libgambatte_sources = [
14-
path
15-
for path in glob.glob("libgambatte/**/*.cpp", recursive=True)
16-
if not path.endswith("file_zip.cpp")
17-
]
12+
def get_extensions() -> list[Extension]:
13+
import numpy # Lazy import; numpy provided via build-system requires
1814

19-
# List all directories containing `.h` files
20-
libgambatte_include_dirs: list[str] = list(
21-
set(
22-
str(Path(path).parent)
23-
for path in glob.glob("libgambatte/**/*.h", recursive=True)
24-
)
25-
)
15+
# Gather all C++ sources (including file_zip.cpp for ZIP support)
16+
# Exclude file.cpp since file_zip.cpp provides the full implementation
17+
libgambatte_sources = [
18+
p
19+
for p in glob.glob("libgambatte/**/*.cpp", recursive=True)
20+
if (ZIP_SUPPORT and not p.endswith("file.cpp"))
21+
or (not ZIP_SUPPORT and not p.endswith("file_zip.cpp"))
22+
]
2623

27-
# The gambatte extension, including libgambatte with the Cython wrapper
28-
gambatte_extension = Extension(
29-
"gambaterm.libgambatte",
30-
language="c++",
31-
include_dirs=[
32-
*libgambatte_include_dirs,
33-
"libgambatte_ext",
34-
numpy.get_include(),
35-
],
36-
extra_compile_args=["-DHAVE_STDINT_H"],
37-
sources=[
38-
*libgambatte_sources,
39-
"libgambatte_ext/libgambatte.pyx",
40-
],
41-
)
24+
# Add unzip C sources for ZIP support
25+
if ZIP_SUPPORT:
26+
libgambatte_sources += glob.glob(
27+
"libgambatte/src/file/unzip/*.c", recursive=True
28+
)
4229

30+
# Add zlib library for ZIP support
31+
libraries = []
32+
if ZIP_SUPPORT:
33+
libraries += ["z"]
4334

44-
# The termblit extension
45-
termblit_extension = Extension(
46-
"gambaterm.termblit",
47-
language="c",
48-
include_dirs=[numpy.get_include()],
49-
sources=["termblit_ext/termblit.pyx"],
50-
)
35+
# Include dirs: parents of all headers
36+
libgambatte_include_dirs = list(
37+
{str(Path(h).parent) for h in glob.glob("libgambatte/**/*.h", recursive=True)}
38+
)
5139

52-
setup(
53-
name="gambaterm",
54-
version="0.12.7",
55-
packages=["gambaterm"],
56-
ext_modules=[gambatte_extension, termblit_extension],
57-
install_requires=[
58-
"numpy~=1.20",
59-
"asyncssh~=2.9",
60-
"prompt_toolkit~=3.0.29",
61-
"sounddevice~=0.4",
62-
"samplerate~=0.1.0", # See https://github.com/tuxu/python-samplerate/issues/19
63-
"python-xlib; sys_platform == 'linux'",
64-
"pynput; sys_platform != 'linux'",
65-
],
66-
extras_require={
67-
"controller-support": ["pygame~=1.9.5"],
68-
},
69-
python_requires=">=3.7",
70-
entry_points={
71-
"console_scripts": [
72-
"gambaterm = gambaterm:main",
73-
"gambaterm-ssh = gambaterm.ssh:main",
40+
gambatte_extension = Extension(
41+
"gambaterm.libgambatte",
42+
language="c++",
43+
include_dirs=[
44+
*libgambatte_include_dirs,
45+
"libgambatte_ext",
46+
numpy.get_include(),
47+
],
48+
extra_compile_args=["-DHAVE_STDINT_H"],
49+
libraries=libraries,
50+
sources=[
51+
*libgambatte_sources,
52+
"libgambatte_ext/libgambatte.pyx",
7453
],
75-
},
76-
package_data={"gambaterm": ["py.typed"]},
77-
description="A terminal frontend for gambatte game boy color emulator ",
78-
long_description=LONG_DESCRIPTION,
79-
long_description_content_type="text/markdown",
80-
url="https://github.com/vxgmichel/gambatte-terminal",
81-
license="GPLv3",
82-
classifiers=[
83-
"Programming Language :: Python",
84-
"Programming Language :: Python :: 3",
85-
"Programming Language :: Python :: 3.8",
86-
"Programming Language :: Python :: 3.9",
87-
"Programming Language :: Python :: 3.10",
88-
"Programming Language :: Python :: 3.11",
89-
"Programming Language :: Python :: 3.12",
90-
"Programming Language :: Python :: 3.13",
91-
"Programming Language :: Python :: 3.14",
92-
],
93-
author="Vincent Michel",
94-
author_email="vxgmichel@gmail.com",
95-
)
54+
)
55+
56+
termblit_extension = Extension(
57+
"gambaterm.termblit",
58+
language="c",
59+
include_dirs=[numpy.get_include()],
60+
sources=["termblit_ext/termblit.pyx"],
61+
)
62+
63+
return [gambatte_extension, termblit_extension]
64+
65+
66+
setup(ext_modules=get_extensions())

termblit_ext/termblit.pyx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
cimport numpy as np
1+
# cython: language_level=3
2+
23
from libc.stdio cimport sprintf
34
from libc.stdlib cimport malloc, free
5+
from libc.stdint cimport uint32_t
46

57
cdef char* move_absolute(char* buff, int x, int y):
68
buff += sprintf(buff, "\033[%d;%dH", x, y)
@@ -141,18 +143,18 @@ cdef char* move_from_to(
141143

142144

143145
def blit(
144-
np.ndarray[np.uint32_t, ndim=2] image,
145-
np.ndarray[np.uint32_t, ndim=2] last,
146+
uint32_t[:, ::1] image,
147+
uint32_t[:, ::1] last,
146148
int refx, int refy, int width, int height,
147149
int color_mode,
148150
):
149151

150152
cdef int current_x = refx
151153
cdef int current_y = refy
152-
cdef int current_fg = -1
153-
cdef int current_bg = -2
154+
cdef uint32_t current_fg = -1
155+
cdef uint32_t current_bg = -2
154156
cdef int row_index, column_index
155-
cdef int color1, color2
157+
cdef uint32_t color1, color2
156158
cdef int new_x, new_y
157159
cdef int invert_print
158160
cdef int image_height = image.shape[0]

0 commit comments

Comments
 (0)