1.COMMENT 2 **************************************************************************** 3 EVENT2.ASM Example file for a mouse event handler 4 (c) 1996,1998 by Dieter Pawelczak - Pass32 Version 2.3 5 ============================================================================ 6 **************************************************************************** 7 8.include system.mac 9.include dpmi.inc 10 11.mem 1024 12.nb 13.data 14 programname db 'c:\command.com',0 15 parameter db 0 16 linestr db ' ',0 17 backstr db ' : ',0 18 xvalue dd 0 19 yvalue dd 0 20 CBSeg dw 0 21 CBOffs dw 0 22 23.code 24 25PROC MouseEventHandler 26 27; Parameters: ES : EDI = real mode register field 28; DS : ESI = real mode stack 29; 30; a typical mouse event handler: 31; 32; AX = ES:INTEAX = mouse event, which activated the handler 33; BX = ES:INTEBX = mouse button, which is actually pressed (bit 0=left, bit 1=right, bit 2=middle) 34; CX = ES:INTECX = mouse position X 35; DX = ES:INTEDX = mouse position Y 36; DI = ES:INTEDI = rel mouse movement X 37; SI = ES:INTESI = rel mouse movement Y 38; 39; note, read return address from stack (DS:ESI) and write address to INTCS 40; and INTIP! 41; note, ES:EDI must point to a valid register transfer buffer when exit 42; last note: you should use a different real mode transfer buffer for 43; event handler and main program (not like here the public 44; dpmi.inc)! 45 46 bt dword ptr es:[inteax],1 ; event left key pressed 47 jc short leftkeypressed 48 bt dword ptr es:[inteax],2 ; event left key not pressed 49 jc short leftkeynotpressed 50 bt dword ptr es:[inteax],3 51 jc short rightkeypressed 52 bt dword ptr es:[inteax],4 53 jc rightkeynotpressed 54EventExit: 55 cld 56 lodsw ; Get real mode ret IP 57 mov es:[intip], ax 58 lodsw ; Get real mode ret CS 59 mov es:[intcs], ax 60 add word ptr es:[intsp], 4 ; correct real mode stack 61 iret 62leftkeypressed: 63 mov ax,440 64 call SystemSound 65 jmp EventExit 66leftkeynotpressed: 67 call SystemNoSound 68 jmp EventExit 69rightkeypressed: 70rightkeynotpressed: 71 push ds ; save stack and transfer 72 push es ; buffer pointer! 73 push esi 74 push edi 75 76 mov ax,cs:[0] ; load ds 77 mov ds,ax 78 xor eax,eax 79 mov ax,word ptr intecx 80 mov xvalue,eax 81 mov ax,word ptr intedx 82 mov yvalue,eax 83 mov edi,offset linestr 84 call mathtostring 85 mov edi,offset backStr 86 mov cx,60 87 mov dx,0 88 call systemprint 89 mov edi,offset linestr 90 mov cx,68 91 mov dx,0 92 call systemprint 93 mov eax,xvalue 94 mov edi,offset linestr 95 call mathtostring 96 mov edi,offset linestr 97 mov cx,62 98 mov dx,0 99 call systemprint 100 101 pop edi ; restore stack and 102 pop esi ; transfer buffer pointer! 103 pop es 104 pop ds 105 jmp EventExit 106ENDP MouseEventHandler 107 108 109 110 111START: 112 mov ax,0 113 int 33h 114 cmp ax,0 115 je MouseError 116 push ds 117 mov ax,ds 118 mov es,ax 119 mov ax,cs 120 mov ds,ax 121 mov esi,offset MouseEventHandler 122 mov edi,offset intedi 123 mov ax,303h 124 int 31h 125 pop ds 126 jc DPMIError 127 mov CBSeg,CX 128 mov CBOffs,DX 129 mov ax,ds 130 mov es,ax 131 mov intes,cx 132 mov intedx,edx 133 mov inteax,14h 134 mov intecx,2+4+8+16 135 mov ax,300h 136 mov bx,33h 137 mov cx,0 138 mov edi,offset intedi 139 int 31h 140 call systemclrscr 141 color(14,0) 142 writeln('Event Handler Installed - press mouse button!') 143 write('Type EXIT to terminate demo!') 144 mov ax,1 145 int 33h ; show mouse 146 color(7,0) 147 writeln(' ') 148 mov edi,offset programname 149 mov esi,offset parameter 150 call SystemExec 151; OK - now disable event handler! 152 mov ax,2 153 int 33h ; hide mouse 154 mov ax,0 155 int 33h ; reset mouse driver 156; OK - now free call back 157 mov cx,CBSeg 158 mov dx,CBOffs ; CX : DX Call Back Function 159 mov ax,0304h ; DPMI Function 0304h 160 int 31h ; Free Real Mode Call Back 161 writeln('Exit demo!') 162 exit(0); 163DPMIError: 164 writeln('Error installing the Event Handler!') 165 exit(3); 166MouseError: 167 writeln('Mouse driver not present!') 168 exit(3); 169END START 170END