home *** CD-ROM | disk | FTP | other *** search
/ Archive Magazine 1996 / ARCHIVE_96.iso / discs / mag_discs / volume_8 / issue_06 / risc_os / Basic < prev    next >
Text File  |  1988-10-05  |  18KB  |  437 lines

  1. ARM BBC BASIC V: changes between 1.02 and 1.04
  2.  
  3. (1) OVERLAY
  4.  
  5. OVERLAY allows a single set of programs (referred to by a pre-initialised
  6. string array) to be loaded into common memory. The LVAR command lists the
  7. first line of libraries or installed libraries; the order of listing is also
  8. the order of searching - which is simply (a) search current program (b)
  9. search any LIBRARYs, last mentioned first (the order shown by LVAR) (c)
  10. search any INSTALLed libraries, again last mentioned first (d) search the
  11. OVERLAY library, starting with the current overlay in core (if there is one)
  12. and then linearly from the start of the OVERLAY array.
  13.  
  14. The OVERLAY statement takes a string array and allocates a single block of
  15. store large enough to hold any single one of the programs: at this stage no
  16. program is actually loaded. The programs referred to in the string array will
  17. be searched for procedure and functions and, once this has been found, the
  18. interpreter will load in the right overlay in order to execute it. One cannot
  19. call items in other overlays from an overlay library (even implicitly via the
  20. main program or other libraries). The search time can be reduced by setting
  21. the approriate element of the array to a null string when that library no
  22. longer needs to be consulted. It is important not to confuse the interpreter
  23. by changing the names in the string array! Another OVERLAY statement will
  24. work (after forgetting all the referenced procedures) but the store used by
  25. the first one will be lost: however, one can add new strings to the existing
  26. array provided the programs referred to are no larger than the largest one
  27. given to the OVERLAY statement.
  28.  
  29. DIM A$(10)
  30. A$(1)="adfs:&.Assistant":A$(2)="net:$.Matrices":A$(3)="net:$.PlotLib"
  31. OVERLAY A$()
  32.  
  33. (2) Save and restore DATA pointer (onto the stack)
  34.  
  35. Since DATA statements can be used in procedure libraries (by using RESTORE
  36. +), transparent use of the DATA pointer is also provided. The current value
  37. can be saved onto the stack just like the error status.
  38.  
  39. LOCAL DATA (may be used anywhere, unlike LOCAL A etc)
  40.    Makes the use of DATA local; i.e. saves the DATA pointer on the stack.
  41.  
  42. RESTORE DATA
  43.    Restore DATA pointer from the stack. An error will occur if the next
  44. thing on the stack is not a DATA pointer.
  45.  
  46. Returning from a function or procedure will restore any DATA pointer it
  47. finds on the stack. LOCAL DATA must be the last thing to be made local in a
  48. procedure or function (apart from LOCAL ERROR).
  49.  
  50. REM "safe" routine for reading in an array
  51. DEF PROCRead(A())
  52. REM going to use local DATA so save status
  53. LOCAL DATA
  54. REM set pointer
  55. RESTORE +0
  56. DATA 1,2,3,4,5,6,7,&99
  57. REM do the job!
  58. ENDPROC
  59. REM end of procedure will restore error status
  60.  
  61. (3) Array initialisation
  62.  
  63. A$()=<factor>,<expression>,<expression> ..
  64. A%()=<factor>,<expression>,<expression> ..
  65. A()=<factor>,<expression>,<expression> ..
  66.  
  67. Array initialisation can be done with all elements that same (A()=1) or with
  68. element by element initialisation (A()=1,2,3,4,5,6 etc.). The element by
  69. element form will leave any unspecified values alone. The order of values
  70. given in the list is "last subscript changes quickest" i.e. for DIM A(2,1),
  71. they would be A(0,0); A(0,1); A(1,0); A(1,1); A(2,0); A(2,1) in order.
  72.  
  73. (4) SUMLEN
  74.  
  75. SUMLEN which returns the sum of the lengths of all the strings in a string
  76. array.
  77.  
  78. (5) MOD
  79.  
  80. MOD which returns the modulus (square root of the sum of the squares of each
  81. element) of a numeric array.
  82.  
  83. Example of (3), (4) and (5):
  84.  
  85. transformation()=1,0,0,0,1,0,0,0,1
  86. coordinate()=coordinate().transformation()
  87. PRINT"There are ";SUMLEN(A$())" characters."
  88. normalisedvector()=vector()/MODvector()
  89.  
  90. (6) ERROR EXT
  91.  
  92. ERROR EXT <number>,<string> passes an error to the caller's error handler
  93.  
  94. (7) QUIT
  95.  
  96. QUIT function: TRUE if BASIC has been called with -quit on command line
  97.  
  98. (8) Store allocation
  99.  
  100. When a string is stored, the current space is immediately used if the number
  101. of words is compatible; otherwise the space is deallocated: it is stored on
  102. the appropriate member of an array of free lists, each list having one size
  103. in words. This makes allocation of the new space for a string very quick:
  104. check the free list corresponding to the desired length, if there is an
  105. entry, take it; otherwise use new space. Use of contiguous store has been
  106. disabled in 1.03 since it gives rise to some strange side effects: programs
  107. running on 1.03 may use fractionally more store than on 1.02, but generally
  108. long term use of strings will result in less used memory.
  109.  
  110. (9) Revised error descriptions
  111.  
  112.  0,"Silly!"
  113.  0,"No room to do this renumber"
  114.  0,"Line numbers larger than 65279 would be generated by this renumber"
  115.  0,"No room"
  116.  0,"Line too long"
  117.  0,"Stopped"
  118.  0,"Invalid LISTO option"
  119.  0,"Invalid TWINO option"
  120.  0,"Corruption of stack"
  121.  0,"Error control status not found on stack for RESTORE ERROR"
  122.  0,"Missing incore name"
  123.  0,"LIST/TWIN found line number reference"
  124.  0,"HELP has no information on this keyword"
  125.  0,"Incorrect in-core file description"
  126.  1,"No such mnemonic"
  127.  1,"No such suffix on EQU"
  128.  2,"Bad immediate constant"
  129.  2,"Bad address offset"
  130.  2,"Assembler limit reached"
  131.  2,"Bad shift"
  132.  3,"Bad register"
  133.  3,"Duplicate register in multiply"
  134.  4,"Missing ="
  135.  4,"Missing = in FOR statement"
  136.  4,"Mistake"
  137.  5,"Missing ,"
  138.  6,"Type mismatch: number needed"
  139.  6,"Type mismatch: numeric variable needed"
  140.  6,"Type mismatch: numeric array needed"
  141.  6,"Type mismatch: string needed"
  142.  6,"Type mismatch: string variable needed"
  143.  6,"Type mismatch: string array needed"
  144.  6,"Type mismatch: array needed"
  145.  6,"Type mismatch between arrays"
  146.  6,"Can't assign to array of this size"
  147.  6,"Array type mismatch as parameter"
  148.  6,"Can't SWAP arrays of different types"
  149.  7,"Not in a function"
  150.  8,"Too low a value for $<number>"
  151.  9,"Missing """
  152.  10,"DIM() function needs an array"
  153.  10,"No room to do matrix multiply with source(s) the same as destination"
  154.  10,"Impossible dimension"
  155.  10,"No end of dimension list )"
  156.  10,"Bad DIM statement"
  157.  10,"Can't DIM negative amount"
  158.  10,"Arrays cannot be redimensioned"
  159.  11,"No room for this DIM"
  160.  11,"No room for this dimension"
  161.  11,"Attempt to allocate insufficient memory"
  162.  12,"Items can only be made local in a function or procedure"
  163.  13,"Not in a procedure"
  164.  14,"Reference array incorrect"
  165.  14,"Unknown array"
  166.  14,"Unknown array in DIM() function"
  167.  14,"Undimensioned array"
  168.  15,"Subscript out of range"
  169.  15,"Incorrect number of subscripts"
  170.  16,"Syntax error"
  171.  17,"Escape"
  172.  18,"Division by zero"
  173.  19,"String too long"
  174.  20,"Number too big"
  175.  20,"Number too big for arc Sine or arc Cosine"
  176.  21,"Negative root"
  177.  22,"Logarithm range"
  178.  23,"Accuracy lost in Sine/Cosine/Tangent"
  179.  24,"Exponent range"
  180.  26,"Unknown or missing variable"
  181.  26,"Can't use array reference here"
  182.  27,"Missing )"
  183.  27,"Missing ("
  184.  27,"Missing ]"
  185.  27,"Missing {"
  186.  27,"Missing }"
  187.  28,"Bad Hex"
  188.  28,"Hex number too large"
  189.  28,"Bad Binary"
  190.  29,"No such function/procedure"
  191.  30,"Bad call of function/procedure"
  192.  31,"Arguments of function/procedure incorrect"
  193.  31,"Invalid RETURN actual parameter"
  194.  31,"Invalid array actual parameter"
  195.  32,"Not in a FOR loop"
  196.  33,"Can't match FOR"
  197.  34,"Bad FOR control variable"
  198.  35,"The step cannot be zero"
  199.  36,"Missing TO"
  200.  37,"No room for function/procedure call"
  201.  38,"Not in a subroutine"
  202.  39,"ON syntax"
  203.  40,"ON range"
  204.  41,"No such line"
  205.  42,"Out of data"
  206.  42,"DATA pointer not found on stack for RESTORE DATA"
  207.  43,"Not in a REPEAT loop"
  208.  44,"Too many nested structures"
  209.  45,"Missing #"
  210.  46,"Not in a WHILE loop"
  211.  47,"Missing ENDCASE"
  212.  48,"OF missing from CASE statement"
  213.  48,"CASE..OF statement must be the last thing on a line"
  214.  49,"Missing ENDIF"
  215.  50,"Bad MOUSE variable"
  216.  51,"Too many input expressions for SYS"
  217.  51,"Too many output variables for SYS"
  218.  52,"Can't install library"
  219.  52,"Bad program used as function/procedure library"
  220.  52,"No room for library"
  221.  
  222. (10) New assembler feature
  223.  
  224. Bit 3 in OPT (opts 8-15) controls an assembler area limit check: the
  225. assembler will check the variable L% to decide if it can deposit information
  226. at the current address (P% or O% depending on OPT as usual) (Note that DIM
  227. P% 1,L% -1 will assign L% a word address (which DIM likes returning) and so
  228. can take a full word of assembly).
  229.  
  230. (11) More exported routines from CALL
  231.  
  232. The value in r14 can be returned to with MOV PC,R14 but it also points to an
  233. array of useful values:
  234.  
  235.  B CALL2REAL ;0th entry in table is return address
  236. ;the following values are words containing an offset from ARGP (R8)
  237. ;word aligned 256 bytes
  238.  & STRACC ;string accumulator
  239. ;word aligned words offset from ARGP
  240.  & PAGE ;current program PAGE
  241.  & TOP ;current program TOP
  242.  & LOMEM ;current variable start
  243.  & HIMEM ;current stack end
  244.  & MEMLIMIT ;limit of available memory
  245.  & FSA ;free space start (high water mark/FD stack limit)
  246.  & TALLY ;value of COUNT
  247.  & TIMEOF ;offset from TIME readable by OSWORD
  248.  & ESCWORD ;exception flag word (contains escflg, trcflg)
  249.  & WIDTHLOC ;value of WIDTH-1
  250. ;internal BASIC routines
  251.  B VARIND ;get value of lv
  252.  B STOREA ;store value into lv
  253.  B STSTORE ;store string into type 128 strings
  254.  B LVBLNK ;convert string "variable name" to lv address and type
  255.  B CREATE ;create new variable
  256.  B EXPR ;use expression analyser on string
  257.  B MATCH ;lexical analyse source string to destination string
  258.  B TOKENADDR ;pointer to string for particular token
  259.  & 0 ;stop point for ****** Minerva programs
  260. ;new on BASIC V 1.03
  261.  & 9 ;length of extensions
  262.  B FSTA ;store fp in r0-r3 as 5 bytes at r9
  263.  B FLDA :load fp from r9 as 5 bytes into r0-r3
  264.  B FADD ;add fp in r0-r3 to 5 bytes at r9, result in r0-r3
  265.  B FSUB ;subtract fp in r0-r3 from 5 bytes at r9, result in r0-r3
  266.  B FMUL ;multiply fp in r0-r3 by 5 bytes at r9, result in r0-r3
  267.  B FDIV ;divide fp in 5 bytes at r9 by r0-r3, result in r0-r3
  268.  B FLOAT ;float an integer in r0 to an fp in r0-r3
  269.  B FIX ;fix an fp in r0-r3 to an integer in r0
  270.  B FSQRT ;square root of r0-r3
  271.  
  272. Note that the list is held in two different forms: the first section is
  273. exactly like BASIC 1.02: a list terminated by zero. The list could not be
  274. simply extended because of some unfortunate assumptions bound into poorly
  275. written application programs, so a second list has been tacked on the end.
  276. A client can check the number of extensions field (i.e. the field after the
  277. zero) and it will be 0 or negative if there aren't any.
  278.  
  279. The pointer TIMEOF is particularly interesting. On Arthur this location
  280. holds a meaningless value; on other systems it holds the offset which should
  281. be subtracted from the time read from the system if one wishes to agree
  282. with the value given by PRINT TIME. However the next three words offset from
  283. the argument register after TIMEOF (i.e. [R8,TIMEOF+4] etc.) contain:
  284.  
  285.   LOCALARLIST: a pointer to a list of local arrays.
  286.   INSTALLLIST: a pointer to the list of installed libraries.
  287.   LIBRARYLIST: a pointer to the list of libraries.
  288.  
  289. The local array list is not going to be much use, but the ability to scan the
  290. libraries allows (say) find commands to be installed which can find a
  291. procedure whereever it is. The list consists of a pointer (0 is the end of
  292. the list) to a word (which is the next pointer) and a BASIC program in
  293. internal form immediately following the word. The list is organised in the
  294. search order.
  295.  
  296. The internal routines are only guarenteed to work in processor user mode.
  297. The following functions are provided:
  298.  
  299. VARIND: entry with r0=address of lv, r9=type of lv, r12=LINE.
  300. Returns with r0..r3 as the value, r9 the type of the value as follows:
  301.  
  302. r9         type    where
  303. 0          string  in STRACC, r2 points to end (r2-STRACC is length)
  304. &40000000  integer in r0
  305. &80000000  float   in r0..r3
  306.  
  307. Uses no other registers (including stack). Possible error if asked to take
  308. value of an array fred(): will need r12 valid for this error to be reported
  309. correctly.
  310.  
  311. STOREA: entry with r0..r3 value, r9=type of value and r4=address of lv,
  312. r5=type of lv, r8=ARGP, r12=LINE (for errors) and r13=SP (for out of store
  313. chcek on string allocation). Will convert between various formats e.g.
  314. integer and float or produce an error if conversion is impossible.
  315. Returns with r0..r7 destroyed. Stack not used.
  316.  
  317. STSTORE: entry with r4=address of lv, r2=length (address of end), r3=address
  318. of start, r8=ARGP, r12=LINE (for out of store error) and r13=SP (for out of
  319. store check). The string must start on a word boundary, the length must be
  320. 255 or less.
  321. Uses r0, r1, r5, r6, r7. Preserves input registers. Stack not used.
  322.  
  323. LVBLNK: entry with r11 pointing to start of string, r8=ARGP, r12=LINE (many
  324. errors possible e.g. subscript error in array) and r13=stack (will be used
  325. for evaluation of subscript list: calls EXPR). The string will be processed
  326. to read one variable name and provide an address and type which can be given
  327. to VARIND.
  328. Returns with NE status if a variable has been found. Address in r0, type (see
  329. above) in r9. If there is an EQ status then if the carry is set it cannot
  330. possibly be a variable else if the carry is clear it could be, but isn't
  331. known to the interpreter (and registers are set to values for CREATE).
  332. Uses all registers.
  333.  
  334. CREATE: create a variable. Input is the failure of LVBLNK to find something.
  335. Thus we have r10=first char of item, r3=second char of item or 0, r4 and r11
  336. pointers to start and end of other chars, r8=ARGP, r12=LINE, r13=STACK, r9
  337. contains the number of zero bytes on the end. It is recommended that CREATE
  338. is called immediately after a failed LVBLNK only.
  339. Uses all registers. Return parameters as LVBLNK.
  340.  
  341. The LVBLNK and CREATE routines can be combined together to provide a routine
  342. which checks for a variable to assign to and creates it if necessary:
  343.  
  344. SAFELV STMFD SP!,{R14}
  345.        BL LVBLNK
  346.        LDMNEFD SP!,{PC}
  347.        LDMCSFD SP!,{PC}
  348.        BL CREATE
  349.        LDMFD SP!,{PC}
  350.  
  351. EXPR: entry with r11 pointing to start of string, r8=ARGP, r12=LINE, r13=STACK.
  352. EXPR stops after reading one expression (like those in the PRINT statement).
  353. Uses all registers. The value is returned like VARIND. If status EQ it read a
  354. string, if status NE and plus it read an integer word (in r0) if status NE
  355. and minus it read a floating point value (in r0..r3). r9 contains the type:
  356. the status can be recreated by TEQ r9,#0. r10 contains the delimiting
  357. character, r11 points to the one after.
  358.  
  359. MATCH: entry with r1=source string (terminated by ASCII CR=13),
  360. r2=destination string, r3=MODE, r4=CONSTA, r13=STACK. Note that MATCH does
  361. not need ARGP or LINE. The MODE value is 0 for LEFT MODE (i.e. before an
  362. equals sign) and 1 for RIGHT MODE (after an equals sign or in an expression).
  363. The CONSTA value is 0 for don't pack constants using token &8D, &8D itself
  364. for pack. Both MODE and CONSTA will be updated during use of the routine
  365. e.g. GOTO will change CONSTA to &8D to read the constant, PRINT will change
  366. MODE to 1 to read the expression. Starting values of MODE=0 and CONSTA=0
  367. will lexcially analyse a statement; MODE=1 and CONSTA=0 an expression;
  368. MODE=0 and CONSTA=&8D is used to extract line numbers in command mode and
  369. probably has little use. MODE affects the values assigned to tokens for
  370. HIMEM etc.
  371. Uses r0-r5. r1 and r2 are left pointing after the CR codes in the strings.
  372. r5 contains status about failures to analyse the line correctly: it can be
  373. used or disregarded: values >= &1000 imply mismatched brackets, bit 8 set
  374. implies a line number was found that was too large to be put into a &8D
  375. constant and if r5 AND 255 equals 1 it implies mismatched string quotes.
  376.  
  377. TOKENADDR: entry with r0 as the token value, r12=pointer to next byte of
  378. token string. The value in r12 is only used when the address of a two byte
  379. token is required. No other register are used or required.
  380. Returns r1 as the pointer to the first character of a string, terminated by a
  381. value >=&7F (which is the first byte of the token value). r0 is set to the
  382. address of the start of the token table itself. r12 will have been
  383. incremented by 1 if a two byte token was used.
  384.  
  385. FSTA: Saves the five byte form of a floating point number. Entry with r0-r3
  386. as the floating point value, r9=address of destination. Stack not used. No
  387. error possible. r2 altered (but this does not affect the fp value of r0-r3).
  388.  
  389. FLDA: Loads the five byte form of a floating point number. Entry with address
  390. in r9. Exit with r0-r3 as floating point value. Stack not used. No error
  391. possible.
  392.  
  393. FADD: Add floating point value in r0-r3 to five byte form at r9. Result in
  394. r0-r3. Stack not used. Overflow error possible. Uses r4-r7.
  395.  
  396. FSUB: Subtract floating point value in r0-r3 from five byte form at r9.
  397. Result in r0-r3. Stack not used. Overflow error possible. Uses r4-r7.
  398.  
  399. FMUL: Multiply floating point value in r0-r3 by five byte form at r9. Result
  400. in r0-r3. Stack not used. Overflow error possible. Uses r4-r7.
  401.  
  402. FDIV: Divide five byte form at r9 by floating point value in r0-r3. Result
  403. in r0-r3. Stack not used. Divide by zero and overflow error possible. Uses
  404. r4-r7.
  405.  
  406. FLOAT: Float an integer in r0 to a floating point value in r0-r3. Stack not
  407. used, no error possible. Sets type field in r9 to FLOATING (&80000000).
  408.  
  409. FIX: Fix a floating point value in r0-r3 to an integer in r0. Stack not used.
  410. Overflow error possible. Sets type field in r9 to INTEGER (&40000000).
  411.  
  412. FSQRT: Square root of floating point value in r0-r3 return in r0-r3. Uses
  413. r4-r7.
  414.  
  415. (12) Sped up areas
  416.  
  417. Simple expressions (indeed very complex ones have been slowed down!). SYS
  418. statement, especially where no results (no TO) are required. String
  419. allocation (by varying amounts depending on what is happening).
  420.  
  421. (13) Bugs fixed
  422.  
  423. 18-Sep-87   division by power of 2 did not check under/overflow.
  424. 24-Sep-87   LOCAL A()
  425. 28-Sep-87   A()=const
  426. 08-Dec-87   LOCAL A():DIM A(1,1) messed stack due to bug in DIM re type (also
  427.             misallocates integer arrays!).
  428. 04-Jan-88   LINE INPUT had sense of LINE flag wrong - misbehaved for A,B ans.
  429. 05-Jan-88   HIMEM=HIMEM wouldn't work.
  430. 08-Feb-88   CREATE was uncallable due to LVBLNK loosing R4.
  431. 26-Feb-88   STRACC postion changed for Arthur 2.00.
  432. 29-Feb-88   $A="" check for <&8000.
  433. 07-Mar-88   50IF<false>THEN50 unescapeable
  434. 12-May-88   INPUT#,a$ at end of file gives end of file message.
  435. 23-May-88   ATN of a large power of 2 went wrong.
  436. 01-Sep-88   WHILE <no sd> failed in TRACE state due to moving LINE in SLOWMUNG
  437.