P21Forth 1.02 is a direct threaded Forth. This means that all the executable words in the dictionary must begin with executable MuP21 instructions. High level defintions created with (colon) or other defining words will be a : list of address of other words. In a direct threaded Forth high level definitions begin with machine code and then are a list of addresses. Defining the word NEWWORD in the following way,
: NEWWORD WORD1 WORD2 WORD3 ;Would create a new executable word called NEWWORD that would contain a list of the addresses of the words WORD1, WORD2, and WORD3. Executing the new NEWWORD word would now have the same effect as executing WORD1 then WORD2 then WORD3.
Low level words are executable words that are written in the assembler of the machine. The Forth word CODE will create a new word written in the MuP21 assembler. These words are written in the Forth assembly language of the MuP21. This is detailed in Chapter 9 on the P21Forth Assembler. Words written in the assembler may be used just like words written in the high level Forth, but they will be much faster.
P21Forth only uses 16 kilowords of memory for the OK operating system code and the initial name and code dictionaries.
1 Megaword DRAM Memory Map FFFFF Top of DRAM - NAMES F0000 | E0000 V D0000 C0000 Disk Block Buffers AAAAA Video Buffer 1 9AAAA Video Buffer 2 90000 80000 70000 60000 50000 40000 30000 ^ 20000 | 10000 Code | 00000 P21Forth bottom 16KThe Forth word UNUSED will place the amount of free memory between the top of the code dictionary (growing upward) and the start of the video buffer, and between the bottom of the name dictionary (growning downward) and the top of the disk block buffers and place this number on the stack. P21Forth 1.02 will initially report over 877055 words of free memory.
Lower 16 Kiloword DRAM Memory Map 4000 reset top of CODE dictionary at boot 3F00 Terminal Input Buffer 3F00 Start of Name dictionary 2E10 bottom of initial Name dictionary 2882 top of initial CODE dictionary / / 880 Start of CODE dictionary 840 Return Stack (builds up) 83A User Variables 6 800 Data Stack (builds up) 600 Character table in OK OS 000 DRAM boot code in OK, OK OSThe MuP21 has a 21 bit addressing space. It addresses 1 megaword of 20 bit DRAM memory in locations 00000-FFFFF. If the carry bit is set on MuP21 in a memory addressing register the MuP21 will address one of several SRAM spaces or the I/O address space. The only address space directly available to the P21Forth is the one megaword DRAM space. P21Forth provides words to access the SRAM and I/O port address space. Internally these words set the carry bit, but P21Forth only represents numbers from 0 to FFFFF, so it is not possible to address the SRAM memory on MuP21 directly in P21Forth.
CODE-address, LINK-address, Count, char1, char2, ... , Lex
The CODE-address contains the address of the executable code or data address in the CODE dictionary. The LINK-address contains the address of the Count cell in the next entry in the NAME dictionary. The Count cell contains a number with the length of the name that follows in char1, char2, ... Finally Lex contains lexical information about this word such as if it is IMMEDIATE or COMPILE-ONLY.
P21Forth 1.02 has many words that are written in high level Colon definitions that would perform much faster if written in CODE. Some of the CODE words are functional, but could be rewritten to run much faster. The graphics bit block transfer words for instance only transfer one cell between memory and video display on each inner loop. If these words were to transfer four cells on each inner loop they would be about four times faster. At the present time GPUT will transfer about 20 full screen graphics per second, it could be optimized to run about four times that fast.