home *** CD-ROM | disk | FTP | other *** search
/ RUN Flagazine: Run 16 / unpacked-run16.zip / PBVOORB.BAS < prev    next >
BASIC Source File  |  1995-01-01  |  10KB  |  341 lines

  1. '┌─────────────────────────────────────────────────────────────────────────┐
  2. '│ Voorbeeld programma bij MC. Dit programma is geschreven in Power Basic. │
  3. '└─────────────────────────────────────────────────────────────────────────┘
  4.  
  5. ''''''''''''''''''''''''''''''''''''''''''''''''''''''
  6. ' Het volgende stukje data wordt gegenereerd door MC '
  7. ' wanneer u kiest voor opslag als Power Basic.       '
  8. ' Het bevat alle informatie van zowel de screenmap   '
  9. ' als de cursormap. De laatste twee DATA statements  '
  10. ' zijn de coordinaten van de Hot-Spot.               '
  11. '                                                    '
  12. ''''''''''''''''''''''''''''''''''''''''''''''''''''''
  13.  
  14. DATA  16383,  8191,  4095,  2047,  1023,   511,   255,   127
  15. DATA  65535, 40129, 34945, 32769, 32799, 32769, 34945, 35009
  16. DATA      0, 16384, 24576, 28672, 30720, 31744, 32256,     0
  17. DATA      0,     0,  8764, 13888, 10816,  8768,  8764,     0
  18. DATA      0,     0
  19.  
  20. '''''''''''''''''''''''''''''
  21. ' Dimensioneer de muistabel '
  22. '                           '
  23. '''''''''''''''''''''''''''''
  24. DIM CurTab(32) as Shared Word
  25.  
  26. '''''''''''''''''''''''''''''''''''''''''''''
  27. ' Bepaal segment en offset van de muistabel '
  28. '                                           '
  29. '''''''''''''''''''''''''''''''''''''''''''''
  30. DIM Dxa as Shared Word           : Dxa=VarPtr(CurTab(1))
  31. DIM Esa as Shared Word           : Esa=VarSeg(CurTab(1))
  32.  
  33. ''''''''''''''''''''''''''''
  34. ' Dimensioneer de Hot-Spot '
  35. '                          '
  36. ''''''''''''''''''''''''''''
  37. DIM HsVer as Shared Word         : HsVer=0
  38. DIM HsHor as Shared Word         : HsHor=0
  39.  
  40. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  41. ' Kijk of de gebruiker met de muis een vlak aanklikt.  '
  42. ' Als dat zo is, wachten tot de knop wordt losgelaten  '
  43. ' en controleren of de muis zich nog steeds binnen     '
  44. ' het vlak bevindt.                                    '
  45. '                                                      '
  46. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  47. Function SquareClicked(x1, y1, x2, y2)
  48.   Ant=-1
  49.   Mx=MouseX
  50.   My=MouseY
  51.   If ((MX>=x1) and (MX<=x2) and (MY>=y1) and (MY<=y2)) then
  52.      If ((LeftButtonPressed) or (RightButtonPressed)) then
  53.        If LeftButtonPressed Then While LeftButtonPressed:Wend
  54.        If RightButtonPressed Then While RightButtonPressed:Wend
  55.        Mx=MouseX
  56.        My=MouseY
  57.        If ((MX>=x1) and (MX<=x2) and (MY>=y1) and (MY<=y2)) then Ant=1
  58.      End If
  59.   End If
  60.   SquareClicked=Ant
  61. End Function
  62.  
  63. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  64. ' Kijk of de gebruiker met de muis een vlak aanklikt.  '
  65. ' Deze functie reageert direkt in tegenstelling tot    '
  66. ' de vorige.                                           '
  67. '                                                      '
  68. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  69. Function SquareClickedNoWait(x1, y1, x2, y2)
  70.   Ant=-1
  71.   Mx=MouseX
  72.   My=MouseY
  73.   If ((MX>=x1) and (MX<=x2) and (MY>=y1) and (MY<=y2)) then
  74.      If ((LeftButtonPressed) or (RightButtonPressed)) then Ant=1
  75.   End If
  76.   SquareClickedNoWait=Ant
  77. End Function
  78.  
  79. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  80. ' Initialiseer de muis. Geeft een 1 terug als de initialisatie '
  81. ' succesvol is verlopen.                                       '
  82. '                                                              '
  83. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  84. Function InitMouse!
  85.   ! push ds
  86.   ! mov  ax,0
  87.   ! int  &H33
  88.   ! mov  state,ax
  89.   ! pop  ds
  90.   If (state=-1) then
  91.     InitMouse=0
  92.     Else
  93.       InitMouse=1
  94.   End if
  95. End Function
  96.  
  97. ''''''''''''''''''''''
  98. ' Toon de muiscursor '
  99. '                    '
  100. ''''''''''''''''''''''
  101. Sub ShowMouse
  102.   ! push ds
  103.   ! mov  ax, 1
  104.   ! int  &H33
  105.   ! pop  ds
  106. End Sub
  107.  
  108. '''''''''''''''''''''''''
  109. ' Verberg de muiscursor '
  110. '                       '
  111. '''''''''''''''''''''''''
  112. Sub HideMouse
  113.   ! push ds
  114.   ! mov  ax,2
  115.   ! int  &H33
  116.   ! pop  ds
  117. End Sub
  118.  
  119. ''''''''''''''''''''''''''''''''''''''''''''''''''''''
  120. ' Retourneert 1 als de linker muistoets werd gedrukt '
  121. '                                                    '
  122. ''''''''''''''''''''''''''''''''''''''''''''''''''''''
  123. Function LeftButtonPressed!
  124. Dim LeftButStat As Local Word
  125.   ! push ds
  126.   ! mov  ax,3
  127.   ! mov  bx,0
  128.   ! int  &H33
  129.   ! mov  LeftButStat,bx
  130.   ! pop  ds
  131.   Select Case LeftButStat
  132.     Case 1,3,5,7
  133.       LeftButtonPressed=1
  134.     Case Else
  135.       LeftButtonPressed=0
  136.   End Select
  137. End Function
  138.  
  139. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  140. ' Retourneert 1 als de middelste muistoets werd gedrukt '
  141. '                                                       '
  142. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  143. Function MidButtonPressed!
  144. Dim MidButStat as Local Word
  145.   ! push ds
  146.   ! mov  ax,3
  147.   ! mov  bx,2
  148.   ! int  &H33
  149.   ! mov  MidButStat,bx
  150.   ! pop  ds
  151.   Select Case MidButStat
  152.     Case 4,5,6,7
  153.       MidButtonPressed=1
  154.     Case Else
  155.       MidButtonPressed=0
  156.   End Select
  157. End Function
  158.  
  159. '''''''''''''''''''''''''''''''''''''''''''''''''''''''
  160. ' Retourneert 1 als de rechter muistoets werd gedrukt '
  161. '                                                     '
  162. '''''''''''''''''''''''''''''''''''''''''''''''''''''''
  163. Function RightButtonPressed!
  164. Dim RightButStat as Local Word
  165.   ! push ds
  166.   ! mov  ax,3
  167.   ! mov  bx,1
  168.   ! int  &H33
  169.   ! mov  RightButStat,bx
  170.   ! pop  ds
  171.   Select Case RightButStat
  172.     Case 2,3,6,7
  173.       RightButtonPressed=1
  174.     Case Else
  175.       RightButtonPressed=0
  176.   End Select
  177. End Function
  178.  
  179. '''''''''''''''''''''''''''''''''''''''''''''''
  180. ' Geef de huidige x-positie van de muis terug '
  181. '                                             '
  182. '''''''''''''''''''''''''''''''''''''''''''''''
  183. Function MouseX!
  184. Dim x as Local Integer
  185.    ! push ds
  186.    ! mov  ax, 3
  187.    ! mov  bx, 0
  188.    ! int  &H33
  189.    ! mov  x, cx
  190.    ! pop  ds
  191.   MouseX=x
  192. End Function
  193.  
  194. '''''''''''''''''''''''''''''''''''''''''''''''
  195. ' Geef de huidige y-positie van de muis terug '
  196. '                                             '
  197. '''''''''''''''''''''''''''''''''''''''''''''''
  198. Function MouseY!
  199. Dim y as Local Integer
  200.    ! push ds
  201.    ! mov  ax, 3
  202.    ! mov  bx, 0
  203.    ! int  &H33
  204.    ! mov  y, dx
  205.    ! pop  ds
  206.   MouseY=y
  207. End Function
  208.  
  209. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  210. ' Bepaal horizontaal interval waarbinnen de muis mag bewegen '
  211. '                                                            '
  212. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  213. Sub MouseSetX(x1,x2 as word)
  214.   Dim Xmin as Word
  215.   Dim Xmax as Word
  216.   Xmin=x1
  217.   Xmax=x2
  218.   ! push ds
  219.   ! mov  ax,7
  220.   ! mov  cx,Xmin
  221.   ! mov  dx,Xmax
  222.   ! int  &H33
  223.   ! pop  ds
  224. End Sub
  225.  
  226. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  227. ' Bepaal vertikaal interval waarbinnen de muis mag bewegen '
  228. '                                                          '
  229. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  230. Sub MouseSetY(y1,y2 as word)
  231.   Dim Ymin as Word
  232.   Dim Ymax as Word
  233.   Ymin=y1
  234.   Ymax=y2
  235.   ! push ds
  236.   ! mov  ax,8
  237.   ! mov  cx,Ymin
  238.   ! mov  dx,Ymax
  239.   ! int  &H33
  240.   ! pop  ds
  241. End Sub
  242.  
  243. '''''''''''''''''''''''''''''''
  244. ' Plaats de muiscursor op x,y '
  245. '                             '
  246. '''''''''''''''''''''''''''''''
  247. Sub MouseXy(x,y as Word)
  248.   Dim Mx as Word
  249.   Dim My as Word
  250.   ! push ds
  251.   ! mov  ax,4
  252.   ! mov  cx,Mx
  253.   ! mov  dx,My
  254.   ! int  &H33
  255.   ! pop  ds
  256. End Sub
  257.  
  258. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  259. ' Definieer een venster waarbinnen de muis mag opereren '
  260. '                                                       '
  261. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  262. Sub MouseWindow(x1, y1, x2, y2)
  263.   ! push ds
  264.   ! mov  ax, &H7
  265.   ! mov  cx, x1
  266.   ! mov  dx, x2
  267.   ! int  &h33
  268.   ! mov  ax, &H8
  269.   ! mov  cx, y1
  270.   ! mov  dx, y2
  271.   ! int  &h33
  272.   ! pop  ds
  273. End Sub
  274.  
  275. ''''''''''''''''''''''''''''''''
  276. ' Laad de grafische muiscursor '
  277. '                              '
  278. ''''''''''''''''''''''''''''''''
  279. Sub MouseLoadCursor
  280.   ! push ds
  281.   ! mov  bx, HsVer
  282.   ! mov  cx, HsHor
  283.   ! mov  ax, ESa
  284.   ! mov  es, ax
  285.   ! mov  ax, DXa
  286.   ! mov  dx, ax
  287.   ! mov  ax, 9
  288.   ! int  &H33
  289.   ! pop ds
  290. End Sub
  291.  
  292. ''''''''''''''''''''''''''''''''''''''''''''''''''
  293. ' Lees de grafische muiscursor en de hot-spot in '
  294. '                                                '
  295. ''''''''''''''''''''''''''''''''''''''''''''''''''
  296. Sub ReadMouseCursor
  297.   Restore
  298.   For Teller=1 To 32
  299.     Read CurTab(Teller)
  300.   Next Teller
  301.   Read HsHor
  302.   Read HsVer
  303. End Sub
  304.  
  305. '''''''''''''''''''''''''''''''''''
  306. '   H O O F D P R O G R A M M A   '
  307. '                                 '
  308. '''''''''''''''''''''''''''''''''''
  309. Cls
  310. If InitMouse=1 Then
  311.   Screen 9,,0,0                                 ' EGA 640*350 kleurenmodus
  312.   Kleur=1                                       ' Teken een kleurig
  313.   For Teller=1 to 640 Step 40                   ' scherm
  314.     Line(Teller,1)-(Teller+39,350),Kleur,BF
  315.     Kleur=Kleur+1
  316.   Next Teller
  317.   Color 15                                      ' Tekenkleur is 15
  318.   Locate 10,25
  319.   Print "Rechter muisknop = Einde"
  320.   Call ReadMouseCursor                          ' Inlezen DATA
  321.   Call MouseLoadCursor                          ' Laad de muiscursor
  322.   ShowMouse                                     ' Toon de muiscursor
  323.   Do
  324.     If LeftButtonPressed=1 Then                 ' Linker muistoets?
  325.       HideMouse                                 ' Verberg de muis
  326.       While LeftButtonPressed=1
  327.         x=MouseX                                ' Lees x en y van de muis
  328.         y=MouseY
  329.         Kleur=Int(14*Rnd)+1
  330.         Gr=Int(10*Rnd)+1
  331.         Line(x-Gr,y-Gr)-(x+Gr,y+Gr),Kleur,BF    ' Teken een blok
  332.         Line(x+Gr,y-Gr)-(x-Gr,y+Gr),1,B
  333.       Wend
  334.       ShowMouse                                 ' Toon de muis
  335.     End If
  336.   Loop Until RightButtonPressed=1               ' Einde
  337.   HideMouse
  338. Else
  339.   Print "Geen muis gevonden!"
  340. End If
  341. End