Qbasicnews.com

Full Version: Mouse in DOS?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Can I use the built in FreeBasic Mouse functions when running my program in Pure DOS?
Only if you are in a graphics mode (set with SCREEN); that requires the gfxlib, which is not finished in the DOS port (and is only available from the CVS for now). If those conditions are met, it'll work just the same as in the Windows version of FreeBASIC.
So at the moment I cannot do it?
Actually you can - you just won't be using FB's commands. The easiest way I can think of would be to use inline assembly to get input from the mouse. I'm not really certain though how to do that in 32-bit. Under 16-bit, you'd simply tie into interrupt 33h. :wink:
What will I be using then, if I'm not using FB's commands?
Interrupts, just like you would in QB
Hmm... Could I be pointed to a tut that explains these "Interupts"?
Not exactly a tutorial (you should be able to find billions of them, everybody seems to think he has the greatest mouse routine ever Smile ), but here's a simple bit of code:
Code:
option explicit

#include "dos/dpmi.bi"

#define MOUSE &H33

dim regs as __dpmi_regs
dim x as integer, y as integer, b as integer

width 80, 25

for y = 1 to 25
    for x = 1 to 80
        locate y, x
        color int(rnd * 16)
        print chr(176);
    next x
next y

' turn off text cursor
locate , , 0

' initialize mouse
regs.x.ax = 0
__dpmi_int(MOUSE, @regs)

' show mouse
regs.x.ax = 1
__dpmi_int(MOUSE, @regs)

do until len(inkey)
    ' get mouse position
    regs.x.ax = 3
    __dpmi_int(MOUSE, @regs)
    x = regs.x.cx \ 8 ' divide by 8 - char width = 8
    y = regs.x.dx \ 8 ' divide by 8 - char height = 8
    b = regs.x.bx
    locate 1, 1
    print using "### ### //"; x, y, bin(b)
loop

' hide mouse
regs.x.ax = 2
__dpmi_int(MOUSE, @regs)

color 7, 0

cls
Quote:Not exactly a tutorial (you should be able to find billions of them, everybody seems to think he has the greatest mouse routine ever ), but here's a simple bit of code:

Who are you refering to?[/b]
Hey, kids! English lesson time! Smile 'Everybody' is singular; therefore, I couldn't say "Everybody thinks they have ...", but instead must use "Everybody thinks he has...", where 'he' refers to 'everybody' Smile In other words, everyone who writes a mouse handler thinks that the mouse handler he or she has written is uber-great etc. Big Grin

Does that code help you do what you want?
Pages: 1 2