1000 REMark TUTOR5_BAS
1005 REMark :
1010 REMark Action routines added for digits & decimal point.
1015 :
1020 initialise
1025 REPeat pointer_loop
1030   action = MCALL(#3 ; \0)
1035   SELect ON action
1040     = 0         : EXIT pointer_loop : REMark ESC
1045     = -10 TO -1 : digit action      : REMark DIGIT key
1050     = -11       : decimal           : REMark DECIMAL POINT
1055     = -15 TO -12: REMark Function
1060     = -16       : REMark EQUALS
1065   END SELect 
1070   SELect ON action
1075     = -16 TO -1: action = MSTAT%(#3, action TO 0)
1080   END SELect 
1085 END REPeat pointer_loop
1090 MCLEAR #3
1095 CLAMP
1100 CLOSE #3
1105 CLOSE #4
1110 STOP
1115 :
1120 :
1125 DEFine PROCedure initialise
1130   OPEN #3,'con_'   : REMark Main console channel
1135   DIM display$(11) : REMark Current number being input
1140   DIM operator$(1) : REMark Arithmetic function to carry out
1145   decimal_point = 0: REMark Assume no DP yet in the number.
1150   OPEN #4,'scr_'   : REMark Display window channel
1155   INK #4,7         : REMark White ink for the display
1160   CSIZE #4,2,0     : REMark Big digits for the display
1165   :
1170   MDRAW#3, 'flp1_calc_men', 0, 0
1175   :
1180   show_answer '0'  : REMark Initialise the display
1185   operator$ = ''   : REMark No previous operation
1190   display$ = ''    : REMark No current input number
1195   running_total = 0: REMark The running total so far !
1200 END DEFine initialise
1205 :
1210 :
1215 DEFine FuNction right_justify$(n$)
1220   :
1225   REMark This function takes a string and returns it
1230   REMark right justified in 11 characters.
1235   :
1240   RETurn FILL$(' ', 11 - LEN(n$)) & n$
1245 END DEFine right_justify$
1250 :
1255 :
1260 DEFine PROCedure show_answer(text$)
1265   :
1270   REMark Print the current answer up on the display
1275   REMark but make it right justified first
1280   :
1285   MWLINK #3, 1, #4 : REMark Overlay #4 on application window 1
1290   PRINT #4, right_justify$(text$)
1295 END DEFine show_answer
1300 :
1305 :
1310 DEFine PROCedure digit(loose_item)
1315   LOCal number
1320   :
1325   REMark Add a single digit to the front of the number
1330   REMark currently being entered. This is held in
1335   REMark DISPLAY$ until an arithmetic action is entered.
1340   :
1345   number = ABS(loose_item) -1: REMark Convert to a digit 0 - 9
1350   IF LEN(display$) < 11
1355      display$ = display$ & number
1360      show_answer display$
1365   ELSE 
1370      BEEP 1000, 5
1375   END IF 
1380 END DEFine digit
1385 :
1390 :
1395 DEFine PROCedure decimal
1400   :
1405   REMark Add a decimal point to the current number
1410   REMark but only if there is not one already.
1415   :
1420   IF NOT (decimal_point)
1425      IF LEN (display$) < 11
1430         decimal_point = 1
1435         display$ = display$ & '.'
1440         show_answer display$
1445      ELSE 
1450         BEEP 1000, 5
1455      END IF 
1460   ELSE 
1465      BEEP 1000, 5
1470   END IF 
1475 END DEFine decimal
1480 :
1485 :
