-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnes.py
99 lines (82 loc) · 2.67 KB
/
nes.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
from cpu import CPU
from rom import Rom
from ppu import PPU
from papu import PAPU
from input import Keyboard
from threading import Thread
class Nes:
#class ExecutionThread(Thread):
# def __init__(self, nes):
# self.nes = nes
# Thread.__init__(self)
#
# def run(self):
# print "Execution thread started."
# while self.nes.isRunning:
# self.nes.cpu.emulate()
class Options:
CPU_FREQ_NTSC= 1789772.5 #1789772.72727272d
CPU_FREQ_PAL= 1773447.4
def __init__(self):
self.preferredFrameRate= 60,
self.fpsInterval= 500 # Time between updating FPS in ms
self.showDisplay= True
self.emulateSound= False
self.sampleRate= 44100 # Sound sample rate in hz
def __init__(self):
self.cpu = CPU(self)
self.ppu = PPU(self)
self.papu = PAPU(self)
self.keyboard = Keyboard(self)
self.rom = None
self.romFile = None
self.mmap = None
self.isRunning = False
self.limitFrames = True
self.fpsFrameCount = 0
self.opts = Nes.Options()
self.frameTime = self.opts.preferredFrameRate
#self.executionThread = Nes.ExecutionThread(self)
def reset(self):
if self.mmap:
self.mmap.reset()
self.cpu.reset()
self.ppu.reset()
self.papu.reset()
def start(self):
if (self.rom and self.rom.valid):
if (not self.isRunning):
self.isRunning = True;
self.ppu.startFrame()
#self.executionThread.start()
else:
print "There is no ROM loaded, or it is invalid."
def printFps(self):
pass
def stop(self):
self.isRunning = False
def reloadRom(self):
if self.romFile:
self.loadRom(self.romFile)
def loadRom(self, file):
if self.isRunning:
self.stop()
print "Loading rom {0}...".format(file)
# Load ROM file
self.rom = Rom(self)
self.rom.load(file)
if self.rom.valid:
print "Rom loaded."
self.reset()
print "Creating rom mapper..."
self.mmap = self.rom.createMapper()
if not self.mmap:
return
self.mmap.loadROM()
# TODO:
self.ppu.setMirroring(self.rom.getMirroringType())
self.romFile = file
print "Initialized NES, ready to start."
else:
print "Invalid ROM: {0}".format(file)
return self.rom.valid