-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathzex.py
More file actions
executable file
·106 lines (71 loc) · 1.77 KB
/
zex.py
File metadata and controls
executable file
·106 lines (71 loc) · 1.77 KB
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
#! /usr/bin/python3
# (C) 2020 by Folkert van Heusden <mail@vanheusden.com>
# released under AGPL v3.0
import sys
import time
from inspect import getframeinfo, stack
from z80 import z80
from screen_kb_dummy import screen_kb_dummy
io = [ 0 ] * 256
ram0 = [ 0 ] * 16384
ram1 = [ 0 ] * 16384
ram2 = [ 0 ] * 16384
ram3 = [ 0 ] * 16384
slots = [ ] # slots
slots.append(( ram0, None, None, None ))
slots.append(( ram1, None, None, None ))
slots.append(( ram2, None, None, None ))
slots.append(( ram3, None, None, None ))
pages = [ 0, 0, 0, 0]
def reset_mem():
ram0 = [ 0 ] * 16384
def read_mem(a):
page = a >> 14
slot = slots[page][pages[page]]
if slot == None:
return 0xee
return slot[a & 0x3fff]
def write_mem(a, v):
global subpage
page = a >> 14
slot = slots[page][pages[page]]
if slot == None:
return
slot[a & 0x3fff] = v
def read_io(a):
return io[a]
def write_io(a, v):
io[a] = v
def debug(x):
pass
dk = screen_kb_dummy(io)
dk.start()
cpu = z80(read_mem, write_mem, read_io, write_io, debug, dk)
fh = open('zexdoc.com', 'rb')
zex = [ int(b) for b in fh.read() ]
fh.close()
p = 0x0100
for b in zex:
write_mem(p, b)
p += 1
cpu.sp = 0xf000
cpu.pc = 0x0100
while True:
if cpu.pc == 0x0005:
if cpu.c == 2:
print('%c' % cpu.e, end='', flush=True)
elif cpu.c == 9:
a = cpu.m16(cpu.d, cpu.e)
str_ = ''
while True:
c = cpu.read_mem(a)
if c == ord('$'):
break
print('%c' % c, end='', flush=True)
str_ += chr(c)
a += 1
if 'Tests complete' in str_:
break
cpu._ret(True, 'bla')
continue
cpu.step()