Sunday, June 02, 2013

Extensions to SIMPL

In the last week I have been thinking about the user interfaces used on minicomputers of the 1960s, in particular the PDP-8, and wondering if a similar front LED and switch panel could be created cheaply as a nostalgic retro accessory shield for the Arduino.

I have added some LEDs to the 12 available digital I/O pins of the Arduino, so that I can recreate LED chaser and "vintage computer" style displays.

I've extended the SIMPL command set so that I can more easily address each LED in turn, or alternatively treat all twelve as a binary numerical display, to display address or data numbers in the range 0 to 4096.

The latest version of SIMPL can be found here on Github Gist:

https://gist.github.com/anonymous/facc9a262c0778aec7b6

Just download the Gist and compile it as an Arduino sketch.  You can then start typing SIMPL commands using the serial monitor window at 115200 baud. Make sure that you have selected the "Both NL and CR" option for the serial monitor.

Output Commands

In order to gain more immediate access to the I/O, I have added some new commands:

a   - sends an analog.Write value to a pin previously named with d
b   - prints out the current value of the milliseconds counter, allowing loop timing to be calculated
c   - prints out the current value of the microseconds counter

h   - sets a digital pin high    eg  6h
l    - sets a digital pin low     eg 13l
n   - decodes a number up to 4095 and displays it on digital pins 2 to 13     eg  1234n

n can be thought of as a very simple binary display.  It has a fast response time and allows the user a simple visible means of checking that a program is executing.

The n command can be useful to examine the characters stored in RAM.  Here it is used to output 1000 characters to the LEDs, starting at RAM address 256.  The characters are sent every 100mS and also printed to the terminal.

255!1000{y@rn100m}

255!    Store 255in y as the starting RAM address
1000{  Perform the loop 1000 times
y         Increment y each time around the loop
@        Move y into x
r          read the contents of RAM into x
n         Send the value to the LED display
100m   100mS delay to slow things down to a sensible speed
}         End of the loop

Decision Making

SIMPL currently lacks the if, then, else decision making, or the switch case structure. This would be a useful addition and I am currently working on some ways of implementing it.

It might be possible to test the x value against certain constants and then execute one of the upper case routines if the test was equal.

Other SIMPL Commands

SIMPL instructions are a mix of lower case ASCII characters, symbols and punctuation marks. These are the primitives, which are interpreted in sequential order by a simple interpreter.  The interpreter is an extension of Ward Cunningham's Txtzyme interpreter, which recognises the following:

a          Send an analog write (PWM) value to a pin
b          print out the current milliseconds count
c          print out the current microseconds count
d          define a digital port pin
e
f
g
h          set pin high
i           read an input
j          skip next instruction
k          access the loop counter
l           set pin low
m         define a delay in milliseconds
n          display a number on a line of LEDs
o          set an output
p          print the x variable to the terminal
q         query a block of RAM locations ( as character)
r          read from RAM
s          read an analogue input
t
u          define a delay in microseconds
v
w         write to RAM
x          increment x
y          increment y (as used in incrementing loop structures)



{}       loop the code contained within the braces

@       copy y to x
!         store x in y
?        Dump the contents of RAM to show the existing words

+
-
*
/
<
>


Numbers can be typed in the range  0 to 65535 and are stored in the x variable and used to control the above instructions.

eg.   6d            define digital port pin 6
       100m       define a delay of 100mS
       10{....}    go around a loop 10 times
       20p          Print 20 to the terminal

To these basic instructions I added a y variable, so that I could do simple maths.  You can store a number in y by using the store symbol !

      20!          Stores the value of 20 into y (by transferring it from x)

To get the contents of y back, we use the fetch symbol  @

     20!@p      Prints the value of 20 from y

We can do simple addition, subtraction, multiplication and division on x and y

     20!5+p      Adds 20 to 5 and prints result       (x=x+y)

     5!30-p      Subtracts 5 from 30 and prints result  (x=x-y)

     16!8*p     Multiplies 8 by 16 and prints result     (x = x*y)
    
     6!30/p       Divides 30 by 6 and prints result      (x=x/y)

Downloading the SIMPL sketch from Github Gist and programming it into a standard Arduino is the first step to discovering a new way to control physical computing devices.

No comments: