★ CODING ★ PROGRAMMING THE Z80 DART ON THE AMSTRAD ★ |
Programming the Z80 DART on the Amstrad |
Introduction This File is an rewrite of my original DART.DOC file, as I have now obtained the RS data sheets for the Z80 DART. One thing this file does NOT cover is If anyone reading this disagrees with, or can expand on the information then I would be glad to hear from them so that I can make the apropriate changes to this file. Programming There are several values which are needed to set up a Z80 Dart so that it can communicate successfully. These are:
The baud rates are not directly programmed to the DART, but to a baud rate generator which then provides the DART with the correct timing signal. In this section, we are programming the baud rate generator (I will refer to BRG). There is a very large range of baud rates available (in theory 65536) and in computer to computer links via just the RS232 then as long as they both use the same value, the link should work without error. However, when talking via modems, there are only a few values which are of any use, these being 2400,1200,300, and 75 (at the moment) so we need to know the right values for these data speeds. Below is a table of data speeds,with the correct value to be programed to the BRG. How to do this will be explained shortly. Table 1
To program to speed the baud rate generator must be told two things. The port addresses are different on the CPC and PCW range. These addresses are:
[N.B. The CPC addresses are for those interfaces conforming to the official Amstrad specification - Amstrad, Pace, etc.] To set Tx rate: LD BC,WMOD |
bit pattern | Data Bits |
a b 0 0 0 1 1 0 1 1 | 5 per char 6 per char 7 per char 8 per char |
For register 3 'a' is bit 7 and 'b' bit 6, and register 5, 'a' is bit 6 and 'b' is bit 5. As all of register 3 is set at the same time (it is not possible to set certain bits at one time, then set different ones later), I will include the other two functions of this register. Bit 0 is set to enable Rx data line, and bit 5 is set to enable Automatic handshaking using RTS and CTS. All other bits are unused but MUST be set to 0.
3) Number of stop bits and 4) Parity
These are included together as they are set at the same time. Both use register 4 as shown below.The appropriate bit settings are shown below that.
bit | value | use |
7 6 5 4 3 2 1 0 | 0 1 0 0 ? ? ? ? | \ Dart Clock mode (unsure of what exactly these / do,but would recommend set as shown) \ Not used / \ Stop bits... / \ Parity...... / |
Bit values for Stop Bits are as follows:
bit 2 | bit 3 | Value |
0 1 1 0 | 1 0 1 0 | 1 Stop bit 1.5 Stop bits 2 Stop bits Illegal |
Bit values for the Parity work slightly differently.
Bit 0 is set to enable Parity Checking.
Bit 1 is set for Even Parity or reset for Odd parity.
Finally I will cover the other main functions you will require.
Reset Port
This must be done to ensure no old parameters are left in the DART when you reset the values. Simply, you need only output an &18 to register 0, as all but one other function of this register is interrupt related.
Error Reset
As you will see later, the DART generates error codes, and to reset the error bits, output &38 to register 0.
Enable Port
To enable the port, you must write the appropriate values to register 5 to pull DTR and RTS high, and enable Tx line. (Also you set the Tx bit/character at the same time). The register bit allocation is as follows:
Bit | Function |
7 6 5 4 3 2 1 0 | Enables DTR when high \ Tx bits/character,(see earlier) / Send break (not covered in text, but set high to enable) Tx enable (set high to allow transmission) Not used Enables RTS when high Not used |
Read Registers As I said previously,we are only concerned with registers 0 and 1. The easiest way to look at each is bitwise.
Register 0
Bit | Function |
7 6 5 4 3 2 1 0 | Rx character available (there is a character for input) (ignore:Interrupt related) Tx buffer empty (you can transmit a character) DCD (Carrier detect) RI (ring indicate) N/C in Amstrad RS232 [are you sure?] CTS Not used Break received |
Register 1
Bit | Function |
7 6 5 4 3 2 1 0 | All sent \ | Not used / Parity error Rx overrun error Framing error Not used |
Actual Programming of the resgisters
To send or receive a value from one of these registers, you must first tell the DART which register you wish to address. This is done by sending the register number to CONPORT. You can then read or write a value ONCE from that register. If you wish to read it again, then you must repeat the process.
For example:
and
ld a,1 ;Set A reg to 1
ld bc,conport ;Set port address
out (c),a ;Select register 1
in a,(c) ;Read contents of read register 1
*NB* The read and write registers are DIFFERENT. You cannot write a value to register 1, then read it back from register 1 as these are in fact two registers. Also, if you omit the register select, the DART will assume register 0, eg:
will write &18 to register 0.
Complete set up
Finally an example on how to set up the port for a practical purpose. The port will be set for 1275 link, 1 stop bit, no parity, no handshake, 8 data bits.
LD BC,WMOD
LD A,36H Write Tx
OUT (C),A
LD BC,SPED0
LD A,83H
OUT (C),A Set Tx
LD A,6 to 75 baud
OUT (C),A
LD BC,WMOD
LD A,76H Write Rx
OUT (C),A
LD BC,SPED1
LD A,68H
OUT (C),A Set Rx
LD A,0 to 1200 baud
OUT (C),A
I hope this information will go at least part way to allowing you to program this chip, and your RS232. When I understand the mechanisms of the interrupts used by the DART, I will update this file to include that information.
S.J.Dibble , https://CPCrulez.fr
|