@@ -49,6 +49,8 @@ def reset(self):
49
49
self ._rxfifo = deque ()
50
50
self ._rxEnable = False
51
51
self ._txEnable = False
52
+ self ._tsrEmpty = True
53
+ self ._thrEmpty = True
52
54
self ._update_isr ()
53
55
54
56
def read_mr (self ):
@@ -59,11 +61,15 @@ def read_mr(self):
59
61
return self ._mr1
60
62
61
63
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
63
69
rxcount = len (self ._rxfifo )
64
70
if rxcount > 0 :
65
71
value |= self .STATUS_RECEIVER_READY
66
- if (rxcount > 1 ):
72
+ if (rxcount > 2 ):
67
73
value |= self .STATUS_FIFO_FULL
68
74
return value
69
75
@@ -107,21 +113,43 @@ def write_cr(self, value):
107
113
self ._update_isr ()
108
114
109
115
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 ()
111
138
112
139
def _update_isr (self ):
113
140
isr = 0
114
141
if self ._txEnable :
115
142
isr |= self .INT_TXRDY
116
143
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 ):
118
145
isr |= self .INT_RXRDY_FFULL
119
146
self ._parent .update_channel_isr (self ._port , isr )
120
147
121
148
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 ()
125
153
126
154
127
155
class MC68681 (Device ):
0 commit comments