delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/04/20/11:16:17

From: firewind AT constellation DOT stu DOT rpi DOT edu (firewind)
Newsgroups: comp.os.msdos.programmer,comp.os.msdos.djgpp
Subject: InDOS Flag
Date: 20 Apr 1997 00:42:42 GMT
Organization: Rensselaer Polytechnic Institute, Troy NY, USA
Lines: 154
Message-ID: <5jboq2$4o4@usenet.rpi.edu>
NNTP-Posting-Host: constellation.stu.rpi.edu
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Heya.

I'm writing a TSR using DJGPP. So far, things are going pretty well, but I
have one problem. At the command prompt, the InDOS flag always seems to be
one. Shouldn't it be zero? Am I doing something wrong? The InDOS flag is
(correctly) at zero during idle times of other applications (Telix and
MS-DOS EDIT were two I tried).

Here's the code:

/* beginning of worx.h */

/*
 * WORX.H
 */
 
#ifndef _WORX_H_ 
#define _WORX_H_
 
#define GET_SCANCODE() inportb(0x60)  
#define MASK_VAR(var) MASK & var 
#define MASK 0xE1
 
unsigned char parse(unsigned int scancode);  
unsigned char shift_symbol(unsigned char ascii); 
 
typedef struct
{
        int shiftstate; 
        int ctrlstate; 
        int altstate; 
        int recurse; 
        int keyready; 
        int status; 
} flag; 
 
#endif

/*end of worx.h*/

/*beginning of worxtsr.c*/

/*
 * WorxTSR, TSR based on my Worx INT 9 handler
 * Source Code by Matt Spencer
 *
 * This code is protected by the GNU General Public License.
 */

#include <conio.h> /* for screen manipulation */
#include <stdio.h> /* printf, et al. */
#include <dpmi.h> /* for DPMI functions */
#include <crt0.h> /* for _crt0_startup_flags */
#include <go32.h> /* for seginfo, _dos_ds, and chain function */
#include <pc.h> /* for inportb */
#include <stdlib.h> /* for malloc, sleep */
#include <sys/farptr.h> /* for DJGPP "far pointer" functions */
#include "worx.h"

int _crt0_startup_flags = _CRT0_FLAG_LOCK_MEMORY;
volatile unsigned char indos = 0, criterr = 0;
volatile unsigned int scancode = NULL;
volatile unsigned char ascii_char = NULL;
volatile unsigned int loops = NULL;
volatile flag flags = {0,0,0,0};
volatile unsigned short es,bx,ds,si;
volailte unsigned int *screen = (unsigned *)malloc(ScreenRows()*ScreenCols()*2);
volatile int x,y;

/*
 * lemme 'splain why these are all global: i'm not really sure how (or even
 * if) allocation would work inside the interrupt function. working off of
 * better safe than sorry, i defined these global. and volatile, of course,
 * since gcc doesn't know when the interrupt will be called
 */

void int_9(void)
{
        scancode = GET_SCANCODE();
        ascii_char = parse(scancode);
        if (ascii_char == 255)
        {                
                indos = _farpeekb(_dos_ds, es*16+bx);
                criterr = _farpeekb(_dos_ds, ds*16+si);
                /* these are equivilent to accessing far pointers to ES:BX 
                   and DS:SI as returned by the interrupts called in main */

                if(criterr == 0)
                {
                        if(indos==0)
                        {
                                x = wherex();
                                y = wherey();
                                ScreenRetrieve(screen);
                                clrscr();
                                printf("\nTSR Test. (%i,%i)\n",criterr,indos);
                                sleep(2);
                                ScreenUpdate(screen);
                                gotoxy(x,y);
                        }
                }
        }
        /* outportb(0x20,0x20); we're not last in chaining order */
}

unsigned char parse(unsigned int scancode)
{
        unsigned char ascii = 1;

        switch(scancode) 
        {
                case 0x38: flags.altstate = 1; ascii = 0; break;
                case (0x38|0x80): flags.altstate = 0; return(1);
                case 0x25: ascii = 'k'; break;
                default: ascii = 1;
        }
        if(flags.altstate && ascii == 'k') return(255); else return(1);
}

int main(void)
{
        _go32_dpmi_seginfo pmint;
        __dpmi_regs regs;

        regs.h.ah = 0x34; /* function 0x34, InDOS address */
        __dpmi_int(0x21, &regs); /* call INT 0x21 */
        es = regs.x.es; /* store ES and BX for use later as "far" pointers */
        bx = regs.x.bx;
        
        regs.x.ax = 0x5D06; /* function 0x5D06, CritErr address */
        __dpmi_int(0x21, &regs); /* call INT 0x21 */
        ds = regs.x.ds; /* store DS and SI for use later as "far" pointers */
        si = regs.x.si;
        
        pmint.pm_selector = _my_cs();
        pmint.pm_offset = (unsigned)&int_9;
        _go32_dpmi_chain_protected_mode_interrupt_vector(9, &pmint);
        /* chain our interrupt function */                

        regs.h.ah = 0x31;
        regs.x.dx = 32;
        __dpmi_int(0x21, &regs);
        /* call INT 0x21, func 0x31; go TSR */

        return(0);
}

/* end of worxtsr.c */

So can anyone tell my what the problem is? If the InDOS flag is supposed
to be 1 at the command prompt, why is this?

Thanks in advance,
Matt (aka firewind)

- Raw text -


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