Skip to Content

Enterprise 64/128 Development

Klive assembles machine code for the Enterprise 64 and 128, runs it in the emulated machine, debugs it at the source level, and exports it as a .com file, the form EXOS loads and starts programs in.

Applies to: Enterprise 128, Enterprise 64

Quick Start

Create a project for the Enterprise and its code/code.kz80.asm is a program that opens a page of text through EXOS and writes into it:

; An Enterprise 64/128 machine-code program: an EXOS "$$APP". Run (or Debug) boots IS-BASIC and types ; LOAD "FILE:KLIVE.COM"; EXOS loads the program at $0100 and starts it there. Export writes the same ; program as a .com file, which LOAD "FILE:name.COM" runs. ; ; EXOS starts the program on its own system stack, so the program sets its stack first. EXOS has ; closed every channel: the program opens a VIDEO: page, shows it and prints into it. .model ENTERPRISE Start: di ld sp,$3FFF ; a stack of the program's own, at the top of page 0 ei ld hl,VideoSetup ; the page's mode, colours and size: EXOS variables 22-25 ld c,22 SetVar: ld d,(hl) ld b,1 ; write... push hl push bc rst $30 ; EXOS call... .defb 16 ; ...16: set an EXOS variable (C: its number, D: the value) pop bc pop hl inc hl inc c ld a,c cp 26 jr nz,SetVar ld a,1 ; channel 1... ld de,VideoName rst $30 .defb 1 ; ...1: open the channel to VIDEO: ld a,1 ld bc,$0101 ; B=1: display the page (@@DISP), C=1: from its first row ld de,$1801 ; D=24 rows, E=at screen row 1 rst $30 .defb 11 ; ...11: the channel's special function ld a,1 ld de,Message ld bc,MessageEnd-Message rst $30 .defb 8 ; ...8: write the text to the channel Done: jr Done ; stay here; a reset ends it ; MODE_VID 0 (hardware text), COLR_VID 0 (two colours), X_SIZ_VID 40 characters, Y_SIZ_VID 24 rows VideoSetup: .defb 0, 0, 40, 24 VideoName: .defb 6 .defm "VIDEO:" ; CR LF starts a new line Message: .defm "Welcome to Klive IDE" .defb 13, 10 .defm "on the Enterprise" .defb 13, 10 MessageEnd:

Press Run: the screen clears and shows the two lines of welcome.

The model

.model ENTERPRISE (any case) assembles for the Enterprise 64 and 128; a source with no .model takes the running machine’s. #ifmod ENTERPRISE and #ifnmod ENTERPRISE pick Enterprise-only parts. Code with no .org goes to $0100. .bank is not available: paging is the program’s own business (ports $B0-$B3), or EXOS’s.

How the code gets into the machine

Run and Debug load the program the way EXOS loads any program, through Klive’s FILE: device:

  1. Klive switches the machine on and, when the ENTERPRISE banner waits for a key, presses one.
  2. At IS-BASIC’s ok it types LOAD "FILE:KLIVE.COM". The FILE: device hands EXOS the assembled program from memory; nothing is written into your FILE: folder.
  3. EXOS loads the program at $0100, pages RAM in at $0000-$BFFF, and starts it at $0100.

Debug works the same way; the debugger stops at your breakpoints once EXOS has started the code. Run needs the FILE: device (Machine › FILE: Device (Host Folder)); with the device off, Run says so and does not start.

EXOS always starts a program at $0100. When the .ent address is elsewhere and $0100-$0102 hold no code, Klive puts a JP to the entry there; when other code is at $0100, Run and Export refuse the program and say why.

Rules of the machine

  • Where code goes. From $0100 to $BFFF. Below $0100 is EXOS’s page-zero area, and while a program runs page 3 ($C000-$FFFF) holds EXOS’s system segment. The assembler warns about code outside the range, and Run and Export refuse it:
    • Z0386: “Code at $xxxx is below $0100: on the Enterprise, EXOS loads a program at $0100 and keeps its own data below it.”
    • Z0387: “Code at $xxxx is too high for the Enterprise: a program may reach $BFFF; from $C000 up is EXOS’s system segment.”
  • The stack. EXOS starts a program on its own system stack, so the program must load SP before interrupts can come: the first interrupt on EXOS’s stack lands the CPU in EXOS. Do it as the template does, with DI, LD SP,..., EI as the first three instructions.
  • Channels. EXOS closes every channel before it starts a program. To show text, open a VIDEO: page and display it, as the template does: an EDITOR: channel alone shows nothing until its page is displayed.
  • Interrupts. NICK’s video interrupt and DAVE’s 1 Hz timer run EXOS’s interrupt handler, which keeps the clock, the keyboard and the sound going. Code that disables interrupts should enable them again.

EXOS calls

RST $30 calls EXOS, with the function’s code in the byte after it:

ld a,1 ; the channel ld de,Message ; the text ld bc,5 ; its length rst $30 .defb 8 ; EXOS 8: write a block to the channel

The call returns after that byte, with the status in A (0 for success). The function codes are 0-11 (the channel functions: open, create, close, destroy, read and write a character or a block, status, special functions) and 16-34 (the system functions: EXOS variables, channel redirection, segments, ROM extensions, modules, the time and the date). Codes 12-15 and those above 34 are not functions.

The disassembler lists the byte after RST $30 as data with the function’s name, for example .defb $08 (EXOS 8: Write block), and Step Over steps over the call and its byte.

Exporting

Export (or expc <file>) writes a .com file, with -f com or by default: EXOS’s 16-byte module header for a new application (module type 5, the length of the code) and the code from $0100. Copy it into the FILE: folder and LOAD "FILE:NAME.COM" loads and starts it, on Klive or on any Enterprise that can read the file. The file always starts itself, so the export has no loader option. -f hex writes Intel HEX instead.

Testing

Z80 unit tests run on the Enterprise: the runner boots the machine to IS-BASIC’s prompt and calls each test. klive run runs an Enterprise project.

Last updated on