home *** CD-ROM | disk | FTP | other *** search
/ Outlet 54 / outlet-54.mgt / t4 < prev    next >
Text File  |  2021-04-18  |  20KB  |  1 lines

  1.         When the FOR command is scanned by the statement loop in1B6F SEPARATOR, reading the syntax parameters at 1A90, the      command is checked to ensure that TO is there. By this time the value of the first parameter of the FOR expression (the VALUE)  is already last value on the calculator stack; the TO token is  simply skipped. It serves a purpose at 2713 S CONT 3 leading to 2723 S OPERTR and 2734 S LOOP, by triggering the evaluation of  the expression.                                                         In 2A52 SLICING, the need for a slicing operation has   already been recognised before the TO is scanned: the last      subscript of an array, or any "(" following a simple string or  the completed expression of an array (2713 S CONT 3), produces acall to SLICING. Any slice of more than one character must have a TO in it; if TO is the first character of the slicing it is   read as "1 TO", if the last it is read as "TO the dimension     limit". You can command PRINT a$( TO ), though it does nothing  very useful, just prints out the whole of a$.                           29D8 SV CLOSE last subscript must be followed by TO                           or ")"                                            29EA SV LOOP slicing indicated by TO                                                                                        token codes, tokens see also character codes and individual token keys                                                              The 91d character codes from A5 RND to FF COPY are      tokens, that is to say that in printouts of the BASIC line a    single character code, produced by a single keystroke, is       _expanded to a string of two or more characters.                        This has nothing to do with the implementation of the   code: <> etc are tokens, + - * / aren't. Nor has it much to do  with the key "mode": all the letter keys in K mode produce      tokens, eleven of them are produced by symbol shift in any mode,and the rest by E mode with or without shift, but other keys in E mode produce symbols.                                                 All the tokens are "printable" characters, see 001C SKIPOVER.                                                                   The tokens are only expanded, ie transformed into       strings of letters or symbols, when they are output to screen orZX printer: each token is represented by its single token code  in the program area, in the variables area if it is incorporatedin strings, in the editing area or in the input area/work space.        For actual printing out of the codes, they are treated  much like "messages", eg the report messages. See under 0C0A PO MSG and Table of tokens. At 0B52 PO T&UDG in the 09F4 PRINT OUT routine, the code is reduced by A5h so that it is now from 00   RND to 5A COPY. This is used by 0C14 PO TABLE and 0C41 PO SEARCHto index into the token table at 0095 and print the token. The  "?" at the beginning of the table isn't counted - it doesn't    seem to be used by the ROM.                                             The use of tokens, which simplifies input by the user   and also simplifies compilation of the BASIC, is a Sinclair     invention and isn't found on other computers, in which all      commands etc must be typed out in full, as in the Spectrum in   128K mode.                                                              Introduction token table                                        0364 K TOKENS all tokens in K/L mode found by "main                           code" (ie capital letter) plus A5                 06A0 SA SCR$ SCREEN$ token checked                              06C3 SA CODE CODE token checked                                 0716 SA LINE LINE token checked                                 09F4 PRINT OUT entered with code in A                           0B24 PO ANY jump to print tokens                                0B52 PO T&UDG jump again to print tokens                        0B5F PO T call and exit for token printing                      0C0A PO MSG prints messages or tokens                           0C10 PO TOKENS entry point for token printing                   0C14 PO TABLE leading space printed for most tokens             0C22 PO EACH prints characters of token                         0F38 ED LOOP all tokens accepted by editing                     10A8 KEY INPUT all tokens accepted by key input                 1795 AUTO LIST tokens expanded in listing of BASIC              1937 OUT CHAR checks tokens before printing edit line           198B EACH STMT can find selected token in BASIC                 1990 EACH S 1 check character with given token                  1C96 PERMS checks for INK to OVER tokens                        1D86 LOOK PROG looks for DATA, DEF FN, NEXT tokens              1E39 PASS BY finds statement following DATA or DEF FN                                                                       top line see automatic line number, print position, 5C6C S  TOP                                                                                                                                 top of calculator stack see CALCULATE                                                                                           top of (possible) RAM see 5CB2 RAMTOP, 5CB4 P RAMT                  The Spectrum chips allow RAM to be read and written up  to the address FFFFh set in 0000 START; 7FFFh in the 16K        Spectrum. But if there is a defect in the chip preventing       certain addresses being written, it will be detected on start-upby 11E2 RAM READ; 02 has been written into every address by 11DCRAM FILL, and this is decremented twice in each address. If any of them fails to reach zero, it is defective, and P RAMT is set at the one below. Thus the computer will still work, though witha reduced RAM.                                                          On a NEW command the check is also made, but only up to the limit set in 5CB2 RAMTOP.                                                                                                       top of screen see DISPLAY AREA                                                                                                  to-power subroutine 3851                                            Called from 0028 FP CALC with literal 06; the executive routine of the "up arrow" operator, printed in this index as    "**", as in many versions of BASIC. X**Y returns the number X tothe power Y. Fractional and negative powers are explained in theold Spectrum handbook on p. 65, pp. 70-71 in the Plus 2 book.           Not called from ROM otherwise, but it is the exit from  384A sqr, used to raise X to the power one-half. Can be called  from ROM direct or through the calculator.                              The subroutine makes use of the EXP and LN functions to simplify the calculation. It is important to understand that    these two functions reverse each other: EXP X means e**X, X = LNY if Y = EXP X = e**X. So EXP LN X = X.                                 If Z = X**Y, then                                                               LN Z = Y * LN X                          unless X is negative, which is an error, or zero.                      Use the ln routine to get LN X, then calculate LN Z as Y* LN X; exit to the exp routine which returns                                         EXP LN Z = Z = X**Y                        as required.                                                          Input parameters: HL and DE point to X and Y, the second last and last values on the stack respectively; they must be on the stack even for direct calls.                                       Action: use the calculator to check X                            - if it is zero jump on to XISO; the sequence not/jump  true is equivalent to "jump on zero"                                    - (non-zero X) calculate LN Z = Y * LN X; 3713 ln will  report "Invalid argument" if X is negative                              - exit to 36C4 exp, which gives a correct result for    non-zero X whatever the value of Y.                                    _385D_XISO (X = zero): if Y is also zero, jump on to ONE         - put a zero on the calculator stack                            - if Y is positive jump on to LAST with zero as the     result; any positive power of zero is zero                              - (Y is negative) calculate one divided by zero, which  reports "Number too big"; correct for zero X and negative Y.           _386A_ONE (zero X; Y**0 is considered to give the result one, whether Y is positive or negative or even zero): clear the calculator stack and put one on it as the result.                      _386C_LAST: exit.                                              Exit: to 36C4 exp, which calculates EXP (Y * LN X), unlessX is zero.                                                             Output parameters: the result on the calculator stack,   X**Y, zero or one                                                       - HL pointing to it                                             - DE pointing to the stack end.                                Exit from:                                                       384A sqr                                                                                                                    trailing space see 0C0A PO MSG                                                                                                  true exponent of FP number, true FP form of numbers, true    numerical bit of FP number see CALCULATE                                                                                           "true" expression see logical value                                                                                             TRUE VIDEO key see colours, INVERSE control code                                                                                truncate subroutine 3214                                            Called from 0028 FP CALC with literal 3A; not called    directly from ROM, but it could so be called from m/c.                  It returns the integer part of X, positive or negative; ie X ignoring any of its decimal/binary/hex digits after the    fractional point.                                                       This isn't precisely the executive routine of any BASIC function; for positive numbers it is the same as INT, but for   negative numbers INT returns the next integer_below, ie further from zero, and truncate returns the next_above, ie closer to    zero.                                                                   The subroutine is more complicated than one might       expect. In a FP number the four mantissa bytes corrected for    positive/negative sign give a 32d-binary-digit representation ofthe number, and to truncate it all you need to do is zero the   digits representing the fractional part; but the only way to    tell which digits are the integer part and which the fractional part is by counting from the left with the true exponent.              Input parameters: HL points to the first byte of the     number X to be truncated; in all the ROM calls this is the last value on the calculator stack, but for direct calls it could be anywhere in memory.                                                    Action: if the first byte of X is zero, return at once;  zero exponent byte means X is in small integer format and there is nothing for the subroutine to do                                     - (full FP format) if it is more than 80h jump on to T  GR ZERO                                                                 - (exponent is less than 80h, so X is less than one)    zero the exponent                                                       - make a bit counter 20h/32d to zero all 32d bits of themantissa                                                                - jump on to NIL BYTES.                                        _3221_T_GR_ZERO and_3233_T_FIRST (exponent is 81h or     more, so X is more than one): if the exponent isn't 91h jump on to T SMALL                                                              - (the exponent is 91h, ie the number is 2 * 65536d     times a mantissa between half and one, or 65536d times a number between one and two) this includes the "wrong number" -65536d.  See under wrong number for a discussion of this part of the ROM,which is misconceived and erroneous.                                   _323F_T SMALL: if the exponent of X is more than 91h jumpon to X LARGE                                                           - (the true exponent is 10h or less, so the result will be less than 10000h, and can be expressed as a small integer)   reverse the exponent, ie subtract it from FFh; transforming it  from the range 81h -> 90h to 7Eh -> 6Fh                                 - add 91h, transforming it to the range 0Fh -> 00; this is a zero counter, the number of binary zero digits to be       inserted at the start of the sixteen-bit representation of X            - load the two hi bytes of the mantissa into DE;        shifting these right with the zero counter will give the        absolute value of truncated X in DE, after correcting the hi bitwhich indicates the +/- sign of X                                       - make a sign flag set to 00 for positive                       - if the hi bit of D is zero jump on to T NUMERIC; X is positive                                                                - (X is negative) make the sign flag FF; negative.             _3252_T_NUMERIC: set the hi bit; now DE holds two bytes  of the true mantissa                                                    - if the zero counter is less than eight jump on to T   TEST                                                                    - (zero counter eight or more; all of the E byte is     fractional part) move D to E                                            - zero D                                                        - take away eight from the zero counter.                       _325E_T_TEST: if the zero counter is zero jump on to T   STORE; no shifting will be needed                                       - (some shifts needed) copy the zero counter into a loopcounter for the shifting loop.                                         _3261_T_SHIFT: shift DE right with zero into the hi bit          - loop back to T SHIFT, counting down the zero counter.        _3267_T_STORE (DE now holds the small integer truncation of X): call 2D8E INT STORE, which makes a small integer at the  pointer address; with zero in the exponent byte, the sign flag  from the C register in the second, E and D in the third and     fourth                                                                  - return.                                                      _326C_T_EXPNENT (entered only from T FIRST, see under    wrong number): get the exponent again.                                 _326D_X_LARGE (the exponent is more than 90h, so X after truncation will still be in full FP format): if the exponent is A0h or more, return; the true exponent is 20h or more, X is     larger than FFFF,FFFFh. All 32d of the binary digits of the     mantissa are used up representing the integer part and the      fractional part isn't represented in FP format at all, so       truncation will have no effect                                          - (X has a fractional part) negate the result of taking A0h from the exponent; the subtraction transformed the exponent from 91h -> 9Fh to F1h -> FFh, so negating, subtracting from    100h, makes 09 -> 01. This is the fractional bit counter, the   number of digits at the lo end of the mantissa which represent  the fractional part of X and therefore are to be zeroed.               _3272_NIL_BYTES: set a pointer on the last mantissa byte         - divide the fractional bit counter by eight; this is   the number of complete mantissa bytes to be zeroed                      - if this byte counter is zero jump on to BITS ZERO.           _327E_BYTE_ZERO: zero the byte at the byte pointer               - move back the byte pointer                                    - loop back to BYTE ZERO counting down the byte counter to zero.                                                               _3283_BITS_ZERO: AND the fractional bit counter with     00000111b/07; this gives the remainder on dividing it by eight, the number of fractional bits to be zeroed in the next byte back        - if the result is zero jump on to IX END                       - make the remainder a loop counter                             - make a mask byte 11111111b/FFh.                              _328A_LESS_MASK: shift the mask left, with zero into its lo bit                                                                  - loop back to LESS MASK counting the loop down to zero;on exit from this loop the mask will be eg 11100000b if the     count was 05                                                            - AND this mask with the last non-zeroed byte; thus     zeroing just the right bits for the correct result.                    _2290_IX_END: restore the pointers as they were input.          Exit: RETs                                                       - from truncate if X was a small integer already                - from T STORE if X was small enough to be made a small integer                                                                 - from X LARGE if X was too big to have a fractional    part                                                                    - from IX END otherwise.                                       Output parameters: truncated X has replaced X                    - HL points to its first byte                                   - DE points one past its last byte; if the subroutine   was called through the calculator, truncated X is the last valueon the stack and DE is the stack end.                                  Called from:                                                     36AF int                                                        36B7 X NEG                                                     Rems:                                                            3014 addition problems with "wrong number" -65536                                                                           T SHIFT 3261 (3214 truncate)                                       Jumps from:                                                      auto                                                                                                                        T SMALL 323F (3214 truncate)                                       Jumps from:                                                      3221 T GR ZERO                                                                                                              T states see time period                                                                                                        T STORE 3267 (3214 truncate)                                       Jumps from:                                                      325E T TEST                                                                                                                 T TEST 325E (3214 truncate)                                        Jumps from:                                                      3252 T NUMERIC                                                                                                              TVDATA system variable 5C0E see 0A75 PO 2 OPER under 09F4   PRINT OUT                                                              Bytes: 2.