DOS interrupt

Discussion in 'C Programming' started by Hartmut, Jan 27, 2006.

  1. Hartmut

    Hartmut Guest

    Hi guys out there...,

    I am not shure if this is the right forum for my Question.

    Have a problem using my own Keyboard interrupt handler. The handler
    works
    fine as long as i do not press keys like pause, arrow keys etc. My
    system
    returns with a stack overflow.
    Is there something i have overseen in my keyboard Interrupt Service
    Routine?
    I just want to get the key pressed and store it in a variable for
    later processing. This comprises all keys available on the keyboard.
    Can't use a while( !_bios_keybrd(_NKEYBRD_READY) ) construct, because
    this
    keeps my program in a trap. See code ready-for-compile code below...

    Sorry, that the code is written in C++ ... ;-)

    My System:
    Pentium II-MMX 233MHz
    Award BIOS v4.51PG
    Pure MS-DOS 6.2 (no MFC or WinX.X installed)
    MS C700 optimizing compiler (PWB)

    //**************************************
    #include <dos.h>
    #include <bios.h>
    #include <iostream.h>
    #include <stdlib>

    #define _DEBUG
    #define TRUE (1==1)
    #define FALSE (1==0)

    typedef int INT;
    typedef unsigned int UINT;
    typedef unsigned char BOOL;
    typedef void (__far __interrupt *KEYBOARDISR)(void);

    class EventHandler
    {
    public:
    EventHandler();
    ~EventHandler();

    public:
    static void (__far __interrupt *old_KeyboardISR)(); /* ptr. to old
    keybrd int handler */
    static void __far __interrupt KeyboardISR(void);
    BOOL KeyboardSetHandler( KEYBOARDISR pISRfunc );
    static INT iEventCounter;
    static UINT m_siKeyStroke;
    void RestoreKeyboard(void);
    };

    // initializing class members
    INT EventHandler::iEventCounter = 0;
    UINT EventHandler::m_siKeyStroke = 0;
    void (__far __interrupt *EventHandler::eek:ld_KeyboardISR)() = NULL;

    // constructor
    EventHandler::EventHandler()
    {
    KeyboardSetHandler( KeyboardISR );
    }

    EventHandler::~EventHandler()
    {
    RestoreKeyboard();
    }

    // sets keyb ISR
    BOOL EventHandler::KeyboardSetHandler( KEYBOARDISR pISRfunc )
    {
    if(pISRfunc == NULL) return(FALSE);
    EventHandler::eek:ld_KeyboardISR = _dos_getvect(0x09);
    _dos_setvect( 0x09, pISRfunc );
    return(TRUE);
    }

    // the Keyboard Interrupt Service Routine
    void __far __interrupt EventHandler::KeyboardISR()
    {
    (*EventHandler::eek:ld_KeyboardISR)(); /* call old interrupt handler */

    /****
    My intention to call the old interrupt handler is to fill the
    AX register value of INT16h with the desired keystroke.
    _bios_keybrd
    should exactly return this value, but it does not (always)...
    ****/
    EventHandler::m_siKeyStroke = (UINT)_bios_keybrd( _NKEYBRD_READ );
    EventHandler::iEventCounter++;

    #ifdef _DEBUG
    // ...ok, i know we schould not call low level I/O stuff
    // in a interrupt handler, but for debugging its ok ;-)
    cout << "Event Counter = " << EventHandler::iEventCounter
    << " Key: " << EventHandler::m_siKeyStroke << endl;
    #endif
    }

    void EventHandler::RestoreKeyboard(void)
    {
    _dos_setvect( 0x09, EventHandler::eek:ld_KeyboardISR );
    }

    int main(void)
    {
    EventHandler kbdEvent;

    while(TRUE) // ...sorry, needs a reboot
    ;

    return(0);
    }
    //**************************************
    Hartmut, Jan 27, 2006
    #1
    1. Advertising

  2. Hartmut

    Mike Wahler Guest

    Re: [OT] DOS interrupt

    "Hartmut" <> wrote in message
    news:...
    > Hi guys out there...,
    >
    > I am not shure if this is the right forum for my Question.
    >
    > Have a problem using my own Keyboard interrupt handler. The handler
    > works


    Same answer as when you posted this to 'alt.comp.lang.learn.c-c++'

    Find a newsgroup about your *platform* (your combination
    of hardware/operating system, etc). C is a *language*,
    not a platform. If you keep going from one language group
    to another, you won't get anywhere.

    -Mike
    Mike Wahler, Jan 27, 2006
    #2
    1. Advertising

  3. Hartmut <> writes:
    > Hi guys out there...,
    >
    > I am not shure if this is the right forum for my Question.


    It's not. Try comp.os.msdos.programmer.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, Jan 27, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tony
    Replies:
    0
    Views:
    1,044
  2. Ben Fairbank
    Replies:
    2
    Views:
    5,454
  3. john san
    Replies:
    19
    Views:
    740
    Diez B. Roggisch
    Feb 18, 2005
  4. tomhr
    Replies:
    27
    Views:
    1,418
    Mike Wahler
    Jan 12, 2006
  5. Robert Wallace

    my own perl "dos->unix"/"unix->dos"

    Robert Wallace, Jan 21, 2004, in forum: Perl Misc
    Replies:
    7
    Views:
    277
    Michele Dondi
    Jan 22, 2004
Loading...

Share This Page