maux
Star on GitHub Buy me a coffee

hello, world, in PLASMA

Watch / hellopla

Filmed on the Apple IIe 80-column display. The same session on the Videx UltraTerm: same keys, same text.

The Videx UltraTerm was an 80-column video card for the Apple IIe, with its own video memory and character generator, real hardware scrolling and more screen modes than the IIe's own 80 columns. This demo runs on either display; the UltraTerm film shows the original Videx UltraTerm, emulated.

A program in PLASMA, written and built without leaving the machine, and then run twice: loaded the ordinary way, and as a single file made by the plasma cutter. The demo types David Schmenk's own hello.pla in vi, writes a Makefile in vi, runs make, which compiles it with plasm, and runs the module with plasma. Then make again, which has nothing to do, and the same program from the plasma cutter.

What it types

Everything it types, in order. A line starting with $ is a command at the shell, RET included; keys lines are single keystrokes to a program (RET, ESC and the control keys are named).

$ cd /tmp
$ mkdir hellopla; cd hellopla
$ cat hello.pla
$ cmp hello.pla /usr/src/examples/HELLOPLA/hello.pla
$ cat Makefile
$ make
$ make
$ ls -l /usr/src/examples/HELLOPLA
$ cp /usr/src/examples/HELLOPLA/HELLO hello
$ cmp hello /usr/src/examples/HELLOPLA/HELLO

What the captions say

On the IIe's own 80 columns:

  1. hello, world, in PLASMA, on the machine itself.
  2. David Schmenk's hello.pla, typed in vi exactly as he wrote it.
  3. A Makefile. make needs a real TAB before each command.
  4. make runs plasm, the PLASMA compiler, on the machine itself.
  5. plasma runs the module.
  6. At every launch, plasma loads its runtime first.
  7. Then it resolves the module's imports: a run-time loader.
  8. plasma hello.mod, the first time: 1.19 million cycles from RETURN to the output.
  9. A capital H and a full stop: Schmenk's spelling, not K&R's.
  10. make again prints nothing, because hello.mod is no older than hello.pla.
  11. The plasma cutter does the loading once, on the host.
  12. HELLO is the same program with that work already done.
  13. plascut makes one file, and the shell runs it.
  14. ./hello, cut by plascut, the first time: 0.92 million cycles.
  15. Against 1.19 million for plasma hello.mod: the loading is done.
  16. ./hello again, warm: 0.24 million cycles.
  17. The 65C02 is no faster. It is doing less.

On the UltraTerm:

  1. hello, world, in PLASMA, on the machine itself.
  2. David Schmenk's hello.pla, typed in vi exactly as he wrote it.
  3. A Makefile. make needs a real TAB before each command.
  4. make runs plasm, the PLASMA compiler, on the machine itself.
  5. plasma runs the module.
  6. At every launch, plasma loads its runtime first.
  7. Then it resolves the module's imports: a run-time loader.
  8. plasma hello.mod, the first time: 1.33 million cycles from RETURN to the output.
  9. A capital H and a full stop: Schmenk's spelling, not K&R's.
  10. make again prints nothing, because hello.mod is no older than hello.pla.
  11. The plasma cutter does the loading once, on the host.
  12. HELLO is the same program with that work already done.
  13. plascut makes one file, and the shell runs it.
  14. ./hello, cut by plascut, the first time: 0.85 million cycles.
  15. Against 1.33 million for plasma hello.mod: the loading is done.
  16. ./hello again, warm: 0.24 million cycles.
  17. The 65C02 is no faster. It is doing less.

The two startups

Each run is timed in cycles of the emulated machine, from the moment RETURN is pressed to the moment the output appears on the screen. The first, plasma hello.mod, loads the runtime, reads the module and resolves its names. The second is a copy of the cut program from /usr/src/examples/HELLOPLA/HELLO: that file was made on the host by plascut, which did the loading once, in advance. Both are run once cold and the cut one again warm; the captions give the figures this run measured, and they differ a little between the two displays. The plasma cutter is described on the Dev page.

The film times them, in cycles of the emulated machine, from the moment RETURN is pressed to the moment the output appears: plasma hello.mod the first time, 1.19 to 1.33 million; the cut ./hello the first time, 0.85 to 0.92 million; and ./hello run again, 0.24 million. (The first run of anything pays to bring its file in from the disk. The figures are to the nearest slice of the recorder's clock, about a sixth of a million cycles.) For this program the cut file saves 0.27 to 0.48 million cycles on the first run.

A TAB, not eight spaces

The Makefile is typed with real TABs. It removes the old module, runs plasm and lists the new one, because plasm exits with success even after a compile error and ls fails when the module is missing, which stops make.

The source is his

The program is src/samplesrc/hello.pla from PLASMA, written by David Schmenk (MIT licence, Copyright © 2010-2022 David Schmenk), unchanged. The lines the film types are compared with the lesson's file, exactly, and the lesson's file is checked against his at the PLASMA version maux builds with.

The gate that proves it

This film is made by site/demos/hellopla.py. Run as assertions, the same file is make check-demo-hellopla, and it runs with the rest of the tests, on both displays. It requires that the lines typed are those of the lesson's hello.pla and Makefile exactly; that cat reads both files back as typed; that cmp finds the typed hello.pla identical to the file on the disk; that make prints the commands and plasm's report in order and 23 bytes compiled; that plasma hello.mod and the cut ./hello both print Hello, world.; that the cut program, started cold, takes fewer cycles than plasma hello.mod started cold, and started again warm fewer than started cold; that cmp finds the copy of the cut program identical to the file on the disk; that the module the machine compiled is, but for the numbering of its imports, the module the host compiler writes; and that the host, reading the disk the machine wrote, finds hello.mod to be a REL file and hello a BIN file whose aux_type is $0800.

Transcript

The screen at every checkpoint the test checks, as the recorder saved it:

== mkdir prints nothing (t=10.7 s)
$ cd /tmp
$ mkdir hellopla; cd hellopla
$

== the source reads back as typed (t=36.5 s)
$ cat hello.pla
include "inc/cmdsys.plh"

puts( \
     "Hello, world.\n" \
    )
done
$

== what vi wrote is the lesson file, byte for byte (t=46.6 s)
$ cmp hello.pla /usr/src/examples/HELLOPLA/hello.pla
$

== the Makefile reads back as typed (TAB = 8 columns) (t=75.6 s)
$ cat Makefile
hello.mod: hello.pla
        rm -f hello.mod
        plasm hello.pla hello.mod
        ls hello.mod
clean:
        rm -f hello.mod
$

== make runs plasm (t=95.7 s)
$ make
rm -f hello.mod
plasm hello.pla hello.mod
PLASMA Compiler v2.21
Data+Code buffer size = $021A


DATA:....1 bytes
INIT:22 bytes

Total bytes compiled: 23
ls hello.mod
hello.mod
$

== make echoes rm, plasm and ls, and plasm compiles 23 bytes (t=95.7 s)
$ make
rm -f hello.mod
plasm hello.pla hello.mod
PLASMA Compiler v2.21
Data+Code buffer size = $021A


DATA:....1 bytes
INIT:22 bytes

Total bytes compiled: 23
ls hello.mod
hello.mod
$

== plasma hello.mod prints Hello, world. (t=113.0 s)
$ plasma hello.mod
Hello, world.
$

== make says nothing (t=131.5 s)
$ make
$

== ls -l the lesson files (t=150.7 s)
$ ls -l /usr/src/examples/HELLOPLA
BIN    10953 2000-01-01 00:00 HELLO
TXT       70 2000-01-01 00:00 hello.pla
TXT      103 2000-01-01 00:00 Makefile
$

== HELLO is a BIN beside the two text files (t=150.7 s)
$ ls -l /usr/src/examples/HELLOPLA
BIN    10953 2000-01-01 00:00 HELLO
TXT       70 2000-01-01 00:00 hello.pla
TXT      103 2000-01-01 00:00 Makefile
$

== cp prints nothing (t=159.4 s)
$ cp /usr/src/examples/HELLOPLA/HELLO hello
$

== ./hello prints Hello, world. (t=162.1 s)
$ ./hello
Hello, world.
$

== ./hello again prints Hello, world. (t=174.5 s)
$ ./hello
Hello, world.
$

== the copy is the staged program, byte for byte (t=192.2 s)
$ cmp hello /usr/src/examples/HELLOPLA/HELLO
$

== on the disk, hello.mod is REL ($FE) and hello is a BIN whose aux_type is $0800 (t=192.2 s)
$ cmp hello /usr/src/examples/HELLOPLA/HELLO
$

== the module plasm wrote on the machine is the one xplasm writes on the host (-AMW), but for the ESD numbering (t=192.2 s)
$ cmp hello /usr/src/examples/HELLOPLA/HELLO
$