Millfork 0.3.24 Ships with a Batch of New Atari Examples
On 2 December 2020 KarolS released Millfork 0.3.24. Millfork is a compiled language designed around 6502-family machines (with back ends for several other 8-bit CPUs too), and it targets the Atari 8-bit among many other platforms. Its change log includes "Even more new Atari examples (thanks to @zbyti)", the result of an AtariAge thread in which zbyti spent the autumn using Millfork to explore the Atari's hardware.
What Millfork is like
Millfork looks a bit like C, but it is built around how the 6502 actually works. Variables can be pinned to fixed addresses (byte hscroli @ $80), arrays can be aligned to page boundaries, and assembly routines sit alongside high-level code with the register they take arguments in declared up front (asm void wait(byte register(a) f)). Interrupt handlers are declared with an interrupt keyword. The Atari target is selected with -t a8 and comes with named hardware registers such as antic_nmien, gtia_colpf2 and os_RTCLOK.
One deliberate design choice surprised newcomers. Arithmetic never promotes to a wider type, so multiplying two bytes gives a byte unless you cast one of them (x = n*word(n)). Millfork's author explained that this is by design. One experienced coder in the thread welcomed it, calling Millfork one of very few true 8-bit languages, because automatic 16-bit promotion is a major source of slow code in other compiled languages.
The examples
Zbyti's examples, collected in his GitHub repository a8-millfork-playground, cover many of the Atari's standard tricks:
- turning off the OS and installing a custom NMI handler with alternating DLIs;
- an endless horizontal fine-scroll using three LMS display-list lines;
- missile-based starfields that reposition one missile on every scan line;
- benchmarks (sieve, chessboard fill, Monte Carlo pi, bubble sort) used to compare Millfork with other Atari languages;
- playing MPT and CMC music by embedding the player and tune with
file("…", 6), which skips the 6-byte Atari binary header.
In the discussion, ilmenit described Millfork as well suited to programs that take over the machine without the OS, since its Atari OS and standard-library support was still thin. Zbyti said he considered Mad Pascal the most mature Atari language, but preferred Millfork for its flexibility and multi-platform targets.
What 0.3.24 changed
Atari-relevant items in the release include entry points other than the start of the segment (also for ZX Spectrum, CoCo, Z1013 and TRS-80), init_rand_seed using POKEY as its randomness source, and new output-format elements. The same release added preliminary TRS-80 and Robotron Z1013 support, pointer-to-interrupt types, better memset-loop detection and the usual optimisation work. 0.3.26 followed in early 2021 with array fields in structs, support for self-modifying assembly code and a report of the compiled program size.
Getting it
Millfork is open source on GitHub at github.com/KarolS/millfork. Releases need a Java runtime (java -jar millfork.jar -t a8 program.mfk). Zbyti's Atari examples include both .mfk sources and ready-to-run .xex files.
Credits
- AtariAge — Millfork — AtariAge forum members
- GitHub — KarolS/millfork releases — GitHub project authors
- GitHub — zbyti/a8-millfork-playground — GitHub project authors
