-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathemuplugin.py
58 lines (41 loc) · 1.32 KB
/
emuplugin.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
import glob
import imp
from os.path import join, basename, splitext, dirname
PLUGINS_DIR = join(dirname(__file__), "plugins")
def importPlugins(dir=PLUGINS_DIR):
# http://tinyurl.com/cfceawr
return [_load(path).plugin for path in glob.glob(join(dir, "[!_]*.py"))]
def _load(path):
# http://tinyurl.com/cfceawr
name, ext = splitext(basename(path))
return imp.load_source(name, path)
class BasePlugin:
"""
Plugin module to interface with a cpu core.
Signaling a shutdown should be done via raising SystemExit within tick()
"""
# Specify if you want to use a different name class name
name = None
# List in the format of [(*args, *kwargs)]
arguments = []
# Set in __init__ if you do not wish to have been "loaded" or called
loaded = True
def tick(self, cpu):
"""
Gets called at the end of every cpu tick
"""
pass
def shutdown(self):
"""
Gets called on shutdown of the emulator
"""
pass
def memory_changed(self, cpu, address, value, oldvalue):
"""
Gets called on a write to memory
"""
pass
def __init__(self, args=None):
self.name = self.__class__.__name__ if not self.name else self.name
# Assign this to your plugin class
plugin = None