Creating a simple text viewer (with an error trapping routine):
<< DATA DUP TYPE -> A
<< IF 'A=/5' THEN DROP "Invalid object type" MSGBOX KILL END >>
OBJ-> DUP -> A << IF 'A=/7' THEN "Invalid number of data lines" MSGBOX CLEAR KILL END >>
1 FOR A A DISP -1 STEP DO UNTIL KEY END DROP >>
DATA contains a list with objects to be displayed on the screen. Note: =/ is the "not equal to" sign, produced by pushing ALPHA, RIGHT SHIFT, 1.
DATA recalls the object of the variable DATA onto the stack. DUP duplicates the data stored in DATA, so that when the next command is executed, the information on the stack is not lost. TYPE checks the object type, and returns the number of the object to the stack. -> A << sets up a subroutine and a new subprogram, while creating the local variable A, which will be used within the subprogram. IF 'A=/5' tests to see that the value of A (the local variable) is not equal to 5. If it does equal 5 (meaning that 'A=/5' is false), then the rest of the IF ... END loop is skipped, because no ELSE command is within this subroutine. However, if A does not equal 5 (meaning that 'A=/5' is true), then execution continues to the THEN command. DROP will delete the current level of the stack (the information that was recalled from DATA). "Invalid object type" is a parameter of the MSGBOX command, which will display the message "Invalid object type" on the screen, and wait for a response from the user. KILL exits the program, because the object type was found to not be a list, and if this error trapping routine was not existant (week 2), the program would error out. END simply ends the current subroutine, and >> closes the subprogram. After it has been determined that the object on a stack is a list, OBJ-> breaks down the list into it's contents and the number of entries. DUP duplicates the number of entries of the list, and this number will be used by the next subprogram and subroutine. -> A << sets up a new subroutine and a new subprogram, while recreating the local variable A. IF 'A=/7' tests the value of A to insure it is not equal to 7 (this is another error trapping routine.) The reason the number 7 is used, is because, there are only 7 lines on the display. The THEN command works the same as before. "Invalid number of data lines" MSGBOX brings up the error message. CLEAR is used to erase all contents off the stack, which is the 7 lines of information extracted from the variable DATA. KILL stops the program because an error was found. END ends the subroutine, and >> ends the subprogram. Now that the error checking routines have determined there is no errors, the rest of the program is the same as the last. 1 sets up the counting loop, and FOR A starts the loop. A recalls the value of A onto the stack, and the DISP command displays the information on the screen, according to the input of the list contained in DATA (that was placed on the stack) and the value of A. -1 STEP replaces the NEXT command usually found at the end of the loop. All that STEP does is forces the program to count in steps, and in this case, the step is -1, so the program will count backwards. (The only reason it counts backwards is to correctly interpert the data in LIST. You can replace this command with NEXT and examine the results.) DO UNTIL KEY END DROP is the same loop used in the last program; it's just a simple key trapping routine.
Creating a simple text viewer:
<< DATA OBJ-> 1 FOR A A DISP -1 STEP DO UNTIL KEY END DROP >>
DATA contains a list with objects to be displayed on the screen. (7)
DATA recalls the object of the variable DATA onto the stack. OBJ-> breaks down the list into it's contents and the number of entries. 1 sets up the counting loop, and FOR A starts the loop. A recalls the value of A onto the stack, and the DISP command displays the information on the screen, according to the input of the list contained in DATA (that was placed on the stack) and the value of A. -1 STEP replaces the NEXT command usually found at the end of the loop. All that STEP does is forces the program to count in steps, and in this case, the step is -1, so the program will count backwards. (The only reason it counts backwards is to correctly interpert the data in LIST. You can replace this command with NEXT and examine the results.) DO UNTIL KEY END DROP is the same loop used in the last program; it's just a simple key trapping routine.
Creating a simple counting program:
<< CLLCD 1 10 FOR A A 1 DISP DO UNTIL KEY END DROP NEXT >>
CLLCD clears the screen. 1 10 FOR A sets up the counting loop, counting from 1 to 10 and storing the current value in A.
A recalls the value of A to the stack. 1 DISP displays the object in the first stack level (the value of A) on the 1st display line.
DO UNTIL KEY END DROP is a simple DO ... END loop that runs the program until a key is pressed. NEXT increments the counter and goes back to the command after the FOR A.
Keep checking back. This site will be updated weekly. If you are having problems with a program, drop me a note.