User Group News
C/C++ User Group
The October C/C++ meeting was, as usual, on the third Tuesday of the month. It began with a Random Access period, an all-comments-welcome section. There were discussions about the recently threatened Federal lawsuit against Microsoft; ActiveX insecurity; mention of the Java and Visual Basic languages; a discussion of Linux as an alternative operating system; choosing an available Linux distribution that seems best; a mention of the Gnu X-Windows system and Netscape's X-Windows based Internet browser.
Group leader Bruce Arnold then showed Ralf Brown's Interrupt List. The list is a Win95 based programmer's reference containing an amazingly detailed compendium of information regarding PC hardware and software. It is available for downloading from any Internet Simtel site for free.
Among other things, using the interrupt list can enable a programmer to interrogate hardware devices... which deftly led to Bruce's main presentation. This month's programming project was designed to interrogate a PC's serial and parallel ports and associate an address and IRQ (Interrupt ReQuest line) for each. Bruce first explained the difference between hardware and software interrupts. Then he explained the difference between interrupts and IRQs. With this knowledge in hand, he showed a C++ class that, using the information gleaned from Ralf Brown's Interrupt List, accomplished his goal.
For testing parallel ports, Bruce's program requires an attached printer or a 1 - 10 jumper. The serial test doesn't require any extra equipment. The program basically sends some data to a hardware port and then detects which IRQ responded. The source code is a real eye-opener for those who would like to learn how to strobe a PC's hardware directly.
Since Windows generally won't allow direct interaction with PC hardware, Bruce's program is DOS-only. From Win95 you must first restart your computer into MS-DOS mode before running it. The program can detect if Windows 3.x, 95, or NT is running and abort so there is no harm if you forget. IBM MicroChannel Architecture computers are not compatible with the logic of the program. For stability, Bruce recommends rebooting the computer to reinitialize the hardware after running it.
You can download the source code and the executable from the ACGNJ ftp site
See SOURCE CODE links below.
// QTEST.cpp b.arnold 10-11-1997 // // Object: Serial/Parallel IRQ Test. // ----------------------------------- // // SAMPLE OUTPUT // ------------- // Irq3 Irq4 Irq5 Irq7 Testing COM1 (03F8) // 0 50 0 0 // // Irq3 Irq4 Irq5 Irq7 Testing COM2 (02F8) // 50 0 0 0 // // Irq3 Irq4 Irq5 Irq7 Testing LPT1 (0378) // 0 0 0 50 #define IRQCOUNTERS 20 void interrupt (far * old_irq[IRQCOUNTERS])(...); unsigned int Count[IRQCOUNTERS] = { 0 }; void interrupt Handler0 (...) {++Count[ 0]; outp(0x20,0x20);} void interrupt Handler1 (...) {++Count[ 1]; outp(0x20,0x20);} void interrupt Handler2 (...) {++Count[ 2]; outp(0x20,0x20);} void interrupt Handler3 (...) {++Count[ 3]; outp(0x20,0x20);} void interrupt Handler4 (...) {++Count[ 4]; outp(0x20,0x20);} void interrupt Handler5 (...) {++Count[ 5]; outp(0x20,0x20);} void interrupt Handler6 (...) {++Count[ 6]; outp(0x20,0x20);} void interrupt Handler7 (...) {++Count[ 7]; outp(0x20,0x20);} void interrupt (far * new_irq[20])(...) = { Handler0,Handler1,Handler2,Handler3,Handler4,Handler5, Handler6,Handler7}; // ---------- CLASS DEFINITIONS ----------------- #define DTR 1 #define RTS 2 class TIrqHandler //� define custom C++ CLASS � { private: int index, irq; public: TIrqHandler(int arg, int pos); void TIrqHandler::Activity(void); ~TIrqHandler(void); }; TIrqHandler::TIrqHandler(int arg, int pos) { irq = arg; index = pos; old_irq[index] = getvect(irq+8); // save old and setup new handler setvect(irq+8, new_irq[index]); } TIrqHandler::~TIrqHandler(void) { setvect(irq+8, old_irq[index]); // return vectors } void TIrqHandler::Activity(void) { printf(" %5u",Count[index]); } ...................