So after much testing I am just about ready to sign off on V 1.0 of the firmware. Aside from writing this project up, it is basically done now.
I've programmed this device with four different selectable serial modes and 8 baud rates.
DIP switch positions 1, 2 and 3 set the baud rate from 1200 baud to 115200 baud.
DIP switch positions 5 and 6 select the mode. The modes are:
0. Basic line printer. Send only.
1. Receive only
2. Receive only with hardware flow control
3. Basic Terminal. Send and receive
Mode 0 is for BASIC Line Printer commands LPRINT and LLIST. This mode is intended for "printing" to a terminal program capable of capturing the output. DIP switch position 4 turns on/off the auto-insertion of LF after CR. This function only applies to Mode 0. Mode 0 doesn't require any driver software. Data bit 7 of port 0x37E8 on the read side is the BUSY bit. This bit is used by the UART firmware for flow-control when inserting a LF. Alternatively, any data value POKE'd or other wise written to port 0x37E8 when in this mode will be transmitted by the UART.
Mode 1 allows the TRS-80 to receive 8-bit data bytes over RS-232. A system interrupt is used to signal to the TRS-80 that a received data byte ready to be read at port 0x37E8. Individual data bytes must not be sent at intervals quicker than what the TRS-80 can read them in from port 0x37E8.
Mode 2 is Mode 1 with the addition of hardware flow control. This is controlled by the UART's RTS output which connects to the CTS input of the sender. Hardware flow control is more efficient than inserting delays between sent characters at high baud rates. In this mode, after the TRS-80 has read in a received byte at 0x37E8, it has to signal to the UART that it is ready to receive the next byte by writing any data value back to 0x37E8. This data value is not read and is not sent. The write strobe is simply used to signal the UART to request the next character from the sender.
With RTS/CTS flow control enabled in your PC terminal program, whole files can be transferred to the TRS-80 in this mode at any of the selectable baud rates.
Mode 3 is a very basic terminal communications mode without flow control. It emulates mode 1 on the receive side and prioritises data reception over transmission. Any attempt to send a byte by writing to port 0x37E8 will be ignored if the UART is busy receiving incoming data. On the transmit side, this mode is not compatible with the line printer commands LPRINT and LLIST. This is because port 0x37E8, on the read side, is now fully utilised for the transfer of received data and cannot faux line printer status.
Mode 3 doesn't require any driver software on the write side. Any data value POKE'd or otherwise written to port 0x37E8 will be spat out of the UART at the selected baud rate, provided that the UART isn't busy copying incoming characters as already mentioned.
The device configures itself as per the DIP switch settings immediately after power-on and reports the configuration status at the selected baud rate:
The UART master reset input is connected to the TRS-80's !SYSRES line, so pressing the NMI reset button on the TRS-80 will cause the UART to reconfigure itself to any change made to the DIP switch settings.