[comp.sys.ibm.pc.misc] QUESTION ABOUT INTERRUPTS AND TIMERS

trux@atop.atop.cs.caltech.edu (Flem Snopes) (04/06/91)

Can anyone out there in netland help me?
I am using a 12Mhz IBM AT clone.
Here is my obstacle:
    I wish to program an interrupt associated with a timer that calls the
    interrupt 8000 times per second.
Here is what I have done already:
    I have used interrupt 1CH and changed the 8253 timer from the standard
    18.2 hz to 8Khz but this has an adverse side affect, it calls interrupt
    08H 8000 times per second which make my system crawl.  I dont know what
    interrupt 08H does, but if you disable it, the system locks.  Also, if
    I hook 08H instead of 1CH, I could theoretically call the original 08H
    at 18.2 hz, but the system locks all the same.  So it appears that 08H
    MUST be called every timer pulse.  
Here are my questions:
    why must 08H be called every timer pulse?  what does 08H do that takes
    so long.  Can I use another timer?  
Thank you.
Please respond to trux@atop.cs.caltech.edu because I dont read this newsgroup
very much.
--
****************************************************************
* Flem Snopes                                                  *
* Dabney 1-58       " From childhood's hour I have not been    *
* Caltech             As others were--I have not seen          *
* Pasadena, CA        As others saw--I could not bring         *
* 91126               My passions from a common spring-- "     *
* 818-564-8011                                                 *
****************************************************************

c60b-1eq@e260-1d.berkeley.edu (Noam Mendelson) (04/06/91)

In article <TRUX.91Apr5123621@atop.atop.cs.caltech.edu> trux@atop.atop.cs.caltech.edu (Flem Snopes) writes:
>Can anyone out there in netland help me?
>I am using a 12Mhz IBM AT clone.
>Here is my obstacle:
>    I wish to program an interrupt associated with a timer that calls the
>    interrupt 8000 times per second.
>Here is what I have done already:
>    I have used interrupt 1CH and changed the 8253 timer from the standard
>    18.2 hz to 8Khz but this has an adverse side affect, it calls interrupt
>    08H 8000 times per second which make my system crawl.  I dont know what
>    interrupt 08H does, but if you disable it, the system locks.  Also, if
>    I hook 08H instead of 1CH, I could theoretically call the original 08H
>    at 18.2 hz, but the system locks all the same.  So it appears that 08H
>    MUST be called every timer pulse.  
>Here are my questions:
>    why must 08H be called every timer pulse?  what does 08H do that takes
>    so long.  Can I use another timer?  

INT 08H does the following things:
	1) Increment a running count of clock ticks at 0040:006C
	2) Decrements the byte at 0040:0040, which controls the timing of
	   the diskette motor
	3) Calls interrupt 1CH

INT 08H is not very CPU-intensive but at 8,000 calls/sec, it's likely
to slow your system down considerably.
Another point: if you change the rate of the timer you _must_ create a new
INT 08H which calls the original INT 08H at the standard interval.  Your
system should not lock when you do this.  I am surprised that your
system did not lock when you changed the rate without modifying INT 08H.
Perhaps you are not doing this correctly.

+==========================================================================+
| Noam Mendelson   ..!agate!ucbvax!web!c60b-1eq | "I haven't lost my mind, |
| c60b-1eq@web.Berkeley.EDU                     |  it's backed up on tape  |
| University of California at Berkeley          |  somewhere."             |

boba@hpwarau.hp.com (Bob Alexander) (04/09/91)

>>                                                                 Also, if
>>    I hook 08H instead of 1CH, I could theoretically call the original 08H
>>    at 18.2 hz, but the system locks all the same.  So it appears that 08H
>>    MUST be called every timer pulse.  
>
>INT 08H does the following things:
>	1) Increment a running count of clock ticks at 0040:006C
>	2) Decrements the byte at 0040:0040, which controls the timing of
>	   the diskette motor
>	3) Calls interrupt 1CH

There's one more, very important thing that Int 08H does: it clears the
interrupt!  This is done by twiddling the 8259A interrupt controllers.
Sorry, but I don't know exactly how.  The bottom line is, if you are
going to set up a timer interrupt routine that doesn't always call the
standard BIOS routine, then you must clear the interrupt yourself.
Otherwise, your system will definitely hang.

I discovered this by using Turbo Debugger to disassemble the BIOS' Int 8
routine.  You can use DOS' DEBUG to do this too.  Find the Int 8 routine
via its interrupt vector and disassemble.  The code for resetting the
8259A should be in there (look for accesses to IO ports 20H and/or 21H.)
Alternatively, perhaps someone else in this group knows how to do it.

  Bob Alexander      | The more the government does,
  boba@hpwala.hp.com | the better libertarianism looks.
  -------------------+---------------------------------------------------
  Organizations don't have opinions: individuals do.  The opinions expressed
  above do not necessarily reflect those of the stockholders, employees, or
  directors of Hewlett-Packard.