Histogram
A histogram is essential to examine random numbers. Or generally, noisy numbers, such as come from a/d conversion. The numbers are binned; the number of occurrences in each bin counted and displayed. In this case, there are 256 bins.
Memory
Of course, there must be 256 words of memory to store the counts. With the Eval board, this could be external RAM. But here's a chance to use neighbors' memory, in this case using 5 nodes (509, 510, 511, 512 and 513). The first 4 can store 51 words, the remaining 13 being used for code. The last can store 56, for a total of 260.
go
An infinite loop. The histogram node (609) talks to the first memory node (509).
- It expects an address and an instruction word
- If the address is less than 51, the node executes the instructions (a push ex)
- Otherwise it sends the address, less 51, and the instruction to the next memory node (510)
- Eventually a node will execute the instructions
- One of the instructions returns a word. Forwarding nodes must relay this (@b !)
There are 3 instructions
- Read word
- Set word to 0
- Increment word
Reading is slow, since the number must ripple back. But, in the case of a histogram, you only read one word per scan line.
The others are fast, since several instructions can be rippling through the nodes at the same time.
The last memory node does not need 5 words of forwarding code. So it can start using memory at that point (3d) and wrapping from 3f to 0.
1+
This code, at address 51, will be executed to increment a bin
- 1 has been copied on the stack
- The address is in register b
Histogram
Drawing the histogram uses run-length video.
go
An infinite loop
- An initialize loop to clear bins
- Sends loop index as address
- 1 will be on the stack of the target node
- And the address in register b
- So dup 2/ b! ; are the instructions it should execute
- 2699 repetitions let the histogram grow 'till it fills the screen, then resets.
- The display loop repeats 256 times, thickening a dot for 768 scan lines
- Again it sends loop index as address
- The instructions are to read and return a word (@b ! ;)
- Repeat dot 3 times
- Finally, a loop to update the histogram during vertical retrace
- Random numbers are read from left (610). This node presents a number, then computes another
- The number (which was masked to 255) is sent as address
- The instructions are dup 1+ ; Where dup copies the 1 on the target nodes's stack and 1+ ; is a jump to code that will complete the increment
- The dups sent to memory identify instructions that don't return a value
init
It's convenient to load node 610 before 609. Yet 610 would start sending numbers before 609 is ready. So 610 waits for a number from 609, which obliges with !.
610 executes a @b from the loading port during init. This code @b go must be in the same word so that loading can complete while 610 is waiting.