/
periphery_simple6809.py
143 lines (108 loc) · 3.87 KB
/
periphery_simple6809.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env python
# encoding:utf8
"""
DragonPy - Dragon 32 emulator in Python
=======================================
:created: 2013-2014 by Jens Diemer - www.jensdiemer.de
:copyleft: 2013-2014 by the DragonPy team, see AUTHORS for more details.
:license: GNU GPL v3 or above, see LICENSE for more details.
"""
import sys
import os
import Queue
try:
import Tkinter
except Exception, err:
print "Error importing Tkinter: %s" % err
Tkinter = None
try:
import pty # only available under Linux
import serial # Maybe not installed
except ImportError:
pass
from dragonpy.components.periphery import PeripheryBase, TkPeripheryBase, \
PeripheryUnittestBase
from dragonpy.utils.logging_utils import log
class Simple6809PeripheryBase(PeripheryBase):
def __init__(self, cfg, memory):
super(Simple6809PeripheryBase, self).__init__(cfg, memory)
self.memory.add_read_byte_callback(self.read_acia_status, 0xa000) # Control/status port of ACIA
self.memory.add_read_byte_callback(self.read_acia_data, 0xa001) # Data port of ACIA
self.memory.add_write_byte_callback(self.write_acia_status, 0xa000) # Control/status port of ACIA
self.memory.add_write_byte_callback(self.write_acia_data, 0xa001) # Data port of ACIA
def write_acia_status(self, cpu_cycles, op_address, address, value):
return 0xff
def read_acia_status(self, cpu_cycles, op_address, address):
return 0x03
def read_acia_data(self, cpu_cycles, op_address, address):
try:
char = self.user_input_queue.get(block=False)
except Queue.Empty:
return 0x0
value = ord(char)
log.info(
# log.critical(
"%04x| (%i) read from ACIA-data, send back %r $%x",
op_address, cpu_cycles, char, value
)
return value
def write_acia_data(self, cpu_cycles, op_address, address, value):
char = chr(value)
log.info("*"*79)
log.info("Write to screen: %s ($%x)" , repr(char), value)
log.info("*"*79)
if value >= 0x90: # FIXME: Why?
value -= 0x60
char = chr(value)
# log.info("convert value -= 0x30 to %s ($%x)" , repr(char), value)
if value <= 9: # FIXME: Why?
value += 0x41
char = chr(value)
# log.info("convert value += 0x41 to %s ($%x)" , repr(char), value)
self.output_queue.put(char)
class Simple6809PeripheryUnittest(PeripheryUnittestBase, Simple6809PeripheryBase):
pass
class Simple6809PeripheryTk(TkPeripheryBase, Simple6809PeripheryBase):
TITLE = "DragonPy - Simple 6809"
GEOMETRY = "+500+300"
KEYCODE_MAP = {
19: 0x03, # Break Key under windows
127: 0x03, # Break Key
}
INITAL_INPUT = "\r\n".join([
# 'PRINT "HELLO WORLD!"',
# '? 123',
'10 FOR I=1 TO 3',
'20 PRINT STR$(I)+" DRAGONPY"',
'30 NEXT I',
'RUN',
'',
'LIST',
]) + "\r\n"
def event_return(self, event):
self.user_input_queue.put("\r")
# self.user_input_queue.put("\n")
# Simple6809Periphery = Simple6809PeripherySerial
Simple6809Periphery = Simple6809PeripheryTk
Simple6809TestPeriphery = Simple6809PeripheryUnittest
def test_run():
import subprocess
cmd_args = [
sys.executable,
# "/usr/bin/pypy",
os.path.join("..", "DragonPy_CLI.py"),
# "--verbosity=5",
# "--verbosity=10", # DEBUG
# "--verbosity=20", # INFO
# "--verbosity=30", # WARNING
# "--verbosity=40", # ERROR
"--verbosity=50", # CRITICAL/FATAL
"--cfg=Simple6809",
# "--max=500000",
# "--max=20000",
# "--max=1",
]
print "Startup CLI with: %s" % " ".join(cmd_args[1:])
subprocess.Popen(cmd_args, cwd="..").wait()
if __name__ == "__main__":
test_run()