home *** CD-ROM | disk | FTP | other *** search
/ Boot Disc 8 / boot-disc-1997-04.iso / PDA_Soft / Pilot / Apps / Cpad / CBASPAD.TXT < prev   
Text File  |  1997-01-09  |  15KB  |  456 lines

  1. Chipmunk Integer Tiny Basic for Pilot
  2. version 0.64
  3. <http://www.nicholson.com/rhn/pilot.html>  
  4.  
  5. This a tiny version of the Basic programming language.
  6. See below for a list of commands, statements & functions.
  7.  
  8. Revision History:
  9.  
  10. -- Version 0.64 --    (97Jan08)
  11.  
  12. Fixed bug in float array assignment (again).
  13. fn 34 returns last pendown tickcount.
  14.  
  15. -- Version 0.62 --    (97Jan06)
  16. Increased the maximum program text size to 4000 characters.
  17. Added playing morse code tones via the sound command.
  18.     sound 660,18,10,"cq de n6ywu",13
  19. Added op "get$",n function (reads string from page).
  20. Added limited form of serial input polling.
  21. Added fn 22 wait/delay/pause function.
  22. Reduced code 0 rsrc size (should fix some install problems.)
  23.  
  24. *** *** WARNING *** ***
  25. The application signature has changed in versions 0.5X from
  26. that of old versions 0.02X.  You will have to *DELETE* old
  27. version 0.2b9, or earlier, of cbasPad *BEFORE* upgrading.
  28. First copy any Basic programs that you wish to save to the
  29. Memo Pad, delete the old version, and then copy your saved
  30. programs back after installing the new version of cbasPad.
  31. If you don't do this your hotsync may crash.
  32.  
  33. -- Version 0.58 --    (96Dec12)
  34. Fixed a string memory leak.
  35. Removed op "dpr" command.
  36. -- Version 0.57 --    (96Dec11)
  37. Changed the ? shortcut to dprint instead of print.
  38. Fixed a string array assignment bug.
  39. Fixed yet another floating point bug (division sign).
  40. -- Version 0.55 --    (96Dec03)
  41. Fixed op "sety" initiazation bug.
  42. Disallow sound 0,d,v  (frequency = 0 causes a crash).
  43. Added morse-code-like beeping.
  44. -- Version 0.54 --    (96Nov23)
  45. Fix to create non null database on first use.
  46. Added "Stop" to input dialog menus.
  47. -- Version 0.53 --    (96Nov17)
  48. Fixed length bug in the mid$(s$,start,length) function.
  49. Fixed peek() to require parenthesis around all parameters.
  50. Cosmetic cleanup of dprint dialog.
  51. Enabled use of float vars as tests in if-then statements.
  52. Added floating point equality test.
  53. -- Version 0.52 --    (96Nov16)
  54. Physical scroll buttons now scroll by page.
  55. Enabled editing in the input dialog.
  56. Added mid$() function.
  57. Reduced screen flash when executing from the main form.
  58. -- Version 0.51 --    (96Nov15)
  59. Added eval() to evaluate a string as an expression.
  60. Fixed a print bug when executing from the main form.
  61. Fixed a few float to int number conversions.
  62. -- Version 0.50 --    (96Oct25)
  63. Fixed a memory allocation leak.
  64. Changed the creator signature type to 'cBAS'.
  65. -- Version 0.02b9 --    (96Oct19)
  66. Exec from main screen now returns to main screen.
  67. Fixed reading the 9th line of input dialog.
  68. Fixed op "db" command item indexing.
  69. Fixed val() to work with hex strings ("0x1abc").
  70. Added hex$() to string functions.
  71. Added standard edit menu to input dialogs.
  72. -- Version 0.02b8 --    (96Oct06)
  73. Fixed integer input statement bug.
  74. Fixed string parameter precedence bugs in val() and len().
  75. Increased size of s$() to 20 elements.
  76. Increased size of dialog form to 9 input fields.
  77. -- Version 0.02b7 --    (96Oct05)
  78. Added dialog form with 8 input fields.
  79. Added auto-dimensioned s$() array of 16 elements.
  80. Edit button replaces auto-edit mode.
  81. Exec button added to main form.
  82. -- Version 0.02b5 --    (96Oct01)
  83. Fixed string initialization bug that can hang machine.
  84. -- Version 0.02b4 --    (96Sept26)
  85. Added dprint command to replace op "dpr".
  86. Restored printing of characters with ASCII value > 129.
  87. Added alpha test versions of trig functions.
  88. Added very limited string variables (max of 8 total).
  89. -- Version 0.02b3 --    (96Sept22)
  90. Fixed handling of tabs in comment lines.
  91. Fixed printing of a few floating point values.
  92. Added rnd() function.
  93. -- Version 0.02b2 --    (96Sept14)
  94. Added experimental versions of sqr(), exp(), log() and ^.
  95. Fixed printing of a few floating point values.
  96. Cleaned up "dpr" dialog box just a little.
  97. Added method to peek at the data of other applications.
  98. -- Version 0.02b1 --    (96Sept09)
  99. Fixed a bug in array assignment.
  100. Fixed a bug that caused crashes on empty input statements.
  101. Disabled tap text select during print output.
  102. Added the command 'op "dpr"' to print to the dialog box.
  103. -- Version 0.02b0 --    (96Sept08)
  104. More floating point expressions allowed.
  105. -- Version 0.02a9 --    (96Sept07)
  106. Added limited function floating point variables.
  107.   *** See the floating point limitations section below. ***
  108. Fixed an error dialog bug.
  109. Error messages are no longer repeated in the text output.
  110. Fixed a bug in illegal string variable names.
  111. -- Version 0.02a8 --    (96Sept05)
  112. Added the "new" command to clear out old programs.
  113. Stopped cursor blink when running.
  114. Increased max "run" time before sleep to 5 minutes.
  115. -- Version 0.02a7 --    (96Aug31)
  116. Fixed input form background display.
  117. Added "input" statement.
  118. Increased maximum text form length to 2K.
  119. -- Version 0.02a5 --    (96Aug24)
  120. Fixed bug in dimensioning arrays on repeated runs.
  121. Added error report dialog.
  122. Renamed Buttons to "SelectAll" and "Exec"
  123. Halt script execution after the first "run" command.
  124. Removed ability to search cbas database.
  125. Added functions to get clipboard Ptr and len.
  126. (I use this and the sersend command to upload memos to my
  127.  Unix workstation.)
  128. -- Version 0.02a4 --    (96Aug18)
  129. Fixed printing negative numbers.
  130. Fixed crash on done button while running.
  131. Fixed HotSync of DB.
  132. Added print hex$(), print chr$()
  133. Cleaned up mislabled resources.
  134. Changed type of app and DB (You should delete the old cBASpadDB.)
  135. Added poke, varptr(), call, serial port transmit.
  136.  
  137. -- Version 0.02a1 --    (96Aug17)
  138.  
  139. Initial Experimental Release.
  140.  
  141. ----------------------------------------------------------------
  142.  
  143. README & Command Summary -- Latest Version
  144.  
  145. Abstract:
  146.  
  147. This a tiny version of the Basic programming language.
  148. Default numbers and variables are 32-bit integers.
  149. Line numbers are required.
  150. Variable names may be up to 15 characters in length.
  151. Hex constants may be entered by preceding them with "0x".
  152. Lines starting with the character '#' are ignored (comments).
  153.  
  154. Supported Operators:
  155.   +  -  *  /  mod
  156.   >  >=  <  <=  =  <>  and  or  xor  not
  157.     
  158. Supported Statement Keywords:
  159.  {let}
  160.   print
  161.   dprint
  162.   input
  163.   goto
  164.   if then
  165.   for to step next
  166.   gosub return
  167.   float
  168.   dim
  169.   end
  170.   new
  171.   rem
  172.  
  173. Supported Functions:
  174.   int()
  175.   rnd()
  176.   fre
  177.     
  178. Usage:
  179.   Statements without line numbers are executed in direct mode
  180.   in the order they are listed.
  181.   
  182.   Statements with line numbers are executed in deferred
  183.   mode, that is only after a "run" or "goto" command.  While
  184.   executing a program in defered mode, all statements without
  185.   line numbers are ignored.
  186.   
  187.   All statements after the first "run" command are ignored.
  188.   
  189.   When making any edits to numbered program lines, it's good
  190.   form to precede all programs lines with a "new" command.
  191.   
  192.   Single statements can be executed by selecting just the line
  193.   the statement is on, and then hitting the "Exec" button.
  194.   
  195.   print        : prints to the end of the program memo text.
  196.   dprint    : prints to a mini-dialog box.
  197.   float     : declares a list of floating point variables.
  198.   fre     : returns size of free dynamic heap space.
  199.   rnd(n) : returns a pseudo random integer in the range 0..n-1
  200.   int(x) : truncates toward zero.
  201.   "and", "or" and "xor" are bitwise operators.
  202.   "not" is a boolean operator and only returns 1 or 0.
  203.   
  204. Some examples:
  205.   
  206.   # this is a comment line (because of the leading '#').
  207.   # multiple statements per line allowed.
  208.   x = 7 : y = 3 + 4
  209.   
  210.   # dprint prints 1 line to a dialog box.
  211.   dprint "hello ",123
  212.   
  213.   dprint "hello ";
  214.   dprint 23+7
  215.   
  216.   # ? is an abbreviation for "dprint"
  217.   ?  x
  218.   
  219.   # print appends text to your program file.
  220.   print chr$(65)
  221.   print "0x";hex$(255)
  222.   
  223.   # input can read numbers or strings.
  224.   input "prompt", y
  225.   input "prompt", a$
  226.   
  227.   # Arrays must be dimensioned.
  228.   # Arrays are limited to one dimension.
  229.   dim a(4)
  230.   for i=0 to 4 : a(i) = i : next i
  231.   
  232. Warnings:
  233.   Integer overflow (> 2^32-1) will not signal any warnings.
  234.   
  235.   If you don't use the "new" command, deleted program statements
  236.   will still be in the execution buffer.
  237.  
  238.   You can lock up your pilot and corrupt ALL your data when
  239.   using peek, poke and call.  Use at your own risk.  HotSync
  240.   and backup often if you want to play with these functions.
  241.   Memory above the first 32K is protected and cannot be poked
  242.   without an OS write enable call (read the SDK docs).
  243.   
  244.   Using sersend will drain the battery much faster than normal.
  245.   
  246.   Installing 0.5x over 0.02x will cause hotsync to crash.
  247.   
  248. Additional Commands:
  249.   dprint    - redirects 1 line of print to a dialog box.
  250.   sound { frequency in Hz }, { duration in mS }, { vol 0..64 }
  251.   sound freq, c_wpm, vol64, morse$ [ , farnsworth_wpm ]
  252.   sound 660, 18, 10, "cq de n6ywu", 13   : rem  An example.
  253.   call a    - 68k machine jsr to addr a
  254.           (You can stuff code in integer arrays.
  255.          Remember that integers are 4 bytes long.)
  256.   sersend { mem_address }, { len }, { baud_rate 2400..19200 }
  257.   float x    - declare x as a float var
  258.   grline x1,y1,x2,y2     - draw line on display [0..159]
  259.   op "sety",y    - replaces line y with following print output.
  260.   op "page","title"    - changes output page
  261.   op "db",type,creat,i    - returns length of DB record i
  262.       - if non zero then 'fn 80' returns pointer to DB record
  263.       - for memo pad data convert 'DATA' & 'memo' to hex
  264.   (If you can't convert ascii to hex, you shouldn't be peeking.)
  265.   op "launch","memo",2    - launches MemoPad with record # 2
  266.   (These commands may change or be removed in future versions!)
  267.   
  268. Additional Functions:
  269.   sqr(x) - square root
  270.   exp(x) - e ^ x
  271.   log(x) - natural log of x
  272.   sin(x) cos(x) tan(x) atn(x) - trig functions for x in radians
  273.   varptr(y) - returns memory address of variable y (or y$).
  274.   len(a$)   - returns length of string a$
  275.   val(a$)   - returns numeric value of a$ or 0
  276.   str$(x) - returns string representation of x
  277.   chr$(c) - returns string of ascii char c, length 1
  278.   hex$(n) - returns hex string
  279.   mid$(a$,s,n) - returns substring of a$ starting at s length n
  280.   eval(q$)  - evaluates string q$ as a numeric expression
  281.   peek(a)   - returns 8-bit byte at address a
  282.   peek(a,2) - returns the 16-bit value at word aligned address a
  283.   peek(a,4) - ... 32-bit value at word aligned address a
  284.   fn 16  - returns seconds timer
  285.   fn 17  - returns tick timer (100 Hz)
  286.   fn 19  - returns length of the clipboard text
  287.   fn 18  - returns memory address of the clipboard text
  288.   fn 20  - returns scaled battery voltage
  289.   fn 22  - waits (pauses) for 2 seconds, returns 0
  290.   fn 24  - returns decimal date
  291.   fn 25  - returns decimal time
  292.   fn 30  - display dialog, returns dialog button status
  293.   fn 33  - returns asc(input$(1)). Waits for 1 graffiti char.
  294.   fn 34  - returns tick time of last pendown or input$ char
  295.   fn 35  - returns memory address of input buffer
  296.   fn 42  - temporarily clears middle of screen, returns 0
  297.   op "gnum", n    - returns a number from line n of the memo
  298.   op "get$", n    - returns a string from line n of the memo
  299.   sersend { buffer_mem_address }, { max_len }, -2
  300.     - returns length of serial data received in buffer.
  301.     This function can only be used after the baud rate has
  302.     been set by a prior "sersend" in the current running program.
  303.     Warning: Using sersend drains the battery much faster.
  304.   (These functions may change or be removed in future versions!)
  305.  
  306. Additional Operators:
  307.   x = (x ^ y)    - raise x to a power; parenthesis are required.
  308.  
  309. Additional Variables:
  310.   String variable name must end with a '$', e.g. name$
  311.   The print, dprint and input commands will take string vars.
  312.   let a$ = "hello" : dprint a$,a$
  313.   There is one string array: s$() - auto-dimensioned on first
  314.   use.  16 elements s$(0) .. s$(15)
  315.  
  316. Additional Dialog Form:
  317.   fn 30  - displays a dialog form with 8 lines
  318.   s$(0), s$(2) ... are the prompt strings
  319.   s$(1), s$(3) ... are the default & return values
  320.   return value is 1 for OK, 2 for A button, 3 for B button
  321.  
  322. Current String Limitations:
  323.   - There are a maximum of 8 string variables.  Use more than
  324.      8 and you will just get aliases to existing strings.
  325.   - The maximum length of a string is 31 characters.
  326.   - Only the "=" comparison works for strings.
  327.   - Complex expressions involving strings are not allowed.
  328.   - Only 1 string array is allowed: s$().
  329.   
  330. Current Floating Point Limitations:
  331.   - Floating point variables must be declared with the
  332.      "float" command before use.
  333.   - Only the "<" , ">" , "=" and "<>" comparisons  will work
  334.      with floating point expressions.
  335.   - You can't use fp variables as indexes in "for" statements.
  336.   - The error of transcendental functions is unknown.
  337.   - Integer math is assumed.  (5/2) is an integer equal to 2
  338.   - (5.0/2.0) with explicit decimal points, is a floating point
  339.     value equal to 2.5
  340.  
  341. Bugs:
  342.   Many.  Please send bug reports to rhn@nicholson.com
  343.   * Bug reports without the version number will be ignored. *
  344.   
  345.   A program must be preceded by "new".
  346.   Some floating point values may print incorrectly. (ROM bug.)
  347.   Some syntax errors are reported without line numbers.
  348.   Deep GOSUB nesting may cause stack overflow crashes.
  349.   Complex expression nesting may cause stack overflow crashes.
  350.   Divide by 0, log(0), overflow, etc. produce undefined results.
  351.   
  352. Rationale:
  353.  Chipmunk Basic 3.5.0 for the MacOS weighs in at over 490K.  In
  354.  the old days, personal computers came with a usable Basic
  355.  interpreter in 8K or less of ROM.
  356.  cbasPad is the result of taking the concept of Chipmunk Basic,
  357.  an interpreter written in portable C, and stripping it down to
  358.  the it's minimum, to see how small it would get.  Currently, a
  359.  few features are being added back to this Pilot version make
  360.  it more useful.
  361.   
  362. Permission:
  363.  Pilot cbasPad is
  364.  Copyright 1996,1997 Ronald H. Nicholson, Jr., All Rights Reserved.
  365.  
  366.  Permission to use, copy and distribute this software without fee
  367.  for non-commercial or educational purposes is hereby granted,
  368.  provided that the above copyright notice appear in all copies,
  369.  and that both the copyright notice and this permission notice
  370.  with the following disclaimer appear in all documentation.
  371.  
  372. Disclaimer:
  373.  This program is distributed in the hope that it will be useful,
  374.  but WITHOUT ANY WARRANTY OF ANY KIND; not even the implied
  375.  warranty of MERCHANTABILITY or fitness for ANY particular
  376.  purpose.
  377.  
  378. Postcard:
  379.   There is NO shareware fee required for personal, noncommercial,
  380.   use of this version of cbasPad. $0.00 (USD) !
  381.   But, if you like this program, please send a postcard to:
  382.     Ronald Nicholson
  383.     1909 Magdalena Cir. #76
  384.     Santa Clara, CA 95051
  385.  
  386. Credits:
  387.   Based on the Pilot MemoPad tutorial,
  388.   which is Copyright ⌐ Palm Computing 1996,
  389.   and on Chipmunk Basic.
  390.  
  391.  
  392. Example 1:
  393.  
  394. # example 1
  395. new
  396. 10 for i=1 to 7 : dprint 3 * i,
  397. 20 next i
  398. run
  399. # Now use the menus to "select all"
  400. # and to "run selection".
  401.  
  402.  
  403. Example 2:
  404.  
  405. # print out character set
  406. new
  407. 10 for c=33 to 255:print chr$ c;:next
  408. run
  409.  
  410.  
  411. Example 3:
  412.  
  413. # send the clipboard text
  414. #   out the serial port
  415. new
  416. 10 a=fn 18 : n=fn 19
  417. 20 if n > 0 then sersend a,n,19200
  418. run
  419.  
  420.  
  421. --
  422. Copyright 1997 Ronald H. Nicholson, Jr.     rhn@nicholson.com
  423. http://www.nicholson.com/rhn/
  424. --
  425.  
  426.  
  427.  
  428.  
  429.  
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.