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.

Wednesday, December 7, 2022

MIPS Development on Linux

Two of the projects from my 2022 project goals use a PIC32 microcontroller. The company that makes them, Microchip, offers an IDE and a compiler which is a port of GCC. The free version of the compiler has some limitations which would make it difficult to finish one of my projects. However, since the PIC32 is a MIPS core, I was able to set up some tools on Linux as an alternative.

The two main limitations of the Microchip compiler are that it doesn't allow GCC's -O3 level optimizations or compile to the MIPS16e instruction set unless you pay for the full version. The loss of MIPS16e is a real bummer since it saves a lot of program memory by using 16-bit instead of 32-bit instructions like ARM's Thumb instruction set. Microchip claims that programs in this format are 40% smaller without losing much performance which would be great for one of my projects. The standard MIPS GCC has none of these limitations, but it also doesn't come with any headers or other files specific to the PIC32. This got me thinking about how I could combine the two tools and use MIPS GCC on Linux to generate part of the program. Running a few tests shows that Microchip's compiler will accept assembly files written for either the 16-bit or 32-bit instruction set, and the linker will accept object files for either instruction set too. This way, all the chip specific parts of the program like initial setup can be compiled with Microchip's compiler while the bulk of the program can be compiled externally with optimizations and linked in later.

Saturday, July 30, 2022

7400 Logic Calculator: One ROM Design

After finishing the new design for my 7400 Logic Calculator, I continued to think about different ways to build a minimal design that would fit in a calculator body. Watching James Sharman's videos about his breadboard computer got me thinking about eliminating the microcode sequencer ROM, which would save a lot of room. It eventually dawned on me that the ALU ROM could be eliminated too if it was combined with the program ROM. ALU operations then become ROM lookups and can share the same circuitry used for looking up constants which also eliminates chips. Based on this, I came up with a modified design using only 18 chips compared to the other design's 21. Best of all, the whole thing fits into just one 32K EEPROM rather than three.

Sunday, July 10, 2022

6502 Interactive Assembler

One of my 2022 Project Goals is a PIC32-based robot which emulates a 6502. While working on the emulation, I kept having to look up details about address modes and flags, so I made a Python program for Linux called i65 to look up information like the addressing mode, size, cycle count, and flags for 6502 instructions (GitHub link). It can take an instruction name or addressing mode as an argument and displays information for any instructions that match.

If the program is started without any arguments, it waits for input and shows all instructions that match what you type until it's narrowed down far enough to show the full information. The Kowalski 6502 simulator has this, and I wanted something similar for Linux.