Mad Pascal
- Year
- 2015
- Publisher
- Open source (GitHub: tebe6502/Mad-Pascal)
- Type
- Language
- Category
- Pascal cross-compiler (Turbo Pascal-style)
- Developer
- Tomasz Biela (Tebe/Madteam)
- Language
- Pascal (compiler written in Pascal; builds with Free Pascal)
- Requirements
- Windows, Linux or macOS PC with Mad Pascal and MADS; output runs on Atari XL/XE (some units need 130XE memory or VBXE)
- Tags
- pascal, compiler, cross-compiler, mad-pascal, tebe, madteam, mads, modern, open-source
Overview
Mad Pascal brings the feel of Borland's Turbo Pascal to the Atari 8-bit. You write Pascal on a modern computer, and the compiler mp translates it into 6502 assembly source. MADS, the Mad-Assembler from the same author, then assembles that into an Atari executable. The code is far faster than interpreted BASIC, and the language is much easier to manage than raw assembly for anything bigger than a demo. Since its 2015 debut it has become one of the main high-level languages of the modern Atari scene, alongside cc65 C, FastBasic and Effectus.
History
Tomasz Biela (Tebe/Madteam) announced Mad Pascal on AtariAge in 2015 with a demo, PasIntro. Gury, of the Atari 8-bit portal, welcomed it: he had expected Free Pascal under the hood and was surprised to find Tebe's own compiler. The compiler is based on Sub-Pascal, a 32-bit real-mode Pascal compiler for 80386+ PCs written by Vasiliy Tereshkov in 2009. Tebe retargeted it at the 6502. Releases came quickly: 1.3.7 and 1.4.0, 1.4.7 in May 2017 (with multiplication optimizations), and 1.5.5 dated 29 April 2018. By February 2024 it had reached version 1.6.9. Source and releases are on GitHub, and the compiler builds with Free Pascal on Windows, Linux and macOS.
The language
Mad Pascal is a subset of Pascal, but a generous one. The project's own list includes:
if,case,for,while,repeat, compound statements, andlabel/goto- records and objects (records with methods)
- procedures and functions with up to 8 parameters, with the function result in a predefined
Resultvariable; static local variables; recursion; separate modules (units) - data types
Byte,Word,Cardinal,ShortInt,SmallInt,Integer,Char,PChar,Boolean,Pointer,File,Text, plus fixed-pointShortReal/Real, IEEESingleand 16-bitFloat16 - one- and two-dimensional arrays (zero-based, treated as pointers as in C) and
string[N]
Variables can be placed at fixed addresses with absolute, so hardware access is easy (CHBAS : byte absolute $2F4;). The standard units are modelled on Turbo Pascal's System, Crt, Graph, Math and SysUtils. That means InitGraph, SetColor, Circle, LineTo, KeyPressed and Delay work much as they did in DOS-era Turbo Pascal. Later versions added music-player units for the scene trackers (CMC, MPT, RMT), a VBXE unit, and a {$R} resource-file mechanism that can load data into extended memory.
Besides the Atari XL/XE, Mad Pascal can target the Commodore 64 (-t c64), the Commodore Plus/4 (-t c4p), the Neo6502 (-t neo) and raw 6502 output.
A first program
uses crt;
var i: byte;
begin
for i := 1 to 5 do
writeln('Hello from Mad Pascal ', i);
repeat until keypressed;
end.
Build it in two steps:
mp hello.pas (produces hello.a65)
mads hello.a65 -x -i:<mad pascal base dir> -o:hello.xex
The -x switch tells MADS to leave out library procedures your program never calls, which keeps executables small. The -i: path must point to Mad Pascal's base directory of runtime routines. A common beginner's mistake is running mp from the wrong directory so that the units cannot be found. Run it from the Mad Pascal folder or give paths relative to it. The output is an ordinary binary-load file (.obx and .xex are the same format) that runs from DOS or directly in an emulator.
Ecosystem and examples
Early users quickly posted demos: player/missile graphics examples by Bostjan Gorisek, line-drawing toys, and ports of type-in games such as Wolves. A solitaire game was even written to compile unchanged under Mad Pascal, Turbo Pascal 7 and Free Pascal. The distribution's example folder grew to include bocianu's game MadKingdom, and AtariAge's "Games in Mad Pascal" topic collects finished titles. Community libraries extend the standard units: bocianu's blibs and the A8MadPascalLibrary are widely used.
Tips
- Keep MADS up to date along with Mad Pascal. The generated code uses newer MADS features: in 2015, users with an old MADS got "Unexpected end of line" errors on the anonymous
@+/@-labels, which arrived in MADS 1.9.5 (fixed in 1.9.6). - Use
absolutevariables andPoke/Peekfor hardware registers, and theGraphunit for OS graphics modes. For display lists and DLIs, drop into inline assembly with anasm { ... };block inside a procedure. - If you want an IDE rather than a batch file, many users run Mad Pascal through the WUDSN IDE for Eclipse. Its author began adding deeper Mad Pascal integration in 2021–22.
Credits
- AtariAge forum — Mad Pascal (main thread, from 2015) — AtariAge forum members, 2015
- AtariAge forum — Mad Pascal thread, later pages (versions 1.3.7–1.5.5) — AtariAge forum members
- AtariAge forum — Games in Mad Pascal — AtariAge forum members
- Mad-Assembler repository README (MADS, Mad Pascal back end) — GitHub project authors
- AtariAge forum — WUDSN IDE thread (Mad Pascal integration, 2021–22) — AtariAge forum members, 2021
- Gury's Atari 8-bit portal — Effectus page — Gury (Atari 8-bit Forever portal)
