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

EXCLNLB

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: EXCLNLB
Read OK:
File size: 0879 bytes
Load address: FF3362
Exec address: 20007
File contents
SECTION "EXCLNLB"

// Floating/fixed point calculator - floating 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 ('swap' should be displayed for f0 and a
// 3-character legend for each of f1 to f9).

LET DISPFNS() BE
$( LET STR = ?
   FNSETMAX := 1           // two sets of functions
   TEST FNSET = 0 THEN
   $( MAXFN := FIRSTFN+9   // all keys in use
      STR := "swap pi  sin cos tan asn acs atn rad deg"
   $)
   ELSE
   $( MAXFN := FIRSTFN+7   // only keys f0 to f7 used
      STR := "swap e   exp ln  sqr -x  x^2 1/x        "
   $)
   CURSOR(0, 23)
   WRITES(STR)
$)


// 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.pi) or T.MONOP if it is a function of one
// variable (e.g. sin).  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          // either pi or e
   $( FUNCOP := FNSET = 0 -> FPI, FE
      RESULTIS T.NUMOP
   $)

   FUNCOP := FNSET = 0 ->
      (KEYNO=2 -> FSIN,
       KEYNO=3 -> FCOS,
       KEYNO=4 -> FTAN,
       KEYNO=5 -> FASIN,
       KEYNO=6 -> FACOS,
       KEYNO=7 -> FATAN,
       KEYNO=8 -> FRAD, FDEG),
      (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 4c 42  |SECTION "EXCLNLB|
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 6c 6f 61 74 69  |culator - floati|
00000040  6e 67 20 70 6f 69 6e 74  20 66 75 6e 63 74 69 6f  |ng point functio|
00000050  6e 20 6b 65 79 0d 0a 2f  2f 20 72 6f 75 74 69 6e  |n key..// routin|
00000060  65 73 2e 0d 0a 2f 2f 20  54 68 65 20 63 61 6c 63  |es...// The calc|
00000070  75 6c 61 74 69 6f 6e 20  70 72 6f 63 65 64 75 72  |ulation procedur|
00000080  65 73 20 75 73 65 64 20  61 72 65 0d 0a 2f 2f 20  |es used are..// |
00000090  63 6f 70 79 72 69 67 68  74 20 52 69 63 68 61 72  |copyright Richar|
000000a0  64 73 20 43 6f 6d 70 75  74 65 72 20 50 72 6f 64  |ds Computer Prod|
000000b0  75 63 74 73 20 4c 74 64  2e 20 28 43 29 20 31 39  |ucts Ltd. (C) 19|
000000c0  38 33 0d 0a 2f 2f 20 57  72 69 74 74 65 6e 20 62  |83..// Written b|
000000d0  79 20 43 20 4a 6f 62 73  6f 6e 20 20 31 39 2f 30  |y C Jobson  19/0|
000000e0  34 2f 38 33 0d 0a 0d 0a  2f 2f 20 43 6f 6e 74 61  |4/83....// Conta|
000000f0  69 6e 73 20 44 49 53 50  46 4e 53 20 26 20 49 4e  |ins DISPFNS & IN|
00000100  54 45 52 50 46 4e 2e 0d  0a 0d 0a 47 45 54 20 22  |TERPFN.....GET "|
00000110  4c 49 42 48 44 52 22 0d  0a 47 45 54 20 22 46 50  |LIBHDR"..GET "FP|
00000120  48 44 52 22 0d 0a 47 45  54 20 22 45 58 43 4c 48  |HDR"..GET "EXCLH|
00000130  44 52 22 0d 0a 0d 0a 0d  0a 2f 2f 20 44 49 53 50  |DR"......// DISP|
00000140  46 4e 53 20 69 73 20 63  61 6c 6c 65 64 20 6f 6e  |FNS is called on|
00000150  20 73 74 61 72 74 75 70  20 61 6e 64 20 77 68 65  | startup and whe|
00000160  6e 65 76 65 72 20 66 75  6e 63 74 69 6f 6e 20 6b  |never function k|
00000170  65 79 20 30 20 69 73 20  70 72 65 73 73 65 64 0d  |ey 0 is pressed.|
00000180  0a 2f 2f 20 74 6f 20 63  68 61 6e 67 65 20 74 68  |.// to change th|
00000190  65 20 75 73 65 20 6f 66  20 74 68 65 20 6f 74 68  |e use of the oth|
000001a0  65 72 20 66 75 6e 63 74  69 6f 6e 20 6b 65 79 73  |er function keys|
000001b0  2e 20 49 74 20 6d 75 73  74 20 73 65 74 20 75 70  |. It must set up|
000001c0  20 74 68 65 0d 0a 2f 2f  20 67 6c 6f 62 61 6c 73  | the..// globals|
000001d0  20 4d 41 58 46 4e 20 26  20 46 4e 53 45 54 4d 41  | MAXFN & FNSETMA|
000001e0  58 20 61 6e 64 20 64 69  73 70 6c 61 79 20 74 68  |X and display th|
000001f0  65 20 66 75 6e 63 74 69  6f 6e 20 6b 65 79 20 75  |e function key u|
00000200  73 61 67 65 20 6f 6e 20  72 6f 77 0d 0a 2f 2f 20  |sage on row..// |
00000210  32 33 20 6f 66 20 74 68  65 20 73 63 72 65 65 6e  |23 of the screen|
00000220  20 28 27 73 77 61 70 27  20 73 68 6f 75 6c 64 20  | ('swap' should |
00000230  62 65 20 64 69 73 70 6c  61 79 65 64 20 66 6f 72  |be displayed for|
00000240  20 66 30 20 61 6e 64 20  61 0d 0a 2f 2f 20 33 2d  | f0 and a..// 3-|
00000250  63 68 61 72 61 63 74 65  72 20 6c 65 67 65 6e 64  |character legend|
00000260  20 66 6f 72 20 65 61 63  68 20 6f 66 20 66 31 20  | for each of f1 |
00000270  74 6f 20 66 39 29 2e 0d  0a 0d 0a 4c 45 54 20 44  |to f9).....LET D|
00000280  49 53 50 46 4e 53 28 29  20 42 45 0d 0a 24 28 20  |ISPFNS() BE..$( |
00000290  4c 45 54 20 53 54 52 20  3d 20 3f 0d 0a 20 20 20  |LET STR = ?..   |
000002a0  46 4e 53 45 54 4d 41 58  20 3a 3d 20 31 20 20 20  |FNSETMAX := 1   |
000002b0  20 20 20 20 20 20 20 20  2f 2f 20 74 77 6f 20 73  |        // two s|
000002c0  65 74 73 20 6f 66 20 66  75 6e 63 74 69 6f 6e 73  |ets of functions|
000002d0  0d 0a 20 20 20 54 45 53  54 20 46 4e 53 45 54 20  |..   TEST FNSET |
000002e0  3d 20 30 20 54 48 45 4e  0d 0a 20 20 20 24 28 20  |= 0 THEN..   $( |
000002f0  4d 41 58 46 4e 20 3a 3d  20 46 49 52 53 54 46 4e  |MAXFN := FIRSTFN|
00000300  2b 39 20 20 20 2f 2f 20  61 6c 6c 20 6b 65 79 73  |+9   // all keys|
00000310  20 69 6e 20 75 73 65 0d  0a 20 20 20 20 20 20 53  | in use..      S|
00000320  54 52 20 3a 3d 20 22 73  77 61 70 20 70 69 20 20  |TR := "swap pi  |
00000330  73 69 6e 20 63 6f 73 20  74 61 6e 20 61 73 6e 20  |sin cos tan asn |
00000340  61 63 73 20 61 74 6e 20  72 61 64 20 64 65 67 22  |acs atn rad deg"|
00000350  0d 0a 20 20 20 24 29 0d  0a 20 20 20 45 4c 53 45  |..   $)..   ELSE|
00000360  0d 0a 20 20 20 24 28 20  4d 41 58 46 4e 20 3a 3d  |..   $( MAXFN :=|
00000370  20 46 49 52 53 54 46 4e  2b 37 20 20 20 2f 2f 20  | FIRSTFN+7   // |
00000380  6f 6e 6c 79 20 6b 65 79  73 20 66 30 20 74 6f 20  |only keys f0 to |
00000390  66 37 20 75 73 65 64 0d  0a 20 20 20 20 20 20 53  |f7 used..      S|
000003a0  54 52 20 3a 3d 20 22 73  77 61 70 20 65 20 20 20  |TR := "swap e   |
000003b0  65 78 70 20 6c 6e 20 20  73 71 72 20 2d 78 20 20  |exp ln  sqr -x  |
000003c0  78 5e 32 20 31 2f 78 20  20 20 20 20 20 20 20 22  |x^2 1/x        "|
000003d0  0d 0a 20 20 20 24 29 0d  0a 20 20 20 43 55 52 53  |..   $)..   CURS|
000003e0  4f 52 28 30 2c 20 32 33  29 0d 0a 20 20 20 57 52  |OR(0, 23)..   WR|
000003f0  49 54 45 53 28 53 54 52  29 0d 0a 24 29 0d 0a 0d  |ITES(STR)..$)...|
00000400  0a 0d 0a 2f 2f 20 49 4e  54 45 52 50 46 4e 20 69  |...// INTERPFN i|
00000410  73 20 63 61 6c 6c 65 64  20 62 79 20 47 45 54 43  |s called by GETC|
00000420  48 20 77 68 65 6e 20 61  20 66 75 6e 63 74 69 6f  |H when a functio|
00000430  6e 20 6b 65 79 20 69 73  20 70 72 65 73 73 65 64  |n key is pressed|
00000440  2e 20 20 49 74 0d 0a 2f  2f 20 6d 75 73 74 20 73  |.  It..// must s|
00000450  65 74 20 46 55 4e 43 4f  50 20 74 6f 20 74 68 65  |et FUNCOP to the|
00000460  20 61 64 64 72 65 73 73  20 6f 66 20 74 68 65 20  | address of the |
00000470  61 70 70 72 6f 70 72 69  61 74 65 20 70 72 6f 63  |appropriate proc|
00000480  65 64 75 72 65 20 74 6f  0d 0a 2f 2f 20 70 65 72  |edure to..// per|
00000490  66 6f 72 6d 20 74 68 65  20 66 75 6e 63 74 69 6f  |form the functio|
000004a0  6e 20 61 6e 64 20 72 65  74 75 72 6e 20 61 20 76  |n and return a v|
000004b0  61 6c 75 65 20 6f 66 20  54 2e 4e 55 4d 4f 50 20  |alue of T.NUMOP |
000004c0  69 66 20 74 68 65 20 66  75 6e 63 74 69 6f 6e 0d  |if the function.|
000004d0  0a 2f 2f 20 70 72 6f 76  69 64 65 73 20 61 20 63  |.// provides a c|
000004e0  6f 6e 73 74 61 6e 74 20  28 65 2e 67 2e 70 69 29  |onstant (e.g.pi)|
000004f0  20 6f 72 20 54 2e 4d 4f  4e 4f 50 20 69 66 20 69  | or T.MONOP if i|
00000500  74 20 69 73 20 61 20 66  75 6e 63 74 69 6f 6e 20  |t is a function |
00000510  6f 66 20 6f 6e 65 0d 0a  2f 2f 20 76 61 72 69 61  |of one..// varia|
00000520  62 6c 65 20 28 65 2e 67  2e 20 73 69 6e 29 2e 20  |ble (e.g. sin). |
00000530  20 4f 6e 20 65 6e 74 72  79 20 43 48 20 68 6f 6c  | On entry CH hol|
00000540  64 73 20 74 68 65 20 63  6f 64 65 20 67 69 76 65  |ds the code give|
00000550  6e 20 62 79 20 74 68 65  0d 0a 2f 2f 20 66 75 6e  |n by the..// fun|
00000560  63 74 69 6f 6e 20 6b 65  79 2e 0d 0a 0d 0a 41 4e  |ction key.....AN|
00000570  44 20 49 4e 54 45 52 50  46 4e 28 29 20 3d 20 56  |D INTERPFN() = V|
00000580  41 4c 4f 46 0d 0a 24 28  20 4c 45 54 20 4b 45 59  |ALOF..$( LET KEY|
00000590  4e 4f 20 3d 20 43 48 20  2d 20 46 49 52 53 54 46  |NO = CH - FIRSTF|
000005a0  4e 20 20 20 2f 2f 20 66  75 6e 63 74 69 6f 6e 20  |N   // function |
000005b0  6b 65 79 20 6e 75 6d 62  65 72 0d 0a 0d 0a 20 20  |key number....  |
000005c0  20 49 46 20 4b 45 59 4e  4f 20 3d 20 31 20 54 48  | IF KEYNO = 1 TH|
000005d0  45 4e 20 20 20 20 20 20  20 20 20 20 2f 2f 20 65  |EN          // e|
000005e0  69 74 68 65 72 20 70 69  20 6f 72 20 65 0d 0a 20  |ither pi or e.. |
000005f0  20 20 24 28 20 46 55 4e  43 4f 50 20 3a 3d 20 46  |  $( FUNCOP := F|
00000600  4e 53 45 54 20 3d 20 30  20 2d 3e 20 46 50 49 2c  |NSET = 0 -> FPI,|
00000610  20 46 45 0d 0a 20 20 20  20 20 20 52 45 53 55 4c  | FE..      RESUL|
00000620  54 49 53 20 54 2e 4e 55  4d 4f 50 0d 0a 20 20 20  |TIS T.NUMOP..   |
00000630  24 29 0d 0a 0d 0a 20 20  20 46 55 4e 43 4f 50 20  |$)....   FUNCOP |
00000640  3a 3d 20 46 4e 53 45 54  20 3d 20 30 20 2d 3e 0d  |:= FNSET = 0 ->.|
00000650  0a 20 20 20 20 20 20 28  4b 45 59 4e 4f 3d 32 20  |.      (KEYNO=2 |
00000660  2d 3e 20 46 53 49 4e 2c  0d 0a 20 20 20 20 20 20  |-> FSIN,..      |
00000670  20 4b 45 59 4e 4f 3d 33  20 2d 3e 20 46 43 4f 53  | KEYNO=3 -> FCOS|
00000680  2c 0d 0a 20 20 20 20 20  20 20 4b 45 59 4e 4f 3d  |,..       KEYNO=|
00000690  34 20 2d 3e 20 46 54 41  4e 2c 0d 0a 20 20 20 20  |4 -> FTAN,..    |
000006a0  20 20 20 4b 45 59 4e 4f  3d 35 20 2d 3e 20 46 41  |   KEYNO=5 -> FA|
000006b0  53 49 4e 2c 0d 0a 20 20  20 20 20 20 20 4b 45 59  |SIN,..       KEY|
000006c0  4e 4f 3d 36 20 2d 3e 20  46 41 43 4f 53 2c 0d 0a  |NO=6 -> FACOS,..|
000006d0  20 20 20 20 20 20 20 4b  45 59 4e 4f 3d 37 20 2d  |       KEYNO=7 -|
000006e0  3e 20 46 41 54 41 4e 2c  0d 0a 20 20 20 20 20 20  |> FATAN,..      |
000006f0  20 4b 45 59 4e 4f 3d 38  20 2d 3e 20 46 52 41 44  | KEYNO=8 -> FRAD|
00000700  2c 20 46 44 45 47 29 2c  0d 0a 20 20 20 20 20 20  |, FDEG),..      |
00000710  28 4b 45 59 4e 4f 3d 32  20 2d 3e 20 46 45 58 50  |(KEYNO=2 -> FEXP|
00000720  2c 0d 0a 20 20 20 20 20  20 20 4b 45 59 4e 4f 3d  |,..       KEYNO=|
00000730  33 20 2d 3e 20 46 4c 4e  2c 0d 0a 20 20 20 20 20  |3 -> FLN,..     |
00000740  20 20 4b 45 59 4e 4f 3d  34 20 2d 3e 20 46 53 51  |  KEYNO=4 -> FSQ|
00000750  52 54 2c 0d 0a 20 20 20  20 20 20 20 4b 45 59 4e  |RT,..       KEYN|
00000760  4f 3d 35 20 2d 3e 20 46  4e 45 47 2c 0d 0a 20 20  |O=5 -> FNEG,..  |
00000770  20 20 20 20 20 4b 45 59  4e 4f 3d 36 20 2d 3e 20  |     KEYNO=6 -> |
00000780  53 51 55 41 52 45 2c 20  52 45 43 49 50 29 0d 0a  |SQUARE, RECIP)..|
00000790  0d 0a 20 20 20 52 45 53  55 4c 54 49 53 20 54 2e  |..   RESULTIS T.|
000007a0  4d 4f 4e 4f 50 0d 0a 24  29 0d 0a 0d 0a 0d 0a 2f  |MONOP..$)....../|
000007b0  2f 20 52 45 43 49 50 20  63 61 6c 63 75 6c 61 74  |/ RECIP calculat|
000007c0  65 73 20 42 20 3a 3d 20  31 2f 41 2e 0d 0a 0d 0a  |es B := 1/A.....|
000007d0  41 4e 44 20 52 45 43 49  50 28 41 2c 20 42 29 20  |AND RECIP(A, B) |
000007e0  3d 20 56 41 4c 4f 46 0d  0a 24 28 20 4c 45 54 20  |= VALOF..$( LET |
000007f0  4f 4e 45 20 3d 20 56 45  43 20 46 50 2e 4c 45 4e  |ONE = VEC FP.LEN|
00000800  0d 0a 20 20 20 52 45 53  55 4c 54 49 53 20 46 44  |..   RESULTIS FD|
00000810  49 56 28 46 46 4c 4f 41  54 28 31 2c 20 4f 4e 45  |IV(FFLOAT(1, ONE|
00000820  29 2c 20 41 2c 20 42 29  0d 0a 24 29 0d 0a 0d 0a  |), A, B)..$)....|
00000830  0d 0a 2f 2f 20 53 51 55  41 52 45 20 63 61 6c 63  |..// SQUARE calc|
00000840  75 6c 61 74 65 73 20 42  20 3a 3d 20 41 2a 41 2e  |ulates B := A*A.|
00000850  0d 0a 0d 0a 41 4e 44 20  53 51 55 41 52 45 28 41  |....AND SQUARE(A|
00000860  2c 20 42 29 20 3d 20 46  4d 55 4c 54 28 41 2c 20  |, B) = FMULT(A, |
00000870  41 2c 20 42 29 0d 0a 0d  0a                       |A, B)....|
00000879
EXCLNLB.m0
EXCLNLB.m1
EXCLNLB.m2
EXCLNLB.m4
EXCLNLB.m5