
014/018 01 Aug 90 10:18:00
From:   Mark Johnston
To:     Darryl Gregorash
Subj:   Re: Game ports and timers
Attr:   
------------------------------------------------
 > Does anyone have any source, or hints, on how  to
 > program  the 8253 timer,  and programming for the
 > game port?

Darryl,
     Actually,  the  timer  and  the  game  port  don't
necessarily have to be used in tandem.  Any timing loop
will suffice, although the system  timer  will  perhaps
give greater accuracy.  The accuracy depends  in  large
part  on what type of computer (PC, XT, AT) the code is
being run on, since interrupts take less time on faster
machines.

 > The  problem  is  one  of  attaching some sort of
 > controller to the game  port,    for  which  high
 > resolution  is  required  (me,  I'd  use hardware
 > specific to the  purpose,  but  this  is  someone
 > else's solution).    This  is  turn  may  require
 > reprogramming the 8253.

     I've  done  some  programming  along  these lines.
There is one problem with the IBM game port design when
it comes to high resolution work, and that is that  the
time  it  takes  to read the port varies with the value
read.  In other words, the value read is a  time  based
on the delay of a 555 IC timer circuit.
     There   are  also  some  tradeoffs  required  when
programming the 8253.  The 8253  Programmable  Interval
Timer is actually 3 timers in one.  They are located at
successive ports in the PC port map starting at 40h. In
the  PC,  timer 0 (port 40h) is attatched to the system
"clock  tick"  interrupt  8,  timer  1  (port  41h)  is
attatched to the system  refresh  timer,  and  timer  2
(port   42h)  is  available  to  be  used  as  a  sound
generation timer, if enabled.  Port 43h is the  control
word register for the 8253 chip.
     To change the rate at which any of  the  3  timers
tick,  a  value is written to the control word register
and then one or two  bytes  is  written  to  the  timer
register which you wish to program.  The value  written
to  the control word register determines how many bytes
for which timer  the  8253  expects  to  be  programmed
subsequently.   (Timer  programming  may be done in any
order independent of the order  of  the  control  words
written,  but the number of bytes written to each timer
must match  the  value  written  to  the  control  word
register.)
     The format of the control word is as follows:

     Bit   7    6    5    4   3  2  1  0

          SC1  SC0  RL1  RL0  1  0  1  0

SC1 and SC0 indicate which counter (0-2 with a value of
3  being  illegal)  you  wish to deal with, RL1 and RL0
indicate the Read/Load command you  wish  to  give,  as
follows:

     RL1  RL0

      0    0   latch value of the selected counter (for later reading)
      1    0   read/load most significant byte only
      0    1   read/load least significant byte only
      1    1   read/load both bytes -- least significant first

     The  8253  counters  are  16  bit countdown timers
which count down from a programmed value.  The timer is
strobed  at  a rate of 1.193182 times per second (1/4th
the original 4.77 Mhz frequency), and intervals may  be
counted   which  range  from  that  frequency  down  to
1/65536th of that frequency (or 18.2 Hz).  The  problem
is  that  the  faster  you  want  the  system to "tick"
(trigger int 8) the interval  which  can  be  timed  is
proportionately shortened.
     I   have   experimented   with   using  the  sound
generation timer for timing independent  of  the  clock
tick  timer,  but  have only succeeded in disabling the
keyboard by that method ... <sigh> ...

 [ to be continued ... ]


--- Qtach2 v1.02 U4
 * Origin: =# The QNX Telegraph #=  Tacoma WA  (206)535-6109 (1:138/110)

