Wednesday, May 8, 2024

MSP430 Development on Linux

For the last few years, I've moved as many of my programming projects as possible from Windows to Linux. This includes PIC32 programming as explained in MIPS Development on Linux. My most recent MSP430 projects like the Electronic Birthday Card, Kitty Salon, and some Christmas tree ornaments for this past Christmas were programmed entirely on Linux. On the other hand, my Tiny Calculator project, which started in 2018, is compiled with IAR Embedded Workbench running on Windows. Since returning to the Tiny Calculator is one of my goals for the coming year, I spent some time improving my MSP430 setup on Linux.

Saturday, March 9, 2024

Calculator Keypads

As described in my 2023 goals post, my plan for the year was to finish enough projects to give a presentation at the 2023 Hewlett-Packard Handheld Conference (HHC). Even though I didn't finish everything on my list, there were still enough interesting things to give a presentation on including my Blinky Robot and 6507 Calculator Forth Virtual Machine. The largest part of the presentation was about building calculator keypads.

While building a circuit board or writing the firmware for a calculator are achievable goals for a hobbyist or amateur, building a keypad tends to be much more challenging. The keys themselves can be made on a 3D printer, but getting good quality labels on the keys is very difficult. Since none of my calculator projects so far have had really good keypads, I decided to try every method available for making keys to compare the results.

3D Model
The 3D model for the test consists of eight rows of five keys each designed in OpenSCAD for my still unfinished 6507 Graphing Calculator. OpenSCAD has been my go-to program for modeling since I started with 3D printing a few years ago. The biggest advantage of this program is that the entire model is specified by a script so nothing needs to be manipulated or placed by hand. This works well for people like me who don't have a lot of artistic talent but feel comfortable with programming. It's cheap and relatively quick to print out a set of these keys on my Ender 3.


Sunday, December 31, 2023

IRC Forth Chatbot

After putting in a lot of work on the 2023 Project Goals for my presentation at HHC 2023, I decided to take a break and work on a few other things for a while. One of those things is a chatbot that connects to IRC and runs Forth code it receives from users. My inspiration for this is the geordi bot which evaluates C code and also runs on IRC. Testing short programs and showing the results immediately is really useful to demonstrate language concepts. Although my Forth chatbot was a really fun project to work on and taught me a lot about several different technologies, I decided not to finish it in the end.

The chatbot is split into two parts. The main program is a Python script that connects to IRC, handles communication, and runs the terminal interface that manages the bot. The second part is a shared library written in C that the Python script loads and calls into to run the Forth code submitted by users. The library is written in C to maximize performance.

Sunday, January 29, 2023

6507 Graphing Calculator: Forth Virtual Machine

As my last post explains, my goal for 2023 is to finish enough projects to give a presentation at HHC 2023. One of the biggest jobs will be finishing the 6507 Graphing Calculator I've been working on the past few years. The latest stage of the project was rewriting part of the firmware in Forth to save space, which turned out to be a failure.

When I last worked on this project, the firmware had reached 9.3K which well exceeds the calculator's 8K EEPROM. This wasn't so concerning since it seemed plausible at the time to implement a tiny Forth core and shrink the firmware by rewriting parts of it in Forth. Also, some parts of the existing firmware, which is all written in assembly, could be improved to save space. With this plan in mind, I started implementing a preprocessor in Python that scans all of the project's assembly files for Forth code and converts it into bytes to embed in the assembly source code. The Forth core uses token threading so each Forth word in the source produces just one byte rather than two as in direct and indirect threading or three with subroutine threading. The Forth system is initiated with a BRK instruction which jumps to the software interrupt handler and begins interpreting the bytes following the BRK. This saves two bytes for every invocation of the Forth system over using JMP or JSR. One of the tokens in the Forth system is assigned the same number as the BRK op code and increments a counter when executed. A corresponding token at the end of each function decrements the counter and switches from Forth back to assembly when the counter reaches zero. With this setup, the program can jump from assembly or Forth to a function written in Forth and continue executing seamlessly. 

Sunday, December 25, 2022

2023 Project Goals

2022 was another year full of all kinds of fun projects like my 7400 Logic Calculator plan, Interactive 6502 Assembler, and embedded programming on Linux. Although these weren't on my list of 2022 Project Goals list, I did learn a lot from them and make progress towards some of the goals on the list. With 2022 coming to a close, it's time to take stock of my progress from 2022 and set some goals for 2023.

2022 Project Goals

6507 Graphing Calculator - Still working
Despite another year of work on this project, there is still a lot of work left to finish it. The plan to reduce the firmware size to fit into an 8K ROM by using a Forth VM didn't work out as expected. After a little more work, I plan to post about my progress on this from 2022 and how the project will proceed in the future.

This is the one project from the list that is completely finished. It even made it onto Hackaday yesterday! As mentioned in the article, what I learned from this project will be useful for other projects like the PIC32 Calculator below.

Tiny Calculator - No progress
Not much to say here. There just wasn't enough time to get to this one.

PIC32 Calculator - Still working
Although I haven't started on this project formally yet, a lot of my projects from 2022 will help me work on this one. As mentioned in the last project goals post, this shouldn't take as long as other calculators since it won't be necessary to write all the firmware from scratch.


2023 Project Goals
This year, my goal is to finish enough projects to give a presentation at the Hewlett-Packard Handheld Conference (HHC) in fall 2023 like my presentations at HHC 2019 and HHC 2021. This will take a lot of focus which I wasn't able to pull off last year. Hopefully, having a firm date and goal in mind will motivate me. Here is the tentative list of topics:

Although not a calculator, this should be really interesting to present on since the 6502 emulator written in MIPS assembly can be used to emulate 6502 calculator firmware on a PIC32. This is a good one to start with since this project is already finished.

As mentioned above, there is still a lot of work left to do for this though I know exactly how to proceed from here. Barring any unforeseen complications, this should be a straightforward project to finish. This will be one of the main topics of the presentation.

Calculator key comparison
This is another topic where I made a lot of progress in the last year but haven't posted anything yet. My goal is to compare many different ways of making calculator keys using 3D printing, laser cutting, cast plastic and other methods.

PIC32 Calculator
This is the same project from my list last year. This will be the most exciting thing to present on if it's ready in time. 
 

Monday, December 19, 2022

PIC32/6502 Blinky Robot

The PIC32 robot from my 2022 Project Goals is finally finished! Building it was a fun way to learn about the MIPS architecture and programming the PIC32. It was also a chance to work on a 6502 emulator that will be useful for other projects.

As far as robots go, this is not a very useful one since all it does is blink its eyes every few seconds. The interesting part is how it does the blinking. Rather than switching the LEDs on then delaying a while before switching them off, the robot runs several layers of emulation with the innermost emulated system blinking the LEDs as fast as possible. All the layers of emulators within emulators combine to produce enough overhead to slow the blinking down to a rate that is visible.

Sunday, December 11, 2022

Tali Forth 2 on Linux

When people on IRC have questions about Forth or I can't remember how a particular word works, it's nice to have a Forth handy to try things out on. For this, I usually open Tali Forth 2 in a browser window on my website. Even though it's a 6502 Forth running in a JavaScript 6502 emulator rather than a native x86 Forth like Gforth, it works just fine for experimenting. Since most of my programming is on Linux now, it seemed like a good idea to have a way to do my tests in a terminal.

There were several choices for getting Tali Forth 2 running on Linux. One of the easiest ways is to use an existing emulator like Py65 since Tali Forth 2 comes with a pre-compiled binary ready to be emulated. However, this was less interesting than using one of my own emulators. Another option was the JavaScript 6502 emulator running on my website. As mentioned in the post about my 6507 calculator, this also runs in a terminal thanks to node.js. Another option was to extract the emulation engine from my 6502 Interactive Assembler, although it seemed this would be time consuming to untangle since the emulator was not designed to work without the assembler. In the end, it was the most convenient to use the 6502 emulator written in MIPS assembly I've been working on for another project using the tools mentioned in my post about MIPS development in Linux. As mentioned in that post, a binary compiled for MIPS will run right from the Ubuntu command line as if it were native thanks to QEMU and also have access to the terminal through Linux syscalls. Going with this emulator was also an opportunity to double check my MIPS code emulates the 6502 correctly.