- DIY
- A
About how I made my small microcomputer
I’m afraid to call it a microcomputer. To me, it’s more of a minimalist LISP machine. Actually, not even a LISP machine. Well, I keep saying it’s not a microcomputer
I’m afraid to call this a "microcomputer." To me, it’s more like a LISP machine on minimal settings. But it's not even really a LISP machine. Well, what can I say, "it’s not a microcomputer."
In principle, my development will do.
Well, the syntax is a bit weak... But as usual, my keyboard doesn’t allow me to do much.
Here’s a small code snippet in my LISP:
(def 01 5)
(def 02 6)
(def 03 + 01 02)
(+ 03 5 1)
The result of this code will be the number 17.
Now, let’s move on to the article (oh god, deduct points for such a long text before the cut).
Tools for developing this machine.
Well, the tools aren’t strictly necessary. But one can talk about many things. For example: sensors, modules, displays, and all that stuff.
I worked in Thonny IDE.
So, here are the development tools and more:
Thonny IDE.
4x4 matrix keyboard (it annoys me because of the number of keys).
OLED display SSD1306 128x64.
Also, what they call "Dupont Line" (but it's easier to say "wires").
Battery (BUT NOT A BATTERY CELL).
And of course – the power button.
A box from another device.
Here’s the kit for creating my LISP machine (oh no, this review turned into a tutorial).
Next: how I made a class for zero.
How I made the firmware.
Yes. I really made a class for zero (why???).
Here’s a code snippet:
class PicoLISP:
def __init__(self):
self.tokens = [(r'\(', 'reserved'), (r'\)', 'reserved'), (r'\+', 'reserved'), (r'def', 'reserved'),
(r'(0[1-9][1-6]|0[1-9])', 'id'), ('[0-9]+', 'int')]
with open('env', 'r') as fr:
self.env = eval(fr.read())
What you can notice:
AGAIN REGEX, HOW MUCH MORE (I can’t help it).
The name of my LISP: PicoLISP.
Variables are loaded from the env file.
There are few tokens, just like the commands (logically).
Now I want to defend the empty class Zero (it even has an empty __init__).
I created it so I wouldn’t always set the variables in the env file to zero. Only when the expression’s result is zero.
I created the display
and keyboard
classes for controlling the keyboard and display (to make it easier). Also, I implemented the SYSCALL(sys_call, **args) function. Why? For SYS_CLEAR, SYS_WRITE, and SYS_INPUT.
SYS_CLEAR (key parameters: display): clear the screen
SYS_WRITE (key parameters: display, text, x, y): output something
SYS_INPUT (key parameters: display, keyboard, text, x, y): ask something (a parody of scanf in C).
I won’t show the function itself. Why? Because it looks bad.
The main action happens in the run function of the PicoLISP class.
The string goes through lexing and parsing. After that, the process ends.
Basically, I don’t feel like describing 417 lines of code line by line.
The main feature is saving variables to a file.
Now, a bit of design and ideas.
To avoid looking at my creation and thinking, "how ugly it looks," I placed everything in a box and carefully glued all the advertisements on it.
I named my computer "PearComputer" (is a pear now a computer?).
On one hand, it’s a cool name, on the other hand, not so much. Oh well.
By the way! At the beginning, a rhythmic melody plays (probably).
I’m writing, but I can’t show you the appearance. So, here’s a photo of the project itself:
I hope you like it.
Conclusion.
Well, here's the project. Here are a couple of tests for you:
(def 01 5)
(01)
This code outputs 5.
(def 01 5)
(+ 01 5 5 5)
(+ 2 2 2 2)
And this one outputs 20 first, then 8.
Hope you liked it!
Have a nice day!
Write comment