Repository navigation
PASTA/80 Version 1.00 RC1
Pre-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 calledpasta. - Optimizer:
--optand--depare now on by default, resulting in lean binaries (use--no-optand--no-depto 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
--ovris no longer needed. Overlays are only generated, and the memory layout only changes, if the program contains at least oneoverlayprocedure or function. In that case resident memory for code, heap and stack now ends at$BFFFon the 128K and at$DFFFon the Next and Agon, even without--ovr. Use the new--no-ovrto switch overlays off; the overlay setting was removed from the mini IDE. - Command-line options:
--run(the.rundirectory format for the Next) is now called--dir, so that--runstays 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,--mosletand--keep. The old spellings--zx48,--zx128,--zxnext,--tap,--sna,--mosand--keepintkeep working. - Printer output: The new
--printeroption redirects everything a program writes to the screen to the printer instead — theLST:device on CP/M, the "P" channel on the Spectrum, andVDU 1on 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
Buildfunction 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/dwoutput lines could exceed Free Pascal's string length, causing a spurious "Expression expected" error on larger programs (issue #130). - Bit operations: Fixed
and/or/xorproducing wrong results forByteoperands 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
--idemode's error handling from leakingAnsiStringinstances on every compile error by switching fromSetJmp/LongJmptoraise/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
tnylpothat enforce that format;ChangeFileExtwas 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: FixedStr(C:Width, S)andStr(S2:Width, S)(theChar/Stringvariants 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
typedeclaration carries no name, which used to leave a blank where the name belonged:B := 42forB: 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--tapeand--dirformats. - Preprocessor symbols: Defines that mirror a command-line switch now carry an
OPT_prefix so they cannot collide with user defines by accident.PRINTERbecameOPT_PRINTER, andOPT_RELEASEwas added. - Start address: The new
--start <addr>option moves the start address of Spectrum programs down from$8000to 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$8000is contended, so code there runs a bit slower, which is why$8000stays the default. The compiler patches theCLEARline 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.Execis replaced by a small shim based onExecuteProcess(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
inlineroutines, too. They used to be emitted unconditionally, so every program carriedRandomize,Hi,Lo,Swap,UpCase,MaxRealand 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 parameterlessRandom(returning aRealwith0 <= x < 1) is now available as a built-in alongsideRandom(n), instead of only under the separate nameRandomReal(issue #97).- Control characters: Caret notation (
^Aetc.) 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:
#$xxis now accepted wherever a character constant is expected (issue #110). - Typed constants: A
String[n]literal can now be used as the value for aChararray typed constant of matching size, matching Turbo Pascal 5.5 behavior (issue #104). - Pointer arithmetic:
Inc/Decnow work on pointer types, taking the size of the pointed-to element into account, like in C (issue #86). forloops: Like Turbo Pascal 3, aforloop 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 IwithB: ByteandI = -1runs 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, useBreak(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
StringorRealconstant 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.
-Vused to be rejected outright for a subrange, andnotonly complemented the low byte.noton aBytevariable is affected the same way and now matches Turbo Pascal 3:not BforB = 1is-2, with the truncation to a byte happening on assignment (issue #156). Inc/Decaccept 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).SizeOfreports the storage actually used instead of the size of the base type. A subrange of10..20occupies one byte and now says so, which also stopsFillChar(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..100was stored in one byte and read back zero-extended, turning-100into156(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).
- Unary operators now reduce a subrange to its base type and compute anything integral in 16 bit, just like the binary operators do.
divtype-checking: Thedivoperator is no longer silently accepted forRealoperands; it used to fall through acasebranch and return garbage instead of being rejected (issue #139).modforRealremoved: Themodoperator no longer acceptsRealoperands. It was an undocumented extension that Turbo Pascal 3 and Free Pascal both reject, and it never checked for errors, so7.5 mod 0.0silently returned7.5. UseX - Int(X / Y) * Yinstead, which also stops with "Division by zero" (issue #140).- Real constants: Real literals outside the range of the type, such as
1E99or1E-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, so15E37is accepted and16E37is 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,Succand the fill value ofFillCharrequire a scalar argument,Renamea string andSeekan integer. Set types, set constructors, set constants,Include/Exclude,inand set operators check that the element types match.caseselectors must be scalar, andcaselabels, 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
CompactHeaptoDefragMemfor clarity. BufLen: The predefined variableBufLencan 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:
SoundandNoSound(Turbo Pascal 3 style) are now available on Agon Light. - Graphics: A new function
GetGraphModereturns the current graphics mode.FloodFillnow 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 signedInteger, and the counter, which MOS increases by two per screen refresh, was not divided by two.Framesnow really counts 60 Hz frames, so its values are half as large as before. The helper functionssysvar_time_loandsysvar_time_hihave been removed.- Agon file bugs: Fixed three file-handling bugs found on real hardware and newer emulators.
Resetused 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 andAppend; reads were unaffected, which is why the bug looked narrower than it was.Renamesilently 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 ofmos_fread/mos_fwritewas read out of theAregister, 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).
- Sound:
- ZX-only:
Soundwas renamed toSoundMsto make its synchronous (blocking) behavior explicit.CursorOn/CursorOffare now available as no-ops, so code that calls them no longer needs to be conditionally compiled out.FloodFillnow 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/1000in 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
USRseveral 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 aRealdirectly 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:
GetMemPageandSetMemPagehad empty bodies. They now read and write the MMU registers$50to$57. - Small heap blocks:
GetMem/FreeMem(and thereforeNew/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, andSeekEolnno longer leave garbage in the unused upper byte of their result, which could show up if theBooleanresult was cast, e.g. viaOrd(issue #132). - Text file edge cases: Fixed EOF detection for
Textfiles 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 internalRegistersvariable 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
IntegerandReal,modby zero, overflow inRealaddition/subtraction/multiplication/division, invalid arguments toLn/Log/Sqrt,Tanat odd multiples of π/2, andRound/Truncoverflow when the result doesn't fit into anInteger(issue #141).Expnow 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
Realformatting: a negative value that rounds to0at the requested precision (e.g.WriteLn(-0.00004:8:3)) now prints-0.000instead of0.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.
ValandReadwere 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,ReadandReadLnnow 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)andStr(X:W:D, S)no longer printERRORwhen 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 returnsTruefor emptyTextfiles instead ofFalse(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, andfile ofvariables now get the platform's actualFileRec/TextRecsize instead of a wasteful, hardcoded 256 bytes (issue #147). Read/ReadLn/Valerror signaling:ReadandReadLnnow throw a runtime error when console or file input doesn't match the target type (e.g."abc"for anInteger), the same wayValalready 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 forInteger,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 capacityN; excess characters on the line are still consumed so parsing continues at the right place (issue #152).Copy/Insert/Deletesafety: A zero (or otherwise invalid) string index now signals a runtime error instead of being silently reinterpreted, matching Turbo Pascal 3.Insert/Deletealso now respect the actual declared capacity of theirvar Stringparameter 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.Closeon 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,Closereported 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:
forloops are faster thanks to a precomputed iteration count (see Language above).- 16-bit integer multiplication for Z80N/eZ80 now uses
mulinstruction. 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
infoand interactivetrycommands 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
--selftestoption 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,--128and--nextselect 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.pasbecametests/core.pasalong with the binary rename. The suites are nowcore,heap,files,more,params,sound,overlaysanderrors. - Negative tests merged: The 30 programs under
tests/errorsplushalt.pasbecame 33 numbered cases in a singletests/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 inmiscdrive 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 andtests/halt.pashave been removed, which leaves the eight suites above (plus an include file used bymore) as the entire test directory (issue #112). - Overlay tests: The new
tests/overlays.pasexercises far calls between overlays and resident code in all directions, including functions,varparameters, 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:
paramsandsoundused 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.dllcan be copied into CSpect's folder. Fab Agon Emulator supports the needed--printer-fileoption 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,--startand--no-ovroptions as well as--moslet,--3dosand--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:
Assertis no longer described as terminating the program (it counts and continues),IOResult,LastErrorandBDosThroware 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/SetNextRegtakeBytevalues,Plot/PointtakeIntegercoordinates on the Agon,Randomis built into the compiler, and switch directives can be combined.