Skip to content

PASTA/80 Version 1.00 RC1

Pre-release
Pre-release

Choose a tag to compare

@pleumann pleumann released this 24 Oct 16:59
· 12 commits to master since this release

"Spit and polish till it shines."

It has taken me longer than planned to get here, but I think it was worth the wait. Lots of bugs and edge cases have been fixed, tests have been added and improved, and directories have been cleaned up. See the sections below for details.

If I had to pick a single change that stands out, it would be the new --selftest parameter. It compiles and runs all of the compiler's test cases for the selected target and prints a nice report at the end. This makes testing the compiler much easier and more convenient, and it will provide a good safety net against future regressions. It also forms the basis of automated building and testing on GitHub now.

This is surely the best version of PASTA/80 yet, and as close to Turbo Pascal 3.0 for CP/M as I've been able to make it. It is the first release candidate for version 1.0 and will be promoted to the final release if no major problems are reported.

Changes that can break existing programs or build scripts have their description set in bold.

Compiler

  • Binary rename: The PASTA/80 binary has been renamed pasta80, mainly to avoid a conflict with an existing Unix/Linux utility called pasta.
  • Optimizer: --opt and --dep are now on by default, resulting in lean binaries (use --no-opt and --no-dep to switch off).
  • Overlays on by default: Like in Turbo Pascal 3, overlays now simply work wherever the platform supports them (128K, Next and Agon binaries), so --ovr is no longer needed. Overlays are only generated, and the memory layout only changes, if the program contains at least one overlay procedure or function. In that case resident memory for code, heap and stack now ends at $BFFF on the 128K and at $DFFF on the Next and Agon, even without --ovr. Use the new --no-ovr to switch overlays off; the overlay setting was removed from the mini IDE.
  • Command-line options: --run (the .run directory format for the Next) is now called --dir, so that --run stays free for a future compile-and-launch option. Several options got shorter or more intuitive spellings, which the documentation now prefers: --48, --128, --next, --tape, --snapshot, --moslet and --keep. The old spellings --zx48, --zx128, --zxnext, --tap, --sna, --mos and --keepint keep working.
  • Printer output: The new --printer option redirects everything a program writes to the screen to the printer instead — the LST: device on CP/M, the "P" channel on the Spectrum, and VDU 1 on Agon, which wraps each character individually so that VDU control codes still reach the VDP (switching the screen off wholesale would swallow them, which is what made the sound test go silent). Since emulators can capture that stream to a file or to their console, this makes it possible to run things like test suites unattended on every supported platform and collect the results automatically.
  • Error locations: Error messages now include the file name and jump to the correct file, fixing incorrectly located errors inside include files (issue #119).
  • Windows build fix: The Build function was reorganized so that source/intermediate files no longer stay locked after a compile error on Windows (issue #116).
  • Code generation: Fixed an internal limit where merged db/dw output lines could exceed Free Pascal's string length, causing a spurious "Expression expected" error on larger programs (issue #130).
  • Bit operations: Fixed and/or/xor producing wrong results for Byte operands whose value came from an operation that had extended into the upper 8 bits (issue #133).
  • IDE memory leaks: Fixed leaking "auxiliary" symbol chains for record fields and forward-declaration signatures (issue #134), and stopped --ide mode's error handling from leaking AnsiString instances on every compile error by switching from SetJmp/LongJmp to raise/try/except, which no longer bypasses Free Pascal's stack cleanup (issue #136). The internal code-emission list is now also explicitly freed between IDE compiles as a preventive measure.
  • CP/M output names: Generated CP/M binaries now always get a proper 8.3 name, so they can be run by tools like tnylpo that enforce that format; ChangeFileExt was also fixed to always use the rightmost dot when deriving a new file name.
  • Code size calculation: Worked around an sjasmplus edge case that could make the reported code size wrong when the assembled code crosses the 64K boundary (issue #138).
  • Stack check: The compiler-generated stack-overflow check now uses the correct value, taking the platform, overlays, and a {$s <n>} setting into account, instead of a stale hard-coded one left over from the days of a fixed 8K stack (issue #151).
  • Str: Fixed Str(C:Width, S) and Str(S2:Width, S) (the Char/String variants with an explicit width) returning garbage; a copy-paste bug made them ignore the width and take the no-format code path instead.
  • Error messages for anonymous types: A type declared inline rather than through a type declaration carries no name, which used to leave a blank where the name belonged: B := 42 for B: String[5] reported "expected , got Integer". Such types are now described by their kind, e.g. "expected anonymous string type, got Integer" (issue #76).
  • Custom BASIC loaders: The new --loader <file> parameter replaces the built-in BASIC loader for the --tape and --dir formats.
  • Preprocessor symbols: Defines that mirror a command-line switch now carry an OPT_ prefix so they cannot collide with user defines by accident. PRINTER became OPT_PRINTER, and OPT_RELEASE was added.
  • Start address: The new --start <addr> option moves the start address of Spectrum programs down from $8000 to as low as $6000, unlocking up to 8K of additional RAM (for instance for the resident part of a 128K program with overlays). Memory below $8000 is contended, so code there runs a bit slower, which is why $8000 stays the default. The compiler patches the CLEAR line of the BASIC loader to match, and provided loaders are now checked for a +3DOS header. The output formats use the actual start address instead of a hard-coded $8000.
  • Long command lines: Command lines for external tools are no longer cut off after 255 characters, which broke launching Fuse from long paths on the Mac. Dos.Exec is replaced by a small shim based on ExecuteProcess (issue #161).
  • Overlay fixes: When an overlay is too large, the size report now shows the correct page and address for it instead of bogus values (issue #164). Forward declarations and their bodies must now be in the same overlay (this is an error otherwise), and a forward procedure called from a nested procedure before its body no longer causes dependency analysis to drop code, which used to end in "label not found" during assembly (issue #169).
  • Alternative comments: Compiler directives now also work in the (*$...*) form, not just in {$...} (issue #167).
  • Include directive: An {$I file} followed by more text on the same line, such as a comment or a statement, now works. The scanner used to read the next character before opening the include file, so a comment swallowed the entire included file, and anything else was glued to its first token (issue #173).
  • String literals in overlays: A string literal that is first used inside an overlay is now stored in that overlay rather than in resident memory, which is the scarcer resource. Literals already used by resident code before the overlay are still shared. The flip side is that a literal used by several overlays, or by resident code only after the overlay, is stored more than once; declaring it as a string constant before the overlays avoids that. Since overlays grow a little, existing programs may need some reshuffling of their overlays (issue #170).
  • 128K overlay overflow: On the 128K, an even-numbered overlay that grows beyond 8K used to silently spill into the following overlay's memory, because the address was still within the Z80's address space and sjasmplus did not complain. This is now reported as an error (issue #171).
  • Inline routines: Dependency analysis now covers inline routines, too. They used to be emitted unconditionally, so every program carried Randomize, Hi, Lo, Swap, UpCase, MaxReal and friends, whether it used them or not.
  • {$a <text>} removed: The undocumented {$a <text>} directive, which wrote its text verbatim into the assembly output, has been removed. {$a+} and {$a-} are unaffected.
  • Assembler version: The warning about an outdated sjasmplus now names the version that was found, e.g. "sjasmplus 1.22.0 recommended, you have 1.21.0." (issue #72).

Language

  • Random: A parameterless Random (returning a Real with 0 <= x < 1) is now available as a built-in alongside Random(n), instead of only under the separate name RandomReal (issue #97).
  • Control characters: Caret notation (^A etc.) now fully matches Turbo Pascal 3/4/5 behavior, including lower-case letters and non-letter characters, resolving ambiguities with pointer types and pointer-array expressions (issue #83).
  • Hex character constants: #$xx is now accepted wherever a character constant is expected (issue #110).
  • Typed constants: A String[n] literal can now be used as the value for a Char array typed constant of matching size, matching Turbo Pascal 5.5 behavior (issue #104).
  • Pointer arithmetic: Inc/Dec now work on pointer types, taking the size of the pointed-to element into account, like in C (issue #86).
  • for loops: Like Turbo Pascal 3, a for loop now computes its 16-bit iteration count once up front and then just counts down, instead of comparing the loop variable with the final value on every step. This is faster (a real-world benchmark went from 1294 to 1252 seconds) and matches TP3 when the bounds exceed the range of the loop variable: for B := 3 downto I with B: Byte and I = -1 runs five times (3, 2, 1, 0, 255), where it used to loop forever. It also means you should not modify the loop counter variable anymore. If you need to terminate the loop early, use Break (issue #163).
  • Negative array bounds: Negative literals are now accepted as bounds, e.g. array[-1..2] or -5..-1 (issue #168).
  • Constant aliases: A String or Real constant declared as an alias of another constant, e.g. const A = 'Hello'; B = A;, no longer fails to compile (issue #172).
  • Subranges: A family of defects where the width of a value and the type it is based on were confused for each other has been fixed.
    • Unary operators now reduce a subrange to its base type and compute anything integral in 16 bit, just like the binary operators do. -V used to be rejected outright for a subrange, and not only complemented the low byte. not on a Byte variable is affected the same way and now matches Turbo Pascal 3: not B for B = 1 is -2, with the truncation to a byte happening on assignment (issue #156).
    • Inc/Dec accept subranges and pick the 8 or 16 bit code path by the size of the variable rather than by its type. They used to fail with "Ordinal or pointer type expected" (issue #156).
    • SizeOf reports the storage actually used instead of the size of the base type. A subrange of 10..20 occupies one byte and now says so, which also stops FillChar(V, SizeOf(V), 0) from writing past the variable (issue #157).
    • A subrange is only packed into a single byte if its lower bound allows it. This changes the size of such variables and of records containing them. Previously only the upper bound was checked, so a range like -100..100 was stored in one byte and read back zero-extended, turning -100 into 156 (issue #158).
    • Assigning to a byte-sized subrange stores one byte. It used to store two and silently overwrite the neighbouring variable, because the assignment used the type that the type check returned rather than the type of the target (issue #159).
  • div type-checking: The div operator is no longer silently accepted for Real operands; it used to fall through a case branch and return garbage instead of being rejected (issue #139).
  • mod for Real removed: The mod operator no longer accepts Real operands. It was an undocumented extension that Turbo Pascal 3 and Free Pascal both reject, and it never checked for errors, so 7.5 mod 0.0 silently returned 7.5. Use X - Int(X / Y) * Y instead, which also stops with "Division by zero" (issue #140).
  • Real constants: Real literals outside the range of the type, such as 1E99 or 1E-99, are now rejected with "Real constant out of range" instead of silently wrapping around to an ordinary-looking wrong value. The compiler applies exactly the rules of the run-time conversion: an exponent of -38 to 37, at most 38 decimals, and a value below 2^127, so 15E37 is accepted and 16E37 is not, as in Turbo Pascal 3. A value too small to represent becomes zero (issue #178).
  • Stricter type checks: A number of places that had no type check, or only a commented-out one, now have one. Ord, Odd, Pred, Succ and the fill value of FillChar require a scalar argument, Rename a string and Seek an integer. Set types, set constructors, set constants, Include/Exclude, in and set operators check that the element types match. case selectors must be scalar, and case labels, including those of variant records, are checked against the selector type. Programs that relied on the missing checks may no longer compile (part of issue #155; range checking is still post-1.0).

Runtime

  • Heap: The heap is now initialized at compile time instead of at runtime, removing redundant startup code (issue #108). The heap-defragmentation procedure was renamed from CompactHeap to DefragMem for clarity.
  • BufLen: The predefined variable BufLen can now be used to limit the length of console input lines, on CP/M, ZX, and Agon alike; a buffer underflow bug was fixed along the way (issue #81).
  • File sizes and pointers: On Agon and the Next, untyped files whose size is not a multiple of 128 bytes (typically files not created by PASTA/80) now count a short last block as a full record. Previously their size came out wrong, and a while not Eof(F) do BlockRead(F, Buf, 1) loop could run forever (issue #166), and file pointer arithmetic on esxDOS no longer breaks for typed files of 64K and more (issue #165).
  • Agon-only:
    • Sound: Sound and NoSound (Turbo Pascal 3 style) are now available on Agon Light.
    • Graphics: A new function GetGraphMode returns the current graphics mode. FloodFill now waits until the VDP has finished the fill, like on the Spectrum, so follow-up drawing no longer races with it.
    • Frames: Fixed two bugs: the low half of the MOS timer was read as a signed Integer, and the counter, which MOS increases by two per screen refresh, was not divided by two. Frames now really counts 60 Hz frames, so its values are half as large as before. The helper functions sysvar_time_lo and sysvar_time_hi have been removed.
    • Agon file bugs: Fixed three file-handling bugs found on real hardware and newer emulators. Reset used to open files with a MOS flag that makes every write land at the end of the file regardless of the file pointer, breaking seek-then-write and Append; reads were unaffected, which is why the bug looked narrower than it was. Rename silently overwrote an existing target instead of reporting a collision, since MOS itself does not refuse that the way CP/M's BDOS does. And the result of mos_fread/mos_fwrite was read out of the A register, which carries nothing usable for those two calls, so block reads and writes could report errors that never happened — the number of bytes actually transferred is the only thing to go by, with end of file showing up as a short count (issue #153).
    • ParamStr(0): Now consistently returns an empty string, like on the other platforms, instead of a hard-coded, MOS-supplied program name that MOS itself has no way of keeping accurate (issue #129).
  • ZX-only:
    • Sound was renamed to SoundMs to make its synchronous (blocking) behavior explicit.
    • CursorOn/CursorOff are now available as no-ops, so code that calls them no longer needs to be conditionally compiled out.
    • FloodFill now also fills the bottom pixel row of the screen (row 175), which it used to leave out (issue #180).
    • Overlay switching: Removed a distracting border animation that played on every overlay change on the 128K and the Next (issue #113).
    • SoundMs: Fixed a missing /1000 in the duration calculation, which made tones play about 1000x longer than requested.
    • ZX re-entrancy: A program that returns to BASIC can now be restarted via USR several times without reloading. The startup code resets the last I/O error and, with overlays, the overlay stack and the current overlay number; variables and the heap deliberately survive such a restart (issue #160).
    • Frames: Now built inline as a Real directly from the frame counter bytes, read with interrupts disabled so the counter cannot tick in between. This is much smaller and faster than the previous floating-point arithmetic.
  • Next-only: GetMemPage and SetMemPage had empty bodies. They now read and write the MMU registers $50 to $57.
  • Small heap blocks: GetMem/FreeMem (and therefore New/Dispose) now handle very small allocations correctly: every real block is padded to at least 4 bytes so it fits into the free list, while 0-byte requests are simply ignored and leave the pointer untouched, matching Turbo Pascal (issue #131).
  • File functions: Eof, Eoln, SeekEof, and SeekEoln no longer leave garbage in the unused upper byte of their result, which could show up if the Boolean result was cast, e.g. via Ord (issue #132).
  • Text file edge cases: Fixed EOF detection for Text files whose size is an exact multiple of 128 bytes, and for brand-new or erased-to-empty files, which previously could seek to a bogus record and silently zero-fill the file up to 64K on the next write. Also fixed a long-standing bug on ZX Next/esxDOS where padding the last sector overwrote the internal Registers variable instead of the actual buffer (issue #101).
  • Math error checking: Mathematical operations now signal a runtime error, similar to Turbo Pascal 3-5: division by zero for Integer and Real, mod by zero, overflow in Real addition/subtraction/multiplication/division, invalid arguments to Ln/Log/Sqrt, Tan at odd multiples of π/2, and Round/Trunc overflow when the result doesn't fit into an Integer (issue #141). Exp now also stops with "Real overflow" when its result is out of range, instead of returning garbage (issue #178).
  • Real formatting: Fixed a sign loss in the math48-based Real formatting: a negative value that rounds to 0 at the requested precision (e.g. WriteLn(-0.00004:8:3)) now prints -0.000 instead of 0.000, matching Turbo Pascal (issue #142).
  • Real conversion accuracy: Reals from about 5.5E11 to just below 1E16 printed about 0.23% too high, and from 1E-15 to 1E-12 too low, in exponential and fixed notation alike. Val and Read were off in the same ranges. The cause was two swapped hex digits in the 1E12 entry of a power-of-ten table, a bug that goes back to the original math48 sources (issue #177).
  • Real input range: Val, Read and ReadLn now detect out-of-range numbers such as '1E99' and report the same error position as Turbo Pascal 3, instead of returning a meaningless value with no error (issue #178).
  • Fixed-point output: Write(X:W:D) and Str(X:W:D, S) no longer print ERROR when the whole part needs more than 15 digits; they fall back to exponential format instead. More than 15 decimals are capped at 15 rather than taken modulo 16, and more than 24 or a negative number of decimals selects exponential format, as in Turbo Pascal 3 (issue #179).
  • Eoln: Now correctly returns True for empty Text files instead of False (issue #145).
  • ScreenWidth/ScreenHeight: Turned from constants into functions, since the actual value can depend on the current screen/graphics mode on some platforms. Existing code that just reads the value keeps working; code that required a compile-time constant (e.g. as an array bound) needs to be adjusted.
  • File type sizes: File, Text, and file of variables now get the platform's actual FileRec/TextRec size instead of a wasteful, hardcoded 256 bytes (issue #147).
  • Read/ReadLn/Val error signaling: Read and ReadLn now throw a runtime error when console or file input doesn't match the target type (e.g. "abc" for an Integer), the same way Val already did; the check is emitted by the compiler itself, so it can be toggled with {$i}. Switching {$i+} back on does not raise a pending error by itself, so the classic idiom {$i-} Reset(F); {$i+} if IOResult <> 0 then ... works as in Turbo Pascal 3 (issue #176). One deliberate difference from TP3: an empty input line now also counts as invalid for Integer, Real, and enum types instead of being silently ignored; wrap the read in {$i-}/{$i+} if you need the old behavior.
  • ReadLn(Text, String[N]): No longer overflows past the target string's declared capacity N; excess characters on the line are still consumed so parsing continues at the right place (issue #152).
  • Copy/Insert/Delete safety: A zero (or otherwise invalid) string index now signals a runtime error instead of being silently reinterpreted, matching Turbo Pascal 3. Insert/Delete also now respect the actual declared capacity of their var String parameter instead of always assuming 255, closing a potential buffer overrun (issue #144). Both are now built-in ("magic") compiler functions rather than RTL library calls.
  • Close on unopened files: Closing a file that was never opened is now silently ignored, as in Turbo Pascal 3. On CP/M, the BDOS used to treat such an FCB as a modified file and could overwrite the directory entry of an existing file with the same name; on the Next, Close reported an error (part of issue #175).
  • Overlay stack overflow: Calling between more than 16 nested different overlays is now detected and reported instead of silently corrupting the overlay stack (issue #146).
  • Overlay far calls: A call from non-overlay code into the overlay that is already active is now tracked properly, so the overlay's own far calls switch back correctly.
  • Performance:
    • for loops are faster thanks to a precomputed iteration count (see Language above).
    • 16-bit integer multiplication for Z80N/eZ80 now uses mul instruction. This speeds up both explicit math and array accesses.
    • Set-offset calculation for Z80N now uses Ped's suggestion based on pixelad/setae/mirror.
    • The overlay/farcall trampoline was optimized further; the outermost overlay call no longer switches the overlay back unnecessarily.

Examples

  • Added an example demonstrating the BeepFX sound-effects library (issue #118).
  • Added a calculator example.
  • Added an Agon screen-mode utility example, with info and interactive try commands for exploring graphics modes.
  • The screen example/test now shows a rectangle for checking overscan.
  • The Barnsley Fern example gained a multi-colour Agon variant, split out into its own dedicated version.
  • Added a DivMod assembly-interop example.

Tests

  • Self-test: The new --selftest option builds and runs every test suite that applies to the chosen target and prints a single table with a PASS/FAIL verdict. CP/M is the default; --agon, --128 and --next select the others, while the 48K Spectrum is rejected outright because the main suite does not fit there without overlays. Which suites apply to which target, which need overlays, which output format and loader to use and which want command-line arguments are kept as tables next to each other, so adding a suite means one row each. A suite that contributes nothing shows up as "???" rather than as zero, and an expected total per platform catches a run that ended early.
  • Renamed suites: tests/all.pas became tests/core.pas along with the binary rename. The suites are now core, heap, files, more, params, sound, overlays and errors.
  • Negative tests merged: The 30 programs under tests/errors plus halt.pas became 33 numbered cases in a single tests/errors.pas, picked by command-line parameter on CP/M and Agon. The ZX targets have no command line, so there the program counts for itself and reports through the exit code; three small launchers in misc drive that. Each case announces the line its log has to end with, so checking a run means comparing that one line, with no table of expectations kept elsewhere. The individual programs, the two shell scripts that used to drive them and tests/halt.pas have been removed, which leaves the eight suites above (plus an include file used by more) as the entire test directory (issue #112).
  • Overlay tests: The new tests/overlays.pas exercises far calls between overlays and resident code in all directions, including functions, var parameters, recursion and nested procedures. It runs on the ZX 128K, the Next and the Agon (with overlays) and as an ordinary program on CP/M, which has none.
  • Assertion counts: params and sound used to only print what they did, which the driver cannot read. They now end with the same "Passed/Failed assertions" tally as the other suites.
  • Unattended runs: The suites terminate their emulator when they are done — a CSpect exit opcode on the Next, a port write on Agon, and a breakpoint file (misc/fuse.brk) for Fuse. On macOS the compiler waits for the emulator to exit, so the log is complete before it is read.
  • Printer capture: A printer plugin for CSpect writes the emulated printer stream to a file. It ships with CSpect 3.4.0.0 (currently a beta for Patreon supporters); for older versions, misc/Printer.dll can be copied into CSpect's folder. Fab Agon Emulator supports the needed --printer-file option since version 1.2.6. For Fuse, a version newer than 1.10.0 is recommended on macOS.
  • HiDPI detection: The macOS display check that scales the emulator window now also recognizes UHD and 4K displays, not just ones that report "Retina".

Documentation

  • Two documents, cross-linked: The README and the RTL reference are now named "Compiler Manual" and "Library Reference" and link to each other from a header line, so either one is one click away from the other.
  • Compiler Manual: Documents the new --selftest, --loader, --start and --no-ovr options as well as --moslet, --3dos and --keep, which had never been mentioned. Several stale facts were corrected along the way: a +3DOS header claimed for the Spectrum Next default output, and the colour constants, which are the eight classic Spectrum colours and available on every target.
  • Library Reference: Assert is no longer described as terminating the program (it counts and continues), IOResult, LastError and BDosThrow are tagged as available on every target rather than only on the ones with file support, and the internal Agon and random-number helpers were added. A final pass fixed further discrepancies with the implementation: file routines are only available on CP/M, Next and Agon, GetNextReg/SetNextReg take Byte values, Plot/Point take Integer coordinates on the Agon, Random is built into the compiler, and switch directives can be combined.