home *** CD-ROM | disk | FTP | other *** search
/ TCE Demo 2 / TCE_DEMO_CD2.iso / demo_cd_.2 / mags / stosser / stoser05.arj / stoser05.msa / A / 45.PNE < prev    next >
Text File  |  1987-04-22  |  11KB  |  448 lines

  1.  
  2.           STOS BITS 'N PIECES
  3.  
  4.                    by
  5.  
  6.         Martin Cubitt July 1993
  7.  
  8.  
  9.  You will probably be aware of the
  10. command inc V which would automatically
  11. increment (add 1 to) the variable V.
  12.  
  13.  What you may not be aware of is the
  14. fact that it is quicker to do two INC's
  15. than to add 2 to a variable too. So: 
  16.  
  17.  V=V+2
  18.  
  19.  would be replaced by
  20.  
  21.  inc V : inc V
  22.  
  23. ----------------------------------------
  24.  
  25.  The TAB(n) function of STOS does not
  26. work as one who has used other BASICs
  27. would expect.
  28.  
  29.  Normally the function will locate the
  30. cursor at the column specified by n. So 
  31. print TAB(7) would locate the cursor in
  32. the x coordinate 7 on the current line,
  33. a bit like locate 7, same.
  34.  
  35.  However, in the STOS version the cursor
  36. moves n places to the right of its curr-
  37. ent position. Not the same thing if the
  38. cursor is not at position 0.
  39.  
  40.  To get over this I have written a comm-
  41. and VTAB and a command LTAB in my EXTRA 
  42. extension (quick plug!). These work by
  43. returning the cursor to the start of the
  44. current line and then moving on n
  45. places. The VTAB command does not work
  46. on a printer as the control code is dif-
  47. ferent.
  48.  
  49.  The LTAB command works on both screen
  50. and printer but it moves right by plac-
  51. ing a space (ASCII 32) at the cursor 
  52. position. This means that anything on 
  53. the screen before the tab position will
  54. be erased.
  55.  
  56.  So to summarise, use VTAB(n) when the
  57. output will not be sent to a printer and
  58. use LTAB when it is.
  59.  
  60. ----------------------------------------
  61.  
  62.  A bug (don't know if it has been fixed
  63. yet!) concerns random access files.
  64.  
  65.  When defining fields using field #N, 15
  66. as A$, 23 as B$ etc. you have to add one
  67. to the length of the fields if the data
  68. uses the entire field length, otherwise
  69. the data will not be stored correctly!
  70.  
  71.  So in the above example you would have
  72. to change the 15 to 16 and the 23 to 24
  73. if the real maximum sizes are 15 and 23!
  74.  Got it?
  75.  
  76. ----------------------------------------
  77.  
  78.  Memory problems? Not you, your Atari!
  79. You have probably been told a million
  80. times but just in case you did not know
  81. you can save memory my ensuring that you
  82. boot STOS from an AUTO folder, avoiding
  83. GEM being installed until you exit your
  84. program.
  85.  
  86.  GEM controls the windows etc. on the
  87. desktop. Many program use GEM functions.
  88. STOS uses its own (typical!).
  89.  
  90.  This means that STOS does not require
  91. GEM to be present in order to run. Boot-
  92. ing from an AUTO folder means that GEM
  93. is not loaded. When GEM is loaded it
  94. takes up around 32K, so not loading it
  95. means you have an extra 32K to play
  96. with.
  97.  
  98.  
  99.  Another way of saving memory is to
  100. remove REM statements from programs.
  101. Personally I think that this is not a
  102. good idea. Trying to follow a program
  103. which you have not used for a while, or
  104. somebody else uses, can be hard enough 
  105. to understand at the best of times with
  106. comments. Remove these and remove the 
  107. educational value of your code.
  108.  
  109.  You would not sell a washing machine
  110. without instructions to save a little
  111. bit of space, would you?
  112.  
  113.  
  114.  You can also save memory (and speed up
  115. your program) by using a memory bank
  116. instead of arrays. As long as you clear-
  117. ly comment how the data will be stored
  118. in the bank this is fine. It is import-
  119. ant to comment fully on the structure of
  120. the bank so that data can be retrieved
  121. easily.
  122.  
  123.  For example, if you had an array to
  124. hold values 0-255 with 5000 elements
  125. (dim V(5000)) you can save a lot of
  126. space.
  127.  
  128.  STOS stores variables in their longword
  129. form which means they take up four bytes
  130. whatever their minimum or maximum size 
  131. is.
  132.  
  133.  So by reserving a bank of 5000*1 = 5000
  134. bytes saves you having an array taking
  135. up 5000*4 = 20000 bytes, a saving of
  136. 15000 bytes!
  137.  
  138.  This example should make the use of
  139. this method a little clearer...
  140.  
  141.  10 dim N(5000)
  142.  20 for LOOP=1 to 5000
  143.  30 N(LOOP)=rnd(255)
  144.  40 next LOOP
  145.  50 input "Element to check (1-5000):";E
  146.  60 if E=0 then 100
  147.  70 if E<1 or E>5000 then 50
  148.  80 print N(E)
  149.  90 goto 50
  150. 100 end
  151.  
  152.  The above program uses standard arrays,
  153. the replacement program...
  154.  
  155.  10 reserve as work 5,5000
  156.  20 NARRAY=start(5)
  157.  30 for LOOP=1 to 5000
  158.  40 poke NARRAY+LOOP-1,rnd(255)
  159.  50 next LOOP
  160.  60 input "Element to check (1-5000):";E
  161.  70 if E=0 then 110
  162.  80 if E<1 or E>5000 then 60
  163.  90 print peek(NARRAY+E-1)
  164. 100 goto 60
  165. 110 end 
  166.  
  167.  Note that the actual position is -1 
  168. from where you want to look. ThIs is
  169. because the memory bank actually goes 0
  170. to 4999 whereas the array goes 1 to 5000
  171.  
  172.  Mathematics can of course be carried
  173. out as if it were a normal array,
  174.  
  175.  instead of
  176.  
  177.  N(12)=N(12)+10
  178.  
  179.  use
  180.  
  181.  poke NARRAY+12-1
  182.  peek(NARRAY+12-1)+10
  183.  
  184.  
  185.  Note (again) that if the value of a
  186. calculation is constant (as in 12-1
  187. above) it is better to actually type
  188. the result so STOS does not need to work
  189. it out.
  190.  
  191.  poke NARRAY+11
  192.  peek(NARRAY+11)+10
  193.  
  194.  
  195.  The same principal can be applied to
  196. multi-dimensional arrays. So the array
  197. N(30,50) becomes a bank of size 30*50=
  198. 1500 and B=A(X,Y) becomes B=peek(NARRAY+
  199. (X-1)*30+(Y-1)).
  200.  
  201.  That's a little confusing so we'll
  202. leave that there!
  203.  
  204.  
  205.  A few people have mentioned that by re-
  206. naming extensions and STOS libraries can
  207. save memory.
  208.  
  209.  As far as the interpreter library goes,
  210. yes. As long as your program (and the 
  211. editor/compiler) does not use it then
  212. there is no need to load it, ie. if you
  213. are writing a program which does not use
  214. any extensions except, say, the STOS
  215. compactor then rename all other
  216. extension (*.EX? files in your STOS 
  217. folder). I rename using the last letter
  218. so EXTRA.EXZ becomes EXTRA.ZZZ. That way
  219. I know what extension letter it is if I
  220. want to re-employ it.
  221.  
  222.  You may want to rename the FLOAT102.LIB
  223. to FLOAT102.LI if your program does not
  224. use floating point.
  225.  
  226.  You must be careful, however. The mouse
  227. needs the SPRITES library and the file
  228. selector uses the WINDOW library.
  229.  
  230.  As far as the compiler goes things are
  231. a little different. Individual commands
  232. from extensions are only loaded if they
  233. are used. For example, if your program
  234. uses the PACK command from the STOS 
  235. compactor extension only the code for
  236. that will be loaded, ignoring the code
  237. for UNPACK. Therefore there is no point
  238. in renaming extensions in your Compiler
  239. folder.
  240.  
  241.  From my experience you cannot (despite
  242. other people's comments) rename the LIB 
  243. routines in the compiler folder other-
  244. wise the compiler has a disk error
  245. because it needs to load all libraries.
  246.  
  247. ----------------------------------------
  248.  
  249.  Did you know there is a bug in the SET
  250. PATTERN command?
  251.  
  252.  If you are using a monochrome monitor
  253. you'll be okay. However the low and med-
  254. ium resolution version do not work. 
  255. Actually Richard Vanner of Mandarin is 
  256. quoted in the STOS Newsletter issues 5
  257. and 6 as saying that these versions of
  258. the command were never finished. Whoops! 
  259. Sounds like some pretty amateur program-
  260. mers to me!
  261.  
  262. ----------------------------------------
  263.  
  264.  Ever heard of the game Gilbert? Well it
  265. was quite a popular game a year or two
  266. ago. It was written in STOS. It was 
  267. compiled using the first working of the
  268. compiler to arrive from France.
  269.  
  270.  The funny thing is Chris Payne at
  271. Mandarin allowed the development team
  272. (from Again Again) to leave of the norm-
  273. ally mandatory STOS credits, on the 
  274. understanding the truth be revealed
  275. after the game had been on the market
  276. for a few months.
  277.  
  278.  The worry was that people would not buy
  279. it if it was written in BASIC.
  280.  
  281.  Would you buy a game if it was written
  282. in BASIC and compiled to machine code?
  283.  
  284.  
  285.  Talking of commercial companies using
  286. STOS, did you know that the maps for
  287. Rainbow Island (the follow up to the
  288. excellent Bubble Bobble) were created by 
  289. Andrew Braybrook using STOS?
  290.  
  291. ----------------------------------------
  292.  
  293.  Back to the bugs.
  294.  
  295.  There are quite a number of 'bugs' in
  296. the STOS compiler. Many of them are
  297. minor bugs, that is that you can change 
  298. your code to fix the problem.
  299.  
  300.  You cannot use calculated ON...GOTO or
  301. ON...GOSUB where the condition is calcu-
  302. lated.
  303.  
  304.  For example,
  305.  
  306.  on (a*3+1) goto ...
  307.  
  308.  will not compile. Instead you must use
  309.  
  310.  c=a*3+1
  311.  on c goto ...
  312.  
  313.  
  314.  This is also true of the collide funct-
  315. ion. The command
  316.  
  317.  if collide ((X*Y+LOOP),X*3+4,Y*2)=1
  318.  then ...
  319.  
  320.  must be replaced with
  321.  
  322.  A=(X*Y+LOOP)
  323.  B=X*3+4
  324.  C=Y*2
  325.  if collide (A,B,C)=1 then...
  326.  
  327. ----------------------------------------
  328.  
  329.  One of the most annoying bugs in STOS
  330. caused me a lot of grief before I real-
  331. ised that Francois was a complete
  332. STOSSER with a silent leading S! (No 
  333. offence but at the time I was very
  334. annoyed!)
  335.  
  336.  It concerns the MID$ command. Some of
  337. you may have come across the bug.
  338.  
  339.  Consider the following simple program:
  340.  
  341.  10 input A$
  342.  20 B$=A$
  343.  30 mid$(A$,2,1)=" "
  344.  40 print B$
  345.  
  346.  Okay, a simple little 4 liner. But it
  347. does not work.
  348.  
  349.  Suppose you entered ABC when prompted
  350. from the input A$ command. A$ now
  351. contains "ABC". Agreed? I hope so!
  352.  
  353.  Line 20 stores the contents of A$ into
  354. B$. So now B$ also contains "ABC". Still
  355. with it?
  356.  
  357.  Line 30 stores a space at position 2 in
  358. the variable A$. So position two was a
  359. "B" but that will be replaced by an A.
  360.  
  361.  Well the good news is that it does. So
  362. it works? No. Line 40 will print out B$.
  363. This should still be "ABC" as we have
  364. not modified since line 20. However, B$
  365. also has a space at position two.
  366.  
  367.  Apparently (according to Mandarin so
  368. take it with a pinch of salt) the bug
  369. concerns use of MID$ after the input and 
  370. inkey$ commands. STOS still regard B$ as
  371. A$ because the variable pointers are the
  372. same. Nice one Mandarin!
  373.  
  374. More importantly you can get around this 
  375. by using the following command instead:
  376.  
  377.  B$=left$(A$,n-1)+" "+right$(A$,len(A$)
  378.  -n)
  379.  
  380.  where n is the position you which to
  381. replace and the space in " " can be re-
  382. placed with any character or string of 
  383. characters.
  384.  
  385.  It's fortunate that STOS does not mind
  386. if you use 
  387.  
  388.  left$(A$,0)
  389.  
  390.  as it returns a null ("")
  391.  
  392.  Many BASICS will not let you do that
  393. because technically it is incorrect.
  394.  
  395. ----------------------------------------
  396.  
  397.  Not a bug (hooray) this one but an un-
  398. documented feature of STOS.
  399.  
  400.  When using the SPRITE command you can
  401. omit the sprite number on the successive
  402. use of the command. That is, as long as 
  403. you have at least one
  404.  
  405.  sprite N,X,Y,P
  406.  
  407.  STOS will regard all subsequent sprite
  408. commands as regarding the previously
  409. used one so you can then use
  410.  
  411.  sprite N,X,Y
  412.  
  413.  Facinating!
  414.  
  415. ----------------------------------------
  416.  
  417.  Did you know...
  418.  
  419.  The FREQUENCY command which should only
  420. be used with a colour monitor. Using it
  421. with a normal television which cannot 
  422. support the frequency change can cause
  423. serious permanent damage to you set. You
  424. have been warned.
  425.  
  426.  The command can only be used in inter-
  427. preter mode. Goodness knows why! If
  428. people want it I can write a simple com-
  429. mand for the EXTRA extension so that 
  430. compiled programs can use it. I do not
  431. know what I would call the command
  432. though.
  433.  
  434.  (How about TOGGLE HERTZ? - Ed.)
  435.  
  436.  
  437.  Also, did you know that you can use the
  438. change mouse command to use a sprite as
  439. the mouse? Of course you did. According
  440. to the STOS Newsletter issue 8 any bank
  441. access or using FILE SELECT$ changes the
  442. mouse back to normal. How annoying!
  443.  
  444.  
  445.  
  446.  CUBITTM/STOS0004/190793
  447.  
  448.