delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/08/11/18:00:29

From: "Michel Gallant" <mgallant AT NOSPAM DOT grassroots DOT ns DOT ca>
Newsgroups: comp.os.msdos.djgpp
Subject: Detecting interrupt on printer port
Lines: 96
Message-ID: <C22A1.62$Qi3.325552@sapphire.mtt.net>
Date: Tue, 11 Aug 1998 20:44:18 GMT
NNTP-Posting-Host: 142.177.31.25
NNTP-Posting-Date: Tue, 11 Aug 1998 17:44:18 ADT
Organization: MTT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Hello,
I'm rather new to C, and I'm trying to write a program which will
detect an interrupt on the parallel port (Triggered by the ACK line).
This is just a test routine at the moment, to be later incorporated
into a larger program.  I finally got all the interrupt-handling
procedures correct, partially thanks to an example program on the
delorie.com website (which chained the 18.2 Hz timer to its own
counter routine.)  My program does the same sort of thing, execept it
resets the interrupt vector completely to its own handler subroutine.
It also sets a printer control register (bit 4 on port 890) which
apparently is needed to enable interrups on ACK (according to HELPPC,
a technical help database by David Jurgens).  However, the counter
(supposed to increment on every interrupt) stays at zero!  My code
given here is a direct adaptation of the code from the DJGPP page,
which will work fine as a timer handler if the INT# is changed from F
to 8, and the `set interrupt' command is changed to the `chain
interrupt' command.  So obviously there is no problem with the code.
Is there some problem in the DPMI interrupt services?  Does it have
something to do with my direct hardware access to port 890 to set the
control register?  Or am I just nuts?  Thanks for any help.  My code
is below.

Michel Gallant

---snip---

//Interrupt Handler test for 0x0F, printer ACK
//line interrupt, adapted from interrupt code by
//Matthew Mastracci
#include <stdio.h>
#include <pc.h>
#include <dpmi.h>
#include <go32.h>

//macros by Shawn Hargreaves from the Allegro library for locking
//functions and variables.
#define LOCK_VARIABLE(x)    _go32_dpmi_lock_data((void *)&x,
(long)sizeof(x));
#define LOCK_FUNCTION(x)    _go32_dpmi_lock_code(x,(long)sizeof(x));

//timer interrupt F is generated when ACK goes LOW (I think)
#define LPINT 15

//global counter
int counter = 0;

//the new ISR, will be called automatically on low ACK once installed

void TickHandler(void)
 {
 counter++;
 }


int main(void)
 {
 //structures to hold selector:offset info for the ISRs
 _go32_dpmi_seginfo OldISR, NewISR;

 //set printer control register bit 4
 //controls whether ACK generates interrupt
 outportb(890, inportb(890)|16);
printf("About to set the vector to the new ISR..\n");
 getkey();

 //lock the functions and variables
 LOCK_FUNCTION(TickHandler);
 LOCK_VARIABLE(counter);

 //load the address of the old printer ISR into the OldISR structure
 _go32_dpmi_get_protected_mode_interrupt_vector(LPINT, &OldISR);

 //point NewISR to the proper selector:offset for handler function
 NewISR.pm_offset = (int)TickHandler;
 NewISR.pm_selector = _go32_my_cs();

 //set up new ISR to be called on low ACK
 _go32_dpmi_set_protected_mode_interrupt_vector(LPINT,&NewISR);

 //notice no changes to counter in this loop- the interrupt
 //changes it
 while (!kbhit())
   printf("%d\n",counter);

 printf("Replacing the new ISR with the old one...\n");

 //load the old printer ISR back
 _go32_dpmi_set_protected_mode_interrupt_vector(LPINT, &OldISR);

 return 0;
}





- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019