Qbasicnews.com

Full Version: A new idea for the mouse...
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Has anyone noticed the problem I have with some of the QBasic GUI's like X-GUI? With the mouse, all the colors warp? Well, last night I thought of a great idea that actually worked, and this should work on ALL computers that support HIGH RESOLUTION (which is what causes that) 256-color graphics and a mouse: initialize the mouse but hide it. Then draw a custom mouse-pointer where the mouse coordinates are:

Code:
pset(mousex, mousey), mousecolor

Or whatever. I did it in Pascal, using a unit that lets me do high resolution 256-color graphics, and it just so happened that I had that same trouble, so I fixed it. The unit even had a pset statement instead of the Pascal "standard" putpixel... Anyhow, I hope this helps some of you with those troubles...
Hrmm, I already did that ages ago, but with another principle:
  • 1. Init mouse
    2. Hide the mouse
    3. Set mouse range to (0, 0)-(0, 0)
    4. Show mouse
    5. GET (0, 0) - (15, 15), YourSprite
    6. Hide the mouse
    7. Set mouse range to (0, 0) - (maxX, maxY)
    8. PUT (MouseX, MouseY), YourSprite, PSET

Wink
what i just do, i just draw my own mouse cursor. then i draw it on the buffer at relmousex, remousey. looks nicer, no flickering, etc. etc.
I've been doing that for a while also. It does work alot better...imho Big Grin

I hate the default cursor with a passion anyway! :evil:
I know, but I can't get the mouse to work in High-resolution 256-color graphics, and I hate screen 13h with a passion cuz it's so low resolution. And I don't like the default mouse cursor either :evil:

Thats why. Otherwise, I'd just as soon use the "normal" method. Also, I don't do QBasic much; I can never figure out the InterruptX stuff so I mostly stick to Pascal and Assembly, but there are programmers more experienced than I am here, even those who don't necessarily use QBasic (and I do use it once in a while) so I figure it's OK to come here. I like helping people too. And there isn't much of a community for Pascal or Assembly, at least not anything worth mentioning Sad

:bounce: :rotfl: :bounce: :rotfl: :bounce: :rotfl: :bounce:
I wrote some codes for mouse using the functions of the Microsoft mouse driver 1.0 (Int33), and that works nicely for me (and it can hide the cursor). I can copy / paste it here, it is not too big. You will need the basic library (to call interrupts), but my code has not got anything other like ASM. It is just QBasic.
Hello World! Wink

Quote:I wrote some codes for mouse using the functions of the Microsoft mouse driver 1.0 (Int33), and that works nicely for me (and it can hide the cursor). I can copy / paste it here, it is not too big. You will need the basic library (to call interrupts), but my code has not got anything other like ASM. It is just QBasic.
Sure, post it here! :bounce: I would like to see how to show the mouse with qb.qlb... I never use the basic library, because I know almost nothing about the interrupts and assembly.
First of all, a few words on interrupts.

Interrupts are small programs set up by the BIOS or some other stay - resident programs. They are somewhere in the memory, so somewhere it is needed to save their position so that they can be called. The first 1 Kb of the conventional memory is for serving this: it stores 4 byte segment:offset values where these programs start. This is called interrupt vector table.
When a program is called it usually needs some input values to work with, and some output values what the caller can process later. This is served through the CPU's built - in memory: the registers.
Calling an interrupt has two steps: first setting the registers to the values needed by the program, then calling the interrupt (what only means jumping to the start offset of it in the memory). After the program finishes it's work, it usually return values in certain registers what can be processed by ours.

QBasic can do all of this safely with it's basic library, it may be only needed to include the "qb.bi" file to have the type declarations of registers and the declaration of the interrupt calling subs.

So here is that little mouse program what can use all of the features included in the Microsoft mouse driver 1.0:

Code:
DEFINT A-Z

'$INCLUDE: 'qb.bi'

DECLARE FUNCTION initmouse () 'Returns 1 if mouse is connected
DECLARE SUB showcursor () 'Shows built in cursor
DECLARE SUB hidecursor () 'Hides built in cursor
DECLARE FUNCTION getbutton1 () 'Returns 1 if left button is down
DECLARE FUNCTION getbutton2 () 'Returns 1 if right button is down
DECLARE FUNCTION getx () 'Gets mouse X position
DECLARE FUNCTION gety () 'Gets mouse Y position
DECLARE SUB poscursor (x AS INTEGER, y AS INTEGER) 'Positions cursor
DECLARE SUB limitcursor (xmin AS INTEGER, xmax AS INTEGER, ymin AS INTEGER, ymax AS INTEGER)
  'Limits cursor movement



SCREEN 9

PRINT initmouse
IF initmouse = 0 THEN SYSTEM
showcursor
a$ = ""
DO
LOCATE 1, 1
PRINT getbutton1
PRINT getbutton2
PRINT getx
PRINT gety
a$ = INKEY$
LOOP UNTIL a$ = CHR$(27)
hidecursor


FUNCTION getbutton1
DIM regs AS regtype
regs.ax = &H3
CALL INTERRUPT(&H33, regs, regs)
IF (regs.bx AND 1) = 1 THEN getbutton1 = 1 ELSE getbutton1 = 0
END FUNCTION

FUNCTION getbutton2
DIM regs AS regtype
regs.ax = &H3
CALL INTERRUPT(&H33, regs, regs)
IF (regs.bx AND 2) = 2 THEN getbutton2 = 1 ELSE getbutton2 = 0
END FUNCTION

FUNCTION getx
DIM regs AS regtype
regs.ax = &H3
CALL INTERRUPT(&H33, regs, regs)
getx = regs.cx
END FUNCTION

FUNCTION gety
DIM regs AS regtype
regs.ax = &H3
CALL INTERRUPT(&H33, regs, regs)
gety = regs.dx
END FUNCTION

SUB hidecursor
DIM regs AS regtype
regs.ax = &H2
CALL INTERRUPT(&H33, regs, regs)
END SUB

FUNCTION initmouse
DIM regs AS regtype
DEF SEG = &H0
a = 0
FOR i = 0 TO 3
  a = a + PEEK(&H33 * 4 + i)
NEXT i
DEF SEG
IF a > 0 THEN
  regs.ax = &H0
  CALL INTERRUPT(&H33, regs, regs)
  IF regs.ax = &HFFFF THEN initmouse = 1 ELSE initmouse = 0
ELSE
  initmouse = 0
END IF
END FUNCTION

SUB limitcursor (xmin AS INTEGER, xmax AS INTEGER, ymin AS INTEGER, ymax AS INTEGER)
DIM regs AS regtype
regs.ax = &H7
regs.cx = xmin
regs.dx = xmax
CALL INTERRUPT(&H33, regs, regs)
regs.ax = &H8
regs.cx = ymin
regs.dx = ymax
CALL INTERRUPT(&H33, regs, regs)
END SUB

SUB poscursor (x AS INTEGER, y AS INTEGER)
DIM regs AS regtype
regs.ax = &H4
regs.cx = x
regs.dx = y
CALL INTERRUPT(&H33, regs, regs)
END SUB

SUB showcursor
DIM regs AS regtype
regs.ax = &H1
CALL INTERRUPT(&H33, regs, regs)
END SUB

You can see here that all functions start with setting certain registers to the needed values (to select which function of the driver want we to use), then calling the interrupt, and finally processing the returned values.

In Initmouse the program first checks if there is something at the memory location of interrupt 33 because if not, calling it will jump to the start of the memory (0000:0000) what results freezing.
For the mouse PSET thing, you may want to XOR the colour:

Code:
DO

MouseDriver 3,b,x,y
c% = POINT(x, y)

'Draw Mouse Location
PSET (x, y), (c% XOR 7) + 1      'I personally like the colour '7' for the PSET

{Your jibberish}

'Erase Mouse
PSET (x, y), c%
LOOP

Alex~