P3 Pascal compiler

In the tape dump at https://history.dcs.ed.ac.uk/archive/languages/pascal/ Stefano B. found a Pascal P3 source and also a P4 source, not equal to what is found sofar for Pascal P4.
The originator is L.ZAFFALON, CUI, GENEVE.

Here an archive (with the original files from the link above in folder ‘original’) with the Pascal P3 and P4 compiler and interpreter sources

(**********************************************
  *                                            *
  *                                            *
  *         PORTABLE PASCAL COMPILER           *
  *         ************************           *
  *                                            *
  *                PASCAL P3                   *
  *                                            *
  *                                            *
  *     AUTHORS:                               *
  *              URS AMMANN                    *
  *              KESAV NORI                    *
  *              CHRISTIAN JACOBI              *
  *                                            *
  *     ADDRESS:                               *
  *                                            *
  *          INSTITUT FUER INFORMATIK          *
  *          EIDG. TECHNISCHE HOCHSCHULE       *
  *          CH-8096 ZUERICH                   *
  *                                            *
  *                                            *
  *     LAST CHANGES COMPLETED IN MAY 76       *
  *                                            *
  *                                            *
  **********************************************)

Pascal-VU compiler

Where the Pascal-U compiler (1976) implements a subset of Standard Pascal, Pascal-VU (1979) implements full ISO Standard Pascal.

The Pascal‐VU compiler produces code for an EM1 machine. There does not exist a hardware EM1 machine. Therefore, EM1 programs must be interpreted, or translated into instructions for a target machine. The following implementations exist:

  • an interpreter running on a PDP‐11 (using UNIX‐6). Normally the interpreter performs some tests to detect undefined integers, integer overflow, range errors, etc. However, one of the options of the interpreter is to skip these tests.
  • a translator into PDP‐11 instructions (using UNIX‐6).

Pascal-VU June 1980 si afound on a tape dump https://www.tuhs.org/Archive/Applications/Shoppa_Tapes/usenix_80_delaware.tar.gz in the folder ‘tanenbaum’.

The header of the Pascal-VU compiler source

program pem(input,output,em1);
{This Pascal compiler  produces EM1 code as described in
   - A.S.Tanenbaum, J.W.Stevenson & H. van Staveren,
	"Description of a experimental machine architecture for use of
	 block structured languages" Informatika rapport xx.
  A description of Pascal is given in
   - K.Jensen & N.Wirth, "PASCAL user manual and report", Springer-Verlag.
  Several options may be given in the normal pascal way. Moreover,
  a positive number may be used instead of + and -. The options are:
	a:	interpret assertions (+);
	c:	C-type strings allowed (-);
	i:	controls the number of bits in integer sets (16);
	l:	insert code to keep track of source lines (+);
	o:	optimize (+);
	r:	check subranges (+);
	s:	accept only standard pascal programs (-);
	t:	trace procedure entry and exit (-);
	v:	produce code for 24 bit addresses (-);
}
{===================================================================}

Downloads

Pascal-VU Reference manual, 1979
Pascal-VU Reference manual V2
seems to be a later version
Pascal-VU June 1980 tape archive + text files
Pascal-VU compiler test programs
Source of Pascal-VU compiler
Source of Pascal-VU compiler EM.h
Pascal-VU reference manual
ISO standard compliance reference
Description of EM1
Version of 2 March 1979

Pascal and the Vrije Universiteit

The Computer Science department of the Vrije Universiteit in Amsterdam is where I learned about programming.
In Pascal, as was usual in those years. Here my interest in compiler writing started, since there was a lot of work done on that subject there. Recursive descent down Wirth compilers, magic!

The first VU Pascal compiler was Pascal-U, initiated by van de Riet, based of course on Wirth’s portable Pascal compiler/interpreter.

Once this compiler was operational on a Unix PDP-11/45, a Pascal interpreter system was developed called BASIS, to help students do practical programming work.

Two Pascal compiler sources have been found by Stefano B. on archived tapes, with files sent out by the Computer Science department of the VU to other universities:

  • Pascal-U July 1977 on tape https://www.tuhs.org/Archive/Applications/Usenix_77/ug091377.tar.gz
  • Pascal-VU June 1980 on tape https://www.tuhs.org/Archive/Applications/Shoppa_Tapes/usenix_80_delaware.tar.gz

On the next pages details of these compilers can be found:

My personal story about the VU Pascal compilers and the time spent in the Computer Science department

In 1978 I choose to do Computer Science as part of my Math and Physics MSc study. I had some experience with a PDP-11 (with papertape, Fortran). And bought a KIM-1 SBC and did some assembler programming. But I wanted to be a professional programmer with a solid theoretical base. And that is what I found in the new and emerging CS faculty. I met Professor Reind van de Riet and enrolled in the program. Exams, a lot of practice with good support by the staff and a MSc as result!
Two educators there taught me about programming: Professor R.P. van de Riet, and, the then young and later so famous, Professor Andrew S. Tanenbaum. Jim van Keulen was excellent in judging the practical assignments. Professor van het Riet advised me to buy “Algorithms + Data Structures = Programs” by Niklaus Wirth. I learned so much from that book!


I wrote my first programs with BASIS, running on the PDP-11/60, typing on a DEC LA120 printer terminal. Still have some print out. Ruud Wiggers did most of the programming of the Basis system.

VU100

In March 1980 Professor van de Riet asked me to write an article for the VU100 Computerkrant, a publication for the computer show at the VU during the 100 year celebration of the University. about hobbycomputers, as I was his student and editor of the computer magazine Radio Bulletin.


Pascal-U

The Computer Science department of the Vrije Universiteit in Amsterdam is where I learned to program.
In Pascal as was usual in those years. Here my interest in compiler writing started, since there was a lot of interest in that subject there.
Two educators there taught me about programming: Professor R.P. van de Riet, and, the then young and later so famous, Professor Andrew S. Tanenbaum.

The first VU Pascal compiler was Pascal-U, initiated by van de Riet, based of course on Wirth’s portable Pascal-P2 compiler/interpreter.

Once this compiler was operational on a Unix PDP-11/45, a Pascal interpreter system was developed called BASIS, to help a student do practical programing work.

Pascal-U July 1977 can be found in a folder called ‘vrije’ on the tape dump at https://www.tuhs.org/Archive/Applications/Usenix_77/ug091377.tar.gz

Header of the Pascal compiler

(*version: 004      date: 1-5-77*)
(*--------------------------------------------------------------
|                                                               |
|       P A S C A L   C O M P I L E R                           |
|       -----------------------------                           |
|                                                               |
|   This compiler processes PASCAL-U1, a subset of              |
|   of standard PASCAL and has been written in this subset.     |
|   It is a modified version of the PASCAL-P2 compiler as       |
|   distributed by the ETH at Zuerich.                          |
|                                                               |
|   Authors:                                                    |
|      Urs Amann, Kesav Nori, Christian Jacobi                  |
|                                                               |
|   Authors of modification:                                    |
|      Rudolf van Bottenburg, Johan Stevenson                   |
|       Vakgroep Informatica                                    |
|       Wiskundig Seminarium                                    |
|       Vrije Universiteit                                      |
|       A M S T E R D A M                                       |
|                                                               |
---------------------------------------------------------------*)

Downloads

Source of Pascal-U compiler
User manual of the Pascal-U compiler
Archive of Pascal-U compiler
Source and man pages and binaries for Unix System 6

Note that the archive contains the source of the compiler, but not of the interpreter.

First part of the Pascal-U manual

PASCAL‐U is the name of the dialect of Pascal implemented on the PDP 11/45 under
the UNIX time‐sharing system.  This dialect is based on PASCAL‐P as  distributed
by  the ETH at Zurich.  The implementation of PASCAL‐U has been developed by the
vakgroep informatica of the  Vrije  Universiteit,  Amsterdam,  The  Netherlands.

                                 2.Some history
                                 ‐‐‐‐‐‐‐‐‐‐‐‐‐‐
The  first  plans  to implement Pascal on the PDP 11/45 were developed under the
guidance of prof. R.P.van de Riet. In those days (mid 1975) the operating system
was  DOS,  a  single user system.  The greatest problem has been the limited ad‐
dress space of the machine.  The Pcompiler produces code for a virtual  machine,
called  the  SC  machine.  Macro expansion of SC instructions to PDP‐11 code was
not feasible due to the addressing limit of the PDP‐11.  Therefore  the  SC  in‐
structions were directly encoded and an interpreter was written to execute them.
The following description concerns work carried out by Rob Thomas, Johan Steven‐
son and later on by Rudolf van Bottenburg.  The first bootstrap used a CDC Cyber
73 computer on which Pascal was available.

At the end of 1975 a preliminary version was running under  DOS.   Many  changes
have  been  made to the PASCAL‐P2 compiler, most of them forced by the different
size for variables of the various standard  types  and  the  address  alignment.
(The  Pcompiler foolishly assumed that integers,reals etc. all occupied the same
number of storage units.)  At the same time, however, the UNIX time‐sharing sys‐
tem  was  installed. That required adjusting the Pascal system.  The interpreter
was rewritten in the UNIX assembly language, and the SC assembler  in  the  high
level language C.

To  minimize  the  space  requirements, some changes were made to the first UNIX
version:
a.based upon static counting of SC‐instructions in the compiler itself, some in‐
  structions of 2 or more bytes with a high frequency got a 1‐byte format.  This
  is not done very systematically, however. Further measurements are needed.
b.a lot of optimization is done concerning label references: offsets instead  of
  indices, distinction between forward and backward, long and short offsets.
c.the handling of input and output is improved.
This  resulted in a 25% saving in space for code, while at the same time the in‐
terpretation speed improved.  The 16000 SC‐instructions for the compiler  itself
are  coded in less than 26000 bytes, inclusive constants.  This system is called
the PASCAL‐U1 system.

One of the projects under development in our department, is the BASIS system. It
is  used  in teaching basic programming techniques to students of several disci‐
plines. BASIS is a big program written in Pascal, in size  comparable  with  the
Pcompiler.  One  of  the  reasons to make Pascal available on the PDP 11/45, has
been this BASIS project.

The plans for the near future are:
a.to adopt the improvements of the P4‐compiler with respect to the P2‐compiler.
b.to allow external procedures.
c.to allow the Pascal user to choose between interpretation and execution of ex‐
  panded  SC‐instructions.  For example, one would like to make the scanner of a
  compiler fast by execution of its expanded code and leave the other parts  in‐
  terpreted,  since for most programs 20% of the program is responsible for more
  than 80% of its execution time.
d.to make some local improvements touched upon in the assembler description.
e.to tune the instruction set of the abstract machine.

    

MAN page for the PASCAL-U compiler



PC(I)                       03/05/77                        PC(I)


NAME
       pc ‐ PASCAL‐U compiler

SYNOPSIS
       pc [‐lpc12rx] file.p [arg1 ...]

DESCRIPTION
       pc  is  the  UNIX pascal compiler. It has an optional flag
       argument.
       If  no  flags are given, pc compiles the program on file.p
       and leaves the bsc‐code on file.b. Diagnostics are written
       to  standard  output.   The effect of the flags is as fol‐
       lows:

       ‐l   produces a complete listing of the program with error
          indications and explained error messages.

       ‐p  makes a partial listing. Only the erroneous lines  are
          listed.

       ‐c  suppresses code generation, does a syntax and semantic
          check only.

       ‐1 performs pass1 of the compiler, leaves the intermediate
          (sc) code on file.i .Pass2 is suppressed, unless the ‐2
          flag is given.

       ‐2 executes pass2 of the compiler and leaves interpretable
          bsc‐code  on  file.b.   If given without the ‐1 flag it
          expects its input on file.i rather than file.p.

       ‐r  runs  the  compiled program by calling the interpreter
          with file.b as codefile.  Arguments given after  file.p
          are passed.

       ‐x invokes sc‐code expansion.(not yet implemented)

       After  an error is detected during pass1, the code generation
       is suppressed.

       The main differences from standard PASCAL are:
       1. The  program has no other file than those in  the  pro‐
          gram heading, which have type text.There may be at most
          eight files, including the predeclared files input  and
          output,  which  are  associated with standard input and
          output.

       2. Formal  parameters must not be functions or procedures.

       3. All  records are packed. The procedure  unpack  is  not
          available.

       4. The  maximum length of string constants is 80.

       5. The  ordinal value of a set element  must lie between 0

                              ‐ 1 ‐


PC(I)                       03/05/77                        PC(I)


          and 63 inclusive.

       6. A  goto  may  not lead out of a  procedure  or function
          body.

       7. After  reset a call of  get is  necessary to initialize
          the buffer of a non‐standard inputfile.

       8. The procedure dispose is not available.  Mark  and  re‐
lease             are  added  to  manipulate  the  heap:
mark(anyptr)          puts the top of  heap  address  in  anyptr.
            release(anyptr)     restore  the  top  of  heap  from
anyptr.


FILES
       file.p  source file
       file.i  intermediate sc‐code
       file.b  bsc‐code, interpretable by pi.
       /lib/ppass1 pass1
       /lib/ppass2 pass2
       /lib/pclist error diagnostics
       /usr/bin/pi interpreter

SEE ALSO
       pi (I), PASCAL‐U1 documentation, PASCAL user manual.

DIAGNOSTICS
       The  diagnostics  are  intended  to  be  self‐explanatory.
       "Memory Fault" may be given if space is exhausted.

BUGS
       Reals can only be written  in  E‐format.   Runtime  checks
       are   not  implemented.   Omitting the filename in read or
       write may give problems.  Empty fields in records and empty  
       statements  can give messages.  Writeln and readln require 
       always a parameterlist .

                              ‐ 2 ‐
    

MAN page for the PASCAL-U interpreter

PI(I)                                                    12/22/76


NAME
       pi   ‐   the PASCAL‐U interpreter


SYNOPSIS
       pi    bscfile   userfile1 ....


DESCRIPTION
       The  binary  stack computer code (BSC) is read  from  bsc‐file.  The
       userfiles  are expected to be the actual  file  parameters to  be
       substituted for the formal file names given in the  pascal program
       heading.   Standard  output and standard input are substituted  for
       the formal names output and input.  The order of the arguments is
       assumed to correspond with the order of the remaining formal file
       names.


SEE ALSO
       pc(I), PASCAL‐U1 documentation, Pascal user manual


DIAGNOSTICS


       All error messages are self explanatory.  A  memory  fault 
       can also indicate: no room left

    

Apple Lisa Pascal

APPLE LISA COMPUTER PASCAL


The 68000-based Lisa computer (1979 – 1985) was unique in that the majority of its system and application software was written in a powerful extended version of Pascal called Lisa Pascal. This software included the operating system (90^000 lines), the Workshop development environment (100,000 lines), 7 application programs (each around 50.000 lines [e.g. LisaWrite, LisaCalc]), and an avalanche of development support programs (e.g. mouse-based editor, telecommunications program, and Pascal language utilities).

Apple’s Lisa Pascal developments began from scratch for Apple when it licensed in 1981 a Motorola 68000 native code Pascal compiler from Silicon Valley Software in California. This compiler was based upon the older P4 compiler from Niklaus Wirth of ETH in Switzerland and consisted of two general passes. Pass 1 produced I-Code, a low-level representation of the high-level Pascal constructs. Pass 2, the code generator, converted the I-Codes to optimized 68000 object code. Apple even considered early in the Lisa’s development using a custom Apple processor which would execute P-Code directly, but the expense of developing such a chip was too much for Apple’s accountants and this project was dropped.

All Lisa development was done with the Lisa Workshop, a command line based development environment similar to Apple’s earlier ][ and /// Pascal systems. The Workshop provided an excellent development environment with its Pascal compiler, mouse-based editor, 68000 assembler, and an extensive collection of utility programs (e.g. Format, XRef, ProcNames). The Workshop supported other languages which included BASIC, COBOL, and C.

Apple produced several versions of Lisa Pascal: 1.0, 2.0, 3.0. Version 3. was the last version and supported the creation of intrinsic units which allowed a single copy of a unit to exist in the system and be used by several programs simultaneously. All versions supported language extensions such as otherwise clause in case statements, longint 32 bit integers, § operator for data addresses, data type coercion, and relaxed ordering of const/type/var sections. A lot of bit-based -functions were also
supported (e. g. BITAND to make bit bashing easier. Inline 68000 assembly code could also be used.

Like the Apple /// Pascal, Lisa Pascal also supported SANE, Apple’s IEEE floating-point implementation. In addition to SANE Apple developed a fairly comprehensive math package called MathLib.
Apple also developed an IEEE floating-point test program which attempted to ring out the bugs in SANE (Jerome Coonen of Apple wrote this test program and its associated test vectors).

Lisa Pascal was a superset of Apple’s older ][ and /// Pascals and, as such, was able to compile ][ and /// Pascal programs which did not make any ][ or /// system calls. Lisa Pascal could also produce a compilation listing complete with the Pascal source code interleaved with the generated 68000 assembly statements.

Apple also developed the Lisa QuickDraw (a. k. a. LisaGraf ) graphics library which formed the heart of what was called Lisa Technology. Though written in 68000 assembly^ Apple provided an extensive Pascal interface to this rather remarkable graphics environment (QuickDraw was later patented by Apple and Bi11 Atkinson. QuickDraw’s creator).

When Apple introduced the Macintosh computer in 1984 all Macintosh programming by Apple and others was done with Lisa Pascal and the Lisa Workshop. For this activity Apple created an extensive set of libraries containing the Macintosh toolbox interfaces. Many important Macintosh programs were written in Lisa Pascal, including MacPaint, MacWrite, MacDraw, and MacTerminal.

The key players behind Lisa Pascal were Ira Rubin and Al Hoffmann.
Apple provided extensive documentation for the Lisa Workshop and Lisa Pascal which included a language manual, an operating system manual, and a Workshop manual. Many internal memos were also released by Apple which described special features of Lisa Pascal.

Lisa Pascal was also used by Apple to develop the Lisa Clascal object-oriented language and the Clascal-based Toolkit class library.

Apple discontinued the Lisa in 1985 in favor of the Macintosh and when Apple’s native Macintosh development environment (MPW) became operational in 1986 Apple dropped support for Lisa Pascal and the Lisa Workshop. Therefore, Lisa Pascal lasted from 1981 to 1986, an eternity in the field of microcomputer languages.

APPLE LISA COMPUTER CLASCAL
Apple’s first foray into the world of object-oriented programming was with the Lisa Clascal (Classes + Pascal) language. Developed from 1983 to 1985 Clascal was an extension of Lisa Pascal which included several new keywords such as methods and subclass. The main concepts behind Clascal were derived from Simula and Smalltalk. Xerox PARC’s experimental object-oriented language.
In addition to Clascal Apple also developed an extensive set of class libraries which were collectively called the Lisa Toolkit. This class library allowed Lisa developers to create Lisa desktop applications (a. k. a. tools) in a fairly short time frame.

Though really used only internally by Apple for its own research efforts Clascal was made available to external developers but without any support by Apple (David Redhed of Seattle Washington created an independent Clascal/Toolkit support group called the Toolkit User’s Group [TUG], but this unfortunately did not last too long). Apple considered enhancing ClascaL but this Clascal-85 effort was extinguished by Apple’s work with Object Pascal for the Macintosh.
Several significant programs were developed with Clascal and the Toolkit including a calendar program, Apple’s Lisa-to-tlacintosh data conversion program, a desktop publishing program, and a fuzzy logic program.
The key player behind Clascal was Larry Tesler, one of the Lisa computer’s designers, and several former Xerox Smalltalk experts.

When Apple dropped all support for Clascal and the Toolkit it provided the Toolkit source code to the public, but the source code to the Clascal compiler was, alas, not made public.

Apple Lisa Pascal compiler sources

I found an archive with the source of the early Lisa Pascal by Silicon Valley Software.

The archive contains images of Lisa disks in dc42 format. In these disk images are the sources (and more) of the Silicon Valley Software Pascal compiler for the Lisa.

The archive, together with sources of the Lisa Operating system and relevant manuals is available here.
The sources are available as original disk images, in Lisa Pascal TEXT and OBJ file format and, with a utility I wrote, in plain text file format.

post

Apple Lisa Pascal sources

On this page:

  • Apple Lisa Pascal and Silicon Valley Software Pascal
  • Apple Lisa Operating system sources
  • Apple Lisa Pascal Compiler sources, converted to plain text files
  • Downloads

Apple Lisa Pascal and Silicon Valley Software Pascal

Apple Lisa Pascal started as a buy in of the Silicon Valley Software (SVS) Pascal compiler. And maintained/expanded the compilers you can read in the sources.
SVS continued selling Pascal compilers, in the manuals you can read references to versions for CP/M and more.

The compiler does multiple passes over the source. An intermediate cod representation is produced, an optimizing code generator produces 68000 object code, a final linker step combines object codes, also from assembler, to a program.

This dialect of Pascal enhanced the language quite a bit. Examples are Units with INTERFACE and IMPLEMENTATION parts. File I/O is not limited to text files, SEEK, BLOCKREAD and BLOCKWRITE are present. String manipulation such as DELETE , COPY INSERT. EXIT, HALT for program control.
Lisa Pascal was not object oriented, that was left to Clascal and Object Pascal later. It was also not an USCD Pascal variant, but developed independently. Clearly based upon the “Wirth School of compilers” but made very practical, with ideas from USCD Pascal, to use as tool for Operating System development.

Apple Lisa Operating system sources

Apple has released recently sources in Lisa Pascal and assembler source format of the Lisa Operating system. The files are in text format. See the Downloads below. Note that the compiler sources refer to files in the operating system archive.

Apple Lisa Pascal Compiler sources

I found an archive with the source of the Lisa Pascal compiler by Silicon Valley Software.
The archive contains images of Lisa disks in dc42 format. In these disk images are the sources (and more) of the Silicon Valley Software 1981 Pascal compiler, maintained by Apple for the Lisa, last updates in these sources 1984 .

Andy McFadden (of Ciderpres fame) analyzed this and advised me to read these disk images on a MacIntosh (10.11 or later) with AppleSauce software, showed me in the following screenshot:
. Thanks to @applepc on Mastodon also!
I installed High Sierra in a Virtualbox and loaded AppleSauce.Using Disk Analisys of the dc42 disk images and exporting delivered exact copies of the files as they are stored in the Apple file system, in Apple Lisa TEXT format.
This format is described in the Apple Lisa documentation (see the Bitsavers archive of Lisa documents) and it was not difficult to write a program to strip the Lisa artefacts and deliver a clean plain ASCII text file. All included in the downlaods below.

Manuals

Lisa Pascal 3.0_Reference Manual 1984
Pascal Reference Manual 1983
Lisa Develpment System Internals Documentation 1984
SVS_Pascal CP/M68K September 1983

Downloads

Lisa Operating system archive in plain Unix text files
Archive with dc42 disk images of Apple Lisa Pascal Compiler
Compiler sources and objects exported files in Lisa TEXT format from dc42 disk images made with AppleSauce
Apple Lisa Pascal compiler sources in plain txt format, with tool to create from TEXT files

Amsterdam Compiler Kit

The last Pascal compiler developed at the Vrije Universiteit is the Pascal compiler in the Amsterdam Compiler Kit.

The Amsterdam Compiler Kit, ACK, is a venerable piece of software that dates back to the early 1980s. It was originally written by Andrew Tanenbaum and Ceriel Jacobs as a commercial product; for many years it was also used as Minix’ native toolchain. After eventually failing as a commercial project, it was made open source under a BSD license in 2003 when it looked like it was going to be abandoned and the code lost.

The ACK contains compilers for ANSI C, K&R C, Pascal, Modula-2, Occam 1, and a primitive Basic. It contains code generators for a large number of architectures, mostly 8 and 16 bit machines; there are also a set of generic optimisation, linker and librarian tools. Each language comes with its own runtime, so if you’re a C programmer you also get a libc. Compared to gcc, it is far smaller, faster and easier to port.

The ACK is still maintained by David Given at https://github.com/davidgiven/ack

It clearly shows that the base of the ACK was laid by the implementation of the Pascal-VU compiler as compiler to code for the virtual EM machine, evolved over time to suit the ACK.

Description of an Experimental machine
Architecture for Block Structured Languages

Wiskundig Seminarium Rapport IR-54 April 1980
The virtual machine for the Pascal-VU compiler
Using Peephole Optimization on Intermediate Code
Januari 1982
A Practical Toolkit for making Portable Compilers
September 1983
Efficient Encoding of Machine Instructions
Does anybody out there want to write HALF of a compiler?
The EM interpreter, 1983
Description of a Machine Architecture for Use with Block Structured Languages
Informatica Rapport IR81, 1983
The ACK Pascal Compiler
ACK EM Pascal source
ACK: A backend table for the 6500

Pascal-M 2k1

Pascal-M 2K1

Pascal-M Compiler Linker Disassembler Loader system
Hans Otten, November 2021 Version 0.9
Applicable license: MIT license. Permission given by Mark Rustad.

Note that this version is still beta quality! Your feedback is appreciated!
Contents

Downloads for Windows, Ubuntu and Raspberry PI OS:
Pascal-M 2K1 programs
Pascal-M 2K1 sources

How the Pascal-M system works

The Pascal-M system will let you write Pascal programs and execute them on the 6502, e.g. the KIM-1 or the console of the PC.
The Pascal dialect is standard Pascal (no reals for example) as described in the second edition of ‘The Pascal User Manual and Report’. It can (could in older versions!) compile itself.

To get a Pascal program running on the KIM-1 the Pascal-M 2K1 system requires the following steps.

  1. Edit Write the text of the Pascal program
  2. Compile Repeat 1 and 2 until no compilation errors
  3. Load Convert the object M-code of the compiler output to binary code
  4. Link Combine the compiled binary and the 6502 interpreter to an executable KIM-1 program
  5. Run Load the Papertape file on the KIM-1 and run it

How to use

Step 1: Write a Pascal program with any text editor on your PC, create ASCII text files.
Save the Pascal source with extension .pas, and keep the editor open. I use Notepad++ on Windows, any editor will do.
Step 2 – 4: Start the PascalM2K1 program, a GUI program, and fill in the name of the Pascal source.
Press Compile and if the Pascal-M compiler sees no errors goto step 3 and press Load else go back to the editor.
Note the load address is needed to tell where the code should go in memory, the default is fine for now.
See the section on ‘Memory layout’.
Step 4 requires to fill in the name of the binary of the 6502 interpreter (default pascalmint2k1.bin, make sure it is found).
Also fill in the name you want for the 6502 program (Binary, a papertape version is produced also).
Fill in the upper memory RAM limit in your KIM-1. the default is for 32K RAM above $2000, max is $9FFF.
Press Link.
Step 5: Take the papertape file via a terminal emulator to the KIM-1 (in TTY mode) and run it from start address $2000

The example file test.pas contains the source:

program ctest ;

begin

  writeln('hello world') ;
  
end.

During the steps of PascalM2k1 many files are produced. If for example you start with helloworld.pas and finally link to runhelloworld.bin the following files will be present:

  • helloworld.pas The Pascal source program you have written
  • helloworld.lst Listing of the source program with compilation results
  • helloworld.obp Px code representation of the Mcode
  • helloworld.err Every step produces a file with the status, error or success.
    Also shown in the status field in PascalM2k1
  • helloworld.bin The Mcode loaded into a binary
  • helloworld.prc The Procedure table binary
  • helloworld.dlst The disassembled Mcode, see the Debug section
  • runhelloworld.bin The runnable program binary
  • runhelloworld.pap The MOS papertape version of he runnable program.

You will only have to keep the helloworld.pas and the resulting program runhelloworld.bin and pap, the others can be made again.

Command Line Utilities

The steps described above for PascalM2k1 can also be done with command line utilities. No argument given will prompt for answers.
Help given with -h. Functionality and steps identical to the PascalM2K1 program. Same files produced.

  • cpascalm2k1.exe Pascal-M compiler V2k1
    Syntax:
    cpascalm2k1 <sourcefile> [V]
    produces sourcefile.err (status) and sourcefile.obp (object) files
    V shows errors on console
  • cpascalmload.exe Loader for Pascal-M 2K1
    Syntax:
    cpascalmload <objectfile>[<loadaddress in hex>]
  • cpascalmlinker.exe Pascal-M linker 2K1
    Syntax:
    cpascalmlinker <binfile from loader> <start adress> <interpreter binary><binary startaddres> <linked program file> <upper memory>
  • cpascalmdis.exeDisassembler for Pascal-M 2K1, see the Debug section
    Syntax:
    cpascalmdis <objectfile> <loadaddress in hex>


Pascal-M limitations

Pascal-M is close to standard Pascal, but there are limits due to the P2 origin (close to the second ‘Pascal User Manual and Report’,
recommended as description for Pascal-M) and the limitations to make a small compiler for an 8 bit target.
When you read the compiler source (pascalmcompiler.inc) you will see it is a real language, and can compile itself
(if you strip all enhancements made by me, see SMPASCAL.PAS on the website for the last version that compiles on the KIM-1!)).

This list sums up the important limitations:

  • Identifiers are unique in the first 8 characters
  • No reals
  • Only text files (7 max)
  • 16 bit integers
  • max store size 32768 bytes
  • set max 63 members
  • max 100 procedures/functions, call depth max 12

Memory layout

A Pascal-M program requires RAM from $2000 and up.
The upper limit is variable and can be maximum $DFFF.
The memory layout of a Pascal-M 2K1 system is:

Interpreter start  $2000 - $2F00 : Pascal-M 6502 interpreter
                   $2F00 - $2FFF : procedure buffer 
Load address       $3000 - + size of M-code
                  .
                  .
          heap growing up
                  .
                  .
          stack growing down
                         - $9FFF = Upper memory 
                           (can be $DFFF for a 48K system) 

The interpreter starts at $2000, point the monitor there and Go. After the Jump the memory layout is found: first location of M-code (default $3000), end of memory (default $9FFF) and end of M-code/start of heap (dependent on the size of the M-code).
The linker fills these addresses.

Console interpreter and debugger

cpascalmint2k1.exe is a command line Mcode interpreter and debugger.
Syntax:
pascalmint2k1 [<name of Mcode object>] [debug]

Without the optional debug parameter the Mcode program is executed:

D:\myfiles\development\PascalM\PascalM2k1\pascal interpreter&amp;amp;gt;pascalmint2k1.exe test.obp
hello world

With the debug parameter a command line drive debugger is started. Use also the Mcode disassembly output to see what is happening in the Mcode machine.

D:\pascalmint2k1.exe test.obp debug
Program ctest    Loaded

PC    = 7CFC
M-Debug &gt;?

Available debug commands :

  B = Breakpoint commands
  C = Show stack contents
  D = Display store
  E = Show stack contents
  G = Continue without debugger
  H = Show heappointer
  I = Insert in store
  M = Show markpointer
  N = Next instruction executed
  P = Show programcounter
  S = Show stackpointer
  T = Show procedure table
  X = Exit interpreter

PC    = 7CFC
M-Debug &gt;
Break subcommand &gt;?

Available Break commands :

  C = Clear all breakpoints
  D = Show  all breakpoints
  S = Set breakpoint


Compiling and building the programs from source

Prerequisites

  • A modern PC and operating system. Windows 10 is where the software has been developed, Raspberry OS /Linux have seen limited tested for now. MacOS may work, untested
  • Development (Compile and run everywhere!) with Freepascal and Lazarus IDE (2.x) see https://www.lazarus-ide.org/
    Any version above 2.0 will be OK, No OS dependent functions are used a.f.a.i.k.
  • The archives with the KIM-1 Simulator sources PascalM2k1sources.zip (or higher version).
  • Unpack in a folder, avoid blanks in folder and filenames
  • Start the IDE by clicking on the relevant .lpi file.
  • Build with Run – Build

The system is made up of main programs that ‘include’ the actual functionality. This way the command line utilities and the GUI pascalM2k1 share the code.
If a change is made to an .inc file both vcalling programs may need attention and tests.
No extra components are used, standard Lazarus will do.
Note that the ‘mode’ of the units is important, the compiler needs mode $delphi.

The 6502 interpreter is living in the folder 6502interpreter.
No special assembler syntax is used, TASM 32 bit for Windows command line is included.

tasm -65 pascalmint2k1.asm -b pascalmint2k1.bin
TASM 6502 Assembler.      Version 3.2 September, 2001.
 Copyright (C) 2001 Squak Valley Software
tasm: pass 1 complete.
tasm: pass 2 complete.
tasm: Number of errors = 0

will produce the pascalmint2k1.bin file required

Port to other systems

The Pascal-M system is easy to port to other systems. Another 6502 system is quite easy, adaptations on the assembler source will be:

  • Character I/O, replace the KIM TTY in/out (note the ‘echo’ adaptation, so no hardware echo on the KIM-1!) with the relevant character I/O routines of the new target
  • Take look at the memory layout of the new target, adapt lower and upper memory address in use. It is possible to let the interpreter be independent in memory from the M-code.
    The Pascal-m2K1 does not support this, you will have to manage the binary files and memory management in the interpreter yourself

Another platform is a bit more work. Use an assembler or compiler, the interpreter needs to be written for the new target. Take the Pascal interpreter as example, it is well documented.

Introduction and history

How I spent 40 years on getting so far ….
Pascal-M is the name of the Pascal compiler written by Mark Rustad, around 1977.
It was based (and mostly identical) to the portable P2 Pascal compiler, from the ETH Zurich group led by Niklaus Wirth.
The Px Pascal compilers are portable compiler-interpreters, quality compilers and easy to adapt interpreter to new hosts.

The adaptations by Mark Rustad were in the code production, the M-code is byte oriented and more efficient in memory demands.
File I/O was stripped as was floating point. Only chars, integers 16 bit and booleans. Uppercase only. Input/output was for a teletype, so input was either the keyboard or a HSR (High Speed Reader), output a printer or a HSP( High Speed Punch) via a software
switch.
Mark Rustad told me he ported the compiler to 6800 and 6809. G.J. van der Grinten did work on the interpreter part for the KIM-1 and wrote a 6502 interpreter.
The Micro Ade editor was adapted to produce Pascal text files.

In 1978 I received from the KIM Club in the Netherlands a version of this Pascal-M system, consisting of a KIM-1 tape with the compiler and interpreter and Micro Ade,
listings of the compiler (in Pascal), preliminary M-code description, the interpreter (in 6502 assembler) and the Micro Ade patches.
It was never made into a product for the KIM club, it was a nightmare to use. From entering text to running a program, all from audio cassette files, it took around an hour.
The old days of papertape and cards were gone already. But the time of cross-compiling or floppy drives connected to the KIM-1 was not there yet.
I got no further than a ‘Hello world’ program once and gave up.

In 1983 I started typing in the source on a PDP-11 with RSX-11M Pascal. And moved on to VAX/VMS with the excellent VMS Pascal. After some years I had the compiler, an interpreter
written in Pascal with debugger and the original 6502 interpreter on tape. This system produced for the second time, in 1986, a running ‘Hello world’ on the KIM-1.
I started expanding the compiler, bringing back P2 functionality like file handling, text files are now supported. Lowercase also. Bugs fixed.

But then I bought a CP/M system and the KIM-1 was put aside. Pascal-M forgotten for several years, Pascal compiler technology not.

I came back in MS-DOS times to the Pascal-M system with the compiler running as a Turbo Pascal (1994, 2003). Then Delphi arrived and the Pascal-M system was brought to live again as Delphi console applications.
In 2020 this was compiled in Freepascal, the compiler was cleaned up (and the original source restored also).

And now in 2021 a Lazarus shell around the steps required to produce a working program was programmed. The 6502 interpreter was finally assembled from source again.
Pressing a couple of buttons is now all it takes to produce a program running on the KIM-1 (and as console on the PC).
The command line utilities are refreshed also. So a ‘Hello World’ takes a a couple of minutes from source editing to running on the KIM-1 (Simulator).
The motivation for the KIM-1 Simulator was mostly for being able to test the Pascal-M system!

Error messages from the compiler

     2 Syntax: identifier expected             
     3 Syntax: Program expected                
     4 Syntax: &quot;)&quot; expected                    
     5 Syntax: &quot;:&quot; exepected                   
     6 Syntax: illegal symbol                  
     7 Syntax: actual parameter list           
     8 Syntax: OF expected                     
     9 Syntax: &quot;(&quot; expected                    
    10 Syntax: type specfication expected      
    11 Syntax: &quot;[&quot; expected                    
    12 Syntax: &quot;&quot; expected                    
    13 Syntax: end expected                    
    14 Syntax: &quot;;&quot; expected                    
    15 Syntax: integer expected                
    16 Syntax: &quot;-&quot; expected                    
    17 Syntax: begin expected                  
    18 Syntax: error in declaration part       
    19 Syntax: error in field list             
    20 Syntax: &quot;,&quot; expected                    
    21 Syntax: &quot;*&quot; expected                    
    50 Syntax: &quot;error in constant              
    51 Syntax: &quot;:=&quot; expected                   
    52 Syntax: then expected                   
    53 Syntax: until expected                  
    54 Syntax: do expected                     
    55 Syntax: to/downto expected              
    56 Syntax: if expected                     
    58 Syntax: ill-formed expression           
    59 Syntax: error in variable               
   101 Identifier declared twice               
   102 Low bound exceeds high-bound            
   103 Identifier is not a type identifier     
   104 Identifier not declared                 
   105 Sign not allowed                        
   106 Number expected                         
   107 Incompatible subrange types             
   110 Tag type must be an ordinal type        
   111 Incompatible with tag type              
   113 Index type must be an ordinal type      
   115 Base type must be scalar or subrange    
   116 Error in type of procedure parameter    
   117 Unsatisfied forward reference           
   118 Forward reference type identifier       
   119 Forward declared : repetition par. list 
   120 Function result: scalar,subrange,pointer
   122 Forward declared: repetition result type
   123 Missing result type in function declar. 
   125 Error in type of standard function par. 
   126 Number of parameters disagrees with decl
   129 Incompatible operands                   
   130 Expression is not of SET type           
   131 Test on equality allowed only           
   132 Inclusion not allowed in set comparisons
   134 Illegal type of operands                
   135 Boolean operands required               
   136 Set element must be scalar or subrange  
   137 Set element types not compatible        
   138 Type must be array                      
   139 Index type is not compatible with decl. 
   140 Type must be record                     
   141 Type must be pointer                    
   142 Illegal parameter substitution          
   143 Illegal type of loop control variable   
   144 Illegal type of expression              
   145 Type conflict                           
   147 Case label and case expression not comp.
   148 Subrange bounds must be scalar          
   149 Index type must not be an integer       
   150 Assignment to standard function illegal 
   152 No such field in this record            
   154 Actual parameter must be a variable     
   155 Control variable declared interm. level 
   156 Value already as a label in CASE        
   157 Too many cases in CASE statement        
   160 Previous declaration was not forward    
   161 Again forward declared                  
   169 SET element not in range 0 .. 63        
   170 String constant must not exceed one line
   171 Integer constant exceeds range(32767) 
   172 Too many nested scopes of identifiers   
   173 Too many nested procedures/functions    
   174 Index expression out of bounds          
   175 Internal compiler error : standard funct
   176 Illegal character found                 
   177 Error in type                           
   178 Illegal reference to variable           
   179 Internal error : wrong size variable    
   180 Maximum number of files exceeded