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

  1.         - call 2FBA FETCH TWO, which gets M and N into ten      registers: M into H'B'C'CB, N into L'D'E'DE; and puts the +/-   sign of the result in the second byte of the M position/result  position, from which it will be retrieved right at the end of   the exit routine in 3195 OFLOW CLR                                      - put the exponent bytes H' and L' on the machine stack         - transfer M' to H'L'HL                                         - zero the lo byte of the result mantissa in A                  - make a bit counter DFh/minus 33d to produce 33d digitsof the result                                                           - jump on into the loop at DIV START.                          _31D2_DIV_LOOP (the carry flag shows in reverse the      result of subtracting N' in D'E'DE from M' in H'L'HL, zero if it"won't go" or set if it will): rotate carry flags left in turn  into A, C, C', B', each one picking up in turn as its lo bit thehi bit of the one before; thus the result in B'C'CA is shifted  one bit left with the new digit going into its lo bit.                 _31DB_DIV_34TH (N' should be shifted right before going  round the loop again. But it is difficult to shift four bytes   right without losing precision in the last bit. So craftily     shift M' left instead, with zero going into the last bit):      double H'L'HL                                                           - if this makes carry jump on to SUBN ONLY; M' is       effectively 33 digits and N' is only 32, so whatever the result of the next subtraction treat it as producing no carry and put aone on the result.                                                     _31E2_DIV_START: take N' in D'E'DE from M' in H'L'HL             - if there is no carry jump on to NO RSTORE                     - (there is carry) add N' back to M' again; "won't go"          - clear the carry flag; signalling "digit zero" for the result                                                                  - jump on to COUNT ONE.                                        _31F2_SUBN_ONLY (only entered from DIV 34th): take N'    from M'; the next line will set carry and put one in the result without regard for the carry from this subtraction.                    _31F9_NO_RSTORE (don't add back): set the carry flag;    signalling "digit one" for the result.                                 _31FA_COUNT_ONE: increment the bit counter; this doesn't affect the carry flag, but it does affect the other flags               - if its hi bit is still set loop back to DIV LOOP; it  is still less than zero                                                 - (33d or 34d turns of loop complete) stack the carry   flag; it represents the 33rd or 34th digit                              - if the bit counter is zero jump back to DIV START; theloop has been turned 33d times [should have jumped to DIV 34TH, see above]                                                              - (34th turn complete; the 33rd and 34th digits are bothon the machine stack in the form of carry flags) move the resultmantissa into D'E'DE                                                    - recover the 34th and 33rd digits and rotate them into bits 6 and 7 of B'; making a five-byte mantissa D'E'DEB', which will be normalized by the exit routine                                  - recover the exponent of N and the exponent of M and   the pointer to the result; it will go wherever M was on entry           - subtract exp M - exp N for the result exponent; these are standard form exponents, with their hi bit set, but the     result of the subtraction is a true exponent and the subtractionwill set the carry flag for a negative result. However it is oneless than the true exponent which actually corresponds to the   mantissa value: the true mantissas M' and N' were both numbers  between a half and one, so the result mantissa should be betweena half and two. But the mantissa actually resulting is between aquarter and one, so in the build-up of its digits it has been   shifted one place right. This is corrected in the exit routine.        Exit: to 313D DIVN EXPT, which makes various checks and  "normalizes" the result into standard FP format before putting  it back in the five bytes of the M position - now the last valueon the calculator stack, if it was on the stack.                       Output parameters: D'E'DEB' holds the 5-byte result      mantissa;_not in standard form, its hi bit doesn't show its signand may even be a leading zero                                          - HL points to the result position                              - the byte after the result pointer holds the result    sign byte, with hi bit marking the sign                                 - A holds the true exponent, less one                           - the carry flag is set if the exponent is negative             - there are two numbers on the machine stack, the top   one a pointer to the N position, the next down the "return      address" pointer                                                        - the calculator memory hasn't been disturbed.                 Called from:                                                     0427 BE OCTAVE                                                  23A3 DR SIN NZ                                                  23C1 DR PRMS                                                    247D CD PRMS1 (twice)                                           2497 DRAW SAVE                                                  2CDA NXT DGT 1                                                  2D6D E DIVSN                                                    36A0 n-mod-m                                                    37DA tan                                                        37E2 atn                                                        3833 asn                                                        385D XISO                                                      Rems:                                                            2F9B PREP ADD lists main arithmetic operations                  2FBA FETCH TWO sign of result saved in sign byte of M           30C0 PREP M/D sets true mantissa, handles sign & zero           316E SHIFT ONE correct precision in rounding                    313D DIVN EXPT used by both multiply and division                                                                           DIV LOOP 31D2 (31AF division)                                      Jumps from:                                                      31FA COUNT ONE                                                                                                              DIVN EXPT subroutine 313D                                           Corrects the exponent of the result of the multiply and division subroutines. Also carries out some tests for arithmeticoverflow and underflow - see under overflow in the index.               The routine is quite short, only 24d bytes to the exit  into TEST NORM, but so concise that rather a lot of explanation is required.                                                            Correcting the true exponent to the full FP form means  essentially flopping its hi bit, because a negative true        exponent will have its hi bit set and a positive one won't, but in FP form this is reversed.                                            This would be simple enough, but for the overflow tests:the exponent byte overflows if it is less than zero or more thanFF in standard form, ie if the true exponent is less than -80h  or more than +7F. However even a +80h true exponent will be     acceptable if the mantissa resulting from division is less than a half, because in normalization the mantissa will be shifted   left and the exponent decremented. There will be at most one    such shift and decrement; both input mantissas are between a    half and one, so the result whether of multiplication or        division can't be less than a quarter.                                  The resulting difficulties are handled by entering the  routine with the exponent byte one less than its "true" value   and with the carry flag signalling whether it is to be read as  positive or negative. The entry value may be anything from 00 - FF:                                                                    - values 00 -> 7F are changed to 80 -> FF, then          incremented to 81 -> 00. 81 -> FF are accepted; they are within the accepted range of positive exponents, and if they are       negative ones, with true exponent minus FFh -> minus 81h, the   result will be indistinguishable from zero in the Spectrum      system and will be set to zero by 3155 TEST NORM. Zero is       accepted as a negative exponent, but rejected as a positive     exponent unless the mantissa will need shifting, which will     reduce it to FF                                                        - values 80 -> FF are changed to 00 -> 7F and rejected ifthey are meant for positive; they would represent true exponentsof 81h -> 100h, which are overflows. If they are meant for      negative they are incremented to 01 -> 80h and accepted, with   the carry flag cleared on entry to TEST NORM. This is no longer read as a flag for "positive", it means "no need to test for    underflow".                                                             There is only one possibility of overflow missed by     these tests: a number whose exponent is made FF in standard     format and whose mantissa before normalizing is FF FF FF FF,    with a 33rd bit which will cause rounding up. This is handled inthe exit routine by 3186 NORML NOW.                                    Input parameters: D'E'DE holds the mantissa of the result        - A holds its exponent, less one; both are in "true"    form                                                                    - HL points to the first byte of the result position:   normally the last but one number on the calculator stack, thoughit will become the last after the exit routines are completed           - the byte after the result pointer holds the sign byte of the result, with its hi bit set for negative                         - the carry flag shows C if the exponent is negative            - there are two numbers on the machine stack, the top   one a pointer to the second number input for the operation, the multiplier/divisor, the next down the "return address" pointer.        Action: rotate the hi bit of the exponent into carry,    flop it and rotate it back; the input carry flag is recovered   unchanged from these three operations [and_the_positive/        negative_flag_is_also_unchanged_from_its_input_value; neither   rotations nor CCF affect it. It would have been nice if Logan   and O'Hara had thought to mention this in their notes. It took  me the best part of a week to figure out what was happening]            - if the P/N flag shows hi bit zero jump on to OFLW1    CLR; ie if the exponent as input was 7F or less                         - (exponent input 80h or more) if the carry flag        indicates a positive exponent report "Number too big"; true     exponent more than +80h                                                 - (negative exponent, now 00 -> 7F) clear the carry     flag; now the only way carry can be set is if the input exponentwas flagged as negative with a "true" value less than 80h,      jumping past this point with the P/N flag. These would be very  small numbers, so from here on carry means "test for underflow".       _3146_OFLW1_CLR: increment the exponent; in the case of  multiplication it reverses the DEC A in 313B MAKE EXPT, for     division the input exponent was one too small for its mantissa, see 31FA COUNT ONE under 31AF division [this also required more explanation than it gets from Logan and O'Hara!]                        - if this doesn't make zero jump on to OFLW2 CLR; the   exponent is either 01 -> 7F with carry, a number probably to be equated with zero; or 01 -> FF without carry, an acceptable     negative or positive exponent                                           - (the exponent is zero) if the carry flag shows C jump on to OFLW2 CLR; INC A doesn't change the carry flag, so carry  is unchanged from input, the exponent is negative and the numberis very small. The carry flag now signals "test for underflow"          - (the incremented exponent is zero, and marked as      positive) if the hi bit of D' is set report "Number too big";   there will be no left shift of the mantissa to reduce exponent  00 to FF.                                                              _3151_OFLW2_CLR: put the exponent byte in the result     pointer address and the 5th mantissa byte B' in A.                     Exit: into 3155 TEST NORM, which checks for arithmetic   underflow, completes "normalization", ie shifts the mantissa    left with decrement of the exponent till it has no leading      binary zeroes and corrects its sign bit, and puts the result on the stack.                                                             Output parameters: HL points to the first byte of the    result FP form                                                          - the byte after the result pointer holds a sign flag           - D'E'DEA holds the 5-byte mantissa                             - the carry flag set signals "test for underflow", ie a normalized exponent of zero or less                                     - there are still two numbers on the machine stack, the top one a pointer to the second number input for the operation, the multiplier/divisor, the next down the "return address"      pointer.                                                               Exit from:                                                       313B MAKE EXPT (30CA multiply)                                  31FA COUNT ONE (31AF division)                                                                                              DIV START 3132                                                     Jumps from:                                                      31AF division                                                   31FA COUNT ONE                                                                                                              DIV 34TH 31DB (31AF division)                                       Label not used in the ROM. It should have been! There isa mistake in ROM at 31FA COUNT ONE, see under 31AF division.                                                                        D L DIAG 24D2 (24B7 DRAW LINE)                                     Jumps from:                                                      24CE D L LOOP                                                                                                               D LETTER 2C1F (2C02 DIM)                                           Jumps from:                                                      2C15 D RUN                                                                                                                  D L HR VT 24DB (24B7 DRAW LINE)                                    Jumps from:                                                      24CE D L LOOP                                                                                                               DL LARGER 24CB (24B7 DRAW LINE)                                    Jumps from:                                                      24B7 DRAW LINE                                                                                                              D L LOOP 24CE (24B7 DRAW LINE)                                     Jumps from:                                                      24EC D L PLOT                                                                                                               D L PLOT 24EC (24B7 DRAW LINE)                                     Exit from:                                                       24F7 D L RANGE                                                                                                              D L RANGE 24F7 (24B7 DRAW LINE)                                    Jumps from:                                                      24DF D L STEP                                                                                                               D L STEP 24DF (24B7 DRAW LINE)                                     Jumps from:                                                      24D4 D L DIAG                                                                                                               DL X GE Y 24C4 (24B7 DRAW LINE)                                    Jumps from:                                                      24B7 DRAW LINE                                                                                                              D NO LOOP 2C2E (2C02 DIM)                                          Jumps from:                                                      auto                                                                                                                        DOUBLE A 338C (335B CALCULATE)                                     Jumps from:                                                      3380 FIRST 3D                                                                                                               double quotes see " (code 22h) at end of alphabet                                                                               DRAW key (FC) see also commands, functions and operators,   KEYBOARD SCANNING                                                       The W key in K mode produces the command DRAW, which canbe followed by print items, but must be followed by two or threenumeric parameters X,Y,Z; each may be negative. X and Y are the number of pixels to the right (X) and up (Y) to be covered by   the DRAWn line, and Z the anticlockwise angle in radians throughwhich the line is to turn - assumed zero, ie a straight line, ifno value is given. See under 2783 get-argt if you aren't sure   about radians. The start of the line is the last position set byPLOT or reached by DRAW or CIRCLE.                                      The command is read by 1B29 STMT L 1 referring through  the syntax offset table 1A48 to the syntax parameter table 1A7A.1AD2 P DRAW causes jumps to 1CBE CLASS 09, which effects FLASH  8; BRIGHT 8; PAPER 8 and then executes any embedded colour itemsbefore putting X and Y on the stack, and via 1C11 CLASS 05 to   1C16 JUMP C R and the executive routine 2382 DRAW.                                                                                  DRAW subroutine 2382                                                Called only from the statement loop by 1AD2 P DRAW in   the syntax parameter table; the executive routine of the DRAW   command. Draws an arc on screen using parameters                       - X: number of pixels to move right, or left if negative        - Y: number of pixels to move up, or down if negative           - G: angle in radians to turn to left, or right if       negative - see under 2783 get-argt if you aren't sure about     radians.                                                                Not easy to call direct from m/c; better to call 2394   (RST 0028h) with the three parameters already on the stack if anarc is required. For a straight line, either do the same with   zero as last parameter, or call 2477 LINE DRAW with only two    parameters on the stack. Beware! These routines, and any using  24B7 DRAW LINE, may switch to the alternate registers.                  If a curved arc isn't called for, there is nothing for  the subroutine to do: it merely exits to 2477 LINE DRAW, which  will draw straight lines without further preparation.