1000 REMark TUTOR4_BAS
1005 REMark :
1010 REMark INITIALISE added to set up the program and
1015 REMark some helper routines have been added
1020 :
1025 initialise
1030 REPeat pointer_loop
1035   action = MCALL(#3 ; \0)
1040   SELect ON action
1045     = 0         : EXIT pointer_loop : REMark ESC
1050     = -10 TO -1 : REMark DIGIT key
1055     = -11       : REMark DECIMAL POINT
1060     = -15 TO -12: REMark Function
1065     = -16       : REMark EQUALS
1070   END SELect 
1075   SELect ON action
1080     = -16 TO -1: action = MSTAT%(#3, action TO 0)
1085   END SELect 
1090 END REPeat pointer_loop
1095 MCLEAR #3
1100 CLAMP
1105 CLOSE #3
1110 CLOSE #4
1115 STOP
1120 :
1125 :
1130 DEFine PROCedure initialise
1135   OPEN #3,'con_'   : REMark Main console channel
1140   DIM display$(11) : REMark Current number being input
1145   DIM operator$(1) : REMark Arithmetic function to carry out
1150   decimal_point = 0: REMark Assume no DP yet in the number.
1155   OPEN #4,'scr_'   : REMark Display window channel
1160   INK #4,7         : REMark White ink for the display
1165   CSIZE #4,2,0     : REMark Big digits for the display
1170   :
1175   MDRAW#3, 'flp1_calc_men', 0, 0
1180   :
1185   show_answer '0'  : REMark Initialise the display
1190   operator$ = ''   : REMark No previous operation
1195   display$ = ''    : REMark No current input number
1200   running_total = 0: REMark The running total so far !
1205 END DEFine initialise
1210 :
1215 :
1220 DEFine FuNction right_justify$(n$)
1225   :
1230   REMark This function takes a string and returns it
1235   REMark right justified in 11 characters.
1240   :
1245   RETurn FILL$(' ', 11 - LEN(n$)) & n$
1250 END DEFine right_justify$
1255 :
1260 :
1265 DEFine PROCedure show_answer(text$)
1270   :
1275   REMark Print the current answer up on the display
1280   REMark but make it right justified first
1285   :
1290   MWLINK #3, 1, #4 : REMark Overlay #4 on application window 1
1295   PRINT #4, right_justify$(text$)
1300 END DEFine show_answer
