-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjunknes.py
111 lines (87 loc) · 3.38 KB
/
junknes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# -*- coding: utf-8 -*-
from ctypes import cdll,\
Structure, POINTER, CFUNCTYPE,\
c_int, c_uint, c_uint8, c_uint16,\
c_void_p
_lib = cdll.LoadLibrary("./libjunknes.so")
def _funcdef(name, res, args):
func = getattr(_lib, name)
func.restype = res
func.argtypes = args
return func
JUNKNES_MIRROR_H = 0
JUNKNES_MIRROR_V = 1
JUNKNES_JOY_A = (1<<0)
JUNKNES_JOY_B = (1<<1)
JUNKNES_JOY_S = (1<<2)
JUNKNES_JOY_T = (1<<3)
JUNKNES_JOY_U = (1<<4)
JUNKNES_JOY_D = (1<<5)
JUNKNES_JOY_L = (1<<6)
JUNKNES_JOY_R = (1<<7)
class Junknes(Structure): pass
class JunknesSoundChannel(Structure):
_fields_ = (
("len", c_int),
("data", POINTER(c_uint8)),
)
class JunknesSound(Structure):
_fields_ = (
("sq1", JunknesSoundChannel),
("sq2", JunknesSoundChannel),
("tri", JunknesSoundChannel),
("noi", JunknesSoundChannel),
("dmc", JunknesSoundChannel),
)
class _JunknesCpuStateP(Structure):
_fields_ = (
("C", c_uint8),
("Z", c_uint8),
("I", c_uint8),
("D", c_uint8),
("V", c_uint8),
("N", c_uint8),
)
class JunknesCpuState(Structure):
_fields_ = (
("PC", c_uint16),
("A", c_uint8),
("X", c_uint8),
("Y", c_uint8),
("S", c_uint8),
("P", _JunknesCpuStateP),
)
JunknesCpuHook = CFUNCTYPE(None, POINTER(JunknesCpuState), c_uint8, c_uint16, c_void_p)
junknes_create = _funcdef("junknes_create",
POINTER(Junknes), (POINTER(c_uint8), POINTER(c_uint8), c_int))
junknes_destroy = _funcdef("junknes_destroy", None, (POINTER(Junknes),))
junknes_hardreset = _funcdef("junknes_hardreset", None, (POINTER(Junknes),))
junknes_softreset = _funcdef("junknes_softreset", None, (POINTER(Junknes),))
junknes_emulate_frame = _funcdef("junknes_emulate_frame", None, (POINTER(Junknes),))
junknes_set_input = _funcdef("junknes_set_input", None, (POINTER(Junknes), c_int, c_uint))
junknes_screen = _funcdef("junknes_screen", POINTER(c_uint8), (POINTER(Junknes),))
junknes_sound = _funcdef("junknes_sound", None, (POINTER(Junknes), POINTER(JunknesSound)))
junknes_before_exec = _funcdef("junknes_before_exec",
None, (POINTER(Junknes), JunknesCpuHook, c_void_p))
JUNKNES_PIXEL_XRGB8888 = 0
class JunknesRgb(Structure):
_fields_ = (
("r", c_uint8),
("g", c_uint8),
("b", c_uint8),
("unused", c_uint8),
)
class JunknesBlit(Structure): pass
class JunknesMixer(Structure): pass
junknes_blit_create = _funcdef("junknes_blit_create",
POINTER(JunknesBlit), (POINTER(JunknesRgb), c_int))
junknes_blit_destroy = _funcdef("junknes_blit_destroy", None, (POINTER(JunknesBlit),))
junknes_blit_do = _funcdef("junknes_blit_do",
None, (POINTER(JunknesBlit), POINTER(c_uint8), c_void_p, c_int))
junknes_mixer_create = _funcdef("junknes_mixer_create",
POINTER(JunknesMixer), (c_int, c_int, c_int))
junknes_mixer_destroy = _funcdef("junknes_mixer_destroy", None, (POINTER(JunknesMixer),))
junknes_mixer_push = _funcdef("junknes_mixer_push",
None, (POINTER(JunknesMixer), POINTER(JunknesSound)))
junknes_mixer_pull_sdl = _funcdef("junknes_mixer_pull_sdl",
None, (c_void_p, POINTER(c_uint8), c_int))