-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTerminal.py
50 lines (42 loc) · 1.27 KB
/
Terminal.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
import threading
import Getch
import sys
import time
import queue
# courtesy https://stackoverflow.com/questions/510357/python-read-a-single-character-from-the-user
class Terminal(threading.Thread):
def __init__(self, p):
self.processor = p
self.charQueue = queue.Queue()
self.kbdready = False
self.dspready = True
# take an integer value as written to memory,
# passed on by the PIA6821 chip and clear its high bit,
def fromApple1(self, val):
# strip high bit
val = val & 0x7f
val = chr(val)
return val
def toApple1(self, val):
val = val.upper()
val = ord(val)
val = val | 0x80
return val
def terminalprint(self, val):
self.dspready = False
val = self.fromApple1(val)
sys.stdout.write(val)
if val == '\r':
sys.stdout.write('\n')
sys.stdout.flush()
# time.sleep(0.0166)
def run (self):
while (1):
c = Getch.getch()
self.kbdready = True
if c == chr(0x05): # ^E
self.processor.reset = True
if c == chr(0x03): # ^C
print("Exiting")
sys.exit()
self.charQueue.put_nowait(self.toApple1(c))