need some help programming a TSR

need some help programming a TSR

Post by PrimeTim » Sat, 26 Jul 2003 08:52:55



Hi,
I'm trying to program a TSR in Turbo C++ 3.0.
I chain the keyboard so if the user hits a specific key, the video
mode changes to text mode 0x03, and displays text.  Easy enough.

My problem is, the TSR is meant to trigger within a DOS game, ie video
mode 0x13 (reg/modex) or perhaps some VESA modes.  

I'm having trouble detecting the screen mode and attributes before changing
to text mode, and then restoring everything.  
I'm trying to use interrupt 10's SAVE/RESTORE state function, but it
doesn't seem to be working correctly.

does anyone know maybe some correct code for the SAVE/RESTORE function?

Thanks,
Ryan

 
 
 

need some help programming a TSR

Post by aurgatho » Sat, 26 Jul 2003 09:35:29


I think you manually need to save the screen, then
restore it.  Of course you need to detect mode and
the location of display memory.

Posting the relevant code can be helpful, BTW.


Quote:> Hi,
> I'm trying to program a TSR in Turbo C++ 3.0.
> I chain the keyboard so if the user hits a specific key, the video
> mode changes to text mode 0x03, and displays text.  Easy enough.

> My problem is, the TSR is meant to trigger within a DOS game, ie video
> mode 0x13 (reg/modex) or perhaps some VESA modes.

> I'm having trouble detecting the screen mode and attributes before
changing
> to text mode, and then restoring everything.
> I'm trying to use interrupt 10's SAVE/RESTORE state function, but it
> doesn't seem to be working correctly.

> does anyone know maybe some correct code for the SAVE/RESTORE function?

> Thanks,
> Ryan


 
 
 

need some help programming a TSR

Post by Alex Russel » Sat, 26 Jul 2003 12:23:07



Quote:> Hi,
> I'm trying to program a TSR in Turbo C++ 3.0.
> I chain the keyboard so if the user hits a specific key, the video
> mode changes to text mode 0x03, and displays text.  Easy enough.

> My problem is, the TSR is meant to trigger within a DOS game, ie video
> mode 0x13 (reg/modex) or perhaps some VESA modes.

> I'm having trouble detecting the screen mode and attributes before
changing
> to text mode, and then restoring everything.
> I'm trying to use interrupt 10's SAVE/RESTORE state function, but it
> doesn't seem to be working correctly.

> does anyone know maybe some correct code for the SAVE/RESTORE function?

> Thanks,
> Ryan

// get old video mode
 in.h.ah=0xf;
 int86(0x10, &in, &out);
 old_mode=out.h.al;

mov    ah 0fh
int        010h
mov    old_mode, al        ; old_mode is a byte

Of course this only works with STANDARD video modes.
You may have to see how VESA lets you ask what the current video mode is.

If you use teh in10 to switch video modes it will often CLEAR video memory,
so you will want to SAVE what was on the screen (at 0x0a000) and restore
after restoring the videomode.

--
Alex Russell

 
 
 

need some help programming a TSR

Post by PrimeTim » Sat, 26 Jul 2003 21:17:21




> // get old video mode
>  in.h.ah=0xf;
>  int86(0x10, &in, &out);
>  old_mode=out.h.al;

> mov    ah 0fh
> int        010h
> mov    old_mode, al        ; old_mode is a byte

> Of course this only works with STANDARD video modes.
> You may have to see how VESA lets you ask what the current video mode
> is.

> If you use teh in10 to switch video modes it will often CLEAR video
> memory, so you will want to SAVE what was on the screen (at 0x0a000)
> and restore after restoring the videomode.

> --
> Alex Russell


Thanks Alex,

I have tried this and it seems to work alright, but what about
video modes like mode-x (320x240), where it has chain-4 disabled.
Is there a way to detect if it is modeX before i get the old video mode?

Also, I tried some VESA routines and they work well inside my programs
main function.  However, they do not work when called from an interrupt
handler.  Any idea why?

Thanks,
Ryan

BTW:  In standard modes i found that the screen data does not need to be
saved, when restoring the screen mode, place an

or al, 128 (set the MSB to high)

and it does not clear the screen when changing modes.

 
 
 

need some help programming a TSR

Post by Alex Russel » Sun, 27 Jul 2003 14:26:08





> > // get old video mode
> >  in.h.ah=0xf;
> >  int86(0x10, &in, &out);
> >  old_mode=out.h.al;

> > mov    ah 0fh
> > int        010h
> > mov    old_mode, al        ; old_mode is a byte

> > Of course this only works with STANDARD video modes.
> > You may have to see how VESA lets you ask what the current video mode
> > is.

> > If you use teh in10 to switch video modes it will often CLEAR video
> > memory, so you will want to SAVE what was on the screen (at 0x0a000)
> > and restore after restoring the videomode.

> > --
> > Alex Russell

> Thanks Alex,

> I have tried this and it seems to work alright, but what about
> video modes like mode-x (320x240), where it has chain-4 disabled.
> Is there a way to detect if it is modeX before i get the old video mode?

> Also, I tried some VESA routines and they work well inside my programs
> main function.  However, they do not work when called from an interrupt
> handler.  Any idea why?

> Thanks,
> Ryan

> BTW:  In standard modes i found that the screen data does not need to be
> saved, when restoring the screen mode, place an

> or al, 128 (set the MSB to high)

> and it does not clear the screen when changing modes.

for mode X, int 0x10 will likely return 0x13 - you would then have to
directly read the vga card ports to see if it is unchained. The old xlib has
asm functions to set xmode, but I can't find code to detect xmode.

I'm not sure why the vesa routines are not working within your tsr.

--
Alex Russell

 
 
 

need some help programming a TSR

Post by aurgatho » Mon, 28 Jul 2003 09:58:46


Quote:> Also, I tried some VESA routines and they work well inside my programs
> main function.  However, they do not work when called from an interrupt
> handler.  Any idea why?

Are the routines you call use DOS or BIOS interrupts?
 
 
 

need some help programming a TSR

Post by PrimeTim » Mon, 28 Jul 2003 10:12:56




Quote:

>> Also, I tried some VESA routines and they work well inside my
>> programs main function.  However, they do not work when called from
>> an interrupt handler.  Any idea why?

> Are the routines you call use DOS or BIOS interrupts?

I suppose BIOS, since i am calling int 10h for VESA and VGA modes,

I've tried a lot of different things...

I tried both VGA and VESA SAVE/RESTORE states,  but neither of those
functions seem to be supported.

I tried getting the video mode before switching to text mode(0x03),
which works well, but i need to grab more than just the old video mode.
I succesfully captured the palette and restored it on reEntry to the
program.

Finally, today i tried grabbing many of the VGA registers before moving
to text mode, and then restoring them again.  (This fixed my problem
with restoring mode-x programs!)  

So basically, I am able to popup my TSR(text mode) in a standard VGA
game(0x13) and exit the popup.  However, for some reason, a little bit
after exiting the popup, my game crashes.  I have no idea why since i am
only manipulating vga registers and such.

I narrowed my problem down to this...
I can retrieve all my information about the VGA screen mode, palette,
and registers.  I can even set the mode to 0x13 (even though that is
what it is already at).  But once i set the mode to text(0x03) and then
restore the old information(mode, palette, etc) the game runs for a bit
then crashes.  

Old dos programs such as Infinity Machine and GameWizard were able to
make the switch to text mode and then restore the screen without
crashing.  However, it is extremely hard to find info on TSR programming
through different screen modes.

Here is some code, if you happen to find a problem

int main ()
{
      old_key = getvect(KEYBOARD);
      setvect (KEYBOARD, key_handle);
      keep (0, prgsize ());            /* terminate and stay resident */
      return 0;

Quote:}

void interrupt key_handle ()
{
  (*old_key)();
  key = GetScanCode();
  if (!visible)
  {
    if (key == 41)
      {
       asm cli;
       testReader();
       asm sti;
      }
  }

Quote:}

int testReader()  //fairly simple
{
 int i;

SaveRegs();
ReadPalette();
_getVidMode();
SetVidMode(0x03);
_setVidMode();
WritePalette();
LoadRegs();
return 1;

Quote:}

void SaveRegs()
{
 int i;
 for (i=0; i<5; i++)
 {
  outp(0x03c4, i);
  settings.SeqRegs[i] = inp(0x03c5);
 }

 for (i=0; i<9; i++)
 {
  outp(0x03ce, i);
  settings.GFXRegs[i] = inp(0x03cf);
 }

 for (i=0; i<25; i++)  //0-6
 {
  outp(0x03d4, i);
  settings.CRTRegs[i] = inp(0x03d5);
 }

Quote:}

void LoadRegs()
{
 int i;
 for (i=0; i<5; i++)
 {
 outp(0x03c4, i);
 outp(0x03c5, settings.SeqRegs[i]);
 }

 for (i=0; i<9; i++)
 {
  outp(0x03ce, i);
  outp(0x03cf, settings.GFXRegs[i]);
 }

 for (i=0; i<25; i++)  //0-6
 {
  outp(0x03d4, i);
  outp(0x03d5, settings.CRTRegs[i]);
 }

Quote:}

void ReadPalette()
{
  int i;
  outp(0x3C6, 0xFF);
  for (i=0; i<256; i++)
  {
   outp(0x3C7,i);
   colors[i].r = inp(0x3C9);
   colors[i].g = inp(0x3C9);
   colors[i].b = inp(0x3C9);
  }

Quote:}

void WritePalette()
{
  int i;
  outp(0x3C6, 0xFF);
  for (i=0; i<256; i++)
  {
   outp(0x3C8,i);

   outp(0x3C9, colors[i].r);
   outp(0x3C9, colors[i].g);
   outp(0x3C9, colors[i].b);
  }

Quote:}

void SetVidMode(unsigned char mode)
{
 _asm {
  mov ah, 0h;
  mov al, mode;
  int 10h;
  }

Quote:}

void _setVidMode()
{
 unsigned char a,b,c;
 a = settings.vidMode;
 b = settings.vidCols;
 c = settings.vidPage;
 _asm {
  mov ah, 0h;
  mov al, a;
  or al, 128;
  int 10h;
  mov ah, 5h;
  mov al, c;
  int 10h;
  }
Quote:}

void _getVidMode()
{
 unsigned char a,b,c;
 _asm {
  mov ah, 0fh;
  int 10h;
  mov a, al;
  mov b, ah;
  mov c, bh;
  }
  settings.vidMode = a;
  settings.vidCols = b;
  settings.vidPage = c;

Quote:}

I'm about outta ideas,  I don't know what else to try.
Thanks,
Ryan
 
 
 

need some help programming a TSR

Post by aurgatho » Mon, 28 Jul 2003 18:18:54





> >> Also, I tried some VESA routines and they work well inside my
> >> programs main function.  However, they do not work when called from
> >> an interrupt handler.  Any idea why?

> > Are the routines you call use DOS or BIOS interrupts?

> I suppose BIOS, since i am calling int 10h for VESA and VGA modes,

> void interrupt key_handle ()
> {
>   (*old_key)();
>   key = GetScanCode();
>   if (!visible)
>   {
>     if (key == 41)
>       {
>        asm cli;
>        testReader();
>        asm sti;
>       }
>   }
> }

> I'm about outta ideas,  I don't know what else to try.

I think you're trying to nest interrupts -- you disable it, then call
testReader
which in turn will eventually call int10h.   I haven't written much
interrupts
lately, but nesting in general is not a smart idea.  Another thing, you only
need to disable interrupts when you absolutely need it, like protecting a
critical section, or preventing other interrupts when inside an ISR.  I
think
you grossly overuse it.   I'll take another look at it tomorrow.
 
 
 

1. I am making a TSR program, need help.

I am making a program in C that (should) terminate and stay resident,
but it only uninstalls a ton of junk in upper RAM.
Could someone please send me code snippets telling how to load a program
into RAM, upper or convention is fine. Thanks

        --theMaker


     I never check the account I am send out of and reading the posts
in      here is quite time-consuming.

2. New 65C02?

3. Need help with serial coms program (tsr)

4. detecting unauthorized uses of modem

5. TSR-programming in assembly, help needed!

6. NaN in other types than double

7. Get Paid when someone can help to convert a DOS program to TSR program

8. Force window on top

9. HELP!: Need TSR or help writing one!

10. Need a good TSR Menu program

11. TSR shell program needed

12. TSR Programming -- Calling another application from TSR

13. TSR programming info needed...