flat assembler
Message board for the users of flat assembler.

Index > DOS > Mouse basics (callback)

Author
Thread Post new topic Reply to topic
DustWolf



Joined: 26 Jan 2006
Posts: 373
Location: Ljubljana, Slovenia
DustWolf
Hello,

Me and a friend are writing a 16bit app to see how things are in real mode.

Trying to get a hold of the mouse, but it's prooving somewhat hard. Here is our code:
Code:
; MS Mouse Interface
MouseInit:
        xor     ax,ax
        int     33h             ;Reset Mouse

        mov     ax, 0Ch
        push    cs
        pop     es
        mov     cx, 1111111b
        mov     dx, MouseHandler
        int     33h             ;Set handler

        ret

MouseHandler:
        mov     [MouseX], cx
        mov     [MouseY], dx
        mov     [MouseButton], bx
        ret

MouseX          dw      ?
MouseY          dw      ?
MouseButton     dw      ?    


This would be the subroutines, MouseInit is called by the main program upon innitialization. Apparently the innitialization is fine and I can find no flaws in the segment:offset values provided in the innitialization, from the dissasembler perspective, but the first time that the handler is called back, the program crashes. Where is the error?

Also, after we manage to get this working, I intend to simply replace this procedure with the one that calls PS2 mouse BIOS instead of the MS Mouse driver since the interface appears identical. Will that work?
Post 28 Oct 2006, 20:30
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7750
Location: Kraków, Poland
Tomasz Grysztar
First: the handler is a far-call, thus you have to use RETF to return from it.
Second: at the time when your handler is called, you may be not guaranteed that DS is what you'd like it to be (I don't remember as it is with mouse handlers exactly, though). In this case you seem to use the same segment for data as for code, so you need DS to be the same as your CS to make your variables accessible. Thus the correct handler should be like:
Code:
MouseHandler:
        push    ds      ; store DS
        push    cs
        pop     ds      ; DS := CS
        mov     [MouseX], cx
        mov     [MouseY], dx
        mov     [MouseButton], bx
        pop     ds      ; restore DS
        retf     
Post 28 Oct 2006, 21:18
View user's profile Send private message Visit poster's website Reply with quote
DustWolf



Joined: 26 Jan 2006
Posts: 373
Location: Ljubljana, Slovenia
DustWolf
Tomasz Grysztar wrote:
Code:
MouseHandler:
        push    ds      ; store DS
        push    cs
        pop     ds      ; DS := CS
        mov     [MouseX], cx
        mov     [MouseY], dx
        mov     [MouseButton], bx
        pop     ds      ; restore DS
        retf     


Thanks. Smile I've figured it'd be something to do with a far call and thus a far return, just didn't know how to spell it in FASM. Didn't remember the DS so thanks there. Smile

And always, thanks for the assembler. Very Happy
Post 28 Oct 2006, 22:00
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.