Skip to content

Commit ec85cd2

Browse files
author
none
committed
mc68681: More careful emulation of the transmit FIFO
discard bytes received while the receiver is off.
1 parent 4526857 commit ec85cd2

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
trace.out
2+
profile.out
23
*.pyc
34
*.bin
45
*.elf

devices/MC68681.py

+35-7
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ def reset(self):
4949
self._rxfifo = deque()
5050
self._rxEnable = False
5151
self._txEnable = False
52+
self._tsrEmpty = True
53+
self._thrEmpty = True
5254
self._update_isr()
5355

5456
def read_mr(self):
@@ -59,11 +61,15 @@ def read_mr(self):
5961
return self._mr1
6062

6163
def read_sr(self):
62-
value = self.STATUS_TRANSMITTER_EMPTY | self.STATUS_TRANSMITTER_READY
64+
value = 0
65+
if self._tsrEmpty:
66+
value |= self.STATUS_TRANSMITTER_EMPTY
67+
if self._thrEmpty:
68+
value |= self.STATUS_TRANSMITTER_READY
6369
rxcount = len(self._rxfifo)
6470
if rxcount > 0:
6571
value |= self.STATUS_RECEIVER_READY
66-
if (rxcount > 1):
72+
if (rxcount > 2):
6773
value |= self.STATUS_FIFO_FULL
6874
return value
6975

@@ -107,21 +113,43 @@ def write_cr(self, value):
107113
self._update_isr()
108114

109115
def write_tb(self, value):
110-
self._parent.console_handle_output(chr(value).encode('latin-1'))
116+
if self._is_console:
117+
self._parent.console_handle_output(chr(value).encode('latin-1'))
118+
if self._tsrEmpty:
119+
# send straight to shift register
120+
self._tx_start()
121+
else:
122+
# buffer in holding register
123+
self._thrEmpty = False
124+
125+
def _tx_start(self):
126+
# start "transmitting" a byte
127+
self._tsrEmpty = False
128+
# 38400bps = ~200µs / byte = ~2000 8MHz CPU cycles
129+
self._parent.callback_after(2000, f'tsr{self._port}', self._tx_done)
130+
131+
def _tx_done(self):
132+
# byte "transmission" completed
133+
self._tsrEmpty = True
134+
# next byte in holding register, start "transmitting" it
135+
if not self._thrEmpty:
136+
self._thrEmpty = True
137+
self._tx_start()
111138

112139
def _update_isr(self):
113140
isr = 0
114141
if self._txEnable:
115142
isr |= self.INT_TXRDY
116143
if self._rxEnable:
117-
if len(self._rxfifo) > (1 if self._mr1 & self.MR1_FFULL_EN else 0):
144+
if len(self._rxfifo) > (2 if self._mr1 & self.MR1_FFULL_EN else 0):
118145
isr |= self.INT_RXRDY_FFULL
119146
self._parent.update_channel_isr(self._port, isr)
120147

121148
def _handle_console_input(self, input):
122-
for c in input:
123-
self._rxfifo.append(c)
124-
self._update_isr()
149+
if self._rxEnable:
150+
for c in input:
151+
self._rxfifo.append(c)
152+
self._update_isr()
125153

126154

127155
class MC68681(Device):

0 commit comments

Comments
 (0)