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!
Didn’t fig forth have a port to the 6502?
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.
Ragsdale’s 6502 FIG assembly source listing became the standard for how to implement and indirect threaded Forth. But his 6502 assembler written in Forth is a fantastic exemplar of what you can do with the language and how nice assembly language can be if you re-think how it is done.
GraFORTH ran on a 6502, and was pretty amazing for the time: Real-time interactive 3D graphics at home, in 1982.
It took more than 1,110 bytes, but not a whole lot more.
6502 doesnt have a boot sector.
Neither does the x86. The boot sector is on the floppy disk.
For the record, neither does x86… That’s just a PC thing
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/
Thanks for sharing!
Wow, love Bench-1! Thanks for the link!
This is a great Overview about how I think of ‘Computer System Solutions’ and the fact that Hardware and Software are not Separate Entity’s.
It’s really hard to teach that aspect. People GENERALLY want to fit Existing Hardware with Software to make things run..
It’s actually Both ( In my Opinion ) Custom Hardware and Custom Software Solutions. The ability to be able to do both, makes for the Elegant Solution.
Wirewrap is an entirely different level of Crazy. I love it.
Cap
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.
forth is known to cause disorders of the nervous system and bowel.
Yes. A write-only language. Coming back to some week-old forth word, I was forced to mentally step through it while visualizing the stack.
“Write-only” is the fault of the programmer, not the language. Although I’m a strong Forth proponent, I will still say that an awful lot of Forth I see from others is quite unreadable.
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.
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.
I consider FORTH as being one of the early Virtual Machines, like CHIP-8, the UCSD P-System, the Smalltalk VM, or (much later) the Java VM. To that end, if you ever have to use another language you might find the charts at https://hyperpolyglot.org/ to be useful. You could use it to make a C-to-FORTH mapping, or an Erlang-to-FORTH mapping, or whatever you might need.
Come to think of it, a great way to learn C would be to modify the backend of Tiny-C so it emits FORTH instead of Z80 assembly language.
German is RPN.
Mark Twain described German accurately.
Search for ‘Mark Twain The Awful German Language’.
From memory:
‘After all the compound words, the clauses of all kinds, the whole convoluted mess, finally comes the verb, at the very end. You then get to untangle the sentence in your head.’
‘Number of computer languages known’ is the best one question proxy I know for computer programmer skill.
Age must be taken into consideration.
Olds, like me, should not be able to come up with an instant answer. More: How do I count them? How well to count? Does getting paid to code in it count?
‘How many programming languages did you know when you started college?’ might be better (for formally trained people).
If the answer to that is 0, to the bin the resume goes.
Would you hire a musician that hadn’t picked up an instrument before music school?
Have to play like Zappa.
German is only verb-final in subordinate clauses: “Berlin is the capital of Germany” vs. “I know that Berlin the capital of Germany is”, for example. But almost half of all languages are truly verb-final, from Armenian to Japanese to Turkish.
I think of it as being closer to the way the brain works to process language. We can’t actually perform “3 + 7” because the addition operation is out of order. We mentally stack the 3 and the + until we get the 7. “3 7 +” is better but it gets harder to communicate as it gets more complicated. To communicate in speaking or writing, infix is more effective. To perform the task, RPN is more effective. C compilers routinely do the conversion to RPN before code generation.
that’s a neat theory. i tend to think the advantages of forth are its epic simplicity and emphasis on factoring. i love it but i don’t feel like my mind is any more disposed to RPN than to infix. and i spend most of my day in C.
in practice i just use forth for embedded environments where i don’t want to write asm, don’t want to configure a C compiler, and don’t want to write a more complicated compiler than a forth one :) i really like forth’s elegance, and reading the pygmy forth source code from one end to the other was a great joy many years ago. but i may never use it again because it doesn’t look like i’ll ever use a micro smaller than the rp2040 in the future
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.
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.
PolyForth IIRC is from Forth Inc, and Elizabeth Rather and was linked with Charles Moore.
Redpower, an ancient mod for Minecraft, had a computer that was essentially a 6502 and a terminal and by default it ran Forth.
I used VICForth back in the day on a 3.5K machine. Made my definitions. Monitored the stack. It was a great cartridge and got me learning more than the “BASIC” and Machine Code (albeit using Data statements to POKE into memory and jump to the code with a lil’ ol’ SYS command).
I remember writing a Forth interpreter in 6502 assembler for the Commodore 64 in about 1984. Good fun, but never used it for anything; the assembly code is much easier to understand than Forth
1,110 bytes. That fits in a 1541 drive’s ram, leaving at least 700 bytes of memory for a forth program. :)
One of the feature if Forth I wish was common in C and other languages has to do with the radix. In Forth you can set any base at any time. You can use hex or binary or rad60 by changing the value of a variable called BASE (I think). But you have to remember the base you are in when you just write a number to it! So there are typically a few base change words defined like HEX and BINARY and DECIMAL. So not need for the pre-processor commands like 0xABCD and 0b11010… (kill all humans). You avoid developing the irritating habit of including the 0x with hex numbers in text.
It makes very nice when entering some data. Easily switching to binary is great for configuring registers or creating masks for various bits and other logic operations. The operations like .S that print the top of the stack will print correctly in any radix.
I made my own 6502 Forth, to run on my Ben Eater inspired 6502 breadboard computer. I then made a 6502 emulator in Forth also, so I could run my own 6502 Forth in emulation.
I also developped SKI Combinators Calculus for my 6502 Forth, cause I could… Isn’t it cool to do SKI calculus on a 6502?
I explain that in my talks, link below 👇
https://adumont.github.io/talks/