News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Accessing Int 33h

Started by srfpala, November 09, 2013, 04:04:26 AM

Previous topic - Next topic

srfpala

I'm using

INCLUDELIB \masm32\lib\Irvine32.lib
INCLUDELIB \masm32\lib\user32.lib
INCLUDELIB \masm32\lib\kernel32.lib

WinASM reports

Clean assemble
Clean link
and Program runs fine.

I add
  mov   ax,1
  int   33h

Program aborts on int 33h  command.

Why ?
What am I missing?
Bob

dedndave

the INTerrupt mechanism is for 16-bit programs
for 32-bit programs, things are very different
if you have a window, the WndProc routine receives mouse messages
for console-mode programs, you receive mouse inputs in the same buffer as the keyboard
there are also a few functions, like GetCursorPos that work asynchronously

decide whether you want a 16-bit or 32-bit program, then proceed from there

kellinka

Hey dedndave, could you go into detail about console mode programs and how the mouse input buffer would work? Or could you provide some sort of sources I could look at to find this information? I've been looking for the last 2 hours about how to do mouse input for console mode and I can't find anything helpful, it took me forever to find this thread to start with.

dedndave

asynchronously, you can always get the mouse position with GetCursorPos

http://msdn.microsoft.com/en-us/library/windows/desktop/ms648390%28v=vs.85%29.aspx

however, you can also perceive mouse actions by examining the input buffer
in this code, i use the same method to look for keys
;***********************************************************************************************

AnyKey  PROC

;UNICODE Aware Wait for Any Console Key Press - DednDave
;version 1, 12-2011
;version 2, 2-2013
;
;  This function returns when any console key is pressed (bKeyDown = 1).
;The function does not return for Shift/Alt/Ctrl keypresses.
;A possible drawback is that all input event records (mouse etc) are removed
;from the console input queue until a key is pressed. In many cases, this is
;not an issue. The virtual key code, virtual scan code, TCHAR character,
;and control key state values are returned in registers.

;Call With: Nothing
;
;  Returns: EAX = TCHAR character (high word of EAX = 0)
;           ECX = control key state flags
;               Bit   Name                Meaning
;                0    RIGHT_ALT_PRESSED   Right ALT key is pressed
;                1    LEFT_ALT_PRESSED    Left ALT key is pressed
;                2    RIGHT_CTRL_PRESSED  Right CTRL key is pressed
;                3    LEFT_CTRL_PRESSED   Left CTRL key is pressed
;                4    SHIFT_PRESSED       SHIFT key is pressed
;                5    NUMLOCK_ON          NUM LOCK light is on
;                6    SCROLLLOCK_ON       SCROLL LOCK light is on
;                7    CAPSLOCK_ON         CAPS LOCK light is on
;                8    ENHANCED_KEY        Key is enhanced
;           EDX: high word = virtual scan code
;            low word (DX) = virtual key code
;
;Also Uses: EBX, ESI, EDI, EBP are preserved

;-------------------------------------------------

    LOCAL   ir          :INPUT_RECORD
    LOCAL   uRecCnt     :UINT
    LOCAL   hStdInp     :HANDLE

;-------------------------------------------------

    INVOKE  GetStdHandle,STD_INPUT_HANDLE
    mov     hStdInp,eax
    .repeat
        INVOKE  ReadConsoleInput,hStdInp,addr ir,1,addr uRecCnt
        movzx   ecx,word ptr ir.EventType
        mov     edx,dword ptr ir.KeyEvent.wVirtualKeyCode
    .until (ecx==KEY_EVENT) && (ecx==ir.KeyEvent.bKeyDown) && (dx!=VK_SHIFT) && (dx!=VK_CONTROL) && (dx!=VK_MENU)
    movzx   eax,word ptr ir.KeyEvent.UnicodeChar
    mov     ecx,ir.KeyEvent.dwControlKeyState
    ret

AnyKey  ENDP

;***********************************************************************************************

notice that it looks for KEY_EVENT's
the INPUT_RECORD structure may also contain MOUSE_EVENT's

http://msdn.microsoft.com/en-us/library/windows/desktop/ms683231%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms684961%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms683499%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms684239%28v=vs.85%29.aspx

i have never used it that way - i usually skip over mouse events - lol
but, it shouldn't be hard to figure out with the documentation
you may also want to use Get/SetConsoleMode

http://msdn.microsoft.com/en-us/library/windows/desktop/ms683167%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms686033%28v=vs.85%29.aspx

you may want to get the current console mode, store it
then set the mode - read inputs
then set the mode back to the original state before exit

dedndave

personally, if i want to use the mouse - i would write a GUI app   :t

EDIT: give me a few minutes to clean up a little example.....

jj2007

Here is a low tech example. The way to go is, as Dave rightly stated, ReadConsoleInput.

include \masm32\MasmBasic\MasmBasic.inc        ; download
  Init
  Cls
  Print "Hold the left mousekey down and move the mouse - hit Escape to quit"
  .Repeat
        invoke Sleep, 1
        invoke GetKeyState, VK_LBUTTON        ; kind of undocumented but it works ;-)
        .if sbyte ptr ah<0
                imul edi, MouseX, 85        ; may need adjustment for different screen resolutions or console fonts
                sar edi, 10
                imul ecx, MouseY, 50        ; may need adjustment
                sar ecx, 10
                Locate(edi, ecx)
                Print "."        ; show the point
        .endif
        invoke GetKeyState, VK_ESCAPE
  .Until sbyte ptr ah<0
  Exit
end start

dedndave

#6
GUI example - the mouse position is in the status bar

you can also handle WM_LBUTTONDOWN and WM_RBUTTONDOWN messages to get clicks

EDIT: removed attachment, see next post

dedndave

i cleaned up my status bar/mouse example a little bit
fixed a couple things...