home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / Dloads / PROGRAMM / MOUSE10.ZIP / MOUSE10.BAS next >
BASIC Source File  |  1992-06-06  |  10KB  |  418 lines

  1. 'MOUSE.BAS, demonstrates the various mouse services
  2.  
  3. 'Copyright (c) 1992 by Seth Leonard
  4.  
  5.  
  6. DEFINT A-Z
  7.  
  8. '---- assembly language functions and subroutines
  9. DECLARE FUNCTION PeekWord% (BYVAL Segment, BYVAL Address)
  10. DECLARE SUB MouseInt (MouseRegs AS ANY)
  11.  
  12.  
  13. '---- BASIC functions and subprograms
  14. DECLARE FUNCTION Bin2Hex% (Binary$)
  15. DECLARE FUNCTION MouseThere% ()
  16. DECLARE FUNCTION WaitButton% ()
  17. DECLARE SUB CursorShape (HotX, HotY, Shape())
  18. DECLARE SUB HideCursor ()
  19. DECLARE SUB MouseTrap (ULRow, ULCol, LRRow, LRCol)
  20. DECLARE SUB MoveCursor (X, Y)
  21. DECLARE SUB ReadCursor (X, Y, Buttons)
  22. DECLARE SUB ShowCursor ()
  23. DECLARE SUB TextCursor (FG, BG)
  24.  
  25. DECLARE SUB Prompt (Message$)   'used for this demo only
  26.  
  27.  
  28. TYPE MouseType                  'similar to DOS Registers
  29.   AX      AS INTEGER
  30.   BX      AS INTEGER
  31.   CX      AS INTEGER
  32.   DX      AS INTEGER
  33.   Segment AS INTEGER
  34. END TYPE
  35.  
  36. DIM SHARED MouseRegs AS MouseType 'so all the subs can get at them
  37. DIM SHARED MousePresent
  38. REDIM Cursor(1 TO 32)           'holds the cursor shape definition
  39.  
  40. IF NOT MouseThere% THEN         'ensure that a mouse is present
  41.   PRINT "No mouse is installed" '  and initialize it if so
  42.   END
  43. END IF
  44. CLS
  45.  
  46.  
  47. DEF SEG = 0                     'see what type of monitor
  48. IF PEEK(&H463) <> &HB4 THEN     'if it's color
  49.   ColorMon = -1                 'remember that for later
  50.   SCREEN 12                     'this requires a VGA
  51.   LINE (0, 0)-(639, 460), 1, BF 'paint a blue background
  52. END IF
  53.  
  54.  
  55. DIM Choice$(1 TO 5)             'display some choices on the screen,
  56. LOCATE 1, 1                     '  so we'll have something to point at
  57. FOR X = 1 TO 5
  58.   READ Choice$(X)
  59.   PRINT Choice$(X);
  60.   LOCATE , X * 12
  61. NEXT
  62. DATA "Choice 1", "Choice 2", "Choice 3", "Choice 4", "Choice 5"
  63.  
  64.  
  65. IF NOT ColorMon THEN            'if it's not color
  66.   CALL TextCursor(-2, -2)       'select a text cursor
  67. END IF
  68.  
  69.  
  70. CALL ShowCursor
  71. CALL Prompt("Point the cursor at a choice, and press a button.")
  72.  
  73.  
  74. DO                              'wait for a button press
  75.   CALL ReadCursor(X, Y, Button)
  76. LOOP UNTIL Button
  77. IF Button AND 4 THEN Button = 3 'for three-button mice
  78.  
  79. CALL Prompt("You pressed button" + STR$(Button) + " and the cursor was at location" + STR$(X) + "," + STR$(Y) + " - press a button.")
  80.  
  81. IF ColorMon THEN                'if it is a color monitor
  82.   RESTORE Arrow                 '  load a custom arrow
  83.   GOSUB DefineCursor
  84. END IF
  85. Dummy = WaitButton%
  86.  
  87.  
  88.  
  89. IF ColorMon THEN                'the hardware can do it
  90.   RESTORE CrossHairs            'set a cross-hairs cursor
  91.   GOSUB DefineCursor
  92.   CALL Prompt("Now the cursor is a cross-hairs, press a button.")
  93.   Dummy% = WaitButton%
  94. END IF
  95.  
  96.  
  97.  
  98. IF ColorMon THEN                'now set an hour glass
  99.   RESTORE HourGlass
  100.   GOSUB DefineCursor
  101. END IF
  102.  
  103.  
  104. CALL Prompt("Now notice how the cursor range is restricted.  Press a button to end.")
  105. CALL MouseTrap(50, 50, 100, 100)
  106. Dummy = WaitButton%
  107.  
  108. IF ColorMon THEN                'restore to 640 x 350
  109.   CALL MouseTrap(0, 0, 349, 639)
  110. ELSE                            'use CGA coordinates for mono!
  111.   CALL MouseTrap(0, 0, 199, 639)
  112. END IF
  113.  
  114. Dummy = InitMouse%              'reset the mouse driver
  115. CALL HideCursor                 'and turn off the cursor
  116. SCREEN 0                        'revert to text mode
  117. END
  118.  
  119.  
  120.  
  121. DefineCursor:
  122.  
  123. FOR X = 1 TO 32                 'read 32 words of data
  124.   READ Dat$                     'read the data
  125.   Cursor(X) = Bin2Hex%(Dat$)    'convert to integer
  126. NEXT
  127. CALL CursorShape(Zero, Zero, Cursor())
  128. RETURN
  129.  
  130.  
  131.  
  132. Arrow:
  133.  
  134. NOTES:
  135. 'The first group of binary data is the screen mask.
  136. 'The second group of binary data is the cursor mask.
  137. 'The cursor color is black where both masks are 0.
  138. 'The cursor color is XORed where both masks are 1.
  139. 'The color is clear where the screen mask is 1 and the cursor mask is 0.
  140. 'The color is white where the screen mask is 0 and the cursor mask is 1.
  141. '
  142. '--- this is the screen mask
  143. DATA "1110011111111111"
  144. DATA "1110001111111111"
  145. DATA "1110000111111111"
  146. DATA "1110000011111111"
  147. DATA "1110000001111111"
  148. DATA "1110000000111111"
  149. DATA "1110000000011111"
  150. DATA "1110000000001111"
  151. DATA "1110000000000111"
  152. DATA "1110000000000011"
  153. DATA "1110000000000001"
  154. DATA "1110000000011111"
  155. DATA "1110001000011111"
  156. DATA "1111111100001111"
  157. DATA "1111111100001111"
  158. DATA "1111111110001111"
  159.  
  160. '---- this is the cursor mask
  161. DATA "0001100000000000"
  162. DATA "0001010000000000"
  163. DATA "0001001000000000"
  164. DATA "0001000100000000"
  165. DATA "0001000010000000"
  166. DATA "0001000001000000"
  167. DATA "0001000000100000"
  168. DATA "0001000000010000"
  169. DATA "0001000000001000"
  170. DATA "0001000000000100"
  171. DATA "0001000000111110"
  172. DATA "0001001100100000"
  173. DATA "0001110100100000"
  174. DATA "0000000010010000"
  175. DATA "0000000010010000"
  176. DATA "0000000001110000"
  177.  
  178.  
  179.  
  180. CrossHairs:
  181.  
  182. DATA "1111111101111111"
  183. DATA "1111111101111111"
  184. DATA "1111111101111111"
  185. DATA "1111000000000111"
  186. DATA "1111011101110111"
  187. DATA "1111011101110111"
  188. DATA "1111011111110111"
  189. DATA "1000000111000000"
  190. DATA "1111011111110111"
  191. DATA "1111011101110111"
  192. DATA "1111011101110111"
  193. DATA "1111000000000111"
  194. DATA "1111111101111111"
  195. DATA "1111111101111111"
  196. DATA "1111111101111111"
  197. DATA "1111111111111111"
  198.  
  199. DATA "0000000010000000"
  200. DATA "0000000010000000"
  201. DATA "0000000010000000"
  202. DATA "0000111111111000"
  203. DATA "0000100010001000"
  204. DATA "0000100010001000"
  205. DATA "0000100000001000"
  206. DATA "0111111000111111"
  207. DATA "0000100000001000"
  208. DATA "0000100010001000"
  209. DATA "0000100010001000"
  210. DATA "0000111111111000"
  211. DATA "0000000010000000"
  212. DATA "0000000010000000"
  213. DATA "0000000010000000"
  214. DATA "0000000000000000"
  215.  
  216.  
  217.  
  218. HourGlass:
  219.  
  220. DATA "1100000000000111"
  221. DATA "1100000000000111"
  222. DATA "1100000000000111"
  223. DATA "1110000000001111"
  224. DATA "1110000000001111"
  225. DATA "1111000000011111"
  226. DATA "1111100000111111"
  227. DATA "1111110001111111"
  228. DATA "1111110001111111"
  229. DATA "1111100000111111"
  230. DATA "1111000000011111"
  231. DATA "1110000000001111"
  232. DATA "1110000000001111"
  233. DATA "1100000000000111"
  234. DATA "1100000000000111"
  235. DATA "1100000000000111"
  236.  
  237. DATA "0000000000000000"
  238. DATA "0001111111110000"
  239. DATA "0000000000000000"
  240. DATA "0000111111100000"
  241. DATA "0000100110100000"
  242. DATA "0000010001000000"
  243. DATA "0000001010000000"
  244. DATA "0000000100000000"
  245. DATA "0000000100000000"
  246. DATA "0000001010000000"
  247. DATA "0000011111000000"
  248. DATA "0000110001100000"
  249. DATA "0000100000100000"
  250. DATA "0000000000000000"
  251. DATA "0001111111110000"
  252. DATA "0000000000000000"
  253.  
  254. FUNCTION Bin2Hex% (Binary$) STATIC  'binary to integer
  255.  
  256.   Temp& = 0
  257.   Count = 0
  258.  
  259.   FOR X = LEN(Binary$) TO 1 STEP -1
  260.     IF MID$(Binary$, X, 1) = "1" THEN
  261.       Temp& = Temp& + 2 ^ Count
  262.     END IF
  263.     Count = Count + 1
  264.   NEXT
  265.  
  266.   IF Temp& > 32767 THEN Temp& = Temp& - 65536
  267.   Bin2Hex% = Temp&
  268.  
  269. END FUNCTION
  270.  
  271. SUB CursorShape (HotX, HotY, Shape()) STATIC
  272.  
  273.   IF NOT MousePresent THEN EXIT SUB
  274.  
  275.   MouseRegs.AX = 9
  276.   MouseRegs.BX = HotX
  277.   MouseRegs.CX = HotY
  278.   MouseRegs.DX = VARPTR(Shape(1))
  279.   MouseRegs.Segment = VARSEG(Shape(1))
  280.  
  281.   CALL MouseInt(MouseRegs)
  282.  
  283. END SUB
  284.  
  285. SUB HideCursor STATIC       'turns off the mouse cursor
  286.  
  287.   IF NOT MousePresent THEN EXIT SUB
  288.  
  289.   MouseRegs.AX = 2
  290.   CALL MouseInt(MouseRegs)
  291.  
  292. END SUB
  293.  
  294. FUNCTION MouseThere% STATIC     'reports if a mouse is present
  295.  
  296.   MouseThere% = 0               'assume there is no mouse
  297.   IF PeekWord%(Zero, (4 * &H33) + 2) = 0 THEN 'if segment = 0
  298.     EXIT FUNCTION                             '  then there's no mouse
  299.   END IF
  300.  
  301.   MouseRegs.AX = 0
  302.   CALL MouseInt(MouseRegs)
  303.   MouseThere% = MouseRegs.AX
  304.   IF MouseRegs.AX THEN MousePresent = -1
  305.  
  306. END FUNCTION
  307.  
  308. SUB MouseTrap (ULRow, ULColumn, LRRow, LRColumn) STATIC
  309.  
  310.   IF NOT MousePresent THEN EXIT SUB
  311.  
  312.   MouseRegs.AX = 7      'restrict horizontal movement
  313.   MouseRegs.CX = ULColumn
  314.   MouseRegs.DX = LRColumn
  315.   CALL MouseInt(MouseRegs)
  316.  
  317.   MouseRegs.AX = 8      'restrict vertical movement
  318.   MouseRegs.CX = ULRow
  319.   MouseRegs.DX = LRRow
  320.   CALL MouseInt(MouseRegs)
  321.  
  322. END SUB
  323.  
  324. SUB MoveCursor (X, Y) STATIC    'positions the mouse cursor
  325.  
  326.   IF NOT MousePresent THEN EXIT SUB
  327.  
  328.   MouseRegs.AX = 4
  329.   MouseRegs.CX = X
  330.   MouseRegs.DX = Y
  331.   CALL MouseInt(MouseRegs)
  332.  
  333. END SUB
  334.  
  335. SUB Prompt (Message$) STATIC    'prints prompt message
  336.  
  337.     V = CSRLIN                  'save current cursor position
  338.     H = POS(0)
  339.     LOCATE 30, 1                'use 25 for SCREEN 9
  340.     CALL HideCursor             'this is very important!
  341.     PRINT LEFT$(Message$, 79); TAB(80);
  342.     CALL ShowCursor             'and so is this
  343.     LOCATE V, H                 'restore the cursor
  344.  
  345. END SUB
  346.  
  347. SUB ReadCursor (X, Y, Buttons)  'returns cursor and button information
  348.  
  349.   IF NOT MousePresent THEN EXIT SUB
  350.  
  351.   MouseRegs.AX = 3
  352.   CALL MouseInt(MouseRegs)
  353.  
  354.   Buttons = MouseRegs.BX AND 7
  355.   X = MouseRegs.CX
  356.   Y = MouseRegs.DX
  357.  
  358. END SUB
  359.  
  360. SUB ShowCursor STATIC           'turns on the mouse cursor
  361.  
  362.   IF NOT MousePresent THEN EXIT SUB
  363.  
  364.   MouseRegs.AX = 1
  365.   CALL MouseInt(MouseRegs)
  366.  
  367. END SUB
  368.  
  369. SUB TextCursor (FG, BG) STATIC
  370.  
  371.   IF NOT MousePresent THEN EXIT SUB
  372.  
  373.   MouseRegs.AX = 10
  374.   MouseRegs.BX = 0
  375.   MouseRegs.CX = &HFF
  376.   MouseRegs.DX = 0
  377.  
  378.   IF FG = -1 THEN                       'maintain FG as the cursor moves?
  379.     MouseRegs.CX = MouseRegs.CX OR &HF00
  380.   ELSEIF FG = -2 THEN                   'invert FG as the cursor moves?
  381.     MouseRegs.CX = MouseRegs.CX OR &H700
  382.     MouseRegs.DX = &H700
  383.   ELSE
  384.     MouseRegs.DX = 256 * (FG AND &HFF)  'use the specified color
  385.   END IF
  386.  
  387.   IF BG = -1 THEN                       'maintain BG as the cursor moves?
  388.     MouseRegs.CX = MouseRegs.CX OR &HF000
  389.   ELSEIF BG = -2 THEN                   'invert BG as the cursor moves?
  390.     MouseRegs.CX = MouseRegs.CX OR &H7000
  391.     MouseRegs.DX = MouseRegs.DX OR &H7000
  392.   ELSE
  393.     Temp = (BG AND 7) * 16 * 256
  394.     MouseRegs.DX = MouseRegs.DX OR Temp 'use the specified color
  395.   END IF
  396.  
  397.   CALL MouseInt(MouseRegs)
  398.  
  399. END SUB
  400.  
  401. FUNCTION WaitButton% STATIC     'waits for a button press
  402.  
  403.   IF NOT MousePresent THEN EXIT FUNCTION
  404.  
  405.   X! = TIMER                    'pause to allow releasing
  406.   WHILE X! + .2 > TIMER         '  the button
  407.   WEND
  408.  
  409.   DO                            'wait for a button press
  410.     CALL ReadCursor(X, Y, Button)
  411.   LOOP UNTIL Button
  412.  
  413.   IF Button AND 4 THEN Button = 3 'for three-button mice
  414.   WaitButton% = Button            'assign the function
  415.  
  416. END FUNCTION
  417.  
  418.