( here are some notes and code for using Pygmy with ) ( the book STARTING FORTH by Leo Brodie ) ( you can load this screen to improve compatibility with ) ( STARTING FORTH & F83 if you do, you must not use I within ) ( FOR NEXT as this screen redefines it for use only by DO LOOP) FORTH : TYPE ( a # - ) ?DUP IF 1- FOR DUP C@ EMIT 1+ NEXT THEN DROP ; : (DO) ( limit index -) 2DUP - IF POP SWAP PUSH SWAP PUSH PUSH -1 ELSE 2DROP 0 THEN ; : (LOOP) ( -) POP POP POP ( limit index) 1+ 2DUP - IF PUSH PUSH 0 ELSE 2DROP -1 THEN SWAP PUSH ; : I ( - n) POP POP POP DUP SWAP PUSH SWAP PUSH SWAP PUSH ; COMPILER : DO ( -) COMPILE (DO) \ IF \ BEGIN ; : LOOP ( a -) COMPILE (LOOP) \ UNTIL \ THEN ; FORTH p. 12 & 13 STARS & CHAPTER 6 DO LOOP +LOOP instead of : STARS 0 DO STAR LOOP ; use : STARS 1- FOR STAR NEXT ; the arguments for DO are limit & starting-index and the loop counts up from starting-index to just before limit e.g. : TST1 7 0 DO I . LOOP ; would print 0 1 2 3 4 5 6 ok FOR ... NEXT only takes one argument, the starting index. It counts down from it to zero, e.g. : TST1 7 FOR I . NEXT ; would print 7 6 5 4 3 2 1 0 ok p. 25 stack underflow and overflow Pygmy does not check for stack overflow or underflow anytime another error occurs - such as typing in a word that it doesn't know - it will reset the stack and the return stack to their correct initial values. The word .S will print the top three items on the stack. This will happen no matter how many items are actually on the stack. Usually this is enough for debugging. p. 50 & p. 83 non-destructive stack print The definition given in the book : .S CR 'S S0 @ 2- DO I @ . -2 +LOOP ; will not work in Pygmy as the following words are not even present in Pygmy 'S S0 2- DO +LOOP. Of course, 2- could be replaced by 2 - However, Pygmy has a built in .S that will non-destructively print the top three items on the stack p. 52 & 53 2SWAP 2DUP 2OVER 2DROP double numbers Pygmy has 2DUP & 2DROP but does not have 2SWAP & 2OVER. Also, I have not implemented double numbers. Chapter 3 the editor To begin editing a specific screen, type n EDIT The ESC key will get you out of the editor. To get back in to the same block, just type ED without giving it a block number. Ignore all the crazy T P F I E TILL etc line editing commands. The editor in Pygmy is much easier to use. There is a short reminder menu on the top line. F3 asks for the string to search for. F1 searches again using the same string. F4 asks for the string to replace it with. F2 does the replace again. F5 will delete the line the cursor is on. F6 will join the following line to the current one. -- continued -- Chapter 3 the editor -- continued -- F7 is the "cut" command and F8 is the "paste" command. Each time you press F7 it copies the current line to the "cut" buffer and moves the cursor down to the next line. Notice that the top status line shows you the count of the number of lines in the "cut" buffer. F8 removes the oldest line from the "cut" buffer and overlays the current line and moves the cursor down to the next line. Try it out on a dummy screen to get the feel for it. Use the arrow keys to move around the screen and just over- type to make your changes, or press the INS key to change to the insert mode. The backspace key deletes one char to left and Del key deletes the current char. Inserts & deletes only apply to the current line. -- continued -- Chapter 3 the editor The PgUp and PgDn keys allow for very fast movement between screens. Press CR to split a line at the cursor and to scroll all the lower lines down. The bottom line will be lost. p. 101 ABORT" Pygmy does not have the IF built into ABORT" Instead of saying DUP 0= ABORT" error " say DUP 0= IF ABORT" error " THEN p. 123 F83's >R is equivalent to Pygmy's PUSH p. 123 F83's R> is equivalent to Pygmy's POP p. 302 F83'S [COMPILE] is equiv to Pygmy's \ that's a backslash - it does not indicate the whole line is commented out as in F83. It forces compilation rather than execution of the following "immediate" word when you are making a colon definition. It only works on words that are in COMPILER. p. 177 <# and number conversion <# does not expect a double number, just a regular 16 bit number. p. 258 TYPE is different in Pygmy. I am undecided on this. F83's TYPE ( addr count - ) Pygmy's ( addr -addr') and it expects the address to contain a count in the 1st byte. Here's a TYPE like Starting Forth expects : TYPE ( addr count - ) ?DUP IF 1- FOR DUP C@ EMIT 1+ NEXT DROP ; CHAPTER 9 internal structure In Pygmy, every definition consists of a two byte link field, a 1 to 32 byte name field, a variable length parameter field. The name field consists of a 1 byte count followed by zero to 31 characters. In a colon definition, the parameter field begins with a 3 byte jump to machine language code that nests down a level. Those 3 bytes are followed by the addresses of the words that make up the definition (2 bytes per address). In a CODE definition - machine language - the parameter field begins with the actual machine code. -- continued -- internal structure -- continued -- The following is information that you will not need unless you write CODE words: The top stack item is kept in register BX. The word must end with an "in-line" next. This is accomplished by the word NXT, Register SI is used for IP so if you want to use SI you need to save & restore it. If DI is used, it must be restored to zero PUSH, & POP, are used for both stacks, see source code examples of switching the value in registers BP & SP