From: p6inf700 AT cicrp DOT jussieu DOT fr (Jimmy OBERTAN) Message-Id: <9704301159.AA39701@ibm1.cicrp.jussieu.fr> Subject: My mouse driver and CLI/STI question To: djgpp AT delorie DOT com Date: Wed, 30 Apr 1997 13:59:43 +0200 (DFT) Content-Type: text Precedence: bulk Hi! Here Dr. Slime! Can anybody tell me if my coding way is good for djgpp? My problem is that i've used this code in a graphic program under Win95, DOS with cwsdpmi and win3.1. Result : under win95 and DOS every thing works well but under win3.1 the kbhit() function dosn't work after calling the Show function. I've perform some tests and find out that the "cli" was the problem. Should i use the dpmi function to enable or disable the virtual interrupt state for all to run properly ? Bye! This is my mouse driver source code: #pragma inline #include #include //#include #include #include "souris.h" #include "stdvideo.h" #include "dpmi.h" #define SPEED 4 #define SPEED_DEC 2 int Mx=0,My=0,Bt=0,lastx=0,lasty=0,etat=Hidden; short LastMouseHandler_seg,LastMouseHandler_ofs; short LastMouseMask; void (* _hide)(int x,int y)=NULL; void (* _show)(int x,int y)=NULL; char SlimeSouris=0; static _go32_dpmi_registers *ATCALL; void MouseSpeed(int en_x,int en_y) { __dpmi_regs r; r.x.ax = 0x0f; r.x.cx = en_x; r.x.dx = en_y; __dpmi_int(0x33, &r); } void TheMouseH(_go32_dpmi_registers *ATCALL) { asm ("pushf;cli"); Mx=ATCALL->x.cx >> 3; My=ATCALL->x.dx >> 3; if (ATCALL->x.ax & 0x02) Bt|=1; else if (ATCALL->x.ax & 0x04) Bt&=~1; if (ATCALL->x.ax & 0x08) Bt|=2; else if (ATCALL->x.ax & 0x10) Bt&=~2; if (ATCALL->x.ax & 0x20) Bt|=4; else if (ATCALL->x.ax & 0x40) Bt&=~4; if (_hide!=NULL && _show!=NULL && (ATCALL->x.ax & 0x01) && etat==Shown) { _hide(lastx,lasty); _show(Mx,My); lastx=Mx;lasty=My; }; asm ("popf"); } void NewMouseHandler(); void MouseOFF(); int MouseON() { __dpmi_regs r; if (SlimeSouris) { etat=Hidden; SetHide(NULL); SetShow(NULL); return 0; } r.x.ax = 0x0; __dpmi_int(0x33, &r); MouseSpeed(1,2); if (r.h.al) { NewMouseHandler(); atexit(MouseOFF); } return(!r.h.al); } int MouseON(int x,int y) { if (MouseON()) return 1; MouseSetResolution(x,y); } void MouseSetResolution(int res_x,int res_y) { __dpmi_regs r; if (!SlimeSouris) return; r.x.ax = 0x07; r.x.cx = 0; r.x.dx = (res_x-1) << 3; __dpmi_int(0x33, &r); r.x.ax = 0x08; r.x.cx = 0; r.x.dx = (res_y-1) << 3; __dpmi_int(0x33, &r); } void NormalShow() {__dpmi_regs r; r.x.ax = 0x01; __dpmi_int(0x33, &r); } void NormalHide() {__dpmi_regs r; r.x.ax = 0x02; __dpmi_int(0x33, &r); } int EtatSouris() { return(etat); } void Hide() { asm ("pushf;cli"); if (_hide==NULL) NormalHide(); else _hide(lastx,lasty); etat=Hidden; asm ("popf"); } void Show() { asm ("pushf;cli"); if (_show==NULL) NormalShow(); else _show(Mx,My); lastx=Mx;lasty=My; etat=Shown; asm ("popf"); } void SetMousePos(int x,int y) {__dpmi_regs r; r.x.ax = 0x04; r.x.cx = x; r.x.dx = y; __dpmi_int(0x33, &r); } void SetHide(void (* func)(int,int)) { _hide=func; } void SetShow(void (* func)(int,int)) { _show=func; } static _go32_dpmi_seginfo *f; void NewMouseHandler() { __dpmi_regs r; f=new _go32_dpmi_seginfo; f->pm_offset=(int)TheMouseH; // printf("%x\n",f->pm_offset); ATCALL=new _go32_dpmi_registers; _go32_dpmi_allocate_real_mode_callback_retf(f, ATCALL); // printf("%x:%x\n",f->rm_segment,f->rm_offset); r.x.ax = 0x14; r.x.cx = 0x0ff; r.x.es = f->rm_segment; r.x.dx = f->rm_offset; __dpmi_int(0x33, &r); LastMouseHandler_seg=r.x.es; LastMouseHandler_ofs=r.x.dx; LastMouseMask=r.x.cx; SlimeSouris=1; } void MouseOFF() { __dpmi_regs r; if (!SlimeSouris) return; delete ATCALL; delete f; _go32_dpmi_free_real_mode_callback(f); r.x.ax = 0x14; r.x.cx = LastMouseMask; r.x.es = LastMouseHandler_seg; r.x.dx = LastMouseHandler_ofs; __dpmi_int(0x33, &r); if (etat==Shown) Hide(); etat=Hidden; SetHide(NULL); SetShow(NULL); SlimeSouris=0; } void Wait(int b) {do { } while (Bt==b); } sorry for the frensh/english scramble! :)