-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapgen.py
41 lines (32 loc) · 1.01 KB
/
mapgen.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
from PIL import Image
from py65.devices.mpu6502 import MPU as NMOS6502
class Machine:
def __init__(self):
self._mpu = NMOS6502()
with open("resources/2-stopped-at-0x1715.ram", "rb") as fp:
self._mpu.memory[:] = fp.read()
@property
def _square(self):
return self._mpu.memory[0x95], self._mpu.memory[0x97]
@_square.setter
def _square(self, xy):
self._mpu.memory[0x95], self._mpu.memory[0x97] = xy
def background_for(self, xy, bad_pc=0xdead):
self._square = xy
start_pc = self._mpu.pc
self._mpu.stPushWord(self._mpu.pc - 1)
self._mpu.pc = 0x1715
while self._mpu.pc != start_pc:
state = self._mpu.step()
return state.a
def main():
m = Machine()
img = Image.new("L", (256, 256))
for y in range(img.height):
for x in range(img.width):
xy = x, y
img.putpixel(xy, m.background_for(xy))
img.save("out.png")
img.show()
if __name__ == "__main__":
main()