BIT
0,D
TEST
JP Z,STATUS LOOP IF NOT READY
IND INPUT ONE DATA BYTE
JP NZ,STATUS LOOP IF NOT 100 BYTES
DONE RET RETURN
The OUTI instruction transfers one byte of data from a memory
location pointed to by the HL register pair to the device whose de-
vice address is in the C register. After the transfer, the contents of
the HL register pair is incremented by one and a byte count in the
R register is decremented by one. The Z flag is set if the contents of
the B register after the decrement is zero. The OUTI is very similar to
the INI except, of course, for the direction of the I/O transfer. The
following code shows the code to set up and implement the OUTI
transfer.
LD HL, BUFFER BUFFER ADDRESS
LD BC,25600+23H 100 BYTES & DEV ADD
STATUS IN D,(C) GET STATUS
BIT 0,D TEST
JP Z,STATUS LOOP IF NOT READY
OUTI OUTPUT 1 DATA BYTE
JP NZ,STATUS LOOP IF NOT 100 BYTES
DONE RET RETURN
The OTIR is an automatic output instruction analogous to the
INIR. From 1 to 256 bytes will be output from the specified block in
memory according to the byte count in the C register. The same im-
plementation as the INIR applies. If the device is slow compared to
the 190,000 byte-per-second rate of the OTIR, I/O, wait states must
be employed to match the speed of the I/O device and the CPU. A
typical output loop using the OTIR is shown next.
WRITE LD HL,BUFFER BUFFER ADDRESS
LD B,200 BYTE COUNT
LD C,30H I/O DEVICE ADDRESS
OTIR OUTPUT 200 BYTES
DONE DONE HERE
The OUTD ands OTDR are almost identical to the OUTI and
OTIR except that the data is written from the output buffer starting
at the buffer end and working back. All other actions are the same.
SOFTWARE I/O DRIVERS
The above discussion included examples of short subroutines in-
tended to read or write one character or block of characters to an
I/O device. The I/O device in question was assumed to be a rela-
225
Need help?
Do you have a question about the Z80 and is the answer not in the manual?
Questions and answers