<s>
The	O
6526/8520	O
Complex	O
Interface	O
Adapter	O
(	O
CIA	O
)	O
was	O
an	O
integrated	O
circuit	O
made	O
by	O
MOS	B-Architecture
Technology	I-Architecture
.	O
</s>
<s>
It	O
served	O
as	O
an	O
I/O	B-Architecture
port	I-Architecture
controller	O
for	O
the	O
6502	B-General_Concept
family	O
of	O
microprocessors	O
,	O
providing	O
for	O
parallel	O
and	O
serial	B-Protocol
I/O	I-Protocol
capabilities	O
as	O
well	O
as	O
timers	B-Device
and	O
a	O
Time-of-Day	O
(	O
TOD	O
)	O
clock	O
.	O
</s>
<s>
The	O
Commodore	B-Device
1570	I-Device
and	O
Commodore	B-Device
1571	I-Device
floppy	O
disk	O
drives	O
contained	O
one	O
CIA	O
each	O
.	O
</s>
<s>
Furthermore	O
,	O
the	O
Amiga	B-Device
home	O
computers	O
and	O
the	O
Commodore	O
1581	O
floppy	O
disk	O
drive	O
employed	O
a	O
modified	O
variant	O
of	O
the	O
CIA	O
circuit	O
called	O
8520	B-Device
.	O
</s>
<s>
8520	B-Device
is	O
functionally	O
equivalent	O
to	O
the	O
6526	B-Device
except	O
for	O
the	O
simplified	O
TOD	O
circuitry	O
.	O
</s>
<s>
Predecessor	O
to	O
CIA	O
was	O
PIA	B-General_Concept
.	O
</s>
<s>
The	O
CIA	O
had	O
two	O
8-bit	O
bidirectional	O
parallel	O
I/O	B-Architecture
ports	I-Architecture
.	O
</s>
<s>
An	O
internal	O
bidirectional	O
8-bit	O
shift	B-General_Concept
register	I-General_Concept
enabled	O
the	O
CIA	O
to	O
handle	O
serial	B-Protocol
I/O	I-Protocol
.	O
</s>
<s>
The	O
chip	O
could	O
accept	O
serial	B-Protocol
input	O
clocked	O
from	O
an	O
external	O
source	O
,	O
and	O
could	O
send	O
serial	B-Protocol
output	O
clocked	O
with	O
one	O
of	O
the	O
built-in	O
programmable	O
timers	B-Device
.	O
</s>
<s>
An	O
interrupt	B-Application
was	O
generated	O
whenever	O
an	O
8-bit	O
serial	O
transfer	O
had	O
completed	O
.	O
</s>
<s>
It	O
was	O
possible	O
to	O
implement	O
a	O
simple	O
"	O
network	B-Architecture
"	O
by	O
connecting	O
the	O
shift	B-General_Concept
register	I-General_Concept
and	O
clock	O
outputs	O
of	O
several	O
computers	O
together	O
.	O
</s>
<s>
The	O
CIA	O
incorporates	O
a	O
fix	O
to	O
a	O
bug	O
in	O
the	O
serial-shift	O
register	O
in	O
the	O
earlier	O
6522	B-Device
VIA	I-Device
.	O
</s>
<s>
The	O
CIA	O
was	O
originally	O
intended	O
to	O
allow	O
fast	O
communication	O
with	O
a	O
disk	O
drive	O
,	O
but	O
in	O
the	O
end	O
could	O
n't	O
be	O
used	O
because	O
of	O
a	O
desire	O
to	O
keep	O
disk	O
drive	O
compatibility	O
with	O
the	O
VIC-20	B-Device
;	O
in	O
practice	O
the	O
firmware	O
of	O
1541	B-Device
drive	O
had	O
to	O
be	O
made	O
even	O
slower	O
than	O
its	O
VIC-20	B-Device
predecessor	O
to	O
workaround	B-Application
a	O
behaviour	O
of	O
the	O
C64	O
's	O
video	O
processor	O
,	O
that	O
,	O
when	O
drawing	O
the	O
screen	O
,	O
turned	O
off	O
the	O
CPU	B-General_Concept
for	O
40	O
microseconds	O
every	O
512	O
microseconds	O
and	O
in	O
that	O
timeslice	O
ca	O
n't	O
listen	O
to	O
the	O
bus	O
,	O
risking	O
to	O
miss	O
some	O
bit	O
.	O
</s>
<s>
Two	O
programmable	B-Device
interval	I-Device
timers	I-Device
were	O
available	O
,	O
each	O
with	O
sub-microsecond	O
precision	O
.	O
</s>
<s>
Each	O
timer	O
consisted	O
of	O
a	O
16-bit	B-Device
read-only	B-Device
presettable	O
down	O
counter	O
and	O
a	O
corresponding	O
16-bit	B-Device
write-only	B-General_Concept
latch	B-General_Concept
.	O
</s>
<s>
Whenever	O
a	O
timer	O
was	O
started	O
,	O
the	O
timer	O
's	O
latch	B-General_Concept
was	O
automatically	O
copied	O
into	O
its	O
counter	O
,	O
and	O
the	O
counter	O
would	O
then	O
decrement	O
with	O
each	O
clock	O
cycle	O
until	O
underflow	O
,	O
at	O
which	O
an	O
interrupt	B-Application
would	O
be	O
generated	O
if	O
the	O
CIA	O
was	O
configured	O
to	O
do	O
so	O
.	O
</s>
<s>
The	O
timer	O
could	O
run	O
in	O
either	O
"	O
one-shot	O
"	O
mode	O
,	O
halting	O
after	O
underflowing	O
,	O
or	O
"	O
continuous	O
"	O
mode	O
,	O
reloading	O
the	O
latch	B-General_Concept
value	O
and	O
starting	O
the	O
timer	O
cycle	O
anew	O
.	O
</s>
<s>
In	O
addition	O
to	O
generating	O
interrupts	B-Application
,	O
the	O
timer	O
output	O
could	O
also	O
be	O
gated	O
to	O
the	O
second	O
I/O	B-Architecture
port	I-Architecture
.	O
</s>
<s>
As	O
configured	O
in	O
the	O
Commodore	O
64	O
and	O
Commodore	B-Device
128	I-Device
,	O
the	O
CIA	O
's	O
timing	O
was	O
controlled	O
by	O
the	O
Ø2	O
system	O
clock	O
,	O
nominally	O
one	O
MHz	O
.	O
</s>
<s>
This	O
meant	O
that	O
the	O
timers	B-Device
decremented	O
at	O
approximately	O
one	O
microsecond	O
intervals	O
,	O
the	O
exact	O
time	O
period	O
being	O
determined	O
by	O
whether	O
the	O
system	O
used	O
the	O
NTSC	O
or	O
PAL	B-Language
video	O
standard	O
.	O
</s>
<s>
If	O
both	O
timers	B-Device
were	O
loaded	O
with	O
the	O
maximum	O
interval	O
value	O
of	O
65	O
,	O
535	O
,	O
a	O
timing	O
interval	O
of	O
one	O
hour	O
,	O
11	O
minutes	O
,	O
34	O
seconds	O
would	O
result	O
.	O
</s>
<s>
A	O
real-time	O
clock	O
is	O
incorporated	O
in	O
the	O
CIA	O
,	O
providing	O
a	O
timekeeping	O
device	O
more	O
conducive	O
to	O
human	O
needs	O
than	O
the	O
microsecond	O
precision	O
of	O
the	O
interval	O
timers	B-Device
.	O
</s>
<s>
Owing	O
to	O
the	O
order	O
in	O
which	O
the	O
registers	O
appear	O
in	O
the	O
system	O
's	O
memory	B-General_Concept
map	I-General_Concept
,	O
a	O
simple	O
loop	O
is	O
all	O
that	O
is	O
required	O
to	O
write	O
the	O
registers	O
in	O
the	O
correct	O
order	O
.	O
</s>
<s>
In	O
addition	O
to	O
its	O
timekeeping	O
features	O
,	O
the	O
TOD	O
can	O
be	O
configured	O
to	O
act	O
as	O
an	O
alarm	O
clock	O
,	O
by	O
arranging	O
for	O
it	O
to	O
generate	O
an	O
interrupt	B-General_Concept
request	I-General_Concept
at	O
any	O
desired	O
time	O
.	O
</s>
<s>
Due	O
to	O
a	O
bug	O
in	O
many	O
6526s	B-Device
(	O
see	O
also	O
errata	O
below	O
)	O
,	O
the	O
alarm	O
IRQ	B-General_Concept
would	O
not	O
always	O
occur	O
when	O
the	O
seconds	O
component	O
of	O
the	O
alarm	O
time	O
is	O
exactly	O
zero	O
.	O
</s>
<s>
The	O
workaround	B-Application
is	O
to	O
set	O
the	O
alarm	O
's	O
tenths	O
value	O
to	O
0.1	O
seconds	O
.	O
</s>
<s>
The	O
ability	O
to	O
work	O
with	O
both	O
power	O
line	O
frequencies	O
allowed	O
a	O
single	O
version	O
of	O
the	O
6526	B-Device
to	O
be	O
used	O
in	O
computers	O
operated	O
in	O
countries	O
with	O
either	O
50	O
or	O
60Hz	O
power	O
.	O
</s>
<s>
It	O
is	O
important	O
to	O
note	O
that	O
contrary	O
to	O
the	O
popular	O
belief	O
,	O
NTSC	O
or	O
PAL	B-Language
video	O
standards	O
are	O
not	O
directly	O
linked	O
to	O
mains	O
power	O
frequency	O
.	O
</s>
<s>
For	O
example	O
,	O
both	O
NTSC	O
and	O
PAL	B-Language
variants	O
of	O
Commodore	O
SX-64	O
use	O
60Hz	O
TOD	O
clock	O
supplied	O
by	O
a	O
dedicated	O
crystal	O
.	O
</s>
<s>
KERNAL	B-Operating_System
operating	O
system	O
in	O
Commodore	O
64	O
for	O
example	O
will	O
determine	O
the	O
video	O
standard	O
during	O
system	O
startup	O
,	O
but	O
tries	O
neither	O
to	O
identify	O
the	O
supplied	O
TOD	O
clock	O
frequency	O
nor	O
to	O
initialise	O
the	O
CIAs	O
correctly	O
on	O
50Hz	O
driven	O
machines	O
.	O
</s>
<s>
The	O
8520	B-Device
revision	O
of	O
the	O
CIA	O
,	O
as	O
used	O
in	O
the	O
Amiga	B-Device
and	O
the	O
Commodore	O
1581	O
disk	O
drive	O
,	O
modified	O
the	O
time-of-day	O
clock	O
to	O
be	O
a	O
24-bit	O
binary	O
counter	O
,	O
replacing	O
the	O
BCD	O
format	O
of	O
the	O
6526	B-Device
.	O
</s>
<s>
The	O
CIA	O
was	O
available	O
in	O
1	O
MHz	O
(	O
6526	B-Device
)	O
,	O
2MHz	O
(	O
6526A	O
)	O
and	O
3MHz	O
(	O
6526B	O
)	O
versions	O
.	O
</s>
<s>
The	O
package	O
was	O
a	O
JEDEC-standard	O
40-pin	O
ceramic	O
or	O
plastic	O
DIP	B-Algorithm
.	O
</s>
<s>
The	O
8520	B-Device
CIA	O
,	O
with	O
its	O
modified	O
time-of-day	O
clock	O
,	O
was	O
used	O
in	O
the	O
Amiga	B-Device
computers	I-Device
.	O
</s>
<s>
Commodore	O
embedded	O
reduced	O
(	O
just	O
4	O
registers	O
)	O
CIA-like	O
logic	O
for	O
the	O
cost	O
reduced	O
Commodore	B-Device
1571	I-Device
inside	O
the	O
C128DCR	O
(	O
See	O
Commodore	B-Device
128	I-Device
)	O
in	O
a	O
gate	O
array	O
called	O
5710	O
which	O
also	O
contains	O
other	O
functions	O
.	O
</s>
<s>
The	O
5710	O
CIA	O
has	O
the	O
serial	B-Protocol
clock	O
for	O
the	O
fast	O
serial	B-Protocol
interface	O
hardwired	O
to	O
a	O
CIA6526	O
equivalent	O
Timer	O
A	O
value	O
of	O
5	O
,	O
leading	O
to	O
a	O
per-bit	O
time	O
of	O
5μs	O
on	O
transmission	O
.	O
</s>
<s>
This	O
is	O
different	O
from	O
what	O
used	O
to	O
be	O
a	O
Timer	O
A	O
value	O
of	O
6	O
in	O
the	O
6526	B-Device
CIA	O
in	O
the	O
original	O
Commodore	B-Device
1571	I-Device
.	O
</s>
<s>
It	O
only	O
contains	O
two	O
port	O
registers	O
and	O
the	O
register	O
to	O
control	O
the	O
serial	B-Protocol
shifter	O
and	O
its	O
event	O
.	O
</s>
<s>
In	O
addition	O
to	O
the	O
aforementioned	O
alarm	O
clock	O
interrupt	B-Application
bug	O
,	O
many	O
CIAs	O
exhibited	O
a	O
defect	O
in	O
which	O
the	O
part	O
would	O
fail	O
to	O
generate	O
a	O
timer	O
B	O
hardware	O
interrupt	B-Application
if	O
the	O
interrupt	B-General_Concept
control	I-General_Concept
register	I-General_Concept
(	O
ICR	O
)	O
was	O
read	O
one	O
or	O
two	O
clock	O
cycles	O
before	O
the	O
time	O
when	O
the	O
interrupt	B-Application
should	O
have	O
actually	O
occurred	O
.	O
</s>
<s>
This	O
defect	O
,	O
as	O
well	O
as	O
logic	O
errors	O
in	O
the	O
Commodore	O
provided	O
(	O
8	O
bit	O
)	O
operating	O
system	O
,	O
caused	O
frequent	O
pseudo-RS-232	O
errors	O
in	O
the	O
Commodore	O
64	O
and	O
Commodore	B-Device
128	I-Device
computers	O
when	O
running	O
at	O
higher	O
baud	O
rates	O
.	O
</s>
