Cross compilation Pascal-M 1978

Some programs here to aid cross compilation for the Pascal-M 1978 compiler, for example to the KIM-1. A cross compiler, a binary loader and a m-code disassembler.
All programs described here come with a Lazarus project and the program source file, which can be compiled on any platform that supports Freepascal . Downloads at the bottom.

Cross compiler V1.0

crosspascalm1978 is essentially the Pascal-M 1978.PAS V1.0 compiler, adapted to compile as command-line application with a standard Pascal compiler (such as Freepascal).

Adaptions are:
– file I/O added, writes to two files and console
– reads Pascal from a textfile  <filename> .pas
– delivers an <filename>.OBP file with PX records
– a <filename>.ERR file with compilation errors if found

– command line arguments:

Pascal source file to compile, <filename> .pas if not given it prompts for the Pascal file to compile.

The cross compiler is essentially the same as the Pascal-M 1978 compiler:
– accepts only uppercase
– Pascal-M subset of standard Pascal, even a subset of the P2 compiler: 16 bit integer, no reals, no file I/O, no GOTO.
– generates exact the same code, including the non-standard external Pascal procedure like TTYIN etc
– can be used to compile any valid Pascal-M program including the Pascal-M 1978 compiler itself.

The Pascal-M compiler delivers a textfile,  a Px record file <filename>.OBP. To interpret this you need a loader to ‘assemble’ the M-code into a binary, see below for the pascalmbinloader.

Example session

D:\myfiles\Pascal-M\1978 KIM-1\bootstrap pascal-m&gt; crosspascalm1978.exe
Pascal-M cross compiler V1.0
Pascal file to compile&gt; test.pas
No errors in test.pas

D:\myfiles\Pascal-M\1978 KIM-1\bootstrap pascal-m&gt;type test.pas
PROGRAM TEST ;

BEGIN

  WRITELN('HELLO WORLD') ;

END.
D:\myfiles\Pascal-M\1978 KIM-1\bootstrap pascal-m&gt;type test.obp
P400TEST    3F
P118B50000BC0B48454C4C4F20574F524C440B0BBD02BD06A116
P9
D:\myfiles\Pascal-M\1978 KIM-1\bootstrap pascal-m&gt;type test.err
No errors in test.pas

Binary loader

The KIM-1 interpreter can only execute M-code if it is already loaded into memory, there is no loader for Px records.
Version v1.0 of the KIM-1 interpreter needs two binaries loaded (and of course the interpreter code itself!)
– the M-code in memory from $2FA3
– the procedure address table at $0200

These binaries are made from the Px file with the program pascalmbinloader.exe

The program is a command-line application, and accepts two optional arguments:
– the M-code objectfile <filename>.OBP
– the load address in memory of the interpreter, default $2FA3 as in the KIM-1 V1 interpreter

If no argument is give the program prompts for the objectfile name.

Output are two binary files:
– <filename>.bin, the M-code loaded in memory
– <filename>.proc, the procedure address list

M-code disassembler

Disassembly of M-code. Command-line application, optional parameter is the .OBP Px objectfile
The second parameter can be the memory load address, default $2FA3 for the V1 KIM-1 interpreter.

If no argument is give the program prompts for the objectfile name.

Output are two text files:
– <filename>.lst a textual paged disassembly of M-code and Procedure address list
– <filename>.asm the assembler source in M-code format (no assembler exists yet!)

A debugging interpreter for Pascal-M 1978 M-code

Command-line application, optional parameter is the .OBP Px objectfile
The second parameter can be ‘debug to start a debugging session. ‘?’ for help on available commands

D:\myfiles\Pascal-M\1978 KIM-1\Pascal-M 1978&gt;pascalm1978int test.obp
Interpreter for Pascal-M 1978 V1.0
Program TEST     Loaded

HELLO WORLD

PASCAL-M END

D:\myfiles\Pascal-M\1978 KIM-1\Pascal-M 1978&gt;pascalm1978int test.obp debug
Interpreter for Pascal-M 1978 V1.0
Program TEST     Loaded

PC    = 07CC
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    = 07CC
M-Debug &gt;

Downloads:

– Cross compiler Pascal-M V1.0
– Binary loader
– Disassembler
– Pascal-M V1.0 source, binaries and disassembly
– Pascal-M V1.0 interpreter in Pascal with debugging facilities
– KIM V1.0 6502 assember interpreter 

Example session, compiles the Pascal-M compiler with the cross compiler, creates binaries and creates disassembly and source.