Monday, November 14, 2011

A Couple Of Cheat Sheets

I have reduced my tutorials on the Green Arrays Editor and the the Green Arrays Simulator to a couple of one pagers. I'm going to post them here for quick reference. Copy and paste to suit.

====
EDITOR


Bring up colorFORTH

“200 edit <cr>” - now editing page 200.

Move the cursor - “J” “K” “L” and “;” keys. If you get too far
lost hit the and you are out of the editor

Exit program “bye”

To continue where you left off type "e" <cr>. Back editing the screen.

Use the “N” key to delete a word at a time.

Pick a color (see chart below) and type in the word you want to add. <cr> and the word is added. You can now add another word. will erase a word if you typed it incorrectly. When you are done typing words of that color hit <spacebar> and you are back in the editor. You can now erase any wrongly entered words or if you need to change a word's color by using the cursor and “A” key.

“F1” key to toggles between decimal and hexidecimal entry modes.

"save" when you are all done and out of the editor.

Color Words:

White - “R” - comment
Yellow - “U” - interpreted words
Red - “I” - define Forth word
Green - “O” - compiled words and numbers
Blue - “X” - display macro (mostly text formatting for now)
Magenta - “,” - variable
Grey - “Z” - compiler feedback
Cyan - “.” - compiled macro call

====

SIMULATOR


Chart in Section 7.5 on Page 31 of the DB004 document.

Type “so <cr>”. Simulator and its control panel.
“F” key to single step
Change focus “M” key.
Back to beginning “A” key.

Leave simulator - <spacebar>

Step/stop - “F”
Fast/slow - “S”
Go continuously - “D”
Back to beginning - “A”

Increase step size +1 - “V”
Decrease step size -1 - “C”
Increase step size +100 - “R”
Decrease step size -100 - “E”

Swap focus (yellow and red cores in the display) - “M”
Scroll through focus core's memory, increasing - “,”
Scroll through focus core's memory, decreasing - “.”
Display alternate core's memory or active core display - “/”

Display sizing
Taller - “Q”
Wider - “W”
Shorter - “Z”
Narrower - “X”

Select focus node. Use the “M” key to move the other node.

Left move - “J”
Right move - “;”
Up move - “K”
Down move - “L”

To move the block of displayed cores around

Left move - “U”
Right move - “P”
Up move - “I”
Down move - “O”

====

Hope that helps.

A 54 Bit Counter

I have a need for a 54 bit counter for a project I'm planning. I need to count an accurate clock without any overflows. Now I admit that at my designed 4.8 MHZ the clock will overflow in 100+ years. If the device is never turned off. Power outages alone ought to reset it oftener than that. What is the device I'm designing? Stay tuned.

Here is a screenshot of the program.


I'm going to go through it line by line using "old" Forth notation where ":" means start a subroutine and ";" means Return (it also means Return in colorForth). In my notation scheme "\\" is the start of a comment. All numbers beginning with an "0x" are hexidecimal. Otherwise they are decimal. This is to make up for the lack of color in normal text display. Since this is for novices I'm going to explain everything on a word by word basis (mostly).

Update: 16 Nov 2011 1822z

The terminology I used below (TOS and NOS for Top Of Stack and Next On Stack) is not in use by GreenArrrays. They are old Forth terms. Green Arrays uses "T" for Top and "S" for Second.

It should also be noted that @p increments the program counter immediately but the program does not go to the next address in the Program Counter until all the slots in a word have executed. Thus you can have constructs in one word such as "@P @P @p ." which is three literals in a row. When executed it puts 3 literals on the stack and increments the program counter three times.

===
user f18 code   // a comment

reclaim         // free up previously used words in the
                // non-core dictionary

100 node 0 org  // the code loads in node 100 at location 0

: zero          // this is a place holder for the compiler
                // no code is compiled

0x0d org        // this is where the counter gets placed
                // it uses 3 locations (54 bits) 

: new-count     // a place holder

0 , 0 , 0 ,     // notice that the yellow color indicates we 
                // are in the interpreter the "," means put 
                // what is on the stack, "0" in this case,
                // at the current location

0x1a org        // old count goes here

: old-count     // a place holder

0 , 0 , 0 ,     // notice that the yellow color indicates we 
                // are in the interpreter the "," means put 
                // what is on the stack, "0" in this case,
                // at the current location

0x1 org +cy     // load at location 1,  +cy translates the 
                // location so that the carry bit is used

: inc-counter   // this subroutine will increment the counter 
                // every time it is called

@p              // fetch word at program counter +1, put it on 
                // the top of the stack (TOS), skip over the 
                // word to execute the next instruction

a!              // put the TOS in "a" register

..              // go to next word with no-ops - as many as 
                // needed

'               // in the interpreter (host) find the target 
                // address of the following subroutine and 
                // put it on the interpreter stack 

new-count       // word to find in the target address space

,               // put the host TOS in the next available 
                // target address 

clc             // clear carry - routine located in the ROM

@               // fetch to the TOS via "a" which now has the 
                // address of new-count in it  - which is to 
                // say get the low order of the count

0x20000         // we are going to add this to the count.
                // normally this number would be 1 but we 
                // want to see carry propagating for testing 
                // purposes. We also could have initialized 
                // the counter to different values for testing

.               // nop - this delay allows the add to 
                // complete before the result is needed 

+               // add the TOS (increment value) to the next 
                // on stack (NOS) (previous counter low order 
                // value)

!+              // store TOS (incremented value) at "a" and 
                // increment "a" 

0x0             // put a zero on top of the stack 

dup             // push the TOS into the NOS, TOS is unchanged

@               // fetch using the "a" register as a pointer

.               // wait to help + complete in time

+               // add the counter middle value to the 0 on 
                // the stack which is to say – propagate the 
                // carry

!+              // save it to address pointed to by "a" (back 
                // where it came from)

@               // fetch using the "a" register as a pointer

.               // wait to help + complete in time

+               // add the counter top value to the 0 on the
                // stack which is to say – propagate the carry

!               // save it to address pointed to by "a" (back 
                // where it came from) do not increment "a" 

zero ;          // this is how you force a jump – a call 
                // followed by a return  - as far as the 
                // compiler knows "zero" is located at 0x0 
                // this will force a jump to 0x0

-cy             // we don't care about the carry anymore

0x0 org         // the next word goes here

: beginner      // we are starting a new word at location 0x0

inc-counter ;   // this jumps to inc-counter

reclaim         // the subroutines created are specific to 
                // this module (local)

After you have entered the program "save" it. Don't forget that Screen 148 must point to "100". Now you can start the simulator

Update: 14 Nov 2011 1731z

I corrected a discrepancy between the screen shot and the listing below it. The screen shot was wrong ("+" missing), The correct screen is now in place. Thanks to commenter forther.

Sunday, November 13, 2011

Getting GA Notices In Real Time

You can get GreenArray Updates by signing up for the RSS feed at GreenArraysTech blog. The link is on the sidebar under Log In. There are several different options for getting feeds sent to you. Since I already get a number of Google Alerts I chose the Google option. I did have to get a Gmail account. That may have only taken a few seconds because I already have a Blogger account. You can also use Yahoo or Bloglines. I also spent a few minutes getting my Gmail routed to my Yahoo account (why is this starting to sound like phone phreaking?).

Saturday, October 15, 2011

Stimulating Simulating

Now that you have learned to edit and have edited Screens 148 and 200 it is time to simulate the code - six NOPs and a jump back to the start. I have done just a "jump to start" program (the hardware guy's minimum standard. A favorite for the Z-80 set.) but then there would be nothing to see. So let us simulate.

Print out the chart in Section 7.5 on Page 31 of the DB004 document. It will help you understand what the simulator is doing.

Type in “so <cr>”. That will bring up the simulator and its control panel. Use the “F” key to single step through the program. Well OK. Node 100 is not the main focus. You can change that by using the “M” key. And change it back with the same key. You are now well into the program and you would probably like to see it from the start. That is what the “A” key is for. Now you can start “F”ing from the beginning.

That is all you need to get you started running programs in the simulator. There are some other commands that will interest you if you want to go deeper. You can try them out on this simple program without getting into much trouble. When you are done the spacebar will get you out of the simulator.

Leave simulator - <spacebar>

Step/stop - “F”
Fast/slow - “S”
Go continuously - “D”
Back to beginning - “A”

Increase step size +1 - “V”
Decrease step size -1 - “C”
Increase step size +100 - “R”
Decrease step size -100 - “E”

Swap focus (yellow and red cores in the display) - “M”
Scroll through focus core's memory, increasing - “,”
Scroll through focus core's memory, decreasing - “.”
Display alternate core's memory or active core display - “/”

Display sizing
Taller - “Q”
Wider - “W”
Shorter - “Z”
Narrower - “X”

Select focus node. Use the “M” key to move the other node.

Left move - “J”
Right move - “;”
Up move - “K”
Down move - “L”

To move the block of displayed cores around

Left move - “U”
Right move - “P”
Up move - “I”
Down move - “O”