Mail Archives: djgpp/1996/06/03/11:10:04
Hi all,
I have a rather complex command line oriented program (similar to gdb)
which uses stdin and stdout to get and show information.
What I want to do is to write my own wrapper program which grabs
stdin and stdout and presents a nicer user interface to the world, but talk
to the low level app through these grabbed input and output.
I started by writing a simple program to see if this is possible (see below).
What it should do is grab the keyboard BIOS interrupt (0x16) and reply
with a carrage return whenever a keypress is asked for.
What seems to happen is that the program gets as far as getchar() and then
waits for ever.
I have also tried replacing the stdinInterrupt with
void stdinInterrupt(_go32_dpmi_registers *r)
{
r->x.ip = OldStdinVector.rm_offset;
r->x.cs = OldStdinVector.rm_segment;
_go32_dpmi_simulate_fcall_iret(r);
}
With the same hanging problem.
Does anyone have any idea what I am doing wrong?
Has anyone done anything similar in the past - any source code?
Thanks for any help
Steve.
/************ start of source code **************/
#include <conio.h>
#include <stdio.h>
#include <go32.h>
#include <dpmi.h>
#include <string.h>
static _go32_dpmi_seginfo NewStdinVector;
static _go32_dpmi_seginfo OldStdinVector;
static _go32_dpmi_registers StdinRegs;
int count = 0;
void stdinInterrupt(_go32_dpmi_registers *r)
{
switch(r->h.ah)
{
case 0: /* get char (blocking) */
r->h.ah = 0x1C; /* scan code */
r->h.al = 0x0D; /* ascii code */
r->x.flags = 0; /* ZF = 0 means char ready (probably not needed) */
break;
case 1: /* report whether character ready */
r->x.flags = 0; /* ZF = 0 means char ready */
break;
case 2: /* get shift status */
r->h.al = 0; /* holds shift state */
break;
}
}
#define INTVECTOR 0x16
void stdinInit()
{
/* Get the bios keyboard services interrupt vector. */
_go32_dpmi_get_real_mode_interrupt_vector(INTVECTOR,&OldStdinVector);
NewStdinVector.pm_offset = (int) stdinInterrupt;
_go32_dpmi_allocate_real_mode_callback_iret(&NewStdinVector,&StdinRegs);
_go32_dpmi_set_real_mode_interrupt_vector(INTVECTOR,&NewStdinVector);
}
void stdinExit()
{
_go32_dpmi_set_real_mode_interrupt_vector(INTVECTOR,&OldStdinVector);
_go32_dpmi_free_real_mode_callback(&NewStdinVector);
}
int main()
{
int ch;
stdinInit();
ch = getchar();
putchar(ch);
stdinExit();
return 0;
}
- Raw text -