Here’s the MESS KC85/3 driver booting into the CAOS 3.1 operating system:
A simple “HELLO WORLD”
Let’s write a simple Hello World program in Z80 machine code:
Enter MODIFY 200 and press the Return key. This starts the system’s memory hex editor command at address 0x0200, which is the start of “user memory”.
Enter the following byte by byte, if you make an error use backspace to correct. Hit the Return key at the end of each line:
7F 7F ,H ,E ,L ,L ,O 01 CD 03 F0 23 ,H ,E ,L ,L ,O 20 ,W ,O ,R ,L ,D 0D 0A 00 C9 .
The single ’.’ dot ends the MODIFY command and returns to the command line.
The ’,’ comma followed by a character means “write the ASCII code of the character as byte”. This makes entering strings much simpler compared to looking up the ASCII value “by hand” in a lookup table.
Now type MENU (Return), the screen will clear and redraw the system menu. Notice that there’s a HELLO at the top of the menu screen. Congratulations, you just extended CAOS with your own custom command!
Now start the command by either typing HELLO or navigating the cursor to the line containing the HELLO and press Return. A string “HELLO WORLD!” should be printed on the screen.
Let’s go quickly through the machine code, we basically only call a system function which does all the hard work for us. Note how the input data to the function is simply appended in the instruction stream behind the CALL instruction, that’s pretty clever!
// this header identifies the command to CAOS (this is data, not code): 7F 7F ,H ,E ,L ,L ,O 01 // execution starts here! // subroutine call to F003 (Z80 is little endian, this calls into the operating system) CD 03 F0 // 23 hex is the system call id to print a string to the screen 23 // string data starts here: // the HELLO WORLD string, 20 hex is "space" ,H ,E ,L ,L ,O 20 ,W ,O ,R ,L ,D // and newline 0D 0A // a zero byte terminates the string 00 // and finally the RET instruction which returns to the command line C9
Programming directly in machine code like this was how I wrote the first few games on the KC85/3 (Pacman and Breakout clones). This required carefully keeping track of function entry addresses and generously placing NOP instructions inside and around functions to have room for editing and bugfixing.
For later games an actual assembler was available which was pure high-level coding heaven ;)
About the KC85/3
The KC85/3 was produced in the mid-80’s by the “VEB Mikroelektronik Kombinat Muehlhausen” and contained a Z80 CPU clone (called U880) at 1.75 MHz, 16kByte RAM and had a 320x256 pixel display. Because of its pixel-addressable color display capabilities it was well suited for games, even though it lacked a sprite hardware, and video memory access was really slow.
KC means “Kleincomputer”, which means”Small Computer” in English.
(more to come…)