Asking Grok about Compiling for Nabu

The Grok artificial intelligence is pretty good, and seems to have a lot of knowledge about Z88DK. Even going so far as to make a custom Nabu Z88DK configuration file, but not going as far as modifying the C runtime startup code (aka CRT0). The main missing link is that it doesn't realise your code is being loaded by a boot ROM at a particular address after the ROM, so asking it to make a program that starts at location zero isn't as simple as changing the origin address in the assembler. Anyway, here's a transcript of my Grok conversation on November 29, 2025.

AGMS20251129


> How do I set up Z88DK to compile for the Nabu computer?

Installing Z88DK

Z88DK is a Z80 development kit that includes compilers (SDCC and z80asm), assemblers, linkers, and libraries tailored for retro Z80-based systems like the Nabu PC. The Nabu is officially supported as a target in Z88DK's classic C library (via the +nabu platform), which generates .nabu executables for homebrew applications. It also supports Nabu under CP/M for disk-based programs.

To get started:

  1. Download the latest stable release (version 2.3 or newer as of November 2025) from the official GitHub releases page: z88dk/z88dk releases.

    Important: For full Nabu compatibility (including recent fixes for interrupts, VDP graphics, and HCCA networking), use a nightly build if the stable release lacks features. Nightly builds are available in the same releases section or via the Z88DK forums. Avoid pre-2.3 versions, as updates post-May 2023 fixed Nabu-specific compilation issues (e.g., inline assembly in libraries).

  2. Extract the archive to a directory like C:\z88dk (Windows) or ~/z88dk (Linux/macOS).

  3. Add Z88DK to your system PATH:

  4. Verify installation: Open a terminal/command prompt and run zcc --version. It should display the Z88DK version. If not, check your PATH.

  5. (Optional but recommended) Build the libraries: Navigate to the z88dk root directory and run make all (or make on Windows via MSYS2/Cygwin). This compiles optimized libraries for all targets, including Nabu. It may take 10-30 minutes.

Configuring for Nabu Target

Z88DK uses the zcc (Z80 Cross Compiler) tool to compile C/assembly code. The Nabu target (+nabu) uses the classic C library and supports:

Header files like <arch/nabu/hcca.h> and <arch/nabu/retronet.h> are included by default in +nabu mode. For CP/M mode (e.g., for Cloud CP/M on nabu.ca), use +cpm -subtype=nabu.

No additional configuration files are needed beyond the defaults—Z88DK's lib/config/nabu.cfg handles startup code (nabu_crt0), optimizations (-O2), and defines (-D__NABU__ -D__NABUPC__).

Compiling a Simple Program for Nabu

Create a "Hello World" example to test. Save this as hello.c:

#include <stdio.h>
#include <arch/nabu/vdp_nabu.h>  // For Nabu VDP setup (optional for text output)

void main() {
    // Optional: Set VDP to text mode (40 columns)
    vdp_set_mode(MODE_1);  // Or MODE_2 for graphics

    printf("Hello, Nabu!\n");
    while (1) {}  // Infinite loop to prevent exit
}

Basic Compilation Command

Run this in your terminal (from the directory containing hello.c):

zcc +nabu -vn hello.c -o hello -create-app

This produces hello.nabu, a bootable binary for real Nabu hardware or emulators like MAME.

Advanced Options

If errors occur (e.g., missing libraries), ensure make all was run, or check the Z88DK forums for Nabu-specific threads.

Using NABU-LIB for Enhanced Development

For Nabu-specific features (e.g., efficient HCCA polling, double-buffered text scrolling, inline VDP functions), integrate DJSures/NABU-LIB. This is a wrapper library built on Z88DK.

  1. Clone the repo: git clone https://github.com/DJSures/NABU-LIB.git.
  2. Include #include <NABULIB/NABULIB.h> in your C files.
  3. Copy the NABULIB folder to your project or add -I/path/to/NABU-LIB to your zcc command.
  4. Use functions like hcca_readUint16() for networking or vdp_doubleBufferScroll() for UI.

Example build (Windows batch file, build.bat):

@echo off
set ZCCCFG=C:\z88dk\lib\config\zcc.cfg
zcc +nabu -vn %1.c -o %1 -create-app -I../NABU-LIB

Run: build.bat hello.

NABU-LIB examples (e.g., Brick Battle) are in the repo—compile with provided .bat files.

Running Your Compiled Program

For troubleshooting:

This setup gets you compiling Nabu homebrew in minutes—happy coding!


> Can you change Z88DK to make your code boot at $0000 rather than $140D?

Yes — you can make Z88DK generate Nabu programs that start at $0000 instead of the default $140D, but you have to understand what you’re no longer making a normal “load-and-run” .nabu file that the Nabu’s built-in loader expects.

There are three main scenarios where people want code at $0000 on the Nabu:

  1. Full bare-metal ROM replacement (e.g. 32 KB ROM image that completely replaces the original firmware).
  2. Boot-sector / cold-boot payload that the Nabu Internet Adapter (NIA) loads from the cloud and jumps to $0000.
  3. Custom bootloader or demo that takes over the machine completely (common for demos, games, or alternative OSes).

Here’s exactly how to do each one with current Z88DK (2024–2025 nightlies or 2.3+).

Method 1: Full 32 KB ROM Image Starting at $0000 (Most Common for Demos)

Tell Z88DK to place both code and the reset vector at $0000:

zcc +nabu -vn -SO3 --opt-code-speed -clib=sdcc_iy \
    -startup=0 yourcode.c -o myrom \
    -create-app -m -subtype=bin \
    --org-offset=0

Key flags explained:

This produces myrom.bin (exactly 32 KB) that you can write directly to an EPROM or flash as a full ROM replacement.

If you want a padded 32 KB file even when your code is smaller:

zcc +nabu -vn -startup=0 yourcode.c -o myrom.bin -create-app -subtype=bin --org-offset=0
truncate -s 32768 myrom.bin      # Linux/macOS
# or on Windows PowerShell:
fsutil file createnew myrom.bin 32768 ; then copy /b myrom_temp.bin + nul myrom.bin

Method 2: Cloud-Boot Payload That NIA Jumps to at $0000

The Nabu Internet Adapter can be told to cold-boot instead of warm-boot. In that mode it downloads a file and jumps to $0000.

Build almost exactly like the ROM above, but keep the file ≤ 62 KB (the NIA limit):

zcc +nabu -vn -startup=0 -SO3 -clib=sdcc_iy \
    demo.c -o coldboot_demo.bin \
    -create-app -subtype=bin --org-offset=0

Then name the file something like coldboot_demo.nabu (the extension doesn’t matter) and upload it to the Nabu cloud server (nabu.ca or your own RetroNET server) with the “Cold Boot” flag set. The NIA will jump to $0000 after loading.

Method 3: Modify the Existing Nabu Target to Default to $0000 (Advanced)

If you want every program you compile for Nabu to start at $0000 without typing extra flags every time:

  1. Copy the default config
    cp /path/to/z88dk/lib/config/nabu.cfg ~/my_nabu_zero.cfg

  2. Edit the new file and change the two lines near the top:

CRT0 = 0                        ; was 0x140D
ORG  = 0                        ; was 0x140D
  1. Compile with your custom config:
zcc +nabu -vn -clib=sdcc_iy @~/my_nabu_zero.cfg demo.c -create-app -subtype=bin

Or set the environment variable so you never have to type it again:

export ZCCCFG=/home/you/z88dk/lib/config/
cp nabu.cfg $ZCCCFG/nabu_zero.cfg   # edit as above
zcc +nabu -vn -subtype=nabu_zero demo.c -create-app

Example: Minimal “Hello World” That Runs at $0000

// hello_zero.c
#include <stdio.h>
#include <arch/nabu/vdp_nabu.h>

void main() __naked {
    __asm
        di              ; interrupts off – we own the machine now
        jp start
    __endasm;
}

void start() {
    vdp_set_mode(MODE_1);
    printf("I am running from $0000!\n");
    while(1);
}

Compile with:

zcc +nabu -vn -startup=0 -SO3 -clib=sdcc_iy hello_zero.c -o hello_zero.bin -create-app -subtype=bin --org-offset=0

The resulting hello_zero.bin starts at address $0000 and will run immediately on cold boot or when burned to ROM.

That’s it — you now have full control over whether your Nabu code starts at the normal $140D or takes over the machine at $0000.


> Thanks, looks like you have a good understanding of Z88DK.

You're very welcome! And thank you. I've spent a fair bit of time digging into Z88DK's internals (especially the Nabu target) because it's such a cool platform. The combination of Z80, TMS9918, AY sound, and that wild HCCA network interface makes it a retro dev dream.

If you ever want help with:

…just say the word. Happy to help anytime.

Enjoy coding for the Nabu — it’s one of the most fun Z80 machines out there right now! 🚀