Posts: 21
Threads: 6
Joined: Jul 2004
Code: DEFINT A-Z
DECLARE SUB mouse (cx, dx, bx)
DECLARE SUB MousePointer (SW)
DIM SHARED a(9) 'Set up array for code
DEF SEG = VARSEG(a(0)) 'Get array segment (nnnn: )
' (two 8 bit)
FOR i = 0 TO 17 'length of DATA to
READ r 'read
POKE VARPTR(a(0)) + i, r 'into array/2 (nnnn:iiii) (one 8 bit)
NEXT i 'until 17
'**************************** Machine Code *********************************
DATA &HB8,&H00,&H00 : ' mov AX,[n] [Swap code-(L),(H)] in AX
DATA &H55 : ' push BP Save BP
DATA &H8B,&HEC : ' mov BP,SP Get BP to c Seg
DATA &HCD,&H33 : ' int 33 Interrupt 33
DATA &H92 : ' xchg AX,[reg] [Swap code-reg] in AX
DATA &H8B,&H5E,&H06 : ' mov BX,[BP+6] Point to (variable)
DATA &H89,&H07 : ' mov [BX],AX Put AX in (variable)
DATA &H5D : ' pop BP Restore BP
DATA &HCA,&H02,&H00 : ' ret 2 Far return
SCREEN 13
'****************************** Mouse set up ******************************
CALL MousePointer(0) 'Reset mouse and
CALL MousePointer(1) 'turn pointer on
CALL MousePointer(3) 'Get coordinates
'****************************** P R O G R A M ******************************
DO 'Put your code here
CALL mouse(cx, dx, bx)
LOCATE 1, 1: PRINT dx; cx; bx 'Put code here
LINE (50, 50)-(80, 70), 15, B
IF bx = 1 THEN
IF dx > 50 AND dx < 80 THEN
IF cx > 50 AND cx < 70 THEN
LOCATE 2, 1: PRINT "You clicked in the box"
END IF
END IF
END IF
LOOP UNTIL INKEY$ = CHR$(27)
END
Alright I got a couple questions & problems with this code. First questions, how can I get the mouse to drag the box where I want to put it to go. Also after I run it, when I come back to QB's screen QB freezes up or gets messed up, how can I fix that?
Posts: 320
Threads: 9
Joined: Dec 2004
I assume that DATA gets run through CALL ABSOLUTE. Either way, it should be doing RETF, not RET. From past experiments, I know RET causes QB to crash.
Also, I think QB uses the same method as C for returning values from functions... which is to move the result into AX.
So in your code, the bottom two lines should change to:
[syntax="ASM"]
mov ax, 2
retf
[/syntax]
Machine code:
&HB8 &H02 &H00 (mov ax, 2)
&HCB (retf)
Hope this fixes at least the crashes... I can't test it because I can't run stuff like that here.
-shiftLynx
img]http://www.cdsoft.co.uk/misc/shiftlynx.png[/img]
Posts: 503
Threads: 31
Joined: Feb 2005
:o Your not seriously using that code for the mouse??!?!?!?!?
There's something called Call Interupt thats soo much simpler and no Hex code!
First off, on your command line (to start QB) after .exe put a /l (that's a L).
Code: '$INCLUDE:'QB.BI'
DIM inregs as RegType, outregs as RegType
inregs.ax = 0
CALL Interrupt (&H33, inregs, outregs)
'You need all of the above to start.
'To get mouse location:
inregs.ax = 3
CALL Interrupt (&H33, inregs, outregs)
MouseButton = outregs.bx 'Returns 0 for none, 1 for left click, 2 for right, 3 for both
MouseX = outregs.cx 'Returns the Xcoordinate, /2 for Screen 13
MouseY = outregs.dx 'Y coordinate
'To turn mouse on: (Do you can see the cursor)
inregs.ax = 1
Call Interrupt(&H33, inregs, outregs)
'To turn mouse off:
inregs.ax = 2
Call Interrupt (&H33, inregs, outregs)
'To Set mouse location:
inregs.ax = 4
inregs.cx = Xpos
inregs.dx = Ypos
Call Interrupt (&H33, inregs, outregs)
You can do more. Here's a Short but though tut:
Mouse Tut
This is really simpler than that stuff. And it works!
i]"But...it was so beautifully done"[/i]
Posts: 285
Threads: 70
Joined: Feb 2005
This is what I have been using for some time. I cannot remember where I found it or to be honest undestand fully how it works using QuickBasic.
Code: REM NOTE INVOKE WITH QUICKBASIC AS QB /l qb
DIM INARY%(7), OUTARY%(7)
CONST ax = 0, bx = 1, CX = 2, dx = 3, bp = 4, si = 5, DI = 6, FL = 7
SCREEN 9: LOCATE 10, 15
PRINT "Left click to display co-ordinates, right click to abort"
INARY%(ax) = 1: CALL INT86OLD(&H33, INARY%(), OUTARY%())
WHILE fin = 0
GOSUB MOUSE
WEND: END
MOUSE:
REM B = 0: WHILE B = 0
INARY%(ax) = 3
CALL INT86OLD(&H33, INARY%(), OUTARY%())
x = OUTARY%(CX): y = OUTARY%(dx): B = OUTARY%(bx)
IF B = 1 THEN CLS : LOCATE 10, 25: PRINT x, y
IF B = 2 THEN fin = 1
C = INT(H * 80 / 640) + 1: l = INT(V * 43 / 342) + 1
TIM = TIMER: WHILE TIMER < TIM + .1: WEND:
RETURN
fin:
INARY%(ax) = 2: CALL INT86OLD(&H33, INARY%(), OUTARY%())
END
Posts: 320
Threads: 9
Joined: Dec 2004
By the way, if you're interested, I wrote a mouse library in asm a while ago. The source code comes with it, so you can modify the lib if you want (assembled with masm).
More info: http://www.cdsoft.co.uk/libs_cdml.php
-shiftLynx
img]http://www.cdsoft.co.uk/misc/shiftlynx.png[/img]
Posts: 2,404
Threads: 153
Joined: Jan 2005
Quote:This is what I have been using for some time. I cannot remember where I found it or to be honest undestand fully how it works using QuickBasic.
Thats simple,. it works just the same as both Mitths a Gins... In QB4.5 INCLUDING 'QB.BI' you can access:
CALL Absolute
CALL Interupt
CALL Int86old
I was recently looking at the QB.BI's source for fun and found that all this went with it... pretty cool, heh heh... just the only diff is that they each take up different amounts of space.. :wink:
Kevin ( x.t.r.GRAPHICS)
Posts: 503
Threads: 31
Joined: Feb 2005
The int86old is one of the older functions...But It still works...I guess...
Do what you want but I think that my way is the simplest.
i]"But...it was so beautifully done"[/i]
Posts: 320
Threads: 9
Joined: Dec 2004
What is more simple than this?
[syntax="QBASIC"]
'$INCLUDE: 'CDML.BI'
CDML.ShowMouse
[/syntax]
-shiftLynx
img]http://www.cdsoft.co.uk/misc/shiftlynx.png[/img]
Posts: 285
Threads: 70
Joined: Feb 2005
Purely for interest, this is how I how I use the Altquick Library. Dunno if it would ever work under FB
Code: REM NOTE INVOKE WITH QUICKBASIC AS QB /l altquick
DECLARE FUNCTION MouseInit% ()
DECLARE SUB MouseHide ()
DECLARE SUB MouseNow (leftButton%, rightButton%, xMouse%, yMouse%)
DECLARE SUB MouseShow ()
SCREEN 9: LOCATE 10, 15: MouseShow
PRINT "Left click to display co-ordinates, right click to abort"
WHILE fin = 0
GOSUB MOUSE
WEND
MouseHide
END
MOUSE:
MouseNow leftButton%, rightButton%, xMouse%, yMouse%
x = xMouse%: y = yMouse%
IF leftButton% THEN CLS : LOCATE 10, 25: PRINT x, y
IF rightButton% THEN fin = 1
TIM = TIMER: WHILE TIMER < TIM + .1: WEND
RETURN
|