From 52ec4ec0764c0a707d4ac013fd6486ac7c991421 Mon Sep 17 00:00:00 2001 From: slederer Date: Sun, 25 Jan 2026 23:23:22 +0100 Subject: [PATCH] docs: add section about units to the pascal programming manual --- doc/pascalprogramming.md | 79 ++++++++++++++++++++++++++++++++++++++++ lib/corelib.s | 2 +- 2 files changed, 80 insertions(+), 1 deletion(-) diff --git a/doc/pascalprogramming.md b/doc/pascalprogramming.md index df5d3fd..454b46b 100644 --- a/doc/pascalprogramming.md +++ b/doc/pascalprogramming.md @@ -235,6 +235,85 @@ In Wirth Pascal, labels must be numbers. Other Pascal dialects also allow normal Tridora-Pascal only allows identifiers as labels. +## Units +Units are the method to create libraries in Tridora-Pascal, that is, codes module that can +be reused in other programs. + +Tridora-Pascal follows the unit syntax that has been established in UCSD-Pascal and is also +used in Turbo Pascal. + +Units are imported with the *USES* keyword, right after the *PROGRAM* statement. +Multiple units can be imported by separating the unit names with commas. + +There are some differences: In Tridora-Pascal, the unit file does not contain the interface +section, only the implementation section. The interface section is instead placed into a +separate file with the extension *.inc*, without any *UNIT* or *INTERFACE* keywords. + +This file will be included by the compiler and should contain +procedure or function declarations (as *EXTERNAL*). It can also contain *TYPE*, +*CONST* and *VAR* statements. + +All Pascal symbols of the unit are imported into the main program. There +is no separate namespace for units. + +### Using an Existing Unit +An existing unit is imported with the *USES* statement that must be placed +immediately after the *PROGRAM* statement. + +The compiler will look for an include file with the unit name and an *.inc* extension. +It will also +tell the assembler to include an assembly language file for each +unit. The filename must be the unit name plus an *.s* extension. + +Since there is no linker in Tridora-Pascal, all imported units will be +assembled together with the main program. + +The compiler looks for unit *.inc* and *.s* files in the current volume or +in the *SYSTEM* volume. + +### Compiling a Unit +A unit implementation file should start with a *UNIT* statement instead of a *PROGRAM* +statement. + +It should be compiled, not assembled. + +When building a program that uses units, the assembler will include an assembly language +file for each unit. + +It is possible to write units in assembly language. This is done by +directly providing the *.s* file and creating an *.inc* file with +the *EXTERNAL* declarations matching the assembly language +file. +#### Example +```pascal +(* UnitExamples.pas *) +program UnitExample; +uses hello; + +begin + sayHello('unit'); +end. +``` + +#### Example Unit Implementation File +```pascal +(* hello.pas *) +unit hello; + +implementation + +procedure sayHello(s:string); +begin + writeln('hello, ', s); +end; + +end. +``` +#### Example Unit Include File +```pascal +(* hello.inc *) +procedure sayHello(s:string); external; +``` ## Compiler Directives Tridora-Pascal understands a small number of compiler directives which are introduced as usual with a comment and a dollar-sign. Both comment styles can be used. diff --git a/lib/corelib.s b/lib/corelib.s index 8b8f403..d147934 100644 --- a/lib/corelib.s +++ b/lib/corelib.s @@ -822,7 +822,7 @@ PUTPIXEL_4BPP: SHL 2 ; * 16 DUP SHL 2; * 64 - ADD ; x*16 + x*64 + ADD ; y*16 + y*64 ADD ; add results together for vmem addr