home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Jason Aller Floppy Collection
/
106.img
/
MIRROR2.ZIP
/
CALC.XTS
< prev
next >
Wrap
Text File
|
1988-12-15
|
12KB
|
397 lines
;*****************************************************************
;* Sample script : Calc version 4 *
;* Simple calculator with user-defined number of decimal places *
;* available up to maximum of 4 (no floating decimal) *
;* (This version is a sub-script of Point-&-Dial) *
;*****************************************************************
abort disable
ad c prism
if #= 1 ju checkspace
cl
al 3n : al 3n
me
[12,15][h]PRISM add-in module must be loaded to run this script.[n]
[14,15]Please consult your Mirror III User's Guide for information
[15,15]on the [h]ADdin load[n] command and use of the [h]MIRROR.CFG[n] file.
.
ab
LABEL CHECKSPACE
; Prism is loaded...check to see if enough SAVESPACE is available.
if (savespace >= 1500) jump all_go
cl
al 3n : al 3n
me
[12,15][h]You need at least 1500 bytes of SAVESCREEN space to run CALC.[n]
[14,15]Please consult your Mirror III User's Guide for information
[15,15]on the [h]ADdin load[n] command and use of the [h]MIRROR.CFG[n] file.
.
ab
LABEL ALL_GO
sc l kk : ;hide command line
sc t
box at 1,1 size 25,80 color "kk"
background return
LABEL DECL
me [10,10]One moment please...
var real op, total, tens[5]
var integer l, r, c, z, count, d
var string ch[2,1], colors[3,2], formt[5,4], pth[67]
var integer mode
; 0 = none, 1 = plus, 2 = minus, 3 = times, 4 = divide, 5 = equal
jump /r setup
jump /r show_calc
me [22,41][wk] Press [Yk]F1[wk] for help
jump show_tape
LABEL LOOP
ch[2] = ch[1]
LABEL LOOP2
; Loop2 is used when keys other than digits & math operators
; are pressed. These other keys are not recorded in ch[2]
z = inkey(-1)
if (z = keyval("esc")) jump exit
sound 1004,10 : ; keyclick
ch[1] = upcase(chr(z))
l = instr("0123456789",ch[1])
if (l > 0) jump acc
l = inlist(z,13,keyval("f1"),keyval("alt-d"),keyval("alt-c"))
if (l = 1) ch[1] = "="
on l jump equal,help,set_decimal,show_tape
l = instr("+-*/PMTD=CS.O",ch[1])
on l jump plus,minus,mult,div,plus,minus,mult,div
on (l-8) jump equal,clear,sign_change,point,exit
if (z = keyval("up-arrow")) scroll at 6,41 size 14,16 : jump loop2
if (ch[1] = "E") jump cl_entry
; An invalid key was pushed. Ignore it.
jump loop2
LABEL ACC
; Build the current operand
l = l - 1
if (op < 0) l = -1 * l
if (mode = 5) mode = 0 : total = 0
if (count = 0) op = (op * 10) + l : ju sayit
; COUNT <> 0 so we must be entering digits after the decimal point
op = op + (l * tens[count])
if (count < 5) count = count + 1
LABEL SAYIT
; Display the current operand
say at 3,10; color colors[1]; op:@(formt[d])
jump loop
LABEL CLEAR
; Flash the CLEAR button & clear the calculator
say at 8,19; color "Ww";" C "
for z = 1 to 2
box at 7,18 size 3,7 style 4 color colors[3] hollow
box at 7,18 size 3,7 style 4 color colors[2] hollow
next
say at 8,19; color "Wb";" C "
say at 3,23; color colors[2]; " "
total = 0
mode = 0
; write to tape
scroll up 2 at 6,41 size 14,16
say at 19,43; color colors[2]; total:@(formt[d]); " c"
jump disp_total
LABEL CL_ENTRY
; Clear current operand, but not operation or total
op = 0
count = 0 : ; RESET DECIMAL (NOT ENTERING DIGITS AFTER THE DEC. PT.)
if (0 < instr(digit+".",ch[2])) say at 3,10; color colors[1]; op:@(formt[d]);
jump loop2
LABEL SIGN_CHANGE
; change operand's sign, if operand is being entered
if (0 <> instr("+-*/PMTD=",ch[2])) jump loop2
op = op * -1
say at 3,10; color colors[1]; op:@(formt[d]);
jump loop2
LABEL POINT
; Handles display of decimal point
if (d = 1) jump loop2 : ;; we are in INTEGER mode. ignore
if (count <> 0) jump loop2 : ;; decimal point was already entered
count = 1 : ;; indicates 1st place after dec.
say at 3,10; color colors[1]; op:@(formt[d])
jump loop2
LABEL PLUS
say at 3,23; color colors[2]; "+"
count = 0
if (0 = instr("+-*/PMTD=",ch[2])) jump plus1
; Here, An operator was the LAST thing entered
mode = 1
scroll at 6,41 size 14,16
say at 19,43; color colors[2]; ; total:@(formt[d]);" +";
jump loop2
LABEL PLUS1
if (mode = 0) jump no_mode
jump /r calc : ;; perform CURRENT operation
say color colors[2]; " +"; : ;; update the tape
mode = 1 : ;; set NEW current operation
jump disp_total
LABEL MINUS
say at 3,23; color colors[2]; "-"
count = 0
if (0 = instr("+-*/PMTD=",ch[2])) jump minus1
; Here, An operator was the LAST thing entered
mode = 2
scroll at 6,41 size 14,16
say at 19,43; color colors[2]; ; total:@(formt[d]);" -";
jump loop2
LABEL MINUS1
if (mode = 0) jump no_mode
jump /r calc : ;; perform CURRENT operation
say color colors[2]; " -"; : ;; update the tape
mode = 2 : ;; set NEW current operation
jump disp_total
LABEL MULT
say at 3,23; color colors[2]; "x"
count = 0
if (0 = instr("+-*/PMTD=",ch[2])) jump mult1
; Here, An operator was the LAST thing entered
mode = 3
scroll at 6,41 size 14,16
say at 19,43; color colors[2]; ; total:@(formt[d]);" x";
jump loop2
LABEL MULT1
if (mode = 0) jump no_mode
jump /r calc : ;; perform CURRENT operation
say color colors[2]; " x"; : ;; update the tape
mode = 3 : ;; set NEW current operation
jump disp_total
LABEL DIV
say at 3,23; color colors[2]; "÷"
count = 0
if (0 = instr("+-*/PMTD=",ch[2])) jump div1
; Here, An operator was the LAST thing entered
mode = 4
scroll at 6,41 size 14,16
say at 19,43; color colors[2]; ; total:@(formt[d]);" ÷";
jump loop2
LABEL DIV1
if (mode = 0) jump no_mode
jump /r calc : ;; perform CURRENT operation
say color colors[2]; " ÷"; : ;; update the tape
mode = 4 : ;; set NEW current operation
jump disp_total
LABEL NO_MODE
; There is no CURRENT operation when the first operator is pressed.
; The default operation is PLUS. Add operand to total.
total = op
; Set the CURRENT mode
;
mode = ((l-1) mod 4) + 1
; Update the tape
scroll at 6,41 size 14,16
say at 19,43 ; color colors[2]; op:@(formt[d]); " "; mid("+-x÷",mode,1)
jump disp_total
LABEL EQUAL
say at 3,23; color colors[2]; " " : ;; Erase displayed operator
if (0 = instr("=+-*/PMTD",ch[2])) jump E1
; Last key was an operator, so display TOTAL line on the tape
; (sequence was, for example: operand operator = )
scroll at 6,41 size 14,16
say at 19,41; color colors[2]; "T "; total:@(formt[d]);
mode = 5
jump loop
LABEL E1
; Last key was NOT an operator. See if there is a CURRENT operator.
count = 0
if (mode <> 0) jump e2
; Here, the user has hit = before entering an operator
total = op
scroll at 6,41 size 14,16
say at 19,41; color colors[2]; "T "; total:@(formt[d]);
jump disp_total
LABEL E2
; Here, = was hit in a "normal" sequence so calculate & display
; (i.e. operand1 operator operand2 = )
jump /r calc
say at 19,41; color colors[2]; "T";
say at 3,10; color colors[1]; total:@(formt[d]);
op = 0
mode = 5
jump loop
LABEL DISP_TOTAL
; Display the total in the Calc display
say at 3,10; color colors[1]; total:@(formt[d]);
if (0 = instr("=+-*/PMTD",ch[2])) op = 0
jump loop
LABEL CALC
; Perform CURRENT operation and update the tape
scroll at 6,41 size 14,16
say at 19,43 ; color colors[2]; op:@(formt[d])
if (mode = 1) total = total + op : jump calc1
if (mode = 2) total = total - op : jump calc1
if (mode = 3) total = total * op : jump calc1
if (op = 0) jump calc_error
total = total / op
LABEL CALC1
scroll at 6,41 size 14,16
say at 19,41; color colors[2]; "S "; str(total:@(formt[d]));
rturn
LABEL CALC_ERROR
; Divide by Zero, or attempt to enter 2nd decimal point
al 7n
say at 3,10; color colors[1]; " ERROR";
say at 19,56; color colors[2]; "E"
; Accept only CLEAR
repeat
z = inkey(-1)
until (0 <> instr("Cc",chr(z)))
jump clear
LABEL HELP
; Display HELP screen, and return to input mode
box at 7,42 size 16,37 style 5 color "rw" save
me
[7,50][Wr]*** CALC HELP ***
[09,44][Kw]P[kw] or [Kw]+[kw] add
[10,44][Kw]M[kw] or [Kw]-[kw] subtract
[11,44][Kw]T[kw] or [Kw]*[kw] multiply
[12,44][Kw]D[kw] or [Kw]/[kw] divide
[14,44][Kw]O[kw] calculator off (exit CALC)
[15,44][Kw]S[kw] change sign of operand
[16,44][Kw]C[kw] clear calculator
[17,44][Kw]E[kw] clear entry
[18,44][Kw]Alt-C[kw] clear calculator & tape
[19,44][Kw]Alt-D[kw] change # of decimal places
[20,44][Kw][kw] tape feed
[22,47][Wr]< Press a key to exit Help >
.
; Wait for key
z = inkey(-1)
restore
jump LOOP2
LABEL SET_DECIMAL
; Allow user to configure # of decimal places displayed
box at 7,42 size 6,37 style 5 color "bw" save
say at 7,45; color "Wb"; "Change Number of Decimal Places"
say at 9,44; color colors[2]; "How many places (0 - 4) ? "
; NOTE: The variable 'd' contains the number of decimal places
; to be displayed PLUS ONE. This is because 'd' is used as
; an array index and CANNOT = 0
z = d-1
input z at 9,70 format 1 color colors[1] only "01234"
d = z + 1
say at 3,28; color colors[2]; "D:"; color colors[1]; z:1
say at 10,44; color colors[2]; "Make this the default (Y/N)?"
ch[1] = "N"
input ch[1] at 10,73 color colors[1] alluc only "YN"
if (ch[1] = "N") restore : jump loop2
; Here we create or update a CALC.CFG file which is to contain
; the number of digits to be displayed after the decimal.
open append pth as 1 size 1
seek 1, 0
write line 1, z
close 1
say at 12,45; color "WB"; "Done!"; color "Wb"; " Press a key..."
z = inkey(50)
restore
jump loop2
LABEL SHOW_TAPE
; Draw the Tape
box at 3,40 size 18,18 color colors[2] style 2
draw from 5,40 to 5,57 color colors[2] style 2 ends "╠" + "╣"
say at 4,45; color colors[2]; "T A P E"
jump clear
LABEL SHOW_CALC
; Draw the Calculator
box at 2,5 size 22,30 style 2 color colors[2]
draw from 4,5 to 4,34 color colors[2] ends "╟╢"
me
[5,9][Bk] P[Ck] R[Gk] I[Yk] S[Rk] M [Wk]C A L C [kk]
.
say at 3,28; color colors[2]; "D:"; color colors[1]; (d-1):1
box at 10,8 size 3,5 across 3 down 4 xsep 2 ysep 1 style 2 color "kw" hollow
for l = 1 to 3
say at 11,(10 + ((l-1)*6)); color colors[2]; l + 6
say at 14,(10 + ((l-1)*6)); color colors[2]; l + 3
say at 17,(10 + ((l-1)*6)); color colors[2]; l
say at 20,(10 + ((l-1)*6)); color colors[2]; mid("±0∙",l,1)
next
box at 7,28 size 3,3 down 5, ysep 1 style 3 color colors[2] hollow
for l = 1 to 5
say at (8 + ((l-1)*3)),29; color colors[2]; mid("+-x÷=",l,1)
next
box at 7,8 size 3,7 across 2 xsep 4 style 4 color colors[2]
say at 8,9; color "Wr"; " O"; color "wr"; "n "
say at 8,19; color "Wb";" C "
rturn
LABEL SETUP
; Initialize variables & colors
box at 1,1 size 25,80 color "kk" style 0
colors[1] = "ky"
colors[2] = "kw"
colors[3] = "Wk"
d = 1 : ;; default # of digits after decimal is 0
tens[1] = 0.1 : ;; used to enter digits after the decimal
tens[2] = 0.01
tens[3] = 0.001
tens[4] = 0.0001
tens[5] = 0.00001
formt[1] = "12" : ;; used for current display mode
formt[2] = "12.1"
formt[3] = "12.2"
formt[4] = "12.3"
formt[5] = "12.4"
; create path name containing path where calc.xts resides,
; followed by the filename CALC.CFG
pth = strip(value("do"),letter + ".",1) + "CALC.CFG"
if -[@(pth)] rt : ;; CALC.CFG doesn't exist
; CALC.CFG exists. Input & validate the configuration
open input pth as 1 size 1
get 1,1,ch[1]
close 1
if (0 = instr("01234",ch[1])) rt
d = int(ch[1]) + 1
rt
LABEL EXIT
for z = 1 to 2
box at 7,8 size 3,7 style 4 color colors[3] hollow
box at 7,8 size 3,7 style 4 color colors[2] hollow
next
say at 8,9; color colors[2]; " O"; color "Kw"; "ff "
LABEL ERROR_LABEL
; Here is where execution is transfered to when user presses the
; ATtention key (to abort CALC)
say at 25,20; color "Wk"; "Press a key to exit CALC...";
z = inkey(40)
sc l kw
cl
var forget op
LABEL KILL_STACK
rt KILL_STACK
end