11

On the ZX Spectrum, you get an interrupt every frame. As I recall, the operating system uses this to periodically scan the keyboard and probably other things also, but you can have your own routine called instead/in addition.

On the Commodore 64, you can somehow program the video chip to produce an interrupt on whichever scanline you choose, and this can somehow be directed to whatever the programmer chooses.

I would like to know if this kind of facility is available on MS-DOS computers. If I write a program for MS-DOS, is there a way to command that the next time the interrupt fires, jump to this routine? Or is there a way to command that in 153 milliseconds, jump to that address?

9
  • For EGA and VGA graphics adapters, you can get a vertical retrace interrupt (but not an interrupt on every scanline or horizontal retrace). For CGA, you can't get an interrupt at all, but you need to poll the status register for vertical retrace. All actions that depend in timing on the beam position need to do cycle counting, or use the timer chip (which can generate interrupts).
    – dirkt
    Commented Aug 31, 2016 at 21:11
  • 1
    By the timer chip, do you mean the same 8254 which Stephen Kitt talks about below? Commented Aug 31, 2016 at 21:13
  • 1
    I think @dirkt is referring to the same timer chip. See the PC Demos FAQ for an example of vertical retrace "interrupt" — vertical retrace doesn't actually produce an interrupt that you can use on the PC, but it updates certain registers reliably, so you can use a timer interrupt to get close and then wait in a polling loop. Commented Sep 1, 2016 at 8:35
  • 3
    @StephenKitt: Yes, same timer chip. Though I think demos like 8088 MPH tend to use cycle counting (and tools to make that easier). And EGA and VGA cards (at least some) actually do produce an interrupt, namely IRQ 2, enable bit 5 in 3d4h index 11h, see e.g. here. Of course even with this IRQ disabled, you can always poll.
    – dirkt
    Commented Sep 1, 2016 at 9:39
  • @dirkt, nice, I'd forgotten about IRQ2! 8088 MPH needs to use cycle counting because it runs on CGA anyway. IIRC 8088 Corruption or 8088 Domination used the Sound Blaster's interrupts for timing... I need to watch the explanation video again! Commented Sep 1, 2016 at 9:44

1 Answer 1

12

The 8254 system timer calls interrupt 08 at regular intervals (18.2 times per second by default), and the latter calls interrupt 1C which is the one you should hook into. You hook into this in the standard DOS way: store the current address at vector 1C, place your routine's address there, and make sure you chain to the previous address from your routine. You need to ensure your routine stays in memory as long as it's vectored in — so you need to either restore the previous vector when your program exits, or terminate and stay resident.

It's possible to program the 8254 to fire the interrupt at other frequencies, but you then need to perform the necessary calculations and chain the interrupts yourself (so that the chain is called 18.2 times per second).

As far as I'm aware there's no built-in way to program a call to a given routine in a certain amount of time, at least not with the kind of resolution you're asking for (some BIOSs support RTC alarms). The usual approach would be to hook into the timer interrupt for that too — for 153ms, you'd wait three ticks...

4
  • 1
    Is the 8254 available on modern computers also? If I just install FreeDOS or something on my relatively recent laptop or whatever, can I use it. Commented Sep 1, 2016 at 19:09
  • 3
    Any PC that can still boot DOS (which is still most of them, I think) will have a 8254 or a simulation thereof (typically in the SuperIO chip). Commented Sep 1, 2016 at 20:52
  • 1
    On modern computers with a modern graphic card/chipset, that graphic card will likely have more advanced features you can use (like a register to give you the current scanline), and while it still may be mostly compatible with older cards (e.g. VGA), some tricks may not work. It would help if you'd describe what exactly are you trying to accomplish, and on what hardware.
    – dirkt
    Commented Sep 2, 2016 at 10:11
  • heh I used to change the PIT i8254 frequency to speed up old MS-DOS games like Tunneler on 80286 based computers. It was fun ... especially for multi player games. Timing in MS-DOS was achieved either by PIT or scanning CMOS clock. For higher resolution RDTSC polling was used but that was available only from x586+. Another possibility is check EGA/VGA/CGA VS/HS sync
    – Spektre
    Commented Jan 3, 2018 at 8:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .