home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 5
/
ctrom5b.zip
/
ctrom5b
/
PROGRAM
/
DIVERSEN
/
TIPI2A
/
TIPI.DOC
< prev
next >
Wrap
Text File
|
1994-11-27
|
138KB
|
4,541 lines
__
/ \ ______
/\ / \ / \
/ \ / \ / \
/ \ /\/\/\/\/\ /\/\/\/\/\/\
/\/\/\/\ / \ / \
/ \ / \ / \
/ \/ \/ \
/ / \ \
/ / \
/ X / ######## #### ##### #### \
/ / \ ######## #### ###### #### \
/ / \ ## ## ## ## ## \
/ / + \ ## ## ###### ## \
/ / + \ ## ## ##### ## \
/ / + \ ## #### ## #### \
/ \___(_)___/ ## #### ## #### \
"A most important, but also a most elusive, aspect of any tool is
its influence on the habits of those who train themselves in its
use. If this tool is a programming language, this influence is --
whether we like it or not -- an influence on our thinking habits."
-- Edsger W. Dijkstra "A Discipline of Programming"
Table of Contents
1. The Preliminaries . . . . . . . . . . . . . . . . . . . . . . 1
1.1 Legal Stuff . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 About the Author . . . . . . . . . . . . . . . . . . . . . 1
1.3 Shareware . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.4 What Registration Buys You . . . . . . . . . . . . . . . . 2
1.5 The Great TIPI Code Contest . . . . . . . . . . . . . . . . 3
1.5.1 What You Can Win . . . . . . . . . . . . . . . . . . . 4
1.6 The Order Form for TIPI 2.0a . . . . . . . . . . . . . . . 5
1.7 TIPI Feedback . . . . . . . . . . . . . . . . . . . . . . . 6
2. A Description of TIPI . . . . . . . . . . . . . . . . . . . . 7
2.1 Introducing TIPI . . . . . . . . . . . . . . . . . . . . . 7
2.2 The Origin of TIPI . . . . . . . . . . . . . . . . . . . . 7
2.3 The Influences . . . . . . . . . . . . . . . . . . . . . . 8
2.4 The Name . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.5 TIPI Qualities . . . . . . . . . . . . . . . . . . . . . . 8
3. Getting Started . . . . . . . . . . . . . . . . . . . . . . . 10
3.1 Installing TIPI . . . . . . . . . . . . . . . . . . . . . . 10
3.1.1 A Note for HP Users . . . . . . . . . . . . . . . . . . 10
3.2 The TIPI Programmer's Workbench . . . . . . . . . . . . . . 11
3.3 The Sample Programs . . . . . . . . . . . . . . . . . . . . 15
4. TIPI Programming . . . . . . . . . . . . . . . . . . . . . . . 16
4.1 Your First TIPI Program . . . . . . . . . . . . . . . . . . 16
4.2 The Basic Principle . . . . . . . . . . . . . . . . . . . . 17
4.3 Defining New Instructions . . . . . . . . . . . . . . . . . 17
5. Stacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
5.1 A Description of TIPI Stacks . . . . . . . . . . . . . . . 18
5.2 Stack Diagrams . . . . . . . . . . . . . . . . . . . . . . 19
5.3 Why You Should Use Stacks . . . . . . . . . . . . . . . . . 19
6. TIPI Math . . . . . . . . . . . . . . . . . . . . . . . . . . 20
6.1 RPN . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
6.2 Integer Math . . . . . . . . . . . . . . . . . . . . . . . 21
7. Variables . . . . . . . . . . . . . . . . . . . . . . . . . . 22
8. The TIPI Debugger . . . . . . . . . . . . . . . . . . . . . . 25
9. Common mistakes of new TIPI Programmers . . . . . . . . . . . 29
10. Notes and Limits . . . . . . . . . . . . . . . . . . . . . . 30
11. Control Instructions . . . . . . . . . . . . . . . . . . . . 31
11.1 BEGIN . . . . . . . . . . . . . . . . . . . . . . . . . . 31
i
Contents ii
11.2 CASE . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
11.3 CASE$ . . . . . . . . . . . . . . . . . . . . . . . . . . 31
11.4 DEFAULT . . . . . . . . . . . . . . . . . . . . . . . . . 32
11.5 DEFAULT$ . . . . . . . . . . . . . . . . . . . . . . . . . 32
11.6 DO . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
11.7 ELSE . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
11.8 ENDCASE . . . . . . . . . . . . . . . . . . . . . . . . . 33
11.9 ENDCASE$ . . . . . . . . . . . . . . . . . . . . . . . . . 33
11.10 ENDIF . . . . . . . . . . . . . . . . . . . . . . . . . . 33
11.11 ENDOF . . . . . . . . . . . . . . . . . . . . . . . . . . 33
11.12 ENDOF$ . . . . . . . . . . . . . . . . . . . . . . . . . 33
11.13 IF . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
11.14 INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . 34
11.15 LEAVE . . . . . . . . . . . . . . . . . . . . . . . . . . 34
11.16 LOOP . . . . . . . . . . . . . . . . . . . . . . . . . . 34
11.17 OF . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
11.18 OF$ . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
11.19 UNTIL . . . . . . . . . . . . . . . . . . . . . . . . . . 35
11.20 WEND . . . . . . . . . . . . . . . . . . . . . . . . . . 35
11.21 WHILE . . . . . . . . . . . . . . . . . . . . . . . . . . 36
12. Data Instructions . . . . . . . . . . . . . . . . . . . . . . 37
12.1 FETCH . . . . . . . . . . . . . . . . . . . . . . . . . . 37
12.2 STORE . . . . . . . . . . . . . . . . . . . . . . . . . . 37
13. Debugging Instructions . . . . . . . . . . . . . . . . . . . 38
13.1 TRACECOL . . . . . . . . . . . . . . . . . . . . . . . . . 38
13.2 TRACEOFF . . . . . . . . . . . . . . . . . . . . . . . . . 38
13.3 TRACEON . . . . . . . . . . . . . . . . . . . . . . . . . 38
13.4 TRACEROW . . . . . . . . . . . . . . . . . . . . . . . . . 39
13.5 TRACEVAR . . . . . . . . . . . . . . . . . . . . . . . . . 39
14. Defining Instructions . . . . . . . . . . . . . . . . . . . . 40
14.1 DEFARRAY . . . . . . . . . . . . . . . . . . . . . . . . . 40
14.2 DEFINE . . . . . . . . . . . . . . . . . . . . . . . . . . 40
14.3 DEFSTR . . . . . . . . . . . . . . . . . . . . . . . . . . 41
14.4 DEFSTRARRAY . . . . . . . . . . . . . . . . . . . . . . . 41
14.5 DEFTABLE . . . . . . . . . . . . . . . . . . . . . . . . . 41
14.6 DEFVAR . . . . . . . . . . . . . . . . . . . . . . . . . . 42
14.7 ENDDEF . . . . . . . . . . . . . . . . . . . . . . . . . . 42
14.8 ENDTABLE . . . . . . . . . . . . . . . . . . . . . . . . . 42
15. DOS Instructions . . . . . . . . . . . . . . . . . . . . . . 43
15.1 CALL . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
15.2 CHDIR . . . . . . . . . . . . . . . . . . . . . . . . . . 43
15.3 COMMAND$ . . . . . . . . . . . . . . . . . . . . . . . . . 43
15.4 ENV$ . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
15.5 FIRSTFILE . . . . . . . . . . . . . . . . . . . . . . . . 44
15.6 GETDIR . . . . . . . . . . . . . . . . . . . . . . . . . . 44
15.7 KILL . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
15.8 MAKEDIR . . . . . . . . . . . . . . . . . . . . . . . . . 45
15.9 NEXTFILE . . . . . . . . . . . . . . . . . . . . . . . . . 45
15.10 REMDIR . . . . . . . . . . . . . . . . . . . . . . . . . 45
15.11 RENAME . . . . . . . . . . . . . . . . . . . . . . . . . 45
Contents iii
16. Graphics Instructions . . . . . . . . . . . . . . . . . . . . 46
16.1 DRAWLINE . . . . . . . . . . . . . . . . . . . . . . . . . 46
16.2 DRAWRECT . . . . . . . . . . . . . . . . . . . . . . . . . 46
16.3 GETFONT . . . . . . . . . . . . . . . . . . . . . . . . . 46
16.4 GETPOINT . . . . . . . . . . . . . . . . . . . . . . . . . 47
16.5 MOVEPEN . . . . . . . . . . . . . . . . . . . . . . . . . 47
16.6 PLOTICON . . . . . . . . . . . . . . . . . . . . . . . . . 47
16.7 PLOTPOINT . . . . . . . . . . . . . . . . . . . . . . . . 48
16.8 PLOTTEXT . . . . . . . . . . . . . . . . . . . . . . . . . 48
16.9 SCREEN . . . . . . . . . . . . . . . . . . . . . . . . . . 48
16.10 SCROLL . . . . . . . . . . . . . . . . . . . . . . . . . 49
16.11 SETCLIP . . . . . . . . . . . . . . . . . . . . . . . . . 49
16.12 SETFONT . . . . . . . . . . . . . . . . . . . . . . . . . 49
16.13 SETLINETYPE . . . . . . . . . . . . . . . . . . . . . . . 49
16.14 SETLOGORG . . . . . . . . . . . . . . . . . . . . . . . . 50
16.15 SETPENCOLOR . . . . . . . . . . . . . . . . . . . . . . . 50
16.16 SETREPRULE . . . . . . . . . . . . . . . . . . . . . . . 50
16.17 SETVMODE . . . . . . . . . . . . . . . . . . . . . . . . 51
16.18 ZOOM . . . . . . . . . . . . . . . . . . . . . . . . . . 51
17. I/O Instructions . . . . . . . . . . . . . . . . . . . . . . 52
17.1 BEEP . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
17.2 BLOAD . . . . . . . . . . . . . . . . . . . . . . . . . . 52
17.3 BSAVE . . . . . . . . . . . . . . . . . . . . . . . . . . 52
17.4 CLOSE . . . . . . . . . . . . . . . . . . . . . . . . . . 53
17.5 CLS . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
17.6 COLOR . . . . . . . . . . . . . . . . . . . . . . . . . . 53
17.7 COLOR? . . . . . . . . . . . . . . . . . . . . . . . . . . 53
17.8 COLUMN . . . . . . . . . . . . . . . . . . . . . . . . . . 54
17.9 COMSTAT . . . . . . . . . . . . . . . . . . . . . . . . . 54
17.10 CONSOLE . . . . . . . . . . . . . . . . . . . . . . . . . 54
17.11 CR . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
17.12 CURRENT . . . . . . . . . . . . . . . . . . . . . . . . . 55
17.13 CURSOR . . . . . . . . . . . . . . . . . . . . . . . . . 55
17.14 DEFSEG . . . . . . . . . . . . . . . . . . . . . . . . . 55
17.15 EOF . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
17.16 EXTENDED . . . . . . . . . . . . . . . . . . . . . . . . 56
17.17 FILEPOS . . . . . . . . . . . . . . . . . . . . . . . . . 56
17.18 GETBYTE . . . . . . . . . . . . . . . . . . . . . . . . . 56
17.19 GETNUM . . . . . . . . . . . . . . . . . . . . . . . . . 57
17.20 GETPORT . . . . . . . . . . . . . . . . . . . . . . . . . 57
17.21 GETVOL . . . . . . . . . . . . . . . . . . . . . . . . . 57
17.22 GET$ . . . . . . . . . . . . . . . . . . . . . . . . . . 57
17.23 INKEY$ . . . . . . . . . . . . . . . . . . . . . . . . . 58
17.24 INPORT . . . . . . . . . . . . . . . . . . . . . . . . . 58
17.25 ISINPUT . . . . . . . . . . . . . . . . . . . . . . . . . 58
17.26 ISOUTPUT . . . . . . . . . . . . . . . . . . . . . . . . 58
17.27 KEY . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
17.28 LF . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
17.29 LOCATE . . . . . . . . . . . . . . . . . . . . . . . . . 59
17.30 MOUSE . . . . . . . . . . . . . . . . . . . . . . . . . . 59
17.31 OPEN . . . . . . . . . . . . . . . . . . . . . . . . . . 59
17.32 OPENCOM . . . . . . . . . . . . . . . . . . . . . . . . . 60
17.33 OUTPORT . . . . . . . . . . . . . . . . . . . . . . . . . 60
17.34 PEEK . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Contents iv
17.35 POKE . . . . . . . . . . . . . . . . . . . . . . . . . . 61
17.36 PRINT . . . . . . . . . . . . . . . . . . . . . . . . . . 61
17.37 PRINTCHR . . . . . . . . . . . . . . . . . . . . . . . . 61
17.38 PRINTER . . . . . . . . . . . . . . . . . . . . . . . . . 61
17.39 PRINT$ . . . . . . . . . . . . . . . . . . . . . . . . . 62
17.40 PUTBYTE . . . . . . . . . . . . . . . . . . . . . . . . . 62
17.41 PUTPORT . . . . . . . . . . . . . . . . . . . . . . . . . 62
17.42 ROW . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
17.43 SETVOL . . . . . . . . . . . . . . . . . . . . . . . . . 62
17.44 SOUND . . . . . . . . . . . . . . . . . . . . . . . . . . 63
17.45 VARPTR . . . . . . . . . . . . . . . . . . . . . . . . . 63
17.46 | . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
18. Math Instructions . . . . . . . . . . . . . . . . . . . . . . 64
18.1 ABS . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
18.2 MAX . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
18.3 MIN . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
18.4 MOD . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
18.5 * . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
18.6 + . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
18.7 - . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
18.8 / . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
18.9 < . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
18.10 = . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
18.11 > . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
19. Miscellaneous Instructions . . . . . . . . . . . . . . . . . 67
19.1 BIT? . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
19.2 BYE . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
19.3 ERROR . . . . . . . . . . . . . . . . . . . . . . . . . . 67
19.4 EVAL . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
19.5 FALSE . . . . . . . . . . . . . . . . . . . . . . . . . . 68
19.6 MACHINE? . . . . . . . . . . . . . . . . . . . . . . . . . 68
19.7 NOT . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
19.8 OFF . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
19.9 RANDOM . . . . . . . . . . . . . . . . . . . . . . . . . . 69
19.10 RANDOMIZE . . . . . . . . . . . . . . . . . . . . . . . . 69
19.11 TICKS . . . . . . . . . . . . . . . . . . . . . . . . . . 69
19.12 TIMEOUT . . . . . . . . . . . . . . . . . . . . . . . . . 70
19.13 TRUE . . . . . . . . . . . . . . . . . . . . . . . . . . 70
19.14 VERSION . . . . . . . . . . . . . . . . . . . . . . . . . 70
19.15 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
19.16 ( . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
19.17 ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
20. Stack Instructions . . . . . . . . . . . . . . . . . . . . . 72
20.1 DEPTH . . . . . . . . . . . . . . . . . . . . . . . . . . 72
20.2 DEPTH$ . . . . . . . . . . . . . . . . . . . . . . . . . . 72
20.3 DROP . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
20.4 DROP$ . . . . . . . . . . . . . . . . . . . . . . . . . . 73
20.5 DUP . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
20.6 DUP$ . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
20.7 OVER . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
20.8 OVER$ . . . . . . . . . . . . . . . . . . . . . . . . . . 73
20.9 PICK . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Contents v
20.10 PICK$ . . . . . . . . . . . . . . . . . . . . . . . . . . 74
20.11 POP . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
20.12 PUSH . . . . . . . . . . . . . . . . . . . . . . . . . . 74
20.13 ROT . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
20.14 ROT$ . . . . . . . . . . . . . . . . . . . . . . . . . . 75
20.15 SWAP . . . . . . . . . . . . . . . . . . . . . . . . . . 75
20.16 SWAP$ . . . . . . . . . . . . . . . . . . . . . . . . . . 75
21. String Instructions . . . . . . . . . . . . . . . . . . . . . 76
21.1 ASC . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
21.2 CHR$ . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
21.3 DATE$ . . . . . . . . . . . . . . . . . . . . . . . . . . 76
21.4 INSTR . . . . . . . . . . . . . . . . . . . . . . . . . . 77
21.5 LCASE$ . . . . . . . . . . . . . . . . . . . . . . . . . . 77
21.6 LEFT$ . . . . . . . . . . . . . . . . . . . . . . . . . . 77
21.7 LEN . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
21.8 LTRIM$ . . . . . . . . . . . . . . . . . . . . . . . . . . 78
21.9 MID$ . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
21.10 PARSE$ . . . . . . . . . . . . . . . . . . . . . . . . . 78
21.11 REPLACE$ . . . . . . . . . . . . . . . . . . . . . . . . 78
21.12 RIGHT$ . . . . . . . . . . . . . . . . . . . . . . . . . 78
21.13 RTRIM$ . . . . . . . . . . . . . . . . . . . . . . . . . 79
21.14 STR$ . . . . . . . . . . . . . . . . . . . . . . . . . . 79
21.15 TIME$ . . . . . . . . . . . . . . . . . . . . . . . . . . 79
21.16 UCASE$ . . . . . . . . . . . . . . . . . . . . . . . . . 79
21.17 VAL . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
21.18 " . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
21.19 +$ . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
21.20 =$ . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Index of TIPI Instructions . . . . . . . . . . . . . . . . . . . 81
Chapter 1
The Preliminaries
1.1 Legal Stuff
DISCLAIMER: This software is provided "as is" without warranty of
any kind, either expressed or implied.
Your registration fee entitles you to distribute TIPI.EXE together
with any TIPI programs you write as well as any EXEs you build
using TIPI's MakeEXE option. If you profit from working with TIPI,
please register it. Thanks!
TIPI.EXE, this manual, the various sample programs and the
utilities included here are copyright (c) 1993,1994 by Kent P.
Peterson. All Rights Reserved.
1.2 About the Author
I'm Kent Peterson and I wrote TIPI and this manual. I currently
live in Issaquah, Washington with my wife, two sons, a cat and a
mess of computers. When I grow up I'd like to be an eighth-century
Taoist hermit. For now I spend my days as a programming manager
for a computer gaming company. I spend my nights and weekends
hacking small computers and drinking way too much coffee.
1.3 Shareware
TIPI 2.0a is provided as shareware. Under the shareware concept,
you can test a program before you buy it. If you find TIPI useful
and valuable to you, please send in the $35 registration fee.
Please distribute this software widely. Shareware works when
people make copies of disks, upload code to the nets and pass good
ideas on to others. I do request that you do not alter this
software or documentation.
1
Chapter 1. The Preliminaries 2
1.4 What Registration Buys You
Peace of Mind -- When you register TIPI, you will have the
satisfaction of knowing that you are helping make the shareware
system work. Instead of feeling guilty each time you use TIPI,
you will feel great knowing you paid a fair price for something
you value.
A Future for TIPI -- Your registration lets me know TIPI is being
used and that there still is a place for independent software
development. Late at night when I want to chuck it all, I'll
remember that you sent me a check and I'll keep on coding.
Free EXEs -- The TIPI Programmer's Workbench can make stand-alone
EXEs from your TIPI programs. An unregistered copy of TIPI can
create these EXEs, but they will contain a shareware reminder.
When you register TIPI, you will receive code that will allow
you to create EXEs without the shareware reminder.
Tech Support -- If you have a problem with TIPI, want clarification
about how some instruction works or need some clue about how to
crack a particular problem, it's good to have someone to ask.
If you're a registered TIPI owner, you can ask me via Email and
I will do my best to respond. If you are not a registered
owner, you can still ask me questions but you stand a
popsicle's chance in Hades of getting an answer.
More TIPI Code -- Registered TIPI users will be sent a disk
containing many more examples of TIPI code. Some of the
programs will be written by me and the rest will be written by
your fellow TIPI programmers. This disk will contain programs
written for the Great TIPI Code Contest and will be sent out in
April of 1995.
Chapter 1. The Preliminaries 3
1.5 The Great TIPI Code Contest
"The Street finds its own uses for things -- uses the manufacturers
never imagined." -- William Gibson
OK, here's the deal. Between now and March 5th, 1995 (that's my
birthday), I'll be accepting entries in the GREAT TIPI CODE
CONTEST. The rules are simple:
. The contest is open to ANY user of TIPI (even if those of you
who haven't gotten around to registering it yet!)
. You entry must consist of a TIPI program you have written that
you think is interesting, practical, fun, neat, cool or (at
least) worth more than the disk space it occupies.
. You may enter as many programs as you like and you may enter as
many times as you like.
. Entries must be submitted either via Email or on MSDOS floppy
disks.
. Your disks will not be returned, nor will your Email costs be
reimbursed.
Email may be sent to either
Internet peterson@halcyon.com
or
Compuserve 72310,2174
Disks may be mailed to
Kent Peterson
GREAT TIPI CODE CONTEST
360 NW Dogwood Street A-201
Issaquah, WA 98027 USA
Copyrights to all code entered into this contest will remain with
you, but any code entered may be distributed to registered TIPI
users.
Chapter 1. The Preliminaries 4
1.5.1 What You Can Win
The author of the niftiest program (as judged by myself, my wife
and some of my nerdy friends) will win
FREE CHOCOLATE!!! -- One box of delicious chocolates from the
world famous Boehm's Chocolates in Issaquah, Washington.
A KEEN TROPHY!!! -- A genuine TIPI Code Contest trophy to show off
to all your friends.
A TRIP TO ISSAQUAH!!! -- A some expense paid trip to beautiful
Issaquah, Washington. The some expenses covered include the
two dollar cost of a metro bus trip from Seattle, WA to
Issaquah. If your costs are more than that, you have to pick
up the balance of the tab.
ESPRESSO AND WITTY CONVERSATION!!! -- If you make it to Issaquah,
I will buy you an Espresso drink of your choice at one of
Issaquah's many Espresso bars and we'll hang out. If you want
to just take the drink and split, that's fine too.
In April of 1995, anyone who has REGISTERED TIPI by March 5, 1995
will receive a disk containing some new TIPI programs written by
myself, the winning entry from the contest and whatever cool
runners-up there were.
Chapter 1. The Preliminaries 5
1.6 The Order Form for TIPI 2.0a
To Register TIPI, please fill out a copy of this page and send it
with you payment to:
Kent Peterson
360 NW Dogwood #A-201
Issaquah, WA 98027-3272
Ship to:
_________________________________________
_________________________________________
_________________________________________
_________________________________________
_________________________________________
Please send:
Qty Description Total
____ TIPI Program Disk @ $35.00 ea $ ________
(Includes registered copy of program,
and manual on disk)
____ TIPI Printed Manual @ $10.00 ea $ ________
(Limit one per registered copy of TIPI)
Sales Tax $ ________
(Washington state residents please add 8.2% sales tax)
Shipping & Handling $ 5.00
Total $ ________
DISK SIZE (CHECK ONE): 5 1/4" [ ] 3 1/2" [ ]
Chapter 1. The Preliminaries 6
1.7 TIPI Feedback
I'm always looking for ways to improve TIPI. And the best source
of ideas for improvements is from TIPI users themselves. So, if
you feel so inclined, take a moment and write down your suggestions
below and send them to me. I appreciate your feedback!
Do you own a palmtop? [ ] Yes [ ] No
Do you use TIPI on [ ] a palmtop [ ] a desktop [ ] both
List the top three things you would like added to TIPI:
1) _________________________________________________________
2) _________________________________________________________
3) _________________________________________________________
In the future, I may port TIPI to another operating system.
Should I
[ ] work on a Windows version
[ ] work on a Macintosh version
[ ] work on an OS/2 version
[ ] work on a GEOS version
[ ] work on a Unix version
[ ] keep working on the DOS version
Please use the remaining space to provide feedback on TIPI features
you like or dislike, or to list new features you'd like to see added
to TIPI. (attach additional sheets if you'd like):
______________________________________________________________
______________________________________________________________
______________________________________________________________
______________________________________________________________
______________________________________________________________
______________________________________________________________
You can also send questions/comments via Internet or Compuserve
Internet peterson@halcyon.com
Compuserve 72310,2174
Chapter 2
A Description of TIPI
2.1 Introducing TIPI
TIPI (pronounced "tepee" like the nomadic dwelling) is a small,
structured programming language for MS-DOS computers. The TIPI
interpreter takes up about 12K bytes of disk space and TIPI
programs are similarly small. TIPI requires about 100K bytes of
RAM to run and is thus well-suited for palmtop computers such as
the Poquet PC, the HP-95LX or the HP100LX.
TIPI contains over 170 instructions and control structures
including Do..Loop, While..Wend and Begin..Until Loops. TIPI also
includes If..Then..Else and Case statements and an integrated
debugger. TIPI is an extensible language, so programmers may add
to the language as they see fit.
2.2 The Origin of TIPI
I created TIPI specifically for programming palmtop computers
although it may also be used for creating programs for desktop or
laptop PCs. I wrote the original version of TIPI (1.0) in 1993 so
I would have a small, elegant programming system for programming my
Atari Portfolio and other small DOS machines. Shortly after I
released the language as shareware in the fall of 1993 it became
obvious that the majority of people using TIPI were running the
language on Hewlett-Packard 95LX and 100LX palmtop computers. I
decided to get myself one of these nifty little HP machines and
concentrate on optimizing the language for use on the HPs. I'm now
the proud and happy owner of an HP100LX and TIPI 2.0a now sports a
bunch of new instructions that take advantage of of some of the
advanced features of the HPs.
7
Chapter 2. A Description of TIPI 8
2.3 The Influences
TIPI is a fairly new language, but it incorporates elements from
various earlier languages. TIPI owes a tremendous amount to
Charles Moore and his language Forth. While TIPI is not Forth, it
is definitely Forth-like and Forth-inspired.
Whatever readability TIPI has is owed to John Kemeny and Thomas
Kurtz. These two gentlemen created a language for the rest of us
and called it BASIC.
Other languages (including C, Pascal and AWK) also influenced the
development of TIPI. In fact it's fair to say that TIPI is nothing
more than my collection of neat ideas I've stolen from various
places. Oh well, Newton wrote about standing on the shoulders of
giants and that's not a bad way to work.
2.4 The Name
The name TIPI is an acronym standing for "Threaded Instruction
Processing Interpreter". While interpreted programs tend to run
slower than compiled programs, interpreters do not require a
separate compile and link stage and thus programs can be quickly
tested and changed. Also, interpreters can be very small, as
evidenced by TIPI's tiny size.
2.5 TIPI Qualities
TIPI was created to be:
Efficient -- TIPI is based on a multi-stack interpreter. This lets
numeric and string data pass quickly and consistently between
instructions, greatly reducing the need for complex internal
parsers and temporary variables.
Structured -- TIPI is very modular. All TIPI instructions have one
entry and one exit point. All instructions are clearly defined
and perform most of their interaction via stacks. TIPI does
not have the spaghetti-generating GOTO instruction.
Small -- TIPI is not a language for creating huge programs. The
basic philosophy of TIPI is that problems should be broken into
small, discrete, easily understood components. In threaded
languages, performance degrades as the threads get longer and
longer threads are what you get when you write big programs.
To keep TIPI reasonably fast, the TIPI interpreter is limited
to processing programs of 32K or less.
Clear -- A program is more than a set of instructions telling a
computer how to solve a particular problem, it is also a
document precisely describing a set of problem solving
procedures. A programming language needs to be comprehensible
to the computer the program will run on and clear to the
Chapter 2. A Description of TIPI 9
programmers who write the code and future programmers who may
have to modify it. With TIPI, every effort has been made to
make the language consistent and easy to read.
Extensible -- Rather than having a complex system of libraries and
includes, TIPI lets you use a text editor to copy commonly used
instruction definitions into your code. This means you can
define your own instructions in TIPI, so you can add the
features you've always wanted in a language.
A good way to think about this is to think about how the
English language is extended by the addition of jargon. Here's
an example. Suppose you didn't know what RAM is. You ask
someone and they tell you "RAM means Random Access Memory" or
"RAM is memory that forgets everything when you shut your
computer off". Let's say that one of these definitions makes
sense to you and you remember it. From now on when you talk
about computers, you can use the word RAM because you know what
it means in terms of things you already knew. You use the
jargon as a quick and easy shorthand for something more
complicated. You have just extended your vocabulary to include
the word RAM.
Where English has words, TIPI has instructions. In the same
way that you add jargon to your English vocabulary by defining
a new word in terms of words you already know, you extend TIPI
by defining new instructions in terms of existing instructions.
Here is a small chunk of TIPI code defining a new instruction
called WAIT which causes program execution to pause until the
user presses a key:
define wait
begin key until
enddef
Once you have defined WAIT, you can use the WAIT instruction
anywhere in your code.
TIPI contains over 170 built-in instructions for the programmer to
use as building blocks. These instructions fall into eleven
categories and are described fully in the later chapters of this
manual.
Chapter 3
Getting Started
3.1 Installing TIPI
TIPI 2.0a is distributed as a single compressed ZIP file named
TIPI2A.ZIP. Using PKUNZIP or an equivalent ZIP file extraction
utility, extract the contents of this file to an empty DOS
directory or onto a floppy. Of course, if you are reading this
file, you have probably already done this.
To install TIPI on a palmtop computer, you really only need
TIPI.EXE and whatever TIPI programs you care to run. To get the
full use of TIPI, however, I suggest that you install the TIPI
Programmer's Workbench, described on the next page.
3.1.1 A Note for HP Users
TIPI comes with some files that are useful to owners of HP 100
series palmtops. The first of these is T.ICN. This is an HP Icon
file and may be used to add the TIPI Programmer's Workbench to the
HP desktop. Another file is TIPI.GDB. This is an HP database file
containing summaries of all of the TIPI instructions. You may
chose to use this instead of the standard help files included with
the workbench.
10
Chapter 3. Getting Started 11
3.2 The TIPI Programmer's Workbench
The TIPI Programmer's Workbench is a tiny integrated environment
for TIPI development. The workbench lets you create, edit and
debug TIPI programs.
The workbench defaults to running as a character-based application,
but users of the HP100LX or HP200LX have the option of running the
workbench with a Graphical User Interface (GUI) that has the look
and feel of the built-in HP icon menus.
The files that make up the workbench are:
CHARTIPI.BAT -- Run this to set TIPI to use the character
workbench.
GUITIPI.BAT -- Run this to set TIPI to use the GUI workbench.
CHARTIPI.DAT -- Data for the character workbench.
GUITIPI.DAT -- Data for the GUI workbench.
T.BAT -- The bat file that runs the workbench.
T.TPI -- The character workbench TIPI program.
TIPIGUI.TPI -- The GUI workbench TIPI program.
T.ICN -- The TIPI icon.
COMMAND.ICN -- The command icon.
DOC.ICN -- The document icon.
DOS.ICN -- The DOS icon.
FACTORY.ICN -- The factory icon.
LOOKUP.ICN -- The lookup icon.
RUN.ICN -- The run icon.
TIPI.EXE -- The TIPI interpreter.
TIPI.GDB -- An HP database file describing the TIPI instructions.
TIPICORE.BIN -- The binary image used to build EXEs.
REGISTER.DAT -- The TIPI registration code.
E.COM -- Dr. David Nye's wonderful freeware text editor. I have
made one modification to this program to make it easier for
palmtop users -- the cursor is now a full size block all the
time. Also note that this editor is not designed for editing
large files. It is fine for TIPI programs (which are 32K or
Chapter 3. Getting Started 12
less), but if you try to load large file (like this document,
for example), it will choke.
E.DOC -- The documentation for E.COM
HELPTIPI.BAT -- The TIPI help system.
HELPTIPI.TPI -- The main help file.
HELPCONT.TPI -- The help file for control instructions.
HELPDATA.TPI -- The help file for data instructions.
HELPDBUG.TPI -- The help file for debugging instructions.
HELPDFIN.TPI -- The help file for defining instructions.
HELPDOS.TPI -- The help file for DOS instructions.
HELPGRAF.TPI -- The help file for graphics instructions.
HELPIO.TPI -- The help file for I/O instructions.
HELPMATH.TPI -- The help file for math instructions.
HELPMISC.TPI -- The help file for misc instructions.
HELPSTAK.TPI -- The help file for stack instructions.
HELPSTRS.TPI -- The help file for string instructions.
All of these files are included with this release, along with
various sample programs to get you started in TIPI programming. I
am a firm believer in learning by example, so the I've included
various programs that you can run, study, learn from and modify.
In addition, the TIPI Programmer's Workbench is composed entirely
of BAT files and TIPI programs, so you may modify it to suit your
preferences once you become familiar with TIPI.
To get familiar with the workbench, start the workbench with the
sample program HANGMAN.TPI. You do this by typing:
T HANGMAN
Chapter 3. Getting Started 13
You will see a screen that looks like this:
+----------------------------------------------------+
| TIPI Programmer's Workbench |
| |
| Version 2.0a |
| |
| |
| [E]dit X |
| [C]hange Program / \ |
| [S]et Command Line / \ |
| [R]un Program / + \ |
| [M]ake EXE / + \ |
| [L]ookup \__( )__/ |
| [D]OS Command |
| |
| Program Name: HANGMAN.TPI |
| Command Line: |
| |
+----------------------------------------------------+
Note: The GUI workbench doesn't look quite like this, but I can't
illustrate it here. It has all the same functions, however, so the
rest of this document applies to the GUI workbench as well as the
character workbench.
On this screen you may select one of the options by pressing one of
the keys in brackets (E,C,S,R,M,L or D) or you may press the [ESC]
key to leave the workbench.
[E] -- will load the current program (in this case HANGMAN.TPI)
into the editor, where you can look at the code or modify it as
you wish. TIPI ships with Dr. David Nye's freeware editor
"E", but if you have a favorite DOS ASCII editor, you can
modify the file T.TPI to use that editor instead.
[C] -- lets you change to another program. [C] will display a list
of the current TIPI files and let you choose one of them to
work on.
[S] -- is used to set the command line that will be used when your
program is run. This option lets you set any command line
arguments that you may want to pass to your program.
[R] -- will run the current program.
[M] -- will make an EXE file from the current TIPI program. If you
have a registered copy of TIPI, this EXE will be fully
functional with no annoying shareware message. If your copy of
TIPI is unregistered, any EXEs it creates will display a
registration reminder before they execute. They will still
work fine, but this should give you incentive to register.
Chapter 3. Getting Started 14
[L] -- will let you lookup the specific details of each of the
built-in TIPI instructions. [L]ookup will take you to a menu
listing each of the various groups of instructions. This menu
will take you to submenus which in turn will take you to the
details of each instruction. Pressing the key listed in the []
will take you to that option, while pressing [ESC] will back
you up one level. This format should let you find the details
you need.
[D] -- will let you run any DOS command you like. This is useful
for copying files, making backups or testing EXEs you have just
made.
[ESC] -- leaves the workbench.
Chapter 3. Getting Started 15
3.3 The Sample Programs
The TIPI sample programs are:
ANYBASE.TPI -- A program to convert integers from any number base
to any other base.
ASCII.TPI -- A program can tell you the ASCII and keycodes for
keystrokes and characters.
BENCH.TPI -- A simple benchmark program to tell you how fast your
PC runs TIPI.
BIRTHDAY.TPI -- A program to play a familiar song.
BUGDEMO.TPI -- A program to demonstrate some of the HP palmtop
graphics. Note -- This program also uses the files AAV1.ICN,
AAV2.ICN, BUG.ICN and BUG2.ICN.
CAL.TPI -- A program that displays the calendar for the current
month.
DEMO.TPI -- A simple demo program.
DIRTEST.TPI -- A program demonstrating TIPI's directory
instructions.
ENVTEST.TPI -- A program demonstrating how TIPI can read the DOS
environment.
ERROR.TPI -- A program to demonstrate the use of the TIPI debugger.
ERROR2.TPI -- A more complicated example to demonstrate the
debugger.
HAIKU.TPI -- A program to generate bad haiku poems.
HANGMAN.TPI -- The game of Hangman. Note -- this program also uses
the file HANGWORD.TXT.
HELLO.TPI -- A TIPI version of the world famous "Hello World!"
program.
MOUSE.TPI -- A program to demonstrate the use of the MOUSE
instruction.
PPUZZLE.TPI -- A puzzle kind of like a Rubik's Cube.
POWERS.TPI -- A program to introduce the extensibility of TIPI.
TIPIREG.TPI -- A program that lets you enter your registration code
to create a registered version of TIPI.
Chapter 4
TIPI Programming
4.1 Your First TIPI Program
Here is a simple little TIPI program:
# HELLO.TPI by Kent Peterson
| Hello World!
begin
key
until
OK, This isn't too bad. It's only five lines long (not counting
blank lines) so we can take the time to explain this program line
by line.
The first line is a comment. A comment is a line that is put in
for a human to read and is ignored by the computer. In TIPI,
anything after the # symbol on a line is ignored by the computer.
The second line prints the message "Hello World!" on the screen.
The | symbol tells TIPI to take the rest of the line and print it
out.
The last three lines form a loop that will wait until the user
presses a key. BEGIN starts the loop. The KEY instruction will
return the keycode of whatever key is pressed or zero if no key is
pressed. UNTIL will branch back to the BEGIN if the stack value is
zero, otherwise execution continues after the UNTIL. In the case
of this program, the are no more instructions after the UNTIL, so
the program ends.
You can run this program by loading it into the workbench by typing
t hello
at the DOS prompt. Pressing [R] will run the program and you will
see that the program DOS in fact print out "Hello World!" and wait
for you to press a key.
16
Chapter 4. TIPI Programming 17
4.2 The Basic Principle
The main idea in TIPI programming is to break your problem up into
little chunks and create instructions to solve the sub-problems.
In this way, you not only create a program to solve this particular
problem, but a language that is useful for solving similar
problems.
4.3 Defining New Instructions
Most languages make you conform to the way the language works.
With TIPI, you mold the language to the problem at hand and the way
you work. The sample programs are filled with examples of ways to
extend the language, but here is a simple sample:
# POWERS.TPI
# by Kent Peterson
# This is a simple program to demonstrate
# how easy it is to add new instructions
# to TIPI.
define square ( n -- n*n )
# Squares a number
dup *
enddef
define cube ( n -- n*n*n )
# Cubes a number
dup square *
enddef
define quad ( n -- n*n*n*n )
# raises a number to the fourth power
square dup *
enddef
"Enter a number" print$
getnum
dup square print cr
dup cube print cr
quad print cr
begin key until
Notice that the definition "square" is used in the definitions of
"cube" and "quad". Once you define an instruction in your program,
you can use it just like a built-in TIPI instruction. When your
code executes, TIPI will jump back to where the new instruction was
defined. If you are running the debugger, you can watch this
happen.
Chapter 5
Stacks
"If one is master of one thing and understands one thing well, one
has at the same time, insight into and understanding of many
things." -- Vincent Van Gogh
5.1 A Description of TIPI Stacks
Programs need to keep track of various details as they execute.
These details may be the results of calculations, the names of
files, information supplied by the user, etc.
Most traditional computer languages use "variables" to store
information. Variables are named areas of computer memory and are
referenced by name. TIPI allows you to create and use various
kinds of variables but most TIPI programming relies on a couple of
efficient mechanisms called "stacks".
A stack is simply a pile of information. You add information to
the top of the stack, one piece at a time. When it is time to
remove information from the pile, you take information from the top
of the stack, one piece at a time.
TIPI has three stacks, which are described below.
The Data Stack -- This stack is the most commonly used. It is used
for storing numbers, the results of calculations, and logical
values.
The String Stack -- This stack stores strings of character data.
In TIPI a string can be up to 80 characters long.
The Return Stack -- This stack is used internally by TIPI. It may
also be used for temporary data storage by using the PUSH and
POP instructions
18
Chapter 5. Stacks 19
5.2 Stack Diagrams
The bulk of this manual consists of descriptions of each of the
hundred-odd built-in TIPI instructions. These descriptions consist
of the name of the instruction, a STACK DIAGRAM which explains what
the instruction does to the Data and String stacks, and a sentence
or two describing what the instruction does. Here is an example:
MID$ <-- This is the name of the
instruction.
Data s l -- <-- These are the stack
String a$ -- b$ <-- diagrams
Returns b$, a string of l <-- This is the description
characters starting at
position s from a$.
What the stack diagrams do is describe what the data and string
stacks look like before the instruction executes and right after
the instruction executes. In these diagrams the "--" separates the
"before" from the "after" and the top of the stack is the right
most entry. Thus
6 2 "TIPI is not BASIC" MID$
would extract 2 characters starting at position 6 in "TIPI is not
BASIC". The result would be the string "is" left on the string
stack.
5.3 Why You Should Use Stacks
One of the best reasons for using the stacks instead of variables
is speed. Working with data on the stack is quicker than always
storing and fetching data to and from a variable.
Another good reason is convenience. All of the TIPI instructions
are constructed to use the stacks. If you use a lot of variables,
you will find yourself doing a lot of unneeded data manipulation.
Once you get used to using stacks, you will see that they help an
awful lot in making your code modular. When you define a new
instuction, if it only uses stack values, you don't have to worry
about bugs cropping up from unintentional changes to variables.
Chapter 6
TIPI Math
6.1 RPN
While many of the instructions in TIPI look very much like BASIC
statements, TIPI is in fact quite different from BASIC. Probably
the greatest difference between TIPI and BASIC is the fact that
TIPI uses a syntax known as RPN. RPN stands for Reverse Polish
Notation (no, it's not an ethnic slur. It refers to the nation of
origin of Jan Lukaciewicz, the mathematicians who originated this
notation.)
RPN is used in many Hewlett-Packard calculators, in the display
language PostScript, in some CPUs, in Forth and now in TIPI. To
most people, RPN looks backwards, but RPN has many advantages.
To add two plus two in BASIC and print out the result, your program
would look something like this:
X=2+2
PRINT X
To do the same thing in TIPI, your program would look like this:
2 2 + print
It may seem weird, but once you get used to RPN, it really does
make things easier. For example, when you want to do more complex
math, you have to use parentheses in BASIC to make sure that
everything gets done in just the order you want, like this:
X=(6+3)*4/3
PRINT X
In TIPI you do it like this
6 3 + 4 * 3 / print
( parentheses mark comments in TIPI )
( just like they do in English. )
20
Chapter 6. TIPI Math 21
6.2 Integer Math
TIPI does all it's math in integer values. That means you can work
with numbers like 6, -584, 47789329 and 0 but you can't have
3.14159 or 6.02^23. Forth purists will tell you that you don't
need floating point math. I'll tell you that TIPI doesn't have it
because it would make TIPI too big and too slow for what I wanted.
And the Forth guys are basically right. I have seen 3-D animation
engines written using only integer math and two friends of mine
have coded an entire hockey game (including player physics and AI)
using only integer math.
The TIPI data stack and all its math instructions work with long
(32 bit) signed values. This means that TIPI can handle integers
from -2,147,483,648 to 2,147,483,647. This is a very wide range
and with some creative scaling, you should be able to handle almost
any problem that you might have thought would require floating
point math. If I get a huge number of registrations and a huge
number of requests for floating point math, a future version of
TIPI may include floating point.
Chapter 7
Variables
In addition to the data and string stacks, TIPI lets you create
integer variables, integer arrays and strings. To use a variable
in your program you must first define it. TIPI also has a data
structure called a TABLE. The proper use of variables and tables
are illustrated in the program VARSAMPLE listed below. More
information can be found in the manual sections describing Defining
Instructions and Data Instructions.
22
Chapter 7. Variables 23
# VARSAMPLE.TPI
# by Kent Peterson
# This program demonstrates the three
# types of variables in TIPI along with
# the table data structure.
defvar price
3 defarray zipcode
defstr Man$
deftable kid$ # This sets the
"Bart" "Lisa" "Maggie" # table kid$ to
endtable # to hold the names
# of three kids.
100 price store # This stores 100 in
# the variable price.
10605 1 zipcode store # This stores
60609 2 zipcode store # different zipcodes
90210 3 zipcode store # in each of the
# three zipcode
# slots.
"Homer" Man$ store # This stores the
# word "Homer" in
# the variable Man$.
# Now let's use these variables
# and the table
"Hi, I'm " print$
Man$ fetch print$ # You have to fetch
# the contents of
# a variable before
# you can print it out.
"." print$ cr
"My kids are named "
print$
1 kid$ print$ # Tables are initialized
# when they are defined
# and they auto-fetch.
# DO NOT USE A FETCH
# with a table.
", " print$
2 kid$ print$
" and " print$
3 kid$ print$
"." print$ cr cr
"My car cost $" print$
Chapter 7. Variables 24
price fetch print
"." print$ cr cr
"My zipcode is " print$
1 zipcode fetch print # Array values
# are fetched and
# and stored using
# their names and
# their index values.
" but I wish it was "
print$
3 zipcode fetch print
"." print$ cr
begin key until # This sequence of
# instructions waits
# until you press
# a key.
Chapter 8
The TIPI Debugger
It would be great if we all could write perfect programs and never
had programs bugs. Unfortunately, that's not the way programming
works. Because programs can have bugs, TIPI has a built-in
debugger. The debugger is actually a program tracer and it will
help you track down bugs and give you a view of what is happening
as TIPI runs your program.
First off, let's run ERROR.TPI a sample program that contains
(gasp) a BUG. Start the TIPI Programmer's Workbench by typing:
T ERROR
and pick [R]un from the menu.
BAM! TIPI will display this error message:
ERROR! 1
Too few stack values with
+
Pressing any key will show you the debugger screen, which looks
like this:
+- Data Depth 1 -+- String Depth 0-+
| 2| ----|
| ----| ----|
| ----| ----|
| ----| ----|
|+ |
|3 = |
+------------------------------------+
This is what's known in the programming biz as a "post-mortem"
dump. This means that you program is dead and you can't really do
anything to fix it right now. This screen is just giving you more
info about what went wrong. In this case what went wrong was the
program tried to add with only one value on the stack. The error
message told you that, and the debugger came up to show you just
what you had on the stacks. The debugger displays the data stack
on the left, the string stack on the right and the instruction just
executed below the data stack. Below that are the instructions it
was about to execute. In a post-mortem dump, pressing any key will
return you to the Workbench.
25
Chapter 8. The TIPI Debugger 26
Now let's use the editor to change the program to fix the bug.
Here is the program:
# ERROR.TPI
# This simple program has a
# bug in it to show you how
# to use the TIPI debugger
3 + 2 =
"The sum is " print$ print
The problem may be fixed by changing the program to read:
# ERROR.TPI
# This simple program had a
# bug in it to show you how
# to use the TIPI debugger
3 2 +
"The sum is " print$ print
By moving the "+" after the 2 and getting rid of the unneeded "=",
the program is fixed. Running the program again will show that all
is well and our program can perform the amazing (well maybe not
amazing!) feat of adding two integers.
But wait, what if we wanted to see more of what's going on? You
can do this by invoking the debugger at any point in your code by
simply adding the instruction "TRACEON". For example, if you
change our little program to look like this:
# ERROR.TPI
# This simple program had a
# bug in it to show you how
# to use the TIPI debugger
traceon
3 2 +
"The sum is " print$ print
The debugger will be displayed from the start. You may step
through the program by pressing the [SPACEBAR]. You will see each
instuction execute and you can watch what it does to the stacks.
By watching a program in this way, you can usually track down bugs
in just a few minutes.
While tracing a program, the following keys are active:
[SPACEBAR] Steps to the next instruction.
[ESC] Quits the debugger until another TRACEON command is executed.
Chapter 8. The TIPI Debugger 27
[END] Ends the program.
In addition to TRACEON there are instructions for turning the trace
window off, placing the trace window elsewhere on the screen and
for tracing the contents of variables. The following program
illustrates the use of these instructions.
This program also has a bug that we will track down using the TIPI
debugger.
# ERROR2.TPI by Kent Peterson 10/1/94
# This is another program used to demonstrate the TIPI debugger
defvar henry
defvar waldo
henry tracevar
waldo tracevar
40 tracecol
# traceon
300 henry store
henry 50 + waldo store
waldo print
Now the bug in this program is that it doesn't do what we want it
to do. The goal of the program is to store the value 300 in henry
and then store fifty more than the value of henry in waldo. The
result should be 350, but the program will instead display 2.
The problem is this program confuses the name of a variable with
its contents. In the second to the last line, 50 is added to henry
and not to the contents of henry. TIPI tracks each variable with a
number and since henry is the first variable in our program, its
number is one. Thus the second to the last line stores 51 in
waldo, instead of 350.
But wait, why then does the last line print out the number 2?
Because the last line makes the same mistake, it confuses a
variable with its contents. To see what's going on remove the #
instuction from in front of the traceon instruction and rerun the
program.
Now you will see the debugging window, but it will look different
than it did in our last example. For one thing, it is located at
the middle of the screen instead of the left edge. That's because
the line that says "40 tracecol" tells TIPI to place it there.
Also the tracewindow is displaying henry and waldo because we have
told TIPI to use those two variables as TRACEVARs.
As you step through the program, you will see the values of henry
and waldo change along with the stack values. You will see the
problem and then you can end the debugger.
Chapter 8. The TIPI Debugger 28
If you change the program to read
# ERROR2.TPI by Kent Peterson 10/1/94
# This is another program used to demonstrate the TIPI debugger
defvar henry
defvar waldo
henry tracevar
waldo tracevar
40 tracecol
traceon
300 henry store
henry fetch 50 + waldo store
waldo fetch print
you will see that the program behaves properly. Once a program has
been completely debugged, all of the tracing commands can be
removed. In fact, If you wish to use TIPI's MAKEEXE option, the
tracing commands MUST be removed because tracing is not supported
by the MAKEEXE option.
Chapter 9
Common mistakes of new TIPI Programmers
. The number one mistake would have to be stack errors. Study
the samples and learn RPN. IT IS WORTH IT. Your code won't be
cluttered with parentheses and the instructions will flow in a
logical order. The debugger will help a lot.
. Another common mistake is confusing the name of a variable with
the contents of a variable. If you have a variable named FRED,
FRED is just it's name. FRED FETCH is how you fetch a value
and FRED STORE is how you store a value.
. Forgetting to end a DEFINE. When TIPI sees a DEFINE, it looks
for the matching ENDDEF. If you don't have a match ENDDEF (or
you misspell it) TIPI gets very confused.
. Forgetting to leave white space around TIPI instructions. The
one that is most commonly screwed up is the "(". In TIPI make
your comments
( Look like this. )
(Not like this.)
29
Chapter 10
Notes and Limits
"When they feel cheated because I just ignore all those bells and
whistles, I can only answer: "Are you quite sure that all those
bells and whistles, all those wonderful facilities of your
so-called "powerful" programming languages belong to the solution
set rather than to the problem set?"." -- Edsger W. Dijkstra "A
Discipline of Programming"
. TIPI is case insensitive. This means that MAX, max and Max all
refer to the same instruction.
. TIPI uses vectored I/O. This means that all of the I/O
commands can be directed to/from files, the console, printers,
etc. See the commands ISINPUT and ISOUTPUT for details.
. Strings are limited to a maximum of 80 characters.
. The maximum depths for the data and return stacks are 80.
. The maximum depth of the string stack is 32.
. The maximum number of named variables is 100.
. The maximum number of array elements is a total of 1000.
. The maximum number of trace variables is 10.
. The maximum number of user-defined instructions is 100.
. The maximum size of a TIPI source (.TPI) file is 32K.
. TIPI always searches it's internal dictionary first, then
searches for new instructions in the order in which they were
defined.
. An instruction must be defined before it is used.
. IF...ELSE...ENDIF constructs may be nested but
CASE...OF...ENDOF and CASE$...OF$...ENDOF$ should NOT be
nested. If you feel you must nest CASE statements, place the
internal CASEs in their own DEFINEs.
30
Chapter 11
Control Instructions
11.1 BEGIN
Data Stack: --
String Stack: --
Starts a BEGIN UNTIL loop. When TIPI encounters an UNTIL, it will
branch back to the BEGIN if the value on the data stack is FALSE.
-----------------------------------------------------------
11.2 CASE
Data Stack: --
String Stack: --
Begins a CASE structure.
-----------------------------------------------------------
11.3 CASE$
Data Stack: --
String Stack: --
Begins a CASE$ structure.
-----------------------------------------------------------
31
Chapter 11. Control Instructions 32
11.4 DEFAULT
Data Stack: n --
String Stack: --
Used within a CASE structure to cover any cases not dealt with by
previous OF clauses.
-----------------------------------------------------------
11.5 DEFAULT$
Data Stack: --
String Stack: a$ --
Used within a CASE$ structure to cover any cases not dealt with by
previous OF$ clauses.
-----------------------------------------------------------
11.6 DO
Data Stack: N --
String Stack: --
Begins a DO loop. Processing continues until a LOOP instruction is
encountered. The loop will be executed N times.
-----------------------------------------------------------
11.7 ELSE
Data Stack: --
String Stack: --
Used within IF ELSE ENDIF constructs.
-----------------------------------------------------------
Chapter 11. Control Instructions 33
11.8 ENDCASE
Data Stack: --
String Stack: --
Ends a CASE structure.
-----------------------------------------------------------
11.9 ENDCASE$
Data Stack: --
String Stack: --
Ends a CASE$ structure.
-----------------------------------------------------------
11.10 ENDIF
Data Stack: --
String Stack: --
Ends an IF ELSE ENDIF construct.
-----------------------------------------------------------
11.11 ENDOF
Data Stack: --
String Stack: --
Ends an OF clause in a CASE structure.
-----------------------------------------------------------
11.12 ENDOF$
Data Stack: --
String Stack: --
Ends an OF$ clause in a CASE$ structure.
-----------------------------------------------------------
Chapter 11. Control Instructions 34
11.13 IF
Data Stack: n --
String Stack: --
If n is non-zero, instructions up to the next ELSE or ENDIF will be
executed. If n is zero, instructions up to the next ELSE or ENDIF
will be skipped.
-----------------------------------------------------------
11.14 INDEX
Data Stack: -- index
String Stack: --
Copies the current DO LOOP index value to the data stack.
-----------------------------------------------------------
11.15 LEAVE
Data Stack: --
String Stack: --
Sets the current INDEX value to one, thus ensuring the current DO
LOOP will be ended on this itteration.
-----------------------------------------------------------
11.16 LOOP
Data Stack: --
String Stack: --
Closes a DO LOOP construct. Decrements INDEX and loops back to the
DO if INDEX > 0, otherwise exits the loop.
-----------------------------------------------------------
Chapter 11. Control Instructions 35
11.17 OF
Data Stack: m n --
String Stack: --
Must be used within a CASE structure. If m is equal to n, the
instructions following the OF will be executed until an ENDOF is
encountered.
-----------------------------------------------------------
11.18 OF$
Data Stack: --
String Stack: a$ b$ --
Must be used within a CASE$ structure. If a$ is equal to b$, the
instructions following the OF$ will be executed until an ENDOF$ is
encountered.
-----------------------------------------------------------
11.19 UNTIL
Data Stack: N --
String Stack: --
Branches back to BEGIN if N is FALSE, otherwise continues.
-----------------------------------------------------------
11.20 WEND
Data Stack: --
String Stack: --
WEND branches back to a previous WHILE.
-----------------------------------------------------------
Chapter 11. Control Instructions 36
11.21 WHILE
Data Stack: n --
String Stack: --
If n is not equal to zero, instructions between the WHILE and the
WEND will be executed. WEND will branch back to the WHILE. If n
is equal to zero, execution branches to then next instruction
following the next WEND.
-----------------------------------------------------------
Chapter 12
Data Instructions
12.1 FETCH
Data Stack: v -- x (if numeric)
String Stack: -- x$ (if string)
Returns the contents of variable v. The type of v (numeric or
string) determines if the contents of the fetch is placed on the
data or the string stack.
-----------------------------------------------------------
12.2 STORE
Data Stack: n v -- (if numeric) v -- (if string)
String Stack: -- s$ --
Stores a value into a variable. The type of v (numeric or string)
determines if the contents of the store is taken from the data or
the string stack.
-----------------------------------------------------------
37
Chapter 13
Debugging Instructions
13.1 TRACECOL
Data Stack: col --
String Stack: --
Sets the column that the trace window will be shown on.
-----------------------------------------------------------
13.2 TRACEOFF
Data Stack: --
String Stack: --
Turns instruction tracing off.
-----------------------------------------------------------
13.3 TRACEON
Data Stack: --
String Stack: --
Turns instruction tracing on. When instruction tracing is on, TIPI
displays an informational window showing the stacks, any TRACEVARs
and the instructions being executed.
-----------------------------------------------------------
38
Chapter 13. Debugging Instructions 39
13.4 TRACEROW
Data Stack: row --
String Stack: --
Sets the row that the trace window will be shown on.
-----------------------------------------------------------
13.5 TRACEVAR
Data Stack: var --
String Stack: --
Adds a var to the trace window.
-----------------------------------------------------------
Chapter 14
Defining Instructions
14.1 DEFARRAY
Data Stack: N --
String Stack: --
Creates an integer array of N elements. The word after DEFARRAY is
used as the name of the array. For example, 10 DEFARRAY BOB would
create a 10 element array named BOB. When using STORE or FETCH
with ARRAY variables, you must precede the ARRAY name with a number
indicating the element to which you are referring. For example, 3
BOB FETCH will fetch the contents of the third element of BOB,
while 77 5 BOB STORE will will store 77 in the fifth element of
BOB. TIPI has enough array space for a total of up to 1000 array
elements in a TIPI program. TIPI also has a limit of 100 distinct
named variables per program.
-----------------------------------------------------------
14.2 DEFINE
Data Stack: --
String Stack: --
DEFINE is used to define new TIPI instructions. The word following
DEFINE is the name of the new TIPI instruction. Following this
will be a sequence of TIPI instructions followed by the word
ENDDEF. Once a new TIPI instructions has been defined, it may be
used just like any of the built-in TIPI instructions. For example,
DEFINE SQUARED DUP * ENDDEF DEFINE CUBED DUP SQUARED * ENDDEF will
create two new TIPI instructions, SQUARED and CUBED which will
respectively square and cube a value on the stack. Up to 100 new
TIPI instructions may be defined in a TIPI program.
-----------------------------------------------------------
40
Chapter 14. Defining Instructions 41
14.3 DEFSTR
Data Stack: --
String Stack: --
Creates a new string variable. The word after DEFSTR is used as
the name of the string. For example DEFSTR MARY will create a new
string variable called MARY. STORE and FETCH are used to place
values into variables and retrieve them respectively.
-----------------------------------------------------------
14.4 DEFSTRARRAY
Data Stack: N --
String Stack: --
Creates a string array of N elements. The word after DEFSTRARRAY
is used as the name of the array. For example, 10 DEFSTRARRAY
WALLY$ would create a 10 element string array named WALLY$. When
using STORE or FETCH with ARRAY variables, you must precede the
ARRAY name with a number indicating the element to which you are
referring. For example, 3 WALLY$ FETCH will fetch the contents of
the third element of WALLY$, while "Hello" 5 WALLY$ STORE will
store "Hello" in the fifth element of WALLY$. TIPI has enough
string array space for a total of up to 100 string array elements
in a TIPI program. TIPI also has a limit of 100 distinct named
variables per program.
-----------------------------------------------------------
14.5 DEFTABLE
Data Stack: --
String Stack: --
Creates a new data table. The word after DEFTABLE is used as the
name of the table. For example, DEFTABLE FRED will create a new
table called FRED. Following the name will be a series of numbers
or TIPI instructions followed by the instruction ENDTABLE. After a
table has been defined, any instruction in the table may be
executed by preceding the table name with the number of the
instruction to execute. For example, 4 FRED would execute the
fourth instruction in FRED.
-----------------------------------------------------------
Chapter 14. Defining Instructions 42
14.6 DEFVAR
Data Stack: --
String Stack: --
Creates a new numeric variable. The word after DEFVAR is used as
the name of the variable. For example, DEFVAR HERB will create a
new variable called HERB. STORE and FETCH are used to place values
into variables and retrieve them respectively.
-----------------------------------------------------------
14.7 ENDDEF
Data Stack: --
String Stack: --
Ends an instruction definition.
-----------------------------------------------------------
14.8 ENDTABLE
Data Stack: --
String Stack: --
Ends a table structure.
-----------------------------------------------------------
Chapter 15
DOS Instructions
15.1 CALL
Data Stack: --
String Stack: program$ param$ --
Calls a DOS program (program$) with the parameter given in param$.
Sets ERROR to 255 if the call is unsuccessful. Otherwise ERROR is
set to zero unless the called DOS program returns its own error
code. Call COMMAND.COM to run batch files.
-----------------------------------------------------------
15.2 CHDIR
Data Stack: --
String Stack: dir$ --
Changes the current DOS directory to the one specified by the top
string on the string stack.
-----------------------------------------------------------
15.3 COMMAND$
Data Stack: --
String Stack: -- Command$
Places a string on the string stack consisting of what followed the
word TIPI on the DOS command line when TIPI was invoked.
-----------------------------------------------------------
43
Chapter 15. DOS Instructions 44
15.4 ENV$
Data Stack: N --
String Stack: -- E$
ENV$ retrieves DOS environment strings. N identifies which string
to retrieve. If the string is not found, a null string ("") is
returned. If the environment string is longer than 80 characters,
TIPI will only return the first 80 characters in the string.
-----------------------------------------------------------
15.5 FIRSTFILE
Data Stack: --
String Stack: filespec$ -- fname$
Finds the first file that matches filespec$. Filespec$ follows the
standard DOS wildcard rules (ie the filespec can contain "*" or "?"
characters).
-----------------------------------------------------------
15.6 GETDIR
Data Stack: num --
String Stack: -- dir$
GETDIR is used to get the current directory. If num = 0 then
GETDIR returns the directory of the current drive. If num is 1
GETDIR uses the A drive, 2 uses the B drive etc. The directory
returned does NOT contain the drive letter or the first "\". Thus,
if the current directory is the root directory, 0 GETDIR will
return a null string ("").
-----------------------------------------------------------
15.7 KILL
Data Stack: --
String Stack: filespec$ --
Kills the specified file.
-----------------------------------------------------------
Chapter 15. DOS Instructions 45
15.8 MAKEDIR
Data Stack: --
String Stack: dirspec$ --
Makes the directory specified in dirspec$. If there is an error,
the system variable ERROR will be set.
-----------------------------------------------------------
15.9 NEXTFILE
Data Stack: --
String Stack: -- file$
Returns the next file that matches the filespec set by a previous
FIRSTFILE command. If there are no more files matching the
filespec, the null string ("") is returned.
-----------------------------------------------------------
15.10 REMDIR
Data Stack: --
String Stack: dir$ --
Removes the directory dir$. The directory should be empty before
you delete it. If REMDIR fails, the system variable ERROR will be
set.
-----------------------------------------------------------
15.11 RENAME
Data Stack: --
String Stack: oldname$ newname$ --
Renames a file.
-----------------------------------------------------------
Chapter 16
Graphics Instructions
16.1 DRAWLINE
Data Stack: row col --
String Stack: --
Draws a line from the current pen location to row, col.
HP only.
-----------------------------------------------------------
16.2 DRAWRECT
Data Stack: fill row col --
String Stack: --
Draws a rectangle from the current pen location to row, col. If
fill is 1 the rectangle is drawn filled. If not the rectangle will
be drawn unfilled.
HP only.
-----------------------------------------------------------
16.3 GETFONT
Data Stack: height width -- HiFontID LoFontID
String Stack: --
Returns the font ID of a font whose characters are height * width
pixels.
HP only.
-----------------------------------------------------------
46
Chapter 16. Graphics Instructions 47
16.4 GETPOINT
Data Stack: row col -- color
String Stack: --
Returns the color of the point at row, col.
HP only.
-----------------------------------------------------------
16.5 MOVEPEN
Data Stack: row col --
String Stack: --
Moves the pen to row col.
HP only.
-----------------------------------------------------------
16.6 PLOTICON
Data Stack: rule row col --
String Stack: icon$ --
Plots an HP icon (.icn) file at location row, col according to
rule. The screen should have been set to a graphics mode and row
and col are given in pixels. Row and col are the locations of the
top left corner of the icon and rule should be set according to the
following table.
0 FORCE
1 AND
2 OR
3 XOR
4 Invert the image and then FORCE
5 Invert the image and then AND
6 Invert the image and then OR
7 Invert the image and then XOR
HP only.
-----------------------------------------------------------
Chapter 16. Graphics Instructions 48
16.7 PLOTPOINT
Data Stack: row col --
String Stack: --
Plots a point at row, col.
HP only.
-----------------------------------------------------------
16.8 PLOTTEXT
Data Stack: Rflag Row Col --
String Stack: Text$ --
Plots Text$ at Row, Col in the current font. If Rflag is 0, text
is plotted horizontally. If Rflag is 1, text is rotated 90
degrees.
HP only.
-----------------------------------------------------------
16.9 SCREEN
Data Stack: Mode --
String Stack: --
Sets the screen mode of a PC according to Mode. The following
table gives values for mode.
Mode Graphics Res. Text Res. Adapters
---- ------------- --------- --------
0 None 25*80*16 Any
1 200*320*4 25*40*4 CGA/EGA/VGA
2 200*640*2 25*80*2 CGA/EGA/VGA
7 200*320*16 25*40*16 EGA/VGA
9 350*640*16 25*80*16 EGA/VGA
13 200*320*256 25*40*16 VGA
-----------------------------------------------------------
Chapter 16. Graphics Instructions 49
16.10 SCROLL
Data Stack: Dir Row Col Color Distance --
String Stack: --
Scrolls a rectangular region of the screen. The region is defined
from the current pen position to Row, Col. Distance is the number
of pixels to scroll. Dir controls the direction of the scroll and
Color controls whether bits scrolled "in" are set or cleared.
HP only.
-----------------------------------------------------------
16.11 SETCLIP
Data Stack: MinRow MinCol MaxRow MaxCol --
String Stack: --
Sets the graphics clipping region.
HP only.
-----------------------------------------------------------
16.12 SETFONT
Data Stack: HiFontID LoFontID --
String Stack: --
Sets a font for use in graphics modes.
HP only.
-----------------------------------------------------------
16.13 SETLINETYPE
Data Stack: Type --
String Stack: --
Sets a line type for graphics plotting.
HP only.
-----------------------------------------------------------
Chapter 16. Graphics Instructions 50
16.14 SETLOGORG
Data Stack: Row Col --
String Stack: --
Sets the logical origin to Row, Col. The logical coordinates are
set off the actual physical screen. Any future coordinate
operations are given relative to the logical origin. SETLOGORG
resets the CLIP REGION to the entire physical screen.
HP only.
-----------------------------------------------------------
16.15 SETPENCOLOR
Data Stack: Color --
String Stack: --
Sets the pen color for graphics drawing commands.
HP only.
-----------------------------------------------------------
16.16 SETREPRULE
Data Stack: Rule --
String Stack: --
Sets the graphics replacement rule according to the following
table:
0 = FORCE
1 = AND
2 = OR
3 = XOR
8 = FORCETEXT
HP only.
-----------------------------------------------------------
Chapter 16. Graphics Instructions 51
16.17 SETVMODE
Data Stack: Mode --
String Stack: --
Sets the current video mode to alpha or graphics and clears the
display. Mode should be set according to the following table:
3 = CGA alpha mode
6 = CGA graphics mode 640*200
7 = HP95LX alpha
32 = HP95LX graphics
HP only.
-----------------------------------------------------------
16.18 ZOOM
Data Stack: Z --
String Stack: --
Changes the zoom mode of the HP100LX. Z should be set according to
the following table:
2 = 80*25 BW
3 = 80*25 Color
7 = 40*16 BW Zoomed
33 = 80*25 BW
128 = 64*18 BW Zoomed
129 = 64*18 Color Zoomed
130 = 40*25 BW Zoomed
131 = 40*25 Color Zoomed
132 = 40*16 BW Zoomed
133 = 40*16 Color Zoomed
HP only.
-----------------------------------------------------------
Chapter 17
I/O Instructions
17.1 BEEP
Data Stack: --
String Stack: --
Produces a short beep.
-----------------------------------------------------------
17.2 BLOAD
Data Stack: addr count --
String Stack: file$ --
Loads count bytes of data to addr from file$. Addr is an address
in the current segment.
-----------------------------------------------------------
17.3 BSAVE
Data Stack: addr count --
String Stack: file$ --
Saves count bytes from addr to file$. Addr is an address in the
current segment.
-----------------------------------------------------------
52
Chapter 17. I/O Instructions 53
17.4 CLOSE
Data Stack: N --
String Stack: --
Closes file N. N should be either a 1 or a 2.
-----------------------------------------------------------
17.5 CLS
Data Stack: --
String Stack: --
Clears the screen and places the cursor in the upper left corner.
-----------------------------------------------------------
17.6 COLOR
Data Stack: Foreground Background --
String Stack: --
Sets the foreground and background colors of the screen for
subsequent prints. Colors are as follows:
0 -- Black 8 -- Dark Gray
1 -- Blue 9 -- Light Blue
2 -- Green 10 -- Light Green
3 -- Cyan 11 -- Light Cyan
4 -- Red 12 -- Light Red
5 -- Magenta 13 -- Light Magenta
6 -- Brown 14 -- Yellow
7 -- Gray 15 -- White
Note -- Background colors 8 to 15 result in blinking text.
-----------------------------------------------------------
17.7 COLOR?
Data Stack: -- flag
String Stack: --
Returns TRUE if a color card is detected, FALSE if a monochrome
card is detected.
Chapter 17. I/O Instructions 54
-----------------------------------------------------------
17.8 COLUMN
Data Stack: -- col
String Stack: --
Places the column of the current cursor position on the data stack.
-----------------------------------------------------------
17.9 COMSTAT
Data Stack: port -- status
String Stack: --
Returns the status of a com port. Port should be 1 or 2. Status
bits as follows:
Bit 0 -- Delta CTS
Bit 1 -- Delta DSR
Bit 2 -- RD
Bit 3 -- Delta receive line signal detect
Bit 4 -- CTS
Bit 5 -- DSR
Bit 6 -- Ring Indicator
Bit 7 -- Received line signal detect
Bit 8 -- Data Ready,
Bit 9 -- Overrun error
Bit 10 -- Parity Error
Bit 11 -- Framing error
Bit 12 -- Break detect error
Bit 13 -- Transfer holding register empty
Bit 14 -- Transfer shift register empty
Bit 15 -- Time-out error.
-----------------------------------------------------------
17.10 CONSOLE
Data Stack: -- 0
String Stack: --
Places the constant 0 on the data stack. The CONSOLE instruction
is used for clarity. For example, the sequence CONSOLE ISINPUT is
much clearer than 0 ISINPUT.
-----------------------------------------------------------
Chapter 17. I/O Instructions 55
17.11 CR
Data Stack: --
String Stack: --
Sends a carriage return to the current output device.
-----------------------------------------------------------
17.12 CURRENT
Data Stack: -- -2
String Stack: --
Places the constant -2 on the data stack. CURRENT is used for
clarity. For example, 1 CURRENT FILEPOS is much clearer than 1 -2
FILEPOS.
-----------------------------------------------------------
17.13 CURSOR
Data Stack: N --
String Stack: --
If N is zero, the cursor will be made invisible. If N is non-zero,
the cursor will be made visible. WARNING! Don't execute a 1
CURSOR unless you have already executed at least one 0 CURSOR.
-----------------------------------------------------------
17.14 DEFSEG
Data Stack: N --
String Stack: --
DEFSEG is used to define the data segment used in subsequent PEEK
and POKE instructions. If N is -1, the data segment is set back to
TIPI's default data segment address.
-----------------------------------------------------------
Chapter 17. I/O Instructions 56
17.15 EOF
Data Stack: -- -1
String Stack: --
Places the constant -1 on the data stack. EOF is used for clarity.
For example, 1 EOF FILEPOS is much clearer than 1 -1 FILEPOS.
-----------------------------------------------------------
17.16 EXTENDED
Data Stack: -- n
String Stack: --
Returns the contents of the system variable EXTENDED. This is used
in conjunction with INKEY$. EXTENDED will be 0 if a "normal" key
is pressed, 1 if an "extended" key is pressed.
-----------------------------------------------------------
17.17 FILEPOS
Data Stack: filenum action -- loc
String Stack: --
FILEPOS is used to position and read the value of a file pointer.
The filenum is a previously opened file number (1 or 2) and the
action is either EOF, CURRENT or a specific location. The number
loc returned on the data stack is the location in the file where
the next action will occur. EOF moves the pointer to the end of
the file, CURRENT keeps it at its current position and any other
number moves the pointer to that location in the file.
-----------------------------------------------------------
17.18 GETBYTE
Data Stack: filenum -- byte
String Stack: --
Gets a single byte from a file whose filenumber is filenum. The
file must have been previously opened and filenum must be either 1
or 2.
-----------------------------------------------------------
Chapter 17. I/O Instructions 57
17.19 GETNUM
Data Stack: -- n
String Stack: --
Gets a number from the current input device.
-----------------------------------------------------------
17.20 GETPORT
Data Stack: Port -- Byte
String Stack: --
Gets a Byte from a serial port. Port may be either 1 or 2,
specifying COM1 or COM2.
-----------------------------------------------------------
17.21 GETVOL
Data Stack: -- Vol
String Stack: --
Gets the system sound volume on an HP100LX. Vol may vary from 0
(silent) to 3 (loudest).
-----------------------------------------------------------
17.22 GET$
Data Stack: --
String Stack: -- string$
Gets a string from the current input device.
-----------------------------------------------------------
Chapter 17. I/O Instructions 58
17.23 INKEY$
Data Stack: --
String Stack: -- k$
Scans the keyboard and returns a one character string. If no key
is pressed, k$ is null (""), otherwise k$ is the character whose
key was pressed. If an extended key was pressed, the system
variable EXTENDED is set to TRUE.
-----------------------------------------------------------
17.24 INPORT
Data Stack: Port -- Byte
String Stack: --
Gets a Byte from a specific hardware port. This is used to read
joysticks, etc.
-----------------------------------------------------------
17.25 ISINPUT
Data Stack: n --
String Stack: --
Sets the current input device to n, where n is either file number 1
or 2 or the CONSOLE. The CONSOLE is device 0.
-----------------------------------------------------------
17.26 ISOUTPUT
Data Stack: n --
String Stack: --
Sets the current output device to n, where n is either filenumber 1
or 2, the PRINTER or the CONSOLE. The CONSOLE is device 0 and the
PRINTER is device 3.
-----------------------------------------------------------
Chapter 17. I/O Instructions 59
17.27 KEY
Data Stack: -- k
String Stack: --
Scans the keyboard and returns a keycode. If no key is pressed, k
is 0.
-----------------------------------------------------------
17.28 LF
Data Stack: --
String Stack: --
Sends a line feed to the current output device.
-----------------------------------------------------------
17.29 LOCATE
Data Stack: row col --
String Stack: --
Places the cursor at row, col.
-----------------------------------------------------------
17.30 MOUSE
Data Stack: AX BX CX DX -- AX BX CX DX
String Stack: --
Calls the low-level mouse interupt. See MOUSE.TPI for examples.
-----------------------------------------------------------
17.31 OPEN
Data Stack: N --
String Stack: T$ F$ --
Opens a file. N is the file number and N may be either a 1 or a 2.
T$ is the type of open and T$ may be either "I", "O", "A" or "R"
which stand for Input, Output, Append or Random respectively. F$
is the name of the file to open.
Chapter 17. I/O Instructions 60
-----------------------------------------------------------
17.32 OPENCOM
Data Stack: Baud Parity Stop Size Port --
String Stack: --
Initializes the serial port. Use settings from the following
tables.
Baud Parity
Value Description Value Description
------------------ ------------------
0 110 baud 0 None
1 150 baud 1 Odd
2 300 baud 3 Even
3 600 baud
4 1200 baud
5 2400 baud
6 4800 baud
7 9600 baud
Stop may be 1 or 2, Port may be 1 or 2, Size may be either 7 or 8
bits.
-----------------------------------------------------------
17.33 OUTPORT
Data Stack: Byte Port --
String Stack: --
Sends a Byte out to a port. Port should be in the range 0 to 255.
-----------------------------------------------------------
17.34 PEEK
Data Stack: Addr -- Byte
String Stack: --
Places the contents of Addr on the data stack. Addr is an address
in the current segment. To change the current segment, use DEFSEG.
-----------------------------------------------------------
Chapter 17. I/O Instructions 61
17.35 POKE
Data Stack: Addr Byte --
String Stack: --
Pokes Byte into Addr. Addr is an address in the current segment.
To change the current segment, use DEFSEG.
-----------------------------------------------------------
17.36 PRINT
Data Stack: n --
String Stack: --
Prints the number n on the current output device.
-----------------------------------------------------------
17.37 PRINTCHR
Data Stack: c --
String Stack: --
Prints the character whose ASCII code is c on the current output
device.
-----------------------------------------------------------
17.38 PRINTER
Data Stack: -- 3
String Stack: --
Places the constant 3 on the data stack. The PRINTER instruction
is used for clarity. For example, the sequence PRINTER ISOUTPUT is
much clearer than 3 ISOUTPUT.
-----------------------------------------------------------
Chapter 17. I/O Instructions 62
17.39 PRINT$
Data Stack: --
String Stack: a$ --
Prints the string a$ on the current output device.
-----------------------------------------------------------
17.40 PUTBYTE
Data Stack: B F --
String Stack: --
Outputs byte B to file F.
-----------------------------------------------------------
17.41 PUTPORT
Data Stack: Byte ComPort --
String Stack: --
Sends a Byte to ComPort 1 or 2
-----------------------------------------------------------
17.42 ROW
Data Stack: -- row
String Stack: --
Places the row of the current cursor position on the data stack.
-----------------------------------------------------------
17.43 SETVOL
Data Stack: Vol --
String Stack: --
Sets the sound volume on an HP100LX. Vol may vary from 0 (silent)
to 3 (loudest).
HP only.
Chapter 17. I/O Instructions 63
-----------------------------------------------------------
17.44 SOUND
Data Stack: freq dur --
String Stack: --
Plays a sound of a given freq and dur. Frequency is in Hertz and
duration is in Milliseconds.
-----------------------------------------------------------
17.45 VARPTR
Data Stack: V -- A
String Stack: --
Places the address of a variable onto the data stack. This may be
used to PEEK and POKE values directly into a variable.
-----------------------------------------------------------
17.46 |
Data Stack: --
String Stack: --
Prints the rest of the current line out to the current output
device.
-----------------------------------------------------------
Chapter 18
Math Instructions
18.1 ABS
Data Stack: n -- N
String Stack: --
Replaces the top value on the data stack with its absolute value.
-----------------------------------------------------------
18.2 MAX
Data Stack: A B -- MAX
String Stack: --
Places the greater of A or B on the data stack.
-----------------------------------------------------------
18.3 MIN
Data Stack: A B -- MIN
String Stack: --
Places the lesser of A or B on the data stack.
-----------------------------------------------------------
64
Chapter 18. Math Instructions 65
18.4 MOD
Data Stack: A B -- C
String Stack: --
Returns A modulo B.
-----------------------------------------------------------
18.5 *
Data Stack: A B -- C
String Stack: --
Multiplies A times B.
-----------------------------------------------------------
18.6 +
Data Stack: A B -- C
String Stack: --
Adds A and B.
-----------------------------------------------------------
18.7 -
Data Stack: A B -- C
String Stack: --
Subtracts B from A.
-----------------------------------------------------------
18.8 /
Data Stack: A B -- C
String Stack: --
Divides A by B.
-----------------------------------------------------------
Chapter 18. Math Instructions 66
18.9 <
Data Stack: A B -- C
String Stack: --
C is TRUE if A is less than B, FALSE otherwise.
-----------------------------------------------------------
18.10 =
Data Stack: A B -- C
String Stack: --
C is TRUE if A equals B, FALSE otherwise.
-----------------------------------------------------------
18.11 >
Data Stack: A B -- C
String Stack: --
C is TRUE if A is greater than B, FALSE otherwise.
-----------------------------------------------------------
Chapter 19
Miscellaneous Instructions
19.1 BIT?
Data Stack: number bit -- flag
String Stack: --
Returns true if bit is set in number.
-----------------------------------------------------------
19.2 BYE
Data Stack: n --
String Stack: --
Exits a TIPI program and returns to DOS. BYE returns the top value
from the data stack as an error level to DOS.
-----------------------------------------------------------
19.3 ERROR
Data Stack: -- n
String Stack: --
Places the number of the current error on the data stack.
-----------------------------------------------------------
67
Chapter 19. Miscellaneous Instructions 68
19.4 EVAL
Data Stack: -- ?
String Stack: I$ -- ?
Evaluates the instruction I$ from the string stack.
-----------------------------------------------------------
19.5 FALSE
Data Stack: -- 0
String Stack: --
Places the value of FALSE (0) on the top of the data stack.
-----------------------------------------------------------
19.6 MACHINE?
Data Stack: -- n
String Stack: --
Returns a number identifying the computer TIPI is running on
according to the following table.
0 = PC
1 = HP95LX
2 = HP100LX
-----------------------------------------------------------
19.7 NOT
Data Stack: n -- m
String Stack: --
Negates the truth value of a flag. If n is non-zero, m is zero.
If n is zero, m is one.
-----------------------------------------------------------
Chapter 19. Miscellaneous Instructions 69
19.8 OFF
Data Stack: --
String Stack: --
Shuts off an HP palmtop computer. OFF has no effect on a PC.
-----------------------------------------------------------
19.9 RANDOM
Data Stack: N -- R
String Stack: --
Replaces N on the data stack with R, a random integer selected from
the range 1 to N (inclusive).
-----------------------------------------------------------
19.10 RANDOMIZE
Data Stack: --
String Stack: --
Initializes the random number generator.
-----------------------------------------------------------
19.11 TICKS
Data Stack: -- t
String Stack: --
Places the current PC tick count on the data stack. A PC ticks
18.2 times per second.
-----------------------------------------------------------
Chapter 19. Miscellaneous Instructions 70
19.12 TIMEOUT
Data Stack: T --
String Stack: --
Controls the auto-timeout feature of the HP palmtops. If T=0,
auto-timeout is disabled. If T is in the range 1 to 65535, the
timout is set to that many ticks (a tick=55 msecs).
Notes:
1. The power-up default value for T is 3276 (3 minutes).
2. If the main batteries are low, the maximum timeout value will
be one minute.
HP only.
-----------------------------------------------------------
19.13 TRUE
Data Stack: -- 1
String Stack: --
Places the constant 1 on the top of the data stack.
-----------------------------------------------------------
19.14 VERSION
Data Stack: -- N
String Stack: --
VERSION leaves an integer N on the data stack. N is equal to the
version number times ten (ie if N is 23 then the TIPI version
number is 2.3).
-----------------------------------------------------------
Chapter 19. Miscellaneous Instructions 71
19.15 #
Data Stack: --
String Stack: --
Identifies a comment. Anything after the # on a line is ignored.
-----------------------------------------------------------
19.16 (
Data Stack: --
String Stack: --
Begins a comment.
-----------------------------------------------------------
19.17 )
Data Stack: --
String Stack: --
Ends a comment.
-----------------------------------------------------------
Chapter 20
Stack Instructions
20.1 DEPTH
Data Stack: -- N
String Stack: --
Places N on the data stack, where N is the depth of the data stack.
-----------------------------------------------------------
20.2 DEPTH$
Data Stack: -- N
String Stack: --
Places N on the data stack, where N is the depth of the string
stack.
-----------------------------------------------------------
20.3 DROP
Data Stack: N --
String Stack: --
Removes the top value from the data stack.
-----------------------------------------------------------
72
Chapter 20. Stack Instructions 73
20.4 DROP$
Data Stack: --
String Stack: A$ --
Removes the top value from the string stack.
-----------------------------------------------------------
20.5 DUP
Data Stack: N -- N N
String Stack: --
Duplicates the top value on the data stack.
-----------------------------------------------------------
20.6 DUP$
Data Stack: --
String Stack: A$ -- A$ A$
Duplicates the top value on the string stack.
-----------------------------------------------------------
20.7 OVER
Data Stack: a b -- a b a
String Stack: --
Copies the second item on the data stack to the top.
-----------------------------------------------------------
20.8 OVER$
Data Stack: --
String Stack: a$ b$ -- a$ b$ a$
Copies the second item on the string stack to the top.
-----------------------------------------------------------
Chapter 20. Stack Instructions 74
20.9 PICK
Data Stack: n -- m
String Stack: --
Places a copy of the data stack's nth item on the top of the data
stack.
-----------------------------------------------------------
20.10 PICK$
Data Stack: n --
String Stack: -- m$
Places a copy of the string stack's nth item on the top of the
string stack.
-----------------------------------------------------------
20.11 POP
Data Stack: -- n
String Stack: --
Pops a value off the return stack.
-----------------------------------------------------------
20.12 PUSH
Data Stack: n --
String Stack: --
Pushes a value to the return stack.
-----------------------------------------------------------
Chapter 20. Stack Instructions 75
20.13 ROT
Data Stack: a b c -- b c a
String Stack: --
Rotates the top three values on the data stack.
-----------------------------------------------------------
20.14 ROT$
Data Stack: --
String Stack: a$ b$ c$ -- b$ c$ a$
Rotates the top three values on the string stack.
-----------------------------------------------------------
20.15 SWAP
Data Stack: a b -- b a
String Stack: --
Swaps the top two values on the data stack.
-----------------------------------------------------------
20.16 SWAP$
Data Stack: --
String Stack: a$ b$ -- b$ a$
Swaps the top two values on the string stack.
-----------------------------------------------------------
Chapter 21
String Instructions
21.1 ASC
Data Stack: -- N
String Stack: A$ -- A$
Places a number N on the data stack, where N is the ASCII value of
the first character of the string on the top of the string stack.
-----------------------------------------------------------
21.2 CHR$
Data Stack: N --
String Stack: -- M$
CHR$ converts an integer N from the data stack to an ASCII
character and places the single character string on the top of the
string stack.
-----------------------------------------------------------
21.3 DATE$
Data Stack: --
String Stack: -- D$
Places the current date on the string stack in the form
"MM-DD-YYYY"
-----------------------------------------------------------
76
Chapter 21. String Instructions 77
21.4 INSTR
Data Stack: -- n
String Stack: a$ b$ -- a$ b$
Searches a$ for the first occurrence of b$. If b$ is in a$, n is
the location where b$ starts in a$. If b$ is not in a$, n is zero.
-----------------------------------------------------------
21.5 LCASE$
Data Stack: --
String Stack: A$ -- a$
Converts any uppercase characters in A$ to lowercase.
-----------------------------------------------------------
21.6 LEFT$
Data Stack: n --
String Stack: a$ -- l$
Returns a string consisting of the n leftmost characters of a$.
For example, "This is a test" 7 LEFT$ would return "This is".
-----------------------------------------------------------
21.7 LEN
Data Stack: -- len
String Stack: a$ -- a$
Places the length of a$ on the data stack.
-----------------------------------------------------------
Chapter 21. String Instructions 78
21.8 LTRIM$
Data Stack: --
String Stack: a$ -- b$
Trims any leading blanks from a$.
-----------------------------------------------------------
21.9 MID$
Data Stack: st len --
String Stack: a$ -- b$
Returns b$, a string of len characters starting at position st from
a$.
-----------------------------------------------------------
21.10 PARSE$
Data Stack: --
String Stack: text$ -- newtext$ word$
Parses the first word from text$.
-----------------------------------------------------------
21.11 REPLACE$
Data Stack: --
String Stack: text$ old$ new$ -- newtext$
Replaces any occurrences of old$ in text$ with new$.
-----------------------------------------------------------
21.12 RIGHT$
Data Stack: n --
String Stack: a$ -- b$
Returns a string consisting of the n rightmost characters of a$.
For example, "This is a test" 6 RIGHT$ would return "a test".
Chapter 21. String Instructions 79
-----------------------------------------------------------
21.13 RTRIM$
Data Stack: --
String Stack: a$ -- b$
Removes any trailing blanks from a$.
-----------------------------------------------------------
21.14 STR$
Data Stack: n --
String Stack: -- n$
Converts an integer from the data stack to a string. For example,
123 STR$ would place the string "123" on the string stack.
-----------------------------------------------------------
21.15 TIME$
Data Stack: --
String Stack: -- t$
Places the current time (in the form "HH:MM:SS") on the string
stack.
-----------------------------------------------------------
21.16 UCASE$
Data Stack: --
String Stack: a$ -- A$
Converts any lowercase letters in a$ to uppercase.
-----------------------------------------------------------
Chapter 21. String Instructions 80
21.17 VAL
Data Stack: -- n
String Stack: s$ --
Converts a string to a number.
-----------------------------------------------------------
21.18 "
Data Stack: --
String Stack: --
Begins and ends a text string.
-----------------------------------------------------------
21.19 +$
Data Stack: --
String Stack: a$ b$ -- c$
Combines a$ and b$ into one string.
-----------------------------------------------------------
21.20 =$
Data Stack: -- C
String Stack: A$ B$ --
C is TRUE if A$ equals B$, FALSE otherwise.
-----------------------------------------------------------
Index of TIPI Instructions 81
", 80 DUP, 73
#, 71 DUP$, 73
(, 71 ELSE, 32
), 71 ENDCASE, 33
*, 65 ENDCASE$, 33
+, 65 ENDDEF, 42
+$, 80 ENDIF, 33
-, 65 ENDOF, 33
/, 65 ENDOF$, 33
<, 66 ENDTABLE, 42
=, 66 ENV$, 44
=$, 80 EOF, 56
>, 66 ERROR, 67
|, 63 EVAL, 68
ABS, 64 EXTENDED, 56
ASC, 76 FALSE, 68
BEEP, 52 FETCH, 37
BEGIN, 31 FILEPOS, 56
BIT?, 67 FIRSTFILE, 44
BLOAD, 52 GET$, 57
BSAVE, 52 GETBYTE, 56
BYE, 67 GETDIR, 44
CALL, 43 GETFONT, 46
CASE, 31 GETNUM, 57
CASE$, 31 GETPOINT, 47
CHDIR, 43 GETPORT, 57
CHR$, 76 GETVOL, 57
CLOSE, 53 IF, 34
CLS, 53 INDEX, 34
COLOR, 53 INKEY$, 58
COLOR?, 53 INPORT, 58
COLUMN, 54 INSTR, 77
COMMAND$, 43 ISINPUT, 58
COMSTAT, 54 ISOUTPUT, 58
CONSOLE, 54 KEY, 59
CR, 55 KILL, 44
CURRENT, 55 LCASE$, 77
CURSOR, 55 LEAVE, 34
DATE$, 76 LEFT$, 77
DEFARRAY, 40 LEN, 77
DEFAULT, 32 LF, 59
DEFAULT$, 32 LOCATE, 59
DEFINE, 40 LOOP, 34
DEFSEG, 55 LTRIM$, 78
DEFSTR, 41 MACHINE?, 68
DEFSTRARRAY, 41 MAKEDIR, 45
DEFTABLE, 41 MAX, 64
DEFVAR, 42 MID$, 78
DEPTH, 72 MIN, 64
DEPTH$, 72 MOD, 65
DO, 32 MOUSE, 59
DRAWLINE, 46 MOVEPEN, 47
DRAWRECT, 46 NEXTFILE, 45
DROP, 72 NOT, 68
DROP$, 73 OF, 35
Index of TIPI Instructions 82
OF$, 35 TRACEVAR, 39
OFF, 69 TRUE, 70
OPEN, 59 UCASE$, 79
OPENCOM, 60 UNTIL, 35
OUTPORT, 60 VAL, 80
OVER, 73 VARPTR, 63
OVER$, 73 VERSION, 70
PARSE$, 78 WEND, 35
PEEK, 60 WHILE, 36
PICK, 74 ZOOM, 51
PICK$, 74
PLOTICON, 47
PLOTPOINT, 48
PLOTTEXT, 48
POKE, 61
POP, 74
PRINT, 61
PRINT$, 62
PRINTCHR, 61
PRINTER, 61
PUSH, 74
PUTBYTE, 62
PUTPORT, 62
RANDOM, 69
RANDOMIZE, 69
REMDIR, 45
RENAME, 45
REPLACE$, 78
RIGHT$, 78
ROT, 75
ROT$, 75
ROW, 62
RTRIM$, 79
SCREEN, 48
SCROLL, 49
SETCLIP, 49
SETFONT, 49
SETLINETYPE, 49
SETLOGORG, 50
SETPENCOLOR, 50
SETREPRULE, 50
SETVMODE, 51
SETVOL, 62
SOUND, 63
STORE, 37
STR$, 79
SWAP, 75
SWAP$, 75
TICKS, 69
TIME$, 79
TIMEOUT, 70
TRACECOL, 38
TRACEOFF, 38
TRACEON, 38
TRACEROW, 39