1CF0 IF drop 1B76 STMT RET 1FC3 UNSTACK Z flag signals dropping of return 1 33A2 fp-calc-2 temporarily drop 3365 RE ENTRY 369B end-calc drop 3365 RE ENTRY address of BASIC line see BASIC line address table for calculator see_Table_of_addresses _(calculator_functions) under "tables" algorithms An algorithm is a series of simple arithmetical steps which by repetition perform a complex calculation; long divisionis a familiar example. Most programming can be regarded as the invention of algorithms operable by the computer. 24B7 DRAW LINE contains one from ZX 80 ROM 24CB DL LARGER it starts here 24EC D L PLOT continued ALL ADDED 300D (3004 ADD BACK) Jumps from: 3004 ADD BACK ALPHA subroutine 2C8D see also 2C88 ALPHANUM, 2D1B NUMERIC Checks if a given character is a letter of the alphabet.A useful routine for m/c programmers. Input parameters: character code in A. Action: compare A with 41 "A", 5B "Z"+1, 61 "a" and 7B "z"+1; complement the carry flag as required for a correct result. Exit: RET. Output parameters: carry is set if A is a letter of the alphabet, A-Z or a-z, otherwise NC - all registers unchanged. Called from: 1F6A DEF FN 1 1F86 DEF FN 3 20ED IN ITEM 3 27BD S FN SBRN 28B2 LOOK VARS 34BC usr-$ alphabetic characters see 2C8D ALPHA ALPHANUM subroutine 2C88 see also 2C8D ALPHA, 2D1B NUMERIC Checks if a given character is a letter of the alphabet or a digit. Input parameters: character code in A. Action: call 2D1B NUMERIC - complement the carry flag - return if this makes carry, indicating a digit. Exit: RET if NUMERIC signals a digit - otherwise into 2C8D ALPHA to check for alphabetic codes. Output parameters: carry set if A is a letter of the alphabet or a digit, 0-9, A-Z or a-z, otherwise NC - all registers unchanged. Called from: 2684 S ALPHNUM 28B2 LOOK VARS 28D4 V CHAR 2913 V SPACES 2943 V PASS 2B1F L TEST CH alphanumeric characters see 2C88 ALPHANUM alternate registers see also 0C1B PO SAVE and 0C88 PO SCR 2 (in 0C55 PO SCR) M/c programmers should beware of the 24B7 DRAW LINE routine, which switches registers each time a pixel is plotted; if an odd number is plotted they remain switched on return. The note at 34B3 usr-no is a little puzzling at first sight: experience soon shows that the BASIC_will crash if USR routines use the HL' register and don't reset it to 2758h, but why is this? and when does HL' originally get set to 2758? The other alternate registers can be used quite freely. The explanation lies in the fact that the only way to use the Spectrum for machine code programming is through a USR routine, and USR is a function. As a function, it is always read as part of the evaluation of an expression, by the 24FB SCANNING routines; therefore it is always evaluated by the call to fp-calc-2in 274C S STK LIST; and the return address from this call, 2758h, is put in HL' for the duration of the USR function at 3362 GEN ENT 2, and recovered from HL' at 369B end-calc. If there is any other number in HL' it will return there, with unpredictable results - unless the value of HL' is craftily calculated; why not return to some chosen address? It is perhaps a pity that the ROM doesn't reset HL' on return from a USR function, as it does reset IY, in 2D2B STACK BC, but it isn't quite easy to see how this could be done. The alternate register instruction EXX is used in 0C3B PO SAVE (twice) 0C88 PO SCR 2 (twice) 11B7 NEW (twice) 11EF RAM DONE (twice) 15E6 INPUT AD 15F2 PRINT A 2 15F7 CALL SUB 18C1 OUT FLASH (twice) 24D4 D L DIAG 24DB D L HR VT 24EC D L PLOT 2DF8 PF POSTVE (twice) 2E1E PF SAVE (twice) 2E6F PF MEDIUM (twice) 2E7B PF BITS (twice) 2ECF PF FRACTN (twice) 2EDF PF FRN LP (twice) 2EEF PF FR EXX (twice) 2F2D PF COUNT (twice) 2FBA FETCH TWO (twice) 2FE5 ONE SHIFT (twice) 2FF9 ADDEND 0 2FFB ZEROS 4/5 3004 ADD BACK 300D ALL ADDED 303E FULL ADDN (twice) 3055 SHIFT LEN (twice) 307C TEST NEG (4 times) 309F ADD REP 6 30A3 END COMPL 30F0 MULT LONG (4 times) 3114 MLT LOOP (twice) 311B NO ADD (twice) 3125 STR MULT (4 times) 3146 OFLW1 CLR (twice) 3151 OFLW2 CLR (twice) 315E SKIP ZERO 316E SHIFT ONE (4 times) 3186 NORML NOW (twice) 3195 OFLW CLR (4 times) 31AF division (4 times) 31D2 DIV LOOP (twice) 31DB DIV 34TH (twice) 31E2 DIV START (4 times) 31F2 SUBN ONLY (twice) 31FA COUNT ONE (twice) 3362 GEN ENT 2 (twice) 3365 RE ENTRY 3380 FIRST 3D (twice) 338E ENT TABLE 33A2 fp-calc-2 33C8 STK CONST (twice) 33DE FORM EXP (twice) 341B stk-zero (4 times) 367A dec-jr-nz (twice) 3686 JUMP 3687 JUMP 2 368F jump-true (twice) 369B end-calc (twice) ALTER STREAM SUBROUTINE see 2070 STR ALTER AND key (C6) see also commands, functions and operators, KEYBOARD SCANNING, logical value, 026A symbol code table The Y key with symbol shift produces the operator AND; it must be both preceded and followed by an expression with a logical value. String expressions may not occur_after the AND, only before. The effect of the operator AND is to give a value to theexpression "X and Y", or "X$ and Y": it is zero or "" (null string) if Y has logical value zero, otherwise it is X or X$. This isn't the same as the Z80 assembly code AND. On execution - after the first expression has been evaluated in 268D S DECIMAL, 25B3 S QUOTE or 26C9 S LETTER - 24FB SCANNING quickly leads to 2723 S OPERTR. Here the token code C6 is looked up in the table of operators at 2795 and the table of priorities at 27B0, giving a value 03C8 in BC: 03 beingthe priority and C8 the code of the AND operator. Now this op code is put on the machine stack in 2790 S NEXT. When the code comes off the calculator stack in 2734 S LOOP, C8 is converted (2773 S TIGHTER) to 08, the literal for the 3524 no-&-no executive routine, or to 10h, the literal for 352D str-&-no. ARCCOS FUNCTION see 3843 acs arc counter see 247D CD PRMS1 arc drawing loop see 2382 DRAW, 2420 DRW STEPS ARC END 245F (2420 DRW STEPS) Jumps from: 2420 DRW STEPS ARC LOOP 2425 (2420 DRW STEPS) Jumps from: 2439 ARC START arcs see 247D CD PRMS1, 2420 DRW STEPS ARCSIN FUNCTION see 3833 asn ARC START 2439 (2420 DRW STEPS) Jumps from: 2420 DRAW STEPS ARCTAN FUNCTION see 37E2 atn argument of DEF FN statements, functions, operations The_arguments of a function, etc, are the numbers or strings on which it operates: X and Y in sin X, abs Y, X + Y, SCREEN$ (X,Y), or X$ and Y$ in X$ + Y$, CODE Y$, &c. _Operands is perhaps a pedantically more correct term when speaking of operators rather than functions, but there's not much in it. 24FB SCANNING operation stacked while 2nd argument read 2712 S CONT 2 paths rejoin after argument read 2734 S LOOP operation scanned but not yet argument 2773 S TIGHTER numeric argument required after AND 27BD S FN SBRN evaluated by SCANNING 27D0 SF BRKT 1 if "()" there are no arguments 27D9 SF ARGMTS reads arguments of DEF FN 2802 SF ARGMT1 saves pointer to 1st argument in DEF FN 2831 SF VALUES evaluated by SCANNING 2843 SF ARG LP discriminate numbers from strings 2852 SF ARG VL evaluate 2885 SF R BR 2 look at character after last argument 288D SF VALUE seek and evaluate 28B2 LOOK VARS searches for arguments 28E3 V TEST FN searches for arguments in run time 2951 STK F ARG checks arguments of DEF FN for vble names 295A SFA LOOP go to next argument arithmetic operations see addition, subtract, multiply, division Strictly speaking there are other arithmetic operations,eg raising to a power: but these four basic ones are what the notes always mean by the term. arithmetic overflow see overflow "Arithmetic overflow" quoted at 31AD as the error report forREPORT 6; should read "Number too big". ARITHMETIC ROUTINES see 2D4F e-to-fp, 335B CALCULATE This heading is used at 2D4F e-to-fp for the routines which precede the calculator subroutine: as well as the fundamental operations of addition, subtraction, multiplication and division, they include manipulation of numbers on and off the stack, conversion of digital or E-format numbers to FP numbers, etc. Introduction - summary of routines available. 3014 addition - first major arithmetic routine 3155 TEST NORM normalization common to all arithmetic routines arrays see also strings, variables Arrays are a special kind of variable, differing from "simple" variables 1. because they cannot be declared simply by a LET, INPUT or READ command; the array must be declared before being given any values, by a separate DIM command which establishes the array in the variables area with all its values or_elements set to zero or "space". 2._numeric_arrays have more than one numeric value, arranged in_dimensions; simple numeric variables only have one numeric value. 3._string_arrays consist of a string or strings of a fixed length; if more than one, all are of the same length and they are similarly arranged in dimensions. A simple string variable has only one string value, and its length can be changed by giving it a new value. String arrays are arrays of characters; their last dimension gives the number of characters in each string element. 4. Only part of an array can be used at a time: if A and B are arrays, you cannot command LET A = B, even if they have the same number of dimensions. Some BASICs allow this, but not Spectrum BASIC. You must use_subscripts to identify which element of the array you want to use: eg LET A(2,3,4) = B(4,3,2). With string arrays this is also true, except that the last dimension needn't be specified, so that one-dimensioned string arrays_can be used all at once. In the variables area, arrays are identified by the first three flag bits of the "variable letter" or "discriminatorbyte", like other types of variable; see under "variables". For all arrays, the first four_leading_bytes are the _initial_parameters: byte 1 is the array letter with its flags bytes 2 and 3 give the length of the array in the variables area, excluding the first three bytes. byte 4 gives the number of dimensions. These are followed by two bytes for each dimension of the array, giving the dimension number. Each dimension can be ofany size. For numeric arrays: byte 1 has the flags 100b and the letter code the dimension numbers are followed by the elements of thearray, each one a 5-byte FP number; the elements are in "alphabetical order" of their subscripts, eg (2,4,3) precedes (4,2,3) but follows (2,3,4). For string arrays: byte 1 has the flags 110b and the letter code the dimension numbers are followed by the elements of thearray, each a single character code, in the same kind of "alphabetical order" as for numeric arrays. For the same number of dimensions a numeric array takes up nearly five times as much RAM as a string array. 0652 SA DATA handling save/load of arrays 0672 SA V OLD loading with already existing name 0685 SA V NEW save/load of arrays 0692 SA DATA 1 set pointer to show start of array 0808 LD CONTRL loading of array 0819 LD CONT 1 check size of array 082E LD DATA loading of array 084C LD DATA 1 make space for new array when loading 1C22 VAR A 1 can't give value to array till dimensioned 1C30 VAR A 2 finds address and length of element 1C46 VAR A 3 puts element params in STRLEN and DEST