Appendix D
Choose a language and a delivery format
Start with the program's intended home. A BASIC-hosted binary can expect a running BASIC environment. An OS-9 process receives an entry point, private working storage, paths and operating-system services. Choosing the environment tells you what to build, how to start it, and what a successful return looks like.
Match the artifact to its consumer
| What you have | Who reads it | How this book used it |
|---|---|---|
| night.b09 | BASIC09 in the OS-9 guest | LOAD reads the editable procedure source into the language workspace. |
| night | The guest’s RUNB runtime | BASIC09 PACK produces a named procedure module containing intermediate code. RUNB takes the procedure’s name. |
| beacon.a | The supplied OS-9 assembler | ASM creates a complete 6809 program module. The source contains the module, entry, storage and closing CRC directives. |
| beacon | OS-9’s loader | Shell+ executes it by name or path. It receives the standard paths and returns by F$Exit. |
| watch.c | The period C compiler in the guest | CC drives several tools. RMA produces relocatable object code and RLINK joins it with the C startup object and library. |
| A CoCo BASIC program or BASIC-hosted machine-language binary | The corresponding ROM BASIC environment | Use the native BASIC, C and assembly books for their VCC Plus workspaces and direct-run conventions. |
The output format is part of an assembler's job. For verification, the bundled LWASM was also run in its OS-9 module output mode on the unchanged Beacon source. Both guest-assembled files matched its 56 output bytes exactly. The reader can produce and execute the complete module using the guest alone.
Compile a small C program in NitrOS-9
This optional exercise uses the cc version 2.3.0 present on the supplied HD0. Start at Shell+ with the usual /dd/cmds execution directory. Use a personal HD1 with fresh names watch.c and watch. Run:
chd /h1
build watch.c
Type the Watch source, one line per question-mark prompt, and press Return on an empty line to finish. This short program uses the C dialect accepted by the period compiler. Its untyped main() uses the compiler's implicit integer return type. The library routine puts writes a string and ends its line. A return value of zero tells the startup code the program completed successfully.
main()
{
puts("night duty");
return 0;
}
Confirm with list watch.c that the opening and closing braces appear on their own lines. In the guest keyboard matrix Control-comma produces the opening brace, and Control-period the closing brace. The Mac's natural keyboard layout also maps brace characters to those combinations.
cc watch.c -f=/h1/watch
Wait for the shell prompt. The explicit output filename is important. The source lives in the data directory, but the linker treats its final output as an executable. Giving it a full HD1 path keeps that file on your practice disk. The compiler created intermediate files as it worked and printed the stages it invoked.
| Stage shown on screen | Job |
|---|---|
| c.prep | Preprocess the C source, including any requested headers or macro expansions. |
| c.pass1 and c.pass2 | Translate the C program in successive passes. |
| c.opt | Optimize the generated assembly. |
| rma | Assemble a relocatable object whose final addresses can be resolved at link time. |
| rlink | Combine the object with /DD/lib/cstart.r and /DD/lib/clib.l to make the executable. |
/h1/watch
ident /h1/watch
Look for night duty and a return to Shell+. Both guest processors produced a 1,759-byte module with a good CRC of $F01AE3 for this exact source and toolchain. Your seven-instruction Beacon supplied its own entry and exit. This C program also carries the startup and library code needed by what you wrote.
Read further
- Microware Systems Corporation. BASIC09 Programming Language Reference Manual, revision H (1984). See “Introduction to BASIC09 Programming” and “Program Statements and Structure” for procedures, loops and declarations.
- Microware Systems Corporation. C Compiler User’s Guide for OS-9 (1983), chapter 1, “The C Compiler System.” The compiler front end and flags above were checked on the supplied image.
- Tandy Corporation. OS-9 Level Two Development System (1987), “Relocating Macro Assembler,” chapters 1–2, 5 and 9. Use its discussion of sections, external references and the linkage editor when you move beyond a single module.
- The NitrOS-9 Project. NitrOS-9 Technical Reference, revision 0.1 (2004), chapters 3–4 and 8. See the module header layout, standard paths and the system-call interface used in Beacon.