Home » Personal collection » Acorn DFS disks » dfs_box03_disk13_bcpl_calc.scp » EXCLNXB

EXCLNXB

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » Personal collection » Acorn DFS disks » dfs_box03_disk13_bcpl_calc.scp
Filename: EXCLNXB
Read OK:
File size: 06FB bytes
Load address: FF37B0
Exec address: 0007
File contents
SECTION "EXCLNXB"

// Floating/fixed point calculator - fixed point function key
// routines.
// The calculation procedures used are
// copyright Richards Computer Products Ltd. (C) 1983
// Written by C Jobson  19/04/83

// Contains DISPFNS & INTERPFN.

GET "LIBHDR"
GET "FPHDR"
GET "EXCLHDR"


// DISPFNS is called on startup and whenever function key 0 is pressed
// to change the use of the other function keys. It must set up the
// globals MAXFN & FNSETMAX and display the function key usage on row
// 23 of the screen ('    ' should be displayed for f0 and a
// 3-character legend for each of f1 to f9).

LET DISPFNS() BE
$( LET STR = ?
   FNSETMAX := 0           // only one set of functions
   MAXFN := FIRSTFN+7      // only keys f0 to f7 used
   CURSOR(0, 23)
   WRITES("     e   exp ln  sqr -x  x^2 1/x        ")
$)


// INTERPFN is called by GETCH when a function key is pressed.  It
// must set FUNCOP to the address of the appropriate procedure to
// perform the function and return a value of T.NUMOP if the function
// provides a constant (e.g. e) or T.MONOP if it is a function of one
// variable (e.g. exp).  On entry CH holds the code given by the
// function key.

AND INTERPFN() = VALOF
$( LET KEYNO = CH - FIRSTFN   // function key number

   IF KEYNO = 1 THEN          // e
   $( FUNCOP := FE
      RESULTIS T.NUMOP
   $)

   FUNCOP := KEYNO=2 -> FEXP,
             KEYNO=3 -> FLN,
             KEYNO=4 -> FSQRT,
             KEYNO=5 -> FNEG,
             KEYNO=6 -> SQUARE, RECIP

   RESULTIS T.MONOP
$)


// RECIP calculates B := 1/A.

AND RECIP(A, B) = VALOF
$( LET ONE = VEC FP.LEN
   RESULTIS FDIV(FFLOAT(1, ONE), A, B)
$)


// SQUARE calculates B := A*A.

AND SQUARE(A, B) = FMULT(A, A, B)

00000000  53 45 43 54 49 4f 4e 20  22 45 58 43 4c 4e 58 42  |SECTION "EXCLNXB|
00000010  22 0d 0a 0d 0a 2f 2f 20  46 6c 6f 61 74 69 6e 67  |"....// Floating|
00000020  2f 66 69 78 65 64 20 70  6f 69 6e 74 20 63 61 6c  |/fixed point cal|
00000030  63 75 6c 61 74 6f 72 20  2d 20 66 69 78 65 64 20  |culator - fixed |
00000040  70 6f 69 6e 74 20 66 75  6e 63 74 69 6f 6e 20 6b  |point function k|
00000050  65 79 0d 0a 2f 2f 20 72  6f 75 74 69 6e 65 73 2e  |ey..// routines.|
00000060  0d 0a 2f 2f 20 54 68 65  20 63 61 6c 63 75 6c 61  |..// The calcula|
00000070  74 69 6f 6e 20 70 72 6f  63 65 64 75 72 65 73 20  |tion procedures |
00000080  75 73 65 64 20 61 72 65  0d 0a 2f 2f 20 63 6f 70  |used are..// cop|
00000090  79 72 69 67 68 74 20 52  69 63 68 61 72 64 73 20  |yright Richards |
000000a0  43 6f 6d 70 75 74 65 72  20 50 72 6f 64 75 63 74  |Computer Product|
000000b0  73 20 4c 74 64 2e 20 28  43 29 20 31 39 38 33 0d  |s Ltd. (C) 1983.|
000000c0  0a 2f 2f 20 57 72 69 74  74 65 6e 20 62 79 20 43  |.// Written by C|
000000d0  20 4a 6f 62 73 6f 6e 20  20 31 39 2f 30 34 2f 38  | Jobson  19/04/8|
000000e0  33 0d 0a 0d 0a 2f 2f 20  43 6f 6e 74 61 69 6e 73  |3....// Contains|
000000f0  20 44 49 53 50 46 4e 53  20 26 20 49 4e 54 45 52  | DISPFNS & INTER|
00000100  50 46 4e 2e 0d 0a 0d 0a  47 45 54 20 22 4c 49 42  |PFN.....GET "LIB|
00000110  48 44 52 22 0d 0a 47 45  54 20 22 46 50 48 44 52  |HDR"..GET "FPHDR|
00000120  22 0d 0a 47 45 54 20 22  45 58 43 4c 48 44 52 22  |"..GET "EXCLHDR"|
00000130  0d 0a 0d 0a 0d 0a 2f 2f  20 44 49 53 50 46 4e 53  |......// DISPFNS|
00000140  20 69 73 20 63 61 6c 6c  65 64 20 6f 6e 20 73 74  | is called on st|
00000150  61 72 74 75 70 20 61 6e  64 20 77 68 65 6e 65 76  |artup and whenev|
00000160  65 72 20 66 75 6e 63 74  69 6f 6e 20 6b 65 79 20  |er function key |
00000170  30 20 69 73 20 70 72 65  73 73 65 64 0d 0a 2f 2f  |0 is pressed..//|
00000180  20 74 6f 20 63 68 61 6e  67 65 20 74 68 65 20 75  | to change the u|
00000190  73 65 20 6f 66 20 74 68  65 20 6f 74 68 65 72 20  |se of the other |
000001a0  66 75 6e 63 74 69 6f 6e  20 6b 65 79 73 2e 20 49  |function keys. I|
000001b0  74 20 6d 75 73 74 20 73  65 74 20 75 70 20 74 68  |t must set up th|
000001c0  65 0d 0a 2f 2f 20 67 6c  6f 62 61 6c 73 20 4d 41  |e..// globals MA|
000001d0  58 46 4e 20 26 20 46 4e  53 45 54 4d 41 58 20 61  |XFN & FNSETMAX a|
000001e0  6e 64 20 64 69 73 70 6c  61 79 20 74 68 65 20 66  |nd display the f|
000001f0  75 6e 63 74 69 6f 6e 20  6b 65 79 20 75 73 61 67  |unction key usag|
00000200  65 20 6f 6e 20 72 6f 77  0d 0a 2f 2f 20 32 33 20  |e on row..// 23 |
00000210  6f 66 20 74 68 65 20 73  63 72 65 65 6e 20 28 27  |of the screen ('|
00000220  20 20 20 20 27 20 73 68  6f 75 6c 64 20 62 65 20  |    ' should be |
00000230  64 69 73 70 6c 61 79 65  64 20 66 6f 72 20 66 30  |displayed for f0|
00000240  20 61 6e 64 20 61 0d 0a  2f 2f 20 33 2d 63 68 61  | and a..// 3-cha|
00000250  72 61 63 74 65 72 20 6c  65 67 65 6e 64 20 66 6f  |racter legend fo|
00000260  72 20 65 61 63 68 20 6f  66 20 66 31 20 74 6f 20  |r each of f1 to |
00000270  66 39 29 2e 0d 0a 0d 0a  4c 45 54 20 44 49 53 50  |f9).....LET DISP|
00000280  46 4e 53 28 29 20 42 45  0d 0a 24 28 20 4c 45 54  |FNS() BE..$( LET|
00000290  20 53 54 52 20 3d 20 3f  0d 0a 20 20 20 46 4e 53  | STR = ?..   FNS|
000002a0  45 54 4d 41 58 20 3a 3d  20 30 20 20 20 20 20 20  |ETMAX := 0      |
000002b0  20 20 20 20 20 2f 2f 20  6f 6e 6c 79 20 6f 6e 65  |     // only one|
000002c0  20 73 65 74 20 6f 66 20  66 75 6e 63 74 69 6f 6e  | set of function|
000002d0  73 0d 0a 20 20 20 4d 41  58 46 4e 20 3a 3d 20 46  |s..   MAXFN := F|
000002e0  49 52 53 54 46 4e 2b 37  20 20 20 20 20 20 2f 2f  |IRSTFN+7      //|
000002f0  20 6f 6e 6c 79 20 6b 65  79 73 20 66 30 20 74 6f  | only keys f0 to|
00000300  20 66 37 20 75 73 65 64  0d 0a 20 20 20 43 55 52  | f7 used..   CUR|
00000310  53 4f 52 28 30 2c 20 32  33 29 0d 0a 20 20 20 57  |SOR(0, 23)..   W|
00000320  52 49 54 45 53 28 22 20  20 20 20 20 65 20 20 20  |RITES("     e   |
00000330  65 78 70 20 6c 6e 20 20  73 71 72 20 2d 78 20 20  |exp ln  sqr -x  |
00000340  78 5e 32 20 31 2f 78 20  20 20 20 20 20 20 20 22  |x^2 1/x        "|
00000350  29 0d 0a 24 29 0d 0a 0d  0a 0d 0a 2f 2f 20 49 4e  |)..$)......// IN|
00000360  54 45 52 50 46 4e 20 69  73 20 63 61 6c 6c 65 64  |TERPFN is called|
00000370  20 62 79 20 47 45 54 43  48 20 77 68 65 6e 20 61  | by GETCH when a|
00000380  20 66 75 6e 63 74 69 6f  6e 20 6b 65 79 20 69 73  | function key is|
00000390  20 70 72 65 73 73 65 64  2e 20 20 49 74 0d 0a 2f  | pressed.  It../|
000003a0  2f 20 6d 75 73 74 20 73  65 74 20 46 55 4e 43 4f  |/ must set FUNCO|
000003b0  50 20 74 6f 20 74 68 65  20 61 64 64 72 65 73 73  |P to the address|
000003c0  20 6f 66 20 74 68 65 20  61 70 70 72 6f 70 72 69  | of the appropri|
000003d0  61 74 65 20 70 72 6f 63  65 64 75 72 65 20 74 6f  |ate procedure to|
000003e0  0d 0a 2f 2f 20 70 65 72  66 6f 72 6d 20 74 68 65  |..// perform the|
000003f0  20 66 75 6e 63 74 69 6f  6e 20 61 6e 64 20 72 65  | function and re|
00000400  74 75 72 6e 20 61 20 76  61 6c 75 65 20 6f 66 20  |turn a value of |
00000410  54 2e 4e 55 4d 4f 50 20  69 66 20 74 68 65 20 66  |T.NUMOP if the f|
00000420  75 6e 63 74 69 6f 6e 0d  0a 2f 2f 20 70 72 6f 76  |unction..// prov|
00000430  69 64 65 73 20 61 20 63  6f 6e 73 74 61 6e 74 20  |ides a constant |
00000440  28 65 2e 67 2e 20 65 29  20 6f 72 20 54 2e 4d 4f  |(e.g. e) or T.MO|
00000450  4e 4f 50 20 69 66 20 69  74 20 69 73 20 61 20 66  |NOP if it is a f|
00000460  75 6e 63 74 69 6f 6e 20  6f 66 20 6f 6e 65 0d 0a  |unction of one..|
00000470  2f 2f 20 76 61 72 69 61  62 6c 65 20 28 65 2e 67  |// variable (e.g|
00000480  2e 20 65 78 70 29 2e 20  20 4f 6e 20 65 6e 74 72  |. exp).  On entr|
00000490  79 20 43 48 20 68 6f 6c  64 73 20 74 68 65 20 63  |y CH holds the c|
000004a0  6f 64 65 20 67 69 76 65  6e 20 62 79 20 74 68 65  |ode given by the|
000004b0  0d 0a 2f 2f 20 66 75 6e  63 74 69 6f 6e 20 6b 65  |..// function ke|
000004c0  79 2e 0d 0a 0d 0a 41 4e  44 20 49 4e 54 45 52 50  |y.....AND INTERP|
000004d0  46 4e 28 29 20 3d 20 56  41 4c 4f 46 0d 0a 24 28  |FN() = VALOF..$(|
000004e0  20 4c 45 54 20 4b 45 59  4e 4f 20 3d 20 43 48 20  | LET KEYNO = CH |
000004f0  2d 20 46 49 52 53 54 46  4e 20 20 20 2f 2f 20 66  |- FIRSTFN   // f|
00000500  75 6e 63 74 69 6f 6e 20  6b 65 79 20 6e 75 6d 62  |unction key numb|
00000510  65 72 0d 0a 0d 0a 20 20  20 49 46 20 4b 45 59 4e  |er....   IF KEYN|
00000520  4f 20 3d 20 31 20 54 48  45 4e 20 20 20 20 20 20  |O = 1 THEN      |
00000530  20 20 20 20 2f 2f 20 65  0d 0a 20 20 20 24 28 20  |    // e..   $( |
00000540  46 55 4e 43 4f 50 20 3a  3d 20 46 45 0d 0a 20 20  |FUNCOP := FE..  |
00000550  20 20 20 20 52 45 53 55  4c 54 49 53 20 54 2e 4e  |    RESULTIS T.N|
00000560  55 4d 4f 50 0d 0a 20 20  20 24 29 0d 0a 0d 0a 20  |UMOP..   $).... |
00000570  20 20 46 55 4e 43 4f 50  20 3a 3d 20 4b 45 59 4e  |  FUNCOP := KEYN|
00000580  4f 3d 32 20 2d 3e 20 46  45 58 50 2c 0d 0a 20 20  |O=2 -> FEXP,..  |
00000590  20 20 20 20 20 20 20 20  20 20 20 4b 45 59 4e 4f  |           KEYNO|
000005a0  3d 33 20 2d 3e 20 46 4c  4e 2c 0d 0a 20 20 20 20  |=3 -> FLN,..    |
000005b0  20 20 20 20 20 20 20 20  20 4b 45 59 4e 4f 3d 34  |         KEYNO=4|
000005c0  20 2d 3e 20 46 53 51 52  54 2c 0d 0a 20 20 20 20  | -> FSQRT,..    |
000005d0  20 20 20 20 20 20 20 20  20 4b 45 59 4e 4f 3d 35  |         KEYNO=5|
000005e0  20 2d 3e 20 46 4e 45 47  2c 0d 0a 20 20 20 20 20  | -> FNEG,..     |
000005f0  20 20 20 20 20 20 20 20  4b 45 59 4e 4f 3d 36 20  |        KEYNO=6 |
00000600  2d 3e 20 53 51 55 41 52  45 2c 20 52 45 43 49 50  |-> SQUARE, RECIP|
00000610  0d 0a 0d 0a 20 20 20 52  45 53 55 4c 54 49 53 20  |....   RESULTIS |
00000620  54 2e 4d 4f 4e 4f 50 0d  0a 24 29 0d 0a 0d 0a 0d  |T.MONOP..$).....|
00000630  0a 2f 2f 20 52 45 43 49  50 20 63 61 6c 63 75 6c  |.// RECIP calcul|
00000640  61 74 65 73 20 42 20 3a  3d 20 31 2f 41 2e 0d 0a  |ates B := 1/A...|
00000650  0d 0a 41 4e 44 20 52 45  43 49 50 28 41 2c 20 42  |..AND RECIP(A, B|
00000660  29 20 3d 20 56 41 4c 4f  46 0d 0a 24 28 20 4c 45  |) = VALOF..$( LE|
00000670  54 20 4f 4e 45 20 3d 20  56 45 43 20 46 50 2e 4c  |T ONE = VEC FP.L|
00000680  45 4e 0d 0a 20 20 20 52  45 53 55 4c 54 49 53 20  |EN..   RESULTIS |
00000690  46 44 49 56 28 46 46 4c  4f 41 54 28 31 2c 20 4f  |FDIV(FFLOAT(1, O|
000006a0  4e 45 29 2c 20 41 2c 20  42 29 0d 0a 24 29 0d 0a  |NE), A, B)..$)..|
000006b0  0d 0a 0d 0a 2f 2f 20 53  51 55 41 52 45 20 63 61  |....// SQUARE ca|
000006c0  6c 63 75 6c 61 74 65 73  20 42 20 3a 3d 20 41 2a  |lculates B := A*|
000006d0  41 2e 0d 0a 0d 0a 41 4e  44 20 53 51 55 41 52 45  |A.....AND SQUARE|
000006e0  28 41 2c 20 42 29 20 3d  20 46 4d 55 4c 54 28 41  |(A, B) = FMULT(A|
000006f0  2c 20 41 2c 20 42 29 0d  0a 0d 0a                 |, A, B)....|
000006fb
EXCLNXB.m0
EXCLNXB.m1
EXCLNXB.m2
EXCLNXB.m4
EXCLNXB.m5