Tutorial: working with disks
This tutorial walks through Klive’s disk tools with one small project. You will make a ZX Spectrum +3 boot disk from a BASIC program and a loading screen, boot it in the emulator, watch the +3 save a file onto it, look at where that file sits on the disk, and finally put everything on an SD card image for the DivMMC. Every picture below was taken by doing exactly these steps.
The tools at a glance
| Tool | Where | What it is for |
|---|---|---|
| Disk Explorer | Double-click a disk image in the project explorer | See and change a disk’s files: preview, add, save, rename, delete, attributes |
| Layout view | The grid button in the Disk Explorer’s header | Every track and sector of a floppy, or a hard disk’s areas and clusters |
disk command | The IDE’s command prompt, scripts, automation | Make disks and change their files with typed commands |
klive disk | Your terminal, without Klive running | The same actions on image files, for scripts and builds |
| Machine › Disks | The menu, the emulator’s media strip | Insert, eject and write-protect disks in the machine’s drives |
| Export Code | expc ... -f dsk / -f trd | Turn a compiled program into a disk that boots it |
| Machine › Interfaces / Machine › SD Card | The menu (Interfaces on the 48K and 128K; SD Card on the +3E) | Connect a DivMMC and choose its SD card |
The disk formats are the ZX Spectrum +3’s .dsk (+3DOS), TR-DOS’s .trd and .scl (the Pentagon
and the Scorpion), and the hard-disk images .img, .hdf and .cim (FAT16 and FAT32, for the
DivMMC and the ZX Spectrum Next). Disk images and the Disk Explorer is the
reference for all of them; this page shows them at work.
1. Make a boot disk for the +3
Create a +3 project
Create a new Klive project for the ZX Spectrum +3 (1 FDD). The examples below call it
DiskTutorial; the disk tools work in any project, and on files outside one too.
Write the program
Save this BASIC program as hello.bas in the project folder. It loads a picture from the disk,
prints a line over it, and saves the whole screen back onto the disk as a new file:
10 BORDER 0: PAPER 0: INK 7: CLS
20 LOAD "title.scr" SCREEN$
30 PRINT AT 21,0; INK 6;"Hello from drive A!"
40 SAVE "copy.scr" SCREEN$
50 PRINT AT 21,0; INK 4;"Saved COPY.SCR "Put a loading screen beside it as title.scr: any 6,912-byte ZX Spectrum screen file will do.
Create a blank disk
Choose Machine › Disks › Create Disk File…. The dialog asks for three things:
- Disk type: the format. On the +3 the choices are CPC disks: Single-sided CPC (180K) is the +3’s own format (173K for files once formatted), the ECPC ones are the same disks as extended DSK images, and the double-sided and 80-track ones are for a second drive. On the Pentagon and the Scorpion the dialog offers TR-DOS disks instead.
- Disk file folder: where the disk goes. It starts at the open project’s
disksfolder (Klive makes the folder when it writes the disk), or atKlive/Disksin your home folder when no project is open. Type another folder or browse for one to put the disk elsewhere. - Disk file name:
gameis enough; Klive adds.dsk(.trdfor a TR-DOS disk).

Click Create. Klive writes a blank, formatted disks/game.dsk, and the project explorer shows
it. At the command prompt, crd ss game does the same without the dialog (with no folder named,
it uses the same default), and so does disk new disks/game.dsk ss.
Put the files on the disk
Type these commands at the IDE’s command prompt (the Commands tab of the tool panel):
disk add disks/game.dsk hello.bas DISK -start 10
disk add disks/game.dsk title.scr
disk ls disks/game.dskdisk addturnshello.basinto a tokenised BASIC program. Calling itDISKmatters: the +3’s Loader menu loads the program of that name.-start 10makes it run from line 10 once it is loaded.- A
.scrfile goes on the disk as a screen: code at 16384, whichLOAD ... SCREEN$reads. disk lslists the disk. Eachdisk addanswers with what it put on the disk (1 file added to the disk., title.scr added to the disk.).

Files can also go on a disk without typing: drag them onto the Disk Explorer. A file added by
dragging has no auto-run line, though; use disk add ... -start when the Loader must run it.
2. Look inside the disk
Double-click game.dsk in the project’s disks folder. The Disk Explorer lists its files, and
selecting one shows what it holds:
123- The selected file, with its kind, size and start: for BASIC, the auto-run line.
- The Auto-run line you set with
-start. - The program’s listing, decoded from the tokenised bytes on the disk.
Select TITLE.SCR and the preview shows it as the screen it is:

The header’s buttons change the disk: Add (+), Save the selected file to your computer, Rename, Delete, and Show deleted files. The buttons above a preview open the file as a memory view or, for code, as disassembly.
3. Boot the disk
Insert the disk
Choose Machine › Disks › Insert Disk into Drive A… and pick disks/game.dsk, or use the drive’s
button in the emulator’s media strip. The Disk Explorer now says In drive A.
Allow writes
A disk goes into the drive write-protected, so a program cannot change it by accident. This program saves a file, so clear Machine › Disks › Write Protect Drive A first. Otherwise the +3 stops at line 40 with Disk is write protected.
Start the machine and choose Loader
Start the machine and press Enter on Loader in the +3’s menu. The +3 loads DISK
from drive A and runs it. The program loads the screen, prints its line and saves the screen as
COPY.SCR:

4. See what the +3 wrote
When the machine writes to the disk, Klive writes the changed sectors back to disks/game.dsk and the open
Disk Explorer shows the change a moment later. COPY.SCR is there, and its preview is the screen
the +3 saved, with the line the program printed:
12- In drive A: this disk is in the running machine’s drive.
- COPY.SCR, written by the +3’s own
SAVE.
You can change a disk while it is in the drive, too. Klive pauses the machine, writes the disk, puts it back in the drive and lets the machine run on.
5. Find the file’s sectors
Select COPY.SCR and click Show the file’s sectors above its preview. The Layout view
shows the disk as its tracks and sectors, coloured by what they hold, with the first sector of the
file selected:

The sector’s details say where it is (cylinder, side, sector and its ID), what it holds, and its
bytes. Here they start with PLUS3DOS: the header +3DOS writes in front of every file. Select
another sector to see its bytes, and click a file’s name to go back to the file.
6. Make an SD card for the DivMMC
The DivMMC is an SD card interface for the 48K, the 128K and the +2A/+3. Its esxDOS operating
system loads .tap, .sna, .scr and other files straight from a FAT card. Klive makes and fills
such cards:
disk new card.img fat16 64
disk add card.img card/GAMES
disk add card.img card/title.scrdisk new makes a 64 MB FAT16 card (fat32 and other sizes work too). Adding a folder
copies it with everything in it. Here card/GAMES holds a copy of game.dsk. Files go onto the
card as they are, under their own long names.
Which format: .img, .hdf or .cim?
The extension you give disk new picks the image format. All three hold the same FAT16 or FAT32
card. Every disk tool on this page works with each of them, and so does the DivMMC. They differ in
how the card is stored in the file:
.img | .hdf | .cim | |
|---|---|---|---|
| What it is | The card’s sectors, byte for byte, from the first to the last | The same sectors after a short RAMsoft header that describes the drive | The same sectors, with the unused ones left out (Klive’s own format) |
| File size | The card’s full size from the start: a 64 MB card is a 64 MB file | The card’s full size, plus the header | Grows with what is on the card: a new 64 MB card is a 1.1 MB file |
| Card sizes | Any | Any | 64 MB to 16 GB |
| Other programs | The common format: other emulators read it, your computer can mount it, and SD card writers copy it to a real card | Read by Spectrum emulators that take hard-disk images | Klive only |
| Used for | Cards you share or put on real hardware | Exchanging disks with other emulators | The ZX Spectrum Next’s card (ks2.cim), and large cards that are mostly empty |
That is the whole difference between a .cim and an .img: the .cim omits the unused
sectors. The card is the same, sector for sector, but a sector nothing has been written to takes no
room in the file. An all-but-empty 16 GB card therefore costs a few megabytes of disk space instead
of 16 GB, and the file grows as you fill the card. The price is that only Klive can open it: to use
a card outside Klive, make it as an .img.
Moving files from one format to another is a matter of copying them: open both images in the Disk
Explorer, Save a file from one to your computer and drop it onto the other, or disk get it
from one and disk add it to the other.
Double-click card.img to browse it:

Double-click a folder to open it; Up goes back. New folder, Add, Save, Rename and Delete work as on a floppy. The Layout view of a card shows the volume’s areas (the reserved sectors, the FATs, the root folder and the data) and a map of the clusters in use, with the selected file’s clusters outlined:

To run esxDOS on the card:
Name your esxDOS ROM
Klive cannot ship esxDOS: get it from its authors. In Settings › Machine, esxDOS ROM takes its 8K ROM file.

Connect the DivMMC and choose the card
Turn on Machine › SD Card › DivMMC Interface (the machine restarts with it), then choose the
card with Machine › SD Card › Select SD Card Image…. For esxDOS to boot, the card needs
esxDOS’s own BIN, SYS and TMP folders: drop them onto the card in the Disk Explorer.
The DivMMC has no card until you choose one, and its card is its own: a ZX Spectrum Next keeps its own card. Machine › SD Card › Remove the SD Card takes the image out again.
Use the dot commands
esxDOS starts with the machine. Its dot commands then work as on the real interface: .ls, .cd GAMES, .tapein, .snapload. Machine › SD Card › Press the NMI Button opens esxDOS’s NMI
menu.
7. The same from your terminal
klive disk does all of this on image files without starting Klive, so a build script can make a
disk or a card:
klive disk new game.dsk sse
klive disk add game.dsk hello.bas DISK --start 10
klive disk add game.dsk title.scr
klive disk ls game.dsk
klive disk new card.img fat16 64
klive disk add card.img GAMES
klive disk ls card.img GAMES --jsonklive disk --help lists every action. A changed floppy image keeps a .bak of the original; a
hard-disk image is changed in place. See the command line.
Where next
- Disk images and the Disk Explorer: every button, the import rules, the Surface view, exporting a program to a disk.
- TR-DOS disks: the Beta 128 interface of the Pentagon 128 and the Scorpion,
and its
.trd/.scldisks, which the same Disk Explorer opens. - Custom ROMs: the esxDOS ROM and the other ROMs Klive cannot ship.