MilliForth-6502, A Forth For The 6502 CPU

Forth is popular on small computers because it is simple to implement, yet quite powerful. But what happens when you really need to shrink it? Well, if your target is the 6502, there’s milliForth-6502.

This is a port of milliForth, which is a fork of sectorforth. The sectorforth project set the standard, implementing a Forth so small it could fit in a 512-byte boot sector. The milliForth project took sectorforth and made it even smaller, weighing in at only 336 bytes. However, both milliForth and sectorforth are for the x86 architecture. With milliForth-6502, [Alvaro G. S. Barcellos] wanted to see how small he could make a 6502 implementation.

So how big is the milliForth-6502 binary? Our tests indicate: 1,110 bytes. It won’t quite fit in a boot sector, but it’s pretty small!

Most of the code for milliForth-6502 is assembly code in sector-6502.s. This code is compiled using tools from the cc65 project. To run the code lib6502 is used for 6502 emulation.

Emulation is all well and good as far as it goes, especially for development and testing, but we’d love to see this code running on a real 6502. Even better would be a 6502 built from scratch! If you get this code running we’d love to hear how it went!

17 thoughts on “MilliForth-6502, A Forth For The 6502 CPU

    1. See https://www.forth.com/resources/forth-programming-language/#31_The_Forth_Interest_Group .  Ragsdale got Army Maj. Robert Selzer to port a version of microForth to the 6502.It goes on to say,

      Selzer and Ragsdale subsequently made substantial modifications and improvements to the model, including exploitation of page zero and stack-implicit addressing architectural features in the 6502.  Many of the enhancements that characterized the later public-domain versions were made during this period, including variable-length name fields and modifications to the dictionary linked-list threading.  A metacompiler on the Jolt could target a significantly changed kernel to a higher address in memory.  A replacement bootable image would then be recompiled by the new kernel into the lower boot address, which could then be written out to disk.  At this point, Ragsdale had a system with which to meet his professional needs for embedded security systems.

      During this period the Forth Interest Group (FIG) was started by Ragsdale, Kim Harris, John James, David Boulton, Dave Bengel, Tom Olsen and Dave Wyland [FIG 1978].  They introduced the concept of a “FIG Forth Model,” a publicly available Forth system that could be implemented on popular computer architectures.

      The FIG Forth Model was derived from Ragsdale’s 6502 system.

  1. There are quite a few Forths running on 6502 and 65c02, in indirect-threaded, direct-threaded, and I believe even subroutine-threaded models.  There’s a somewhat active forum about it at http://forum.6502.org/viewforum.php?f=9 .  I use Forth on my 65c02 workbench computer because it is so quick to develop software on.  You can see the workbench computer, which I use as kind of a “Swiss army knife of the workbench,” at http://wilsonminesco.com/BenchCPU/

  2. As other point out, 6502 has had Forth options for a long time.
    https://www.computinghistory.org.uk/det/5989/Forth/

    I had a Forth ROM for my beeb (model B). But I hardly used it since the 6502 small C compiler came out shortly after I managed to save up for the Forth ROM, and C just seemed like a much better alternative to coding in assembly compared to Forth.

    Still, quite impressive project, I am sure the Acornsoft Forth was bigger than 1110bytes. I believe it was on a 16kb ROM, but not sure how much of the ROM was used.

      1. I think there’s something to the kind of brain one is born with.  RPN also goes contrary to how we’re taught in the early grades, and to how our English language works.  I don’t speak any Korean, but I understand the Korean language is RPN, and Koreans pick up on RPN languages much more easily.  Where we would say “put on shoes,” they would say something like “shoes, install.”  (I verified this with a Korean roommate of our son’s when he was living on campus at the university.)

        Forth was very natural for me to pick up and run with though.  OTOH, I absolutely cannot latch onto C.  I have been through the standard K&R C book which was recommended, and a “C For Dummies” (or something like that), and gave up.  I seem to have a Forth brain, and once I found Forth, I decided I was done picking up languages.  This was home.

        1. Well I’m glad you found your home! I’ve been programming for 30 years, and I’m almost embarrassed to say it, but PHP is my language of choice. It’s just a very practical language which you can take in myriad directions. Object oriented, procedural, functional, optional strong typing, traits, concurrency… PHP can do it all! And with PHP there is no compile step required.

  3. I remember a few very useable Forths that I ran on my old Atari 800 back in the early 80’s , not necessarily all tiny implementations, but all perfectly useable and bootable off a sector of a floppy disk or tape.
    One that comes to mind was PolyForth by a UK software house called BigNose Software (I think). That actually did graphics and multitasking on the 800. I wrote a 2D CAD program using it.

    The code is out there, somewhere. I had a 6502 assembler source listing (FigForth79 I think it was) that was bootstrappable from quite minimal basic Forth code into a full Forth by loading more Forth code.

    1. figForth was a little before Forth 79.

      But yes, a nice thing about Forth is the incremental compilation and that new things you write become part of the language itself, and the user can “get under the hood” and modify the compiler itself.  It even had the tools to do OOP before it was called that.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.