Date: Thu, 17 Aug 1995 13:26:36 +1100 From: Bill Currie Subject: mem locking and rm callbacks To: djgpp AT sun DOT soe DOT clarkson DOT edu Organization: Tait Electronics Ltd. I am implementing a mouse class and I'm having problems with the callback function (0xC). I have locked down all the memory except the stack and I am still getting page access errors. I imagine this is from the stack not being locked down, but I don't know where it is. Below is the relavent code for anyone to look over. The likely cause of the errors is in TMouse::setUserFunction. TIA Bill #ifndef __tmouse_h #define __tmouse_h #pragma interface #ifndef __dj_include_dpmi_h_ #include #endif class TMouse { protected: unsigned present:1; int numButtons; static __dpmi_raddr callBack; static __dpmi_regs regs; static void mouse_func(); static void (*mouseCallback)(short,short,short,short,short,short); public: TMouse(); ~TMouse(); int getButtons(); void showCursor(); void hideCursor(); short getPos(short &x, short &y); void setPos(short x, short y); void getPress(short &c, short &x, short &y, short &s); void getRelease(short &c, short &x, short &y, short &s); void setHRange(short mi, short ma); void setVRange(short mi, short ma); void setUserFunction(void (*func)(short,short,short, short,short,short),short mask); }; extern TMouse Mouse; #endif // __tmouse_h #pragma implementation "tmouse.h" #include #include "tui.h" TMouse Mouse; void (*TMouse::mouseCallback)(short,short,short,short,short,short); __dpmi_regs TMouse::regs; __dpmi_raddr TMouse::callBack; void TMouse::mouse_func() { // if (mouseCallback) // mouseCallback(regs.x.ax,regs.x.cx,regs.x.dx,regs.x.di,regs.x.si,regs.x.bx); } static void eofunc(){} /* stolen from sb03_dj2 by Joel H. Hunter*/ int lock_memory(const void *ptr, unsigned long bytes) { unsigned long base; if(__dpmi_get_segment_base_address(_my_ds(),&base)!=-1) { __dpmi_meminfo mem; mem.handle=0; mem.size=bytes; mem.address=(unsigned long)((char *)ptr+base); if(__dpmi_lock_linear_region(&mem)!=-1) return 1; } return -1; } [irrelevant code clipped] void TMouse::setUserFunction(void (*func)(short,short,short, short,short,short),short mask) { __dpmi_regs r; if (!callBack.segment) { lock_memory(mouse_func,(unsigned long)eofunc-(unsigned long)mouse_func); lock_memory(&callBack,sizeof(callBack)); lock_memory(&mouseCallback,sizeof(mouseCallback)); lock_memory(®s,sizeof(regs)); __dpmi_allocate_real_mode_callback(mouse_func,®s,&callBack); } mouseCallback=func; r.x.ax=0x000c; r.x.es=callBack.segment; r.x.dx=callBack.offset16; r.x.cx=mask; __dpmi_simulate_real_mode_interrupt(0x33,&r); } +--------------+-----------------------------------+ |Bill Currie | "Watch that first step..." | |Christchurch | Jump trooper motto. | |New Zealand | | +--------------+-----------------------------------+