~vdupras/collapseos

0f834511932e62724feaaf073e121608eac6c13b — Virgil Dupras 3 years ago 772c0c4
trs80: Improve RS-232 driver

I could drive my RC2014 from my TRS-80 4P (using the Remote Shell
coming in the next commit)! A challenge I faced was that the RC2014
spits characters too fast and the CTS line of its ACIA modules
(both the 6850 and SIO/2 ones) are hard-wired to ground, making
flow control difficult. I solved this, for now, by lowering comm
speed.

This driver improvement makes CL<? faster and makes baud rate
configurable in CL$.
3 files changed, 35 insertions(+), 6 deletions(-)

M arch/z80/trs80/blk.fs
M doc/hw/acia.txt
M doc/hw/z80/trs80.txt
M arch/z80/trs80/blk.fs => arch/z80/trs80/blk.fs +13 -4
@@ 9,7 9,7 @@ Load with "602 LOAD".

There is also the RECV program at B612.
( ----- 602 )
1 8 LOADR+
1 9 LOADR+
( ----- 603 )
CODE (key?) ( -- c? f )
    A 0x08 LDri, ( @KBD )


@@ 100,10 100,19 @@ EXX, ( unprotect BC ) ;CODE
: FD! ['] @WRSEC SWAP FD@! ;
: FD$ ['] FD@ ['] BLK@* **! ['] FD! ['] BLK!* **! ;

: CL$ 0x02 0xe8 PC! ( UART RST ) 0xee 0xe9 PC! ( 9600 bauds )
    0b01101100 0xea PC! ( word8 no parity RTS ) ;
( ----- 611 )
: CL$ ( baudcode -- )
0x02 0xe8 PC! ( UART RST ) DUP 4 LSHIFT OR 0xe9 PC! ( bauds )
    0b01101101 0xea PC! ( word8 no parity no-RTS ) ;
: CL> BEGIN 0xea PC@ 0x40 AND UNTIL 0xeb PC! ;
: CL< BEGIN 0xea PC@ 0x80 AND UNTIL 0xeb PC@ ;
CODE _
    0xea INAi, 0x80 ANDi, IFZ, PUSH0, ELSE,
    0xeb INAi, PUSHA, PUSH1, THEN,
;CODE
: CL<? _ IF 1 EXIT THEN
    0b01101100 0xea PC! ( RTS )
    1 TICKS ( 100 us ) _
    0b01101101 0xea PC! ( no-RTS ) ;
( ----- 612 )
( We process the 0x20 exception by pre-putting a mask in the
  (HL) we're going to write to. If it wasn't a 0x20, we put a

M doc/hw/acia.txt => doc/hw/acia.txt +13 -0
@@ 28,3 28,16 @@ can be raised) very much. We have to take extra care, when
communicating from modern system, not to send too much data too
fast. But for COS-to-COS communication, this simple system
works.

# Broken hardware

Some designs are broken with this scheme. For example, the
RS2014 SIO module hard-wires CTS to GND because the FTDI
connector doesn't have such a pin (modern computers can always
handle the load).

In these cases, a solution would be to use Break signals as a
workaround, but I prefer avoiding complexity for now. So when
you deal with broken design, you'll have to sidestep it either
by implementing your own Break handling or by lowering com-
munication speed.

M doc/hw/z80/trs80.txt => doc/hw/z80/trs80.txt +9 -2
@@ 270,8 270,15 @@ means there's a limit of 100 blocks per disk.
You'll need to send those blocks through RS-232. First, let's
initialize the driver with CL$. This driver does not require
the TRS-DOS driver to be loaded. Also, it is hardcoded to
"no parity, 8 bit words, 9600 bauds". Now, let's have the CL
take over the prompt:
"no parity, 8 bit words". And takes a "baud code" as an argu-
ment. It's a 0-15 value with these meanings:

00 50          01 75           02 110          03 134.5 
04 150         05 300          06 600          07 1200 
08 1800        09 2000         0a 2400         0b 3800 
0c 4800        0d 7200         0e 9600         0f 19200

After CL$ is called, let's have the CL take over the prompt:

    ' CL> ' EMIT **!
    ' CL< ' KEY **!