www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/14/06:33:23

From: nikki AT gameboutique DOT co (nikki)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: hello world
Date: 14 Feb 1997 10:23:19 GMT
Organization: GameBoutique Ltd.
Lines: 71
Message-ID: <5e1een$jq2@flex.uunet.pipex.com>
References: <5draph$fhk$2 AT thor DOT atcon DOT com>
<3301fbcd DOT 2363628 AT news DOT ox DOT ac DOT uk>
NNTP-Posting-Host: www.gameboutique.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

>>i am using the 32-bit protected mode (version 2, i think)
>>and what about my keyboard handler that worked in ms C? can i just 
>>(rewrite it) or will the protected mode not let me change the dos 
>>interrupt? aaargh!!
> 
> It will need some rewriting; however, I strongly recommend that you
> get Allegro. It's a library of useful games routines, including a
> decent keyboard handler, graphics routines, sound, etc etc. Look at:
> 

you're also quite welcome to use mine, it's about as fast as you can be.
only a pmode handler setup here although you can use a realmode one too if
you really want.


#include <go32.h>
#include <dpmi.h>

unsigned char keytable[128];

void NewInt9(void)
{
asm volatile ("inb $0x60\n\t"                // get from 0x60
              "movb %%al,%%bl\n\t"           // bl=offset         1 uv
              "movb $0xff,%%cl\n\t"          // load pressed to c 1 uv
              "andl $0x0000007f,%%ebx\n\t"   // clear it out      2 uv
              "addb $0x80,%%al\n\t"          // add force carry   2 uv
              "adcb $0,%%cl\n\t"             // release if carry  3 u
              "movb $0x20,%%al\n\t"          //                   3 uv
              "movb %%cl,(%%edi,%%ebx)\n\t"  // update entry      4 uv
              "outb $0x20\n\t"               // reset the PIC
             :
             : "D" (keytable)
             : "eax", "ebx", "ecx", "edi");
}
void LOCKint9() { }

(inside main)

   _go32_dpmi_seginfo old_handler,my_callback;

   _go32_dpmi_lock_data(keytable,128);
   _go32_dpmi_lock_data(&keytable,sizeof(keytable));
   _go32_dpmi_lock_code(NewInt9,(unsigned long)(LOCKint9-NewInt9));
   _go32_dpmi_get_protected_mode_interrupt_vector(9,&old_handler);
   my_callback.pm_selector=_go32_my_cs();
   my_callback.pm_offset=(unsigned long)NewInt9;
   _go32_dpmi_allocate_iret_wrapper(&my_callback);
   _go32_dpmi_set_protected_mode_interrupt_vector(9,&my_callback);
   // keyboard interrupt should now be replaced we hope

(and remember to release the irq when you're finished!!)

   _go32_dpmi_set_protected_mode_interrupt_vector(9,&old_handler);
   _go32_dpmi_free_iret_wrapper(&my_callback);   // must replace the keyboard :)



hope that's some help to anyone who's looking for one. it's basically 4 cycles
in the main loop, but there's those two in/out's which take 21 cycles under
pmode which is a shame. i could try and read it directly from the keyboard
buffer instead but it's probably not a very good idea. if anyone can see a 
way to improve it let me know of course :)

regards,
nik


-- 
Graham Tootell           
nikki AT gameboutique DOT com  

- Raw text -


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