115 
4.3  SELECTING  AN OPERATING  MODE 
Port 
A 
of 
the 
PIO may be  operated in  any 
of 
four 
distinct modes: Mode 0 
(output 
mode), Mode  1 
(input 
mode), 
Mode  2  (bidirectional 
mode)
, and Mode  3 
(control 
mode)
. 
Note 
that 
the 
mode 
number
s have  been selected  for  mne-
monic significance; i.e. 
0 
=Out
, 1 
=In
, 2 
=Bidirectional. 
Port 
B can operate in any 
of 
these modes 
except 
Mode 2. 
The mode 
of 
operation 
must 
be established 
by 
writing a 
control 
word 
to 
the PIO in 
the 
following format: 
Ds 
X  X 
mode word 
signifies mode word 
to be set 
Do 
X= 
unused bit 
Bits D
7 
and D
6 
form 
the 
binary code for the desired 
mode 
according 
to 
the 
following table: 
07 
06 
Mode 
0  0  0 
(output) 
0 
1 
1 
(input) 
0  2 (bidirectional) 
3 
(control) 
Bits D
5 
and D
4 
are ignored.  Bits D
3
-D
0 
must 
be set 
to 
1111 
to 
indicate "
Set 
Mode" . 
Selecting Mode 0  enables any data 
written 
to 
the 
port 
output 
register 
by 
the 
CPU 
to 
be 
output 
to 
the 
port 
data 
bus. The 
contents 
of 
the 
output 
register may be changed 
at 
a
ny 
time 
by 
the 
CPU simply 
by 
writing a new data word 
to 
the 
port. 
Also, 
the 
current 
contents 
of 
the 
output 
register may be  read 
back 
to 
the Z-80A-CPU at any time 
through 
execution 
of 
an 
input 
instruction. 
With Mode 
0  active, a 
dat
a write from 
the 
CPU  causes 
the 
Ready handshake line 
of 
that 
port 
to 
go 
high 
to 
notify 
the peripheral 
that 
data 
is 
available. This  signal  remains high 
until 
a  strobe 
is 
received  from 
the 
peripheral. The rising 
edge 
of 
the 
strobe generates an 
interrupt 
(if 
it has 
been 
enabled) and causes 
the 
Ready line  to 
go 
inactive. This very 
simple handshake 
is 
similar 
to 
that 
used in 
many 
peripheral devices. 
Selecting Mode 
1 puts 
the 
port 
into 
the 
input 
mode. 
To 
start handshake 
operation
, 
the 
CPU merely performs an 
input 
read  operation from 
the 
port. 
This activates 
the 
Ready 
line 
to 
the 
peripheral 
to 
signify 
that 
data should be loaded 
into 
the 
empty 
input 
register. The peripheral device 
then 
strobes data 
into 
the 
port 
input 
register using the strobe line . 
Again, 
the 
rising edge 
of 
the 
strobe causes an 
interrupt 
request 
(if 
it 
h::rs 
been 
enabled) and deactivates 
the 
Ready signal. 
Data may be strobed 
into 
the 
input 
register  regardless 
of 
the 
state 
of 
the Ready signal 
if 
care 
is 
taken 
to 
prevent a 
data 
overrun 
condition
. 
Mode 
2 
is 
a bidirectional 
data 
transfer mode which uses  all  four handshake lines. Therefore only 
Port 
A  may  be 
used  for  Mode  2  operation. Mode  2 
operation 
uses  the 
Port 
A  handshake  signals  for 
output 
control 
and 
the 
Port 
B 
handshake signals  for 
input 
control. 
Thus
, 
both 
A RDY and B 
RDY 
may be  active simultaneously. The only operation-
al 
difference 
between 
Mode  0  and 
the 
output 
portion 
of 
Mode 2 
is 
that 
data 
from 
the 
Port 
A 
output 
register 
is 
allowed 
on 
to 
the 
port 
data bus only 
when 
A STB 
is 
active in 
order 
to 
achieve bidirectional capability. 
Mode  3 
operation 
is 
intended 
for status 
and 
control applications and does 
not 
utilize 
the 
handshake signals. When 
Mode 
3 
is 
selected, 
the 
next 
control word sent 
to 
the PIO must define which 
of 
the 
port 
data bus lines are 
to 
be inputs 
and which are 
outputs. 
The format 
of 
the 
control 
word 
is 
shown below: 
Ds 
Do 
1/0s 
1/0
0