home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 10: Diskmags / nf_archive_10.iso / MAGS / ST_NEWS / STN_01_C.MSA / DATA_DOC21 < prev    next >
Text File  |  1994-03-14  |  14KB  |  490 lines

  1.  üGEM VDI CALLS PART IIÇ by Manus
  2.  
  3. In  this article,  I'll give you some more GEM-routines which  you 
  4. can use in ST BASIC. The subjects in this article are:
  5.  - getting the mouse-position
  6.  - definition of a new mouse
  7.  - mark-statements
  8.  - some graphic statements
  9.  
  10. üMOUSE-POSITION AND KEYSÇ:
  11.  
  12. To  get  the  mouse-position is  certainly  the  most  interesting 
  13. routine  in  GEM,  because  with this routine you  can  make  your 
  14. programs  professional;  no more input of a  character,  but  just 
  15. click the wanted option.
  16. The  routine gives you the wanted values in the variables  XMOUSE, 
  17. YMOUSE  and  KEY,  but remember we have to correct the  values  in 
  18. XMOUSE and YMOUSE (see PART 1, RECTANGLE).
  19. The variable KEY can have three different values:
  20.  
  21.  
  22.  
  23.    Pressed key       Value
  24.  -------------       -----
  25.      Left              1
  26.      Right             2
  27.  Left and right        3
  28.  
  29.  
  30. The syntax is:
  31.  
  32.      ägosub MOUSE Ç 
  33.  
  34. The routine is:
  35.  
  36. 63000 MOUSE:
  37. 63002 ' <----- XMOUSE ; YMOUSE ; KEY
  38. 63004 poke contrl, 124
  39. 63006 vdisys
  40. 63008 xmouse = peek(ptsout    ) - 1
  41. 63010 ymouse = peek(ptsout + 2) - 38
  42. 63012 key = peek(intout)
  43. 63014 return
  44.  
  45. Try this:
  46.  
  47. 5   ' merge "MOUSE.bas"
  48. 10  fullw 2: clearw 2
  49. 20  color 1,1,1,1,1
  50. 30  start:   gosub MOUSE
  51. 40  if key = 1 then pcircle xmouse, ymouse, 5, 0, 3600:
  52. 50  if key = 2 then gotoxy 0,0 : print xmouse, ymouse
  53. 60  if key = 3 then clearw 2
  54. 70  goto start
  55.  
  56. üSHOW-MOUSEÇ:
  57.  
  58. Sometimes,  it  is very annoying that you can not see  the  mouse-
  59. symbol at all times,  because he gets invisible with every  output 
  60. on the screen or every input on your keyboard.  Only when you move 
  61. the mouse, you can see him again.
  62. With  the next GEM-routine you can make the mouse visible  at  any 
  63. time you want.The syntax is:
  64.  
  65.      ägosub SHOWMOUSE Ç
  66.  
  67. The routine is:
  68.  
  69. 63030 SHOWMOUSE:
  70. 63032 poke contrl, 122
  71. 63034 poke intin, 0
  72. 63036 vdisys
  73. 63038 return
  74.  
  75. üMOUSE-SHAPEÇ:
  76.  
  77. The Atari has 8 different mouse-shapes,  which we can also use  in 
  78. Basic. The mouse-shapes are:
  79.    Shape:           Value:
  80. ---------------     ------
  81. Arrow                 0
  82. Stretched rounded X   1
  83. Bee                   2
  84. Pointing hand         3
  85. Open hand             4
  86. Cross                 5
  87. Fat cross             6
  88. Outlined cross        7
  89. To do this,  we have to use a little AES-programming.  The  syntax 
  90. is:
  91.      äMOUSENUMBER = 0...7 :
  92.      gosub MOUSESHAPE  
  93. Ç
  94.                      The routine is:
  95. 63280 MOUSESHAPE:
  96. 63282 ' -----> MOUSENUMBER
  97. 63284 '         0 - 7
  98. 63286 if mousenumber > 7 then return
  99. 63288 add# = gb
  100. 63290 gintin = peek(add# + 8 )
  101. 63292 addrin = peek(add# + 16)
  102. 63294 poke gintin, mousenumber
  103. 63296 poke addrin, 0
  104. 63298 gemsys (78)
  105. 63300 return
  106.   
  107. üDEFINITION OF A MOUSE-SYMBOLÇ:
  108.  
  109. It is possible to create your own mouse-symbol,  like in  drawing-
  110. programs,   with   the   VDI-routine  111.   The  grid   and   the 
  111. backgroundgrid are each 16 words of 16 bits. We have to POKE these 
  112. values  on  certain addresses.  The backgroundgrid  defines  which 
  113. screenpoint of the field (16 by 16) under the mouse-symbol has  to 
  114. stay visible and which point has to been wiped.  That is specially 
  115. important when the mouse-symbol goes over a dark field.  Therefore 
  116. it is advisable to make the backgroundgrid greater then the mouse-
  117. grid.
  118. We have to use the next addresses:
  119.  INTIN + 8    color of the mouse: black or white
  120.  INTIN + 6    color of the backgroundgrid
  121.  INTIN + 2  ) point of the mouse, valid for determination
  122.  INTIN + 4  )  of the mouse-position
  123. In the following program we have put the information of  different 
  124. mouse-symbols in DATA-lines. To read these DATA we have to put the 
  125. DATA-pointer to these data.
  126. The syntax is:
  127.  
  128.                äRestore dataline 
  129.                gosub MOUSEDATA Ç
  130.  
  131. The routine is on the next page.
  132.  
  133. 63140 '--------------- MOUSEDATA --------------------------
  134. 63141 HAMMER:
  135. 63142 data 96,480,960,1984,3968,8064
  136. 63143 data 7936,16256,15872,32512,32512,65408
  137. 63144 data 65408,65472,63424,65504,25568,65520
  138. 63145 data 496,62456,248,508,124,254
  139. 63146 data 62,127,31,63,14,31
  140. 63147 data 4,14
  141. 63150 COFFEE:
  142. 63151 data 4624,16184,9248,32376,4640,16368
  143. 63152 data 4672,16352,4384,16352,2624,8128
  144. 63153 data 0,16320,16352,32764,16380,32766
  145. 63154 data 16358,32767,16354,32767,16358,32767
  146. 63155 data 16380,32767,16352,32766,8128,16352
  147. 63156 data 0,8128
  148. 63160 WORM:
  149. 63161 data 0,8064,8064,16320,16320,32736
  150. 63162 data 26208,65520,30560,65520,32736,65532
  151. 63163 data 29132,65534,16318,32767,8054,16383
  152. 63164 data 7782,16383,7372,16382,7384,16380
  153. 63165 data 4080,8184,2022,4095,60,2046
  154. 63166 data 24,62
  155. 63199 '-------------------------------------------------
  156. 63200 MOUSEDATA:
  157. 63202 '---> restore line
  158. 63204 for a = 0 to 15
  159. 63206 read gridfront,gridback
  160. 63208 poke intin + a * 2 + 42, gridfront
  161. 63210 poke intin + a * 2 + 10, gridback
  162. 63212 next
  163. 63214 '-------------------------------------------------
  164. 63250 MOUSENEW:
  165. 63252 poke contrl    , 111
  166. 63254 poke contrl + 6, 37
  167. 63256 poke intin    , 5
  168. 63258 poke intin + 2, 5
  169. 63260 poke intin + 4, 1
  170. 63262 poke intin + 6, 0
  171. 63264 poke intin + 8, 1
  172. 63266 vdisys
  173. 63268 out 2,7
  174. 63270 return
  175.  
  176.  
  177. Example:
  178.  
  179. 5   ' merge "MOUSEDATA.bas"
  180. 6   ' merge "SHOWMOUSE.bas"
  181. 9   '
  182. 10  restore worm: gosub mousedata: gosub showmouse
  183. 20  waiting = inp(2)
  184. 30  restore hammer: gosub mousedata: gosub showmouse
  185. 40  waiting = inp(2)
  186. 50  restore coffee: gosub mousedata: gosub showmouse
  187. 60  waiting = inp(2)
  188. 70  end
  189. ü
  190. MOUSE-EDITORÇ:
  191.  
  192. This  next  program  can  be  used  to  create  mouse-symbols;  it 
  193. calculates  the  necessary  bit-values  and  pokes  them  in   the 
  194. addresses. After the input of:
  195.                 ägosub MOUSEEDITOR Ç
  196. the new calculated mouse-symbol appears on the screen.
  197. You  have to write down the decimal values of the  mouse-grid  and 
  198. its  backgroundgrid  and put them in DATA-lines (see  line  63106, 
  199. remove the REM-statement) like in MOUSEDATA. Using DATA-statements 
  200. is much faster then using this program for your new mouse-symbol.
  201. When your new mouse-symbol disappears you can recall it through:
  202.                ägosub MOUSENEW Ç
  203. The routine is:
  204.  
  205. 63050 MOUSEEDITOR:
  206. 63052 dim a$(16),b$(16)
  207. 63054 a$( 0)="---*--*----*----":b$( 0)="--******--***---"
  208. 63056 a$( 1)="--*--*----*-----":b$( 1)="-******--****---"
  209. 63058 a$( 2)="---*--*---*-----":b$( 2)="--**********----"
  210. 63060 a$( 3)="---*--*--*------":b$( 3)="--*********-----"
  211. 63062 a$( 4)="---*---*--*-----":b$( 4)="--*********-----"
  212. 63064 a$( 5)="----*-*--*------":b$( 5)="---*******------"
  213. 63066 a$( 6)="----------------":b$( 6)="--********------"
  214. 63068 a$( 7)="--*********-----":b$( 7)="-*************--"
  215. 63070 a$( 8)="--************--":b$( 8)="-**************-"
  216. 63072 a$( 9)="--*********--**-":b$( 9)="-***************"
  217. 63074 a$(10)="--*********---*-":b$(10)="-***************"
  218. 63076 a$(11)="--*********--**-":b$(11)="-***************"
  219. 63078 a$(12)="--************--":b$(12)="-***************"
  220. 63080 a$(13)="--*********-----":b$(13)="-**************-"
  221. 63082 a$(14)="---*******------":b$(14)="--*********-----"
  222. 63084 a$(15)="----------------":b$(15)="---*******------"
  223. 63086 for a = 0 to 15
  224. 63088 gridfront = 0: gridback = 0
  225. 63090 for b = 15 to 0 step -1
  226. 63092 if mid$(a$(a),b+1,1)="*" then bit = 1 else bit = 0
  227. 63094 gridfront = gridfront + 2 ^(15 - b) * bit
  228. 63096 if mid$(b$(a),b+1,1)="*" then bit = 1 else bit = 0
  229. 63098 gridback = gridback + 2^(15 - b) * bit
  230. 63100 next
  231. 63102 poke intin + a * 2 + 42, gridfront
  232. 63104 poke intin + a * 2 + 10, gridback
  233. 63106 ' lprint gridfront, gridback
  234. 63108 next
  235. 63110 goto mousenew
  236. 63112 '---------------------------------------------------
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243. üPOLYMARKÇ:
  244.  
  245. We can use different drawings as mark, these drawings are:
  246.  - point                      - cross
  247.  - star                       - rectangle
  248.  - slanting cross             - diamond
  249. All marks can be made in every size. The syntax is:
  250.      äXPOS = .... : YPOS = ....
  251.      MARKFORM = ....
  252.      MARKSIZE = ....
  253.      gosub POLYMARK 
  254. ÇTo draw an other one:  
  255.      äXPOS = .... : YPOS = ....
  256.      gosub POLYMARK Ç
  257. It is possible to draw several marks at the same time.  We have to 
  258. use some addresses:
  259.     PTSIN + 4, PTSIN + 6, ....    Positionparameters
  260.     CONTRL + 2                    Number of marks
  261.  
  262. Theoretically we can  wipe a mark by drawing  it  again  with  the 
  263. backgroundcolor.  But then we lose the background-information  and 
  264. it is impossible to draw on dark backgrounds.
  265. Therefore  we  use  the routine 'TEXTFORM'  with  its  option  XOR 
  266. (form=3). By using XOR twice we get the original screeninformation 
  267. again and the background stays unchanged.
  268. The routine is:
  269.  
  270. 63400 POLYMARK:
  271. 63402 ' ----> XPOS ; YPOS
  272. 63404 ' ----> MARKFORM ; MARKSIZE
  273. 63406 '
  274. 63408 poke contrl    , 18
  275. 63410 poke contrl + 2, 0
  276. 63412 poke contrl + 6, 1
  277. 63414 poke intin, markform
  278. 63416 vdisys
  279. 63418 poke contrl    , 19
  280. 63420 poke contrl + 2, 1
  281. 63422 poke contrl + 6, 0
  282. 63424 poke ptsin    , 0
  283. 63426 poke ptsin + 2, marksize
  284. 63428 vdisys
  285. 63430 '
  286. 63432 MARKSETTING:
  287. 63434 ' (----> XPOS ; YPOS )
  288. 63436 poke contrl    , 7
  289. 63438 poke contrl + 2, 1 : ' or more
  290. 63440 poke ptsin    , xpos + 1
  291. 63442 poke ptsin + 2, ypos + 38
  292. 63444 vdisys
  293. 63446 return
  294. 63448 '---------------------------------------------------
  295.  
  296. The routine 'TEXTFORM':
  297.  
  298. 65130 TEXTFORM:
  299. 65132 ' -----> FORM ( 1 - 4)
  300. 65134 '
  301. 65138 poke contrl    ,32
  302. 65140 poke contrl + 2,0
  303. 65142 poke contrl + 6,1
  304. 65144 poke intin, form
  305. 65146 vdisys
  306. 65148 return
  307.  
  308.  
  309. A test:
  310.  
  311. 5   ' merge "POLYMARK.bas"
  312. 6   ' merge "TEXTFORM.bas"
  313. 9   '
  314. 10  fullw 2: clearw 2
  315. 20  color 1,1,1,1,1
  316. 30  form = 3: gosub TEXTFORM
  317. 40  pellipse 310, 200, 140, 80, 0, 3600
  318. 50  start:
  319. 60  xpos = 50: ypos = 160 : marksize = 50
  320. 70  for markform = 1 to 7
  321. 80  xpos = xpos + 60
  322. 90  gosub POLYMARK
  323. 100 next
  324. 110 gotoxy 15,11: print "ST NEWS IS THE BEST"
  325. 120 waiting = inp(2)
  326. 125 end
  327. 130 goto start
  328.  
  329.  
  330.  
  331. üPOLYLINEÇ:
  332.  
  333. This  routine  is the same as the statement 'LINEF' in  ST  Basic, 
  334. but much faster.
  335. The syntax is:
  336.  
  337.      äXCOORD ( 1,.....,N ) 
  338.      YCOORD ( 1,.....,N ) 
  339.      gosub POLYLINE Ç
  340. ä
  341. ÇThe routine is:
  342.  
  343. 64300 POLYLINE:
  344. 64301 ' -----> NUMBER ; XCOORD ; YCOORD
  345. 64302 poke contrl    , 6
  346. 64304 poke contrl + 6, 0
  347. 64306 poke contrl + 2, number
  348. 64308 for i = 0 to number
  349. 64310 poke ptsin + i * 4, xcoord(i) + 1
  350. 64312 poke ptsin + 2 + i * 4, ycoord(i) + 38
  351. 64314 next
  352. 64316 vdisys
  353. 64318 return
  354. 64320 '---------------------------------------------------
  355.  
  356. Try this and compare the speed:
  357.  
  358. 5   ' merge "POLYLINE.bas"
  359. 9   '
  360. 10  dim xcoord(200), ycoord(200)
  361. 20  fullw 2: clearw 2
  362. 30  number = 80
  363. 40  for i = 0 to number
  364. 50  xcoord(i) = 10 + i * 600/number
  365. 60  ycoord(i) = 100 + rnd(1) * 200
  366. 70  next
  367. 80  gosub polyline
  368. 90  waiting = inp(2)
  369. 100 end
  370.  
  371.  
  372.  
  373.  
  374.  
  375. üPOLYGONÇ:
  376.  
  377. With this routine we can draw and fill all imaginable figures. The 
  378. routine works much faster then the 'LINEF' - and 'FILL'-statement.
  379. The grid is defined through the 'COLOR'-statement.
  380. The syntax is:
  381.  
  382.     äXCOORD ( 1,.....,N ) 
  383.     YCOORD ( 1,.....,N ) 
  384.     gosub POLYGON Ç
  385.  
  386. The routine is:
  387.  
  388. 64140 POLYGON:
  389. 64142 ' -----> ANGLES ; XCOORD ; YCOORD
  390. 64144 poke contrl    , 9
  391. 64146 poke contrl + 6, 0
  392. 64148 poke contrl + 2, angles
  393. 64150 for i = 1 to angles
  394. 64152 poke ptsin + (i - 1) * 4, xcoord(i) + 1
  395. 64154 poke ptsin + 2 + (i - 1) * 4, ycoord(i) + 38
  396. 64156 next
  397. 64158 vdisys
  398. 64160 return
  399. 64162 '---------------------------------------------------
  400.  
  401. Example:
  402.  
  403. 5   ' merge "POLYGON.bas"
  404. 9   '
  405. 10  dim xcoord(20), ycoord(20)
  406. 20  color 1,1,1,7,2
  407. 30  fullw 2: clearw 2
  408. 40  angles = 6
  409. 50  for i = 1 to angles
  410. 60  read xcoord(i), ycoord(i)
  411. 70  next
  412. 80  gosub polygon
  413. 90  waiting = inp(2)
  414. 100 end
  415. 110 data  10,100,400, 40,250,200
  416. 120 data 380,290,150,230, 70,240
  417.  
  418.  
  419. üPOLYGON2Ç:
  420.  
  421. This routine is a special Polygon-routine for drawing  symmetrical 
  422. polygons with self-defined number of angles.
  423. The syntax is:
  424.  
  425.     äXPOS = ....   : YPOS = ....
  426.     RADIUS = .... : ANGLES = ....
  427.     gosub POLYGON2 Ç
  428.  
  429. The 'COLOR'-statement defines the grid. The routine is:
  430.  
  431. 64100 POLYGON2:
  432. 64102 ' -----> XPOS ; YPOS
  433. 64104 '        RADIUS ; ANGLES
  434. 64106 phi = 3.141593/angles/2
  435. 64108 STAR:
  436. 64110 ' -----> PHI
  437. 64112 poke contrl    , 9
  438. 64114 poke contrl + 6, 0
  439. 64116 poke contrl + 2, angles
  440. 64118 for angle = 0 to angles * 4 step 4
  441. 64120 poke ptsin+angle    ,  1+xpos+cos(phi*angle)*radius
  442. 64122 poke ptsin+(angle+2), 38+ypos+sin(phi*angle)*radius
  443. 64124 next
  444. 64126 vdisys
  445. 64128 return
  446. 64130 '--------------------------------------------------
  447.  
  448. Example:
  449.  
  450. 5   ' merge "POLYGON2.bas"
  451. 9   '
  452. 10  fullw 2: clearw 2
  453. 20  color 1,1,1,7,2
  454. 30  xpos = -50 : ypos = 150
  455. 35  radius = 50
  456. 40  for angles = 3 to 7
  457. 50  xpos = xpos + 120
  458. 55  gosub polygon2
  459. 60  next
  460. 70  waiting = inp(2)
  461. 80  end
  462.  
  463. üSTARSÇ:
  464.  
  465. Using the routine 'POLYGON2' and with  a little adjustment of  the 
  466. angle  and  like  magic  beautiful  stars  appear  on  the  screen 
  467. (something for Christmas ?)
  468.  
  469. 5   ' merge "POLYGON2.bas"
  470. 9   '
  471. 10  fullw 2: clearw 2
  472. 20  color 1,1,1,8,2
  473. 30  ypos = 150 : radius = 50
  474. 40  angles = 7
  475. 50  xpos = 100 : phi = 3.1416/2/angles * 2   : gosub star
  476. 60  xpos = 200 : phi = 3.1416/2/angles * 3   : gosub star
  477. 70  xpos = 300 : phi = 3.1416/2/angles * 2.8 : gosub star
  478. 80  xpos = 400 : phi = 3.1416/2/angles * 1.7 : gosub star
  479. 90  xpos = 500 : phi = 3.1416/2/angles * 2.5 : gosub star
  480. 100 angles = 11: ypos = 250
  481. 110 xpos = 100 : phi = 3.1416/angles * 1.5   : gosub star
  482. 120 xpos = 200 : phi = 3.1416/angles * 2     : gosub star
  483. 130 xpos = 300 : phi = 3.1416/angles * 2.5   : gosub star
  484. 140 xpos = 400 : phi = 3.1416/angles * 1.9   : gosub star
  485. 150 xpos = 500 : phi = 3.1416/angles * 2.6   : gosub star
  486. 160 waiting = inp(2)
  487. 170 end
  488.  
  489.  
  490.