ChipMaster's bwBASIC This also includes history going back to v2.10. *WARN* some binary files might have been corrupted by CRLF.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

442 lines
16 KiB

  1. Bywater BASIC Interpreter/Shell, version 1.10
  2. ---------------------------------------------
  3. Copyright (c) 1992, Ted A. Campbell
  4. for bwBASIC version 1.10, 1 November 1992
  5. CONTENTS:
  6. 1. DESCRIPTION
  7. 2. TERMS OF USE
  8. 3. COMMANDS AND FUNCTIONS IMPLEMENTED
  9. 4. SOME NOTES ON USAGE
  10. 5. UNIMPLEMENTED COMMANDS AND FUNCTIONS
  11. 6. SOME NOTES ON COMPILATION
  12. 7. THE STORY OF BYWATER BASIC
  13. 8. COMMUNICATIONS
  14. 1. DESCRIPTION
  15. The Bywater BASIC Interpreter (bwBASIC) implements a large
  16. superset of the ANSI Standard for Minimal BASIC (X3.60-1978)
  17. in ANSI C and offers shell program facilities as an extension
  18. of BASIC.
  19. The set of BASIC commands and functions implemented is fairly
  20. limited (see section three below), although more commands and
  21. functions are implemented than appear in the specification
  22. for Minimal BASIC. There are no commands that are terminal- or
  23. hardware specific. (Seriously -- CLS may work under bwBASIC
  24. on your DOS-based pc, but that is because bwBASIC shells
  25. out to DOS when it does not recognize CLS and executes CLS there.)
  26. The interpreter is slow. Whenever faced with a choice between
  27. conceptual clarity and speed, I have consistently chosen
  28. the former. The interpreter is the simplest design available,
  29. and utilizes no system of intermediate code, which would speed
  30. up considerably its operation. As it is, each line is interpreted
  31. afresh as the interpreter comes to it.
  32. bwBASIC implements one feature not available in previous BASIC
  33. interpreters: a shell command can be entered interactively at the
  34. bwBASIC prompt, and the interpreter will execute it under a
  35. command shell. For instance, the command "dir *.bas" can be
  36. entered in bwBASIC (under DOS, or "ls -l *.bas" under UNIX) and
  37. it will be executed as from the operating system command line.
  38. Shell commands can also be given on numbered lines in a bwBASIC
  39. program, so that bwBASIC can be used as a shell programming
  40. language. bwBASIC's implementation of the RMDIR, CHDIR, MKDIR,
  41. NAME, KILL, ENVIRON, and ENVIRON$() commands and functions
  42. offer further shell-processing capabilities.
  43. 2. TERMS OF USE:
  44. The bwBASIC source code and executables produced from it can be
  45. used subject to the following statement which is included in
  46. the header to all the source code files:
  47. All U.S. and international copyrights are claimed by the
  48. author. The author grants permission to use this code
  49. and software based on it under the following conditions:
  50. (a) in general, the code and software based upon it may be
  51. used by individuals and by non-profit organizations; (b) it
  52. may also be utilized by governmental agencies in any country,
  53. with the exception of military agencies; (c) the code and/or
  54. software based upon it may not be sold for a profit without
  55. an explicit and specific permission from the author, except
  56. that a minimal fee may be charged for media on which it is
  57. copied, and for copying and handling; (d) the code must be
  58. distributed in the form in which it has been released by the
  59. author; and (e) the code and software based upon it may not
  60. be used for illegal activities.
  61. 3. BASIC COMMANDS AND FUNCTIONS IMPLEMENTED:
  62. ABS( number )
  63. ASC( string$ )
  64. ATN( number )
  65. CHAIN [MERGE] file-name [, line-number] [, ALL]
  66. CHR$( number )
  67. CINT( number )
  68. CLEAR
  69. CLOSE [[#]file-number]...
  70. COMMON variable [, variable...]
  71. COS( number )
  72. CSNG( number )
  73. CVD( string$ )
  74. CVI( string$ )
  75. CVS( string$ )
  76. DATA constant[,constant]...
  77. DATE$
  78. DEF FNname(arg...)] = expression
  79. DEFDBL letter[-letter](, letter[-letter])...
  80. DEFINT letter[-letter](, letter[-letter])...
  81. DEFSNG letter[-letter](, letter[-letter])...
  82. DEFSTR letter[-letter](, letter[-letter])...
  83. DELETE line[-line]
  84. DIM variable(elements...)[variable(elements...)]...
  85. END
  86. ENVIRON variable-string = string
  87. ENVIRON$( variable-string )
  88. EOF( device-number )
  89. ERASE variable[, variable]...
  90. ERL
  91. ERR
  92. ERROR number
  93. EXP( number )
  94. FIELD [#] device-number, number AS string-variable [, number AS string-variable...]
  95. FOR counter = start TO finish [STEP increment]
  96. GET [#] device-number [, record-number]
  97. GOSUB line
  98. GOTO line
  99. HEX$( number )
  100. IF expression THEN statement [ELSE statement]
  101. INPUT [# device-number]|[;]["prompt string";]list of variables
  102. INSTR( [start-position,] string-searched$, string-pattern$ )
  103. INT( number )
  104. KILL file-name
  105. LEFT$( string$, number-of-spaces )
  106. LEN( string$ )
  107. LET variable = expression
  108. LINE INPUT [[#] device-number,]["prompt string";] string-variable$
  109. LIST line[-line]
  110. LOAD file-name
  111. LOC( device-number )
  112. LOF( device-number )
  113. LOG( number )
  114. LSET string-variable$ = expression
  115. MERGE file-name
  116. MID$( string$, start-position-in-string[, number-of-spaces ] )
  117. MKD$( double-value# )
  118. MKI$( integer-value% )
  119. MKS$( single-value! )
  120. NAME old-file-name AS new-file-name
  121. NEW
  122. NEXT counter
  123. OCT$( number )
  124. ON variable GOTO|GOSUB line[,line,line,...]
  125. ON ERROR GOSUB line
  126. OPEN O|I|R, [#]device-number, file-name [,record length]
  127. file-name FOR INPUT|OUTPUT|APPEND AS [#]device-number [LEN = record-length]
  128. OPTION BASE number
  129. POS
  130. PRINT [# device-number,][USING format-string$;] expressions...
  131. PUT [#] device-number [, record-number]
  132. RANDOMIZE number
  133. READ variable[, variable]...
  134. REM string
  135. RESTORE line
  136. RETURN
  137. RIGHT$( string$, number-of-spaces )
  138. RND( number )
  139. RSET string-variable$ = expression
  140. RUN [line][file-name]
  141. SAVE file-name
  142. SGN( number )
  143. SIN( number )
  144. SPACE$( number )
  145. SPC( number )
  146. SQR( number )
  147. STOP
  148. STR$( number )
  149. STRING$( number, ascii-value|string$ )
  150. SWAP variable, variable
  151. SYSTEM
  152. TAB( number )
  153. TAN( number )
  154. TIME$
  155. TIMER
  156. TROFF
  157. TRON
  158. VAL( string$ )
  159. WEND
  160. WHILE expression
  161. WIDTH [# device-number,] number
  162. WRITE [# device-number,] element [, element ]....
  163. If DIRECTORY_CMDS is set to TRUE when the program is compiled,
  164. then the following commands will be available:
  165. CHDIR pathname
  166. MKDIR pathname
  167. RMDIR pathname
  168. If DEBUG is set to TRUE when the program is compiled then
  169. the following debugging commands (unique to bwBASIC) will
  170. be available:
  171. VARS (prints a list of all variables)
  172. CMDS (prints a list of all commands)
  173. FNCS (prints a list of all functions)
  174. If COMMAND_SHELL is set to TRUE when the program is compiled,
  175. then the user may enter a shell command at the bwBASIC prompt.
  176. 4. SOME NOTES ON USAGE:
  177. An interactive environment is provided, so that a line with a
  178. line number can be entered at the bwBASIC prompt and it will be
  179. added to the program in memory.
  180. Line numbers are not strictly required, but are useful if the
  181. interactive enviroment is used for programming. For longer
  182. program entry one might prefer to use an ASCII text editor, and
  183. in this case lines can be entered without numbers. In this case,
  184. however, one will not be able to alter the numberless lines
  185. within the interactive environment.
  186. Command names and function names are not case sensitive,
  187. so that "Run" and "RUN" and "run" are equivalent and "abs()"
  188. and "ABS()" and "Abs()" are equivalent. HOWEVER: variable
  189. names ARE case sensitive in bwbASIC, so that "d$" and "D$"
  190. are different variables. This differs from some BASIC
  191. implementations where variable names are not case sensitive.
  192. A filename can be specified on the command line and will be
  193. LOADed and RUN immediately, so that the command line
  194. bwbasic prog.bas
  195. will load and execute "prog.bas".
  196. All programs are stored as ASCII text files.
  197. TRUE is defined as -1 and FALSE is defined as 0 in the default
  198. distribution of bwBASIC. These definitions can be changed by
  199. those compiling bwBASIC (see file BWBASIC.H).
  200. Assignment must be made to variables. This differs from some
  201. implementations of BASIC where assignment can be made to a
  202. function. Implication: "INSTR( 3, x$, y$ ) = z$" will not
  203. work under bwBASIC.
  204. Notes on the implementation of specific commands:
  205. CVI(), CVD(), CVS(), MKI$(), MKD$(), MKS$(): These functions
  206. are implemented, but are dependent on a) the sizes for integer,
  207. float, and double values on particular systems, and b) how
  208. particular versions of C store these numerical values. The
  209. implication is that data files created using these functions
  210. on a DOS-based microcomputer may not be translated correctly
  211. by bwBASIC running on a Unix-based computer. Similarly, data
  212. files created by bwBASIC compiled by one version of C may not be
  213. readable by bwBASIC compiled by another version of C (even under
  214. the same operating system). So be careful with these.
  215. ENVIRON: The ENVIRON command requires BASIC strings on either
  216. side of the equals sign. Thus:
  217. environ "PATH" = "/usr/bin"
  218. It might be noted that this differs from the implementation
  219. of ENVIRON in some versions of BASIC, but bwBASIC's ENVIRON
  220. allows BASIC variables to be used on either side of the equals
  221. sign. Note that the function ENVIRON$() is different from the
  222. command, and be aware of the fact that in some operating systems
  223. an environment variable set within a program will not be passed
  224. to its parent shell.
  225. ERR: Note that if PROG_ERRORS has been defined when bwBASIC is
  226. compiled, the ERR variable will not be set correctly upon
  227. errors. It only works when standard error messages are used.
  228. FOR and NEXT: In this implementation of bwBASIC, a NEXT
  229. statement must appear in the first position in a program
  230. line; it cannot appear in a line segment beyond a colon.
  231. INPUT: bwBASIC cannot support the optional feature of INPUT
  232. that suppresses the carriage-return and line-feed at the end
  233. of the input. This is because ANSI C does not provide for any
  234. means of input other than CR-LF-terminated strings.
  235. 5. UNIMPLEMENTED COMMANDS AND FUNCTIONS
  236. There are a few items not implemented that have been so long
  237. a part of standard BASICs that their absence will seem surprising.
  238. In each case, though, their implementation would require opera-
  239. ting-system-specific functions or terminal-specific functions
  240. that ANSI C cannot provide. Some specific examples:
  241. CALL In some versions of BASIC, CALL is used to call a
  242. machine language subroutine, but machine language
  243. routines are highly system-specific. In other
  244. BASICs (conforming to the more complete ANSI
  245. definition of BASIC), CALL is used to call a
  246. named subroutine. Although it's possible that
  247. bwBASIC could develop as a numberless BASIC
  248. with named subroutine calls, these features
  249. are not implemented in this earliest released
  250. version.
  251. CLOAD See CALL above (machine language subroutines).
  252. CONT See RESUME below (programmer ignorance?).
  253. DEF USR See CALL above (machine language subroutines).
  254. EDIT EDIT would be especially nice, but requires some
  255. specific knowledge of how particular computers
  256. handle interaction between the screen and the
  257. keyboard. This knowledge isn't available within
  258. the bounds of ANSI C alone ("innerhalb die Grenzen
  259. der reinen Vernunft," with apologies to Immanuel
  260. Kant).
  261. FRE() The ability to report the amount of free memory
  262. remaining is system-specific due to varying patterns
  263. of memory allocation and access; consequently this
  264. ability is not present in ANSI C and this function
  265. is not available in bwBASIC.
  266. FILES The FILES command requires a list of files conforming
  267. to a specifier; ANSI C does not provide this. When
  268. COMMAND_SHELL is defined as TRUE, users might want
  269. to issue operating-system commands such as "DIR"
  270. (DOS) or "ls -l" (Unix) to get a list of files.
  271. INKEY$ This function requires a keyboard scan to indicate
  272. whether a key is pending. Although this facility
  273. is easily available on microcomputers (it is part
  274. of the minimal CP/M Operating System), it is not
  275. easily available on some more complex systems.
  276. Consequently, it's not part of the C standard and
  277. bwBASIC has not implemented INKEY$.
  278. INPUT$() Similar to INKEY$ above, ANSI C by itself is not
  279. able to read unechoed keyboard input, and can read
  280. keyboard input only after a Carriage-Return has
  281. been entered.
  282. INP Calls to hardware ports, like machine-language
  283. routines, are highly system-specific and cannot
  284. be implemented in ANSI C alone.
  285. LLIST See LPRINT below.
  286. LPOS See LPRINT below.
  287. LPRINT and LLIST, etc., require access to a printer device,
  288. and this varies from one system to another. Users
  289. might try OPENing the printer device on their own
  290. operating system (e.g., "/dev/lp" on Unix systems,
  291. or "PRN" under DOS) and see if printing can be done
  292. from bwBASIC in this way.
  293. NULL In this case, I am convinced that NULL is no longer
  294. necessary, since very few printers now require NULLs
  295. at the end of lines.
  296. OUT See INP above (calls to hardware ports).
  297. PEEK() PEEK and POKE enabled earlier BASICs to address
  298. particular memory locations. Although bwBASIC
  299. could possibly implement this command (POKE) and
  300. this function (PEEK()), the limitation would be
  301. highly limited by the different systems for
  302. memory access in different systems.
  303. POKE see PEEK() above.
  304. RENUM Since unnumbered lines can be entered and
  305. executed under bwBASIC, it would not be
  306. possible to implement a RENUM routine.
  307. RESUME Is this possible under ANSI C? If so, I
  308. simply have failed to figure it out yet.
  309. Mea culpa (but not maxima).
  310. USR See CALL and DEF USR above (machine language
  311. subroutines).
  312. VARPTR See PEEK and POKE above.
  313. WAIT See INP and OUT above.
  314. 6. SOME NOTES ON COMPILATION
  315. bwBASIC is written in ANSI C and takes advantage of some of the
  316. enhancements of ANSI C over the older K&R standard. The program
  317. expects to find standard ANSI C include files (such as ).
  318. Because there is nothing terminal- or hardware-specific about it,
  319. I should hope that it would compile correctly under any ANSI C
  320. compiler, but you may have to construct your own makefile.
  321. Two makefiles are currently provided: "makefile.qcl" will compile
  322. the program utilizing the Microsoft QuickC (tm) line-oriented
  323. compiler on DOS-based p.c.'s, and "makefile.gcc" will compile
  324. the program utilizing the ANSI option of Gnu C++. I have also
  325. compiled the program utilizing Borland's Turbo C++ (tm) on DOS-
  326. based machines.
  327. No alterations to flags are necessary for varied environments,
  328. but the beginning of file allows the user to set
  329. some debugging flags and to control some program defaults.
  330. The file has a number of language-specific message
  331. sets that can be controlled by setting the appropriate language
  332. flag.
  333. 7. THE STORY OF BYWATER BASIC
  334. This program was originally begun in 1982 by my grandmother, Mrs.
  335. Verda Spell of Beaumont, TX. She was writing the program using
  336. an ANSI C compiler on an Osborne I CP/M computer and although my
  337. grandfather (Lockwood Spell) had bought an IBM PC with 256k of
  338. RAM my grandmother would not use it, paraphrasing George Herbert
  339. to the effect that "He who cannot in 64k program, cannot in 512k."
  340. She had used Microsoft BASIC and although she had nothing against
  341. it she said repeatedly that she didn't understand why Digital
  342. Research didn't "sue the socks off of Microsoft" for version 1.0
  343. of MSDOS and so I reckon that she hoped to undercut Microsoft's
  344. entire market and eventually build a new software empire on
  345. the North End of Beaumont. Her programming efforts were cut
  346. tragically short when she was thrown from a Beaumont to Port
  347. Arthur commuter train in the summer of 1986. I found the source
  348. code to bwBASIC on a single-density Osborne diskette in her knitting
  349. bag and eventually managed to have it all copied over to a PC
  350. diskette. I have revised it slightly prior to this release. You
  351. should know, though, that I myself am an historian, not a programmer.
  352. 8. COMMUNICATIONS:
  353. Ted A. Campbell
  354. Bywater Software
  355. P.O. Box 4023
  356. Duke Station
  357. Durham, NC 27706
  358. USA
  359. email: tcamp@acpub.duke.edu