-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnes_ppu.py
66 lines (46 loc) · 1.36 KB
/
nes_ppu.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
from bitarray import bitarray
class NesPPU():
currentX = 0
current_scan_line = 0 #y position on screen
end_of_current_frame = False
pixel_buffer = None
nmi_counter = 0
status_register = bitarray('00000000', endian='little')
vblank_flag = 0
renderer = None
#Constants to say which bit in the status register is what
VBLANK_BIT = 7
def startFrame(self):
print ('start frame')
def execute_cycles_for_instruction(self, cycles):
cycles *= 3 #for every 1 cpu cycle the ppu has 3
for i in range (0,cycles):
if self.end_of_current_frame:
#self.end_of_current_frame = False
self.startVBlank()
return
self.currentX += 1
if (self.currentX >= 341):
self.endCurrentScanLine()
self.currentX = 0
def endCurrentScanLine(self):
scanline = self.current_scan_line
if (scanline == 261):
#last line
self.current_scan_line = -1 #wrap around (gets incremeneted to 0)
self.end_of_current_frame = True
self.setVBlankFlag(1)
print ('end of frame')
self.current_scan_line += 1
def getStatusRegister(self):
status = self.status_register.tobytes()
self.setVBlankFlag(0)
return status
def setVBlankFlag(self, val):
self.status_register[self.VBLANK_BIT] = val
self.vblank_flag = val
def startVBlank(self):
self.endFrame()
def endFrame(self):
#self.renderer.drawPixelsToWindow(self.pixel_buffer)
return