Commodore 128 Tips & Tricks

Go to content


CP/M Plus (3.0) on Commodore 128 works with Zilog Z80 CPU

CP/M is one of modes working on Commodore 128. It's 8-bit operating system. Here are some tips to work with CP/M.

Most of the old-schoolers know the following:

SYS 32800,123,45,6 (named
Easter Egg)

... but while disassembling the Z80 ROM you can find a similar one available in CP/M too.
You can activate it with the following key sequence:


This displays Easter Egg in CP/M operating system:

How to copy files from a C64 disk image to a CP/M disk image

Download the CP/M files that you want to transfer to CP/M disks. Use e.g.
DiskImagery64 to copy the CP/M files onto a standard, blank .D64 image (typical Commodore format).

Now boot your C128
Vice Emulator into CP/M mode (using a standard CP/M disk)

CPMXTRA.D64 disk to B drive (device 9). This disk image is in CP/M archive in downloads.

This program allows to copy your CP/M files on your standard CBM disk to a CP/M disk. In this disk image is a little gem called
RDCBM. Using it you can now copy binary files from the CBM disk image to a CP/M disk image where they will be quite happy.

Just change
to drive B, and execute RDCBM. This will load a menu that lets you copy files from CBM disks to CP/M disks. You'll put the regular .D64 disk containing the CP/M files in the A drive and a suggested blank CP/M disk in drive B, then choose these menu options:

set your drives. [S] does this. It will ask for "Letter of CBM drive: " - use A.

Next, it will ask for letter of
CP/M drive; choose B.

You will then be asked for the
CP/M File Name (Drive B): - this is the name that the file on A: will be copied to.

You'll have to copy the files one by one if you have multiple CP/M files to transfer.


1. Attach CP/M system to #8 and boot
2. Attach blank.D64 to #9
4. Attach CPMXTRA.D64 to #9
5. Change A: to B:
6. Run RDCBM
7. Attach source.D64 to #8
8. Attach blank.D64 to #9
9. Choice [S] - setup drives: CBMDRIVE=A/CPMDRIVE=B
10.Choice [B] - binary copy: select CBM file, set name of CPM file

Reading CP/M directory:

CP/M directories (and related file organisation) has nothing in common with the native commodore filesystem.
A small correction at the beginning - the 1581, you're referring to with your question regarding the autostart 'usr' file, doesn't use gcr coding at all - there's only a mfm controller (wd1770) inside - it uses either it's native mfm format or a so called 'logical' format which is somewhat compatible to the former diskdrives with 256byte sectors.
1581 physical layout: tracks 0 to 79, 10 x 512byte sectors 1 to 10, 2 sides
1581 logical (emulated): tracks 1 to 80, 40 x 256byte sectors 0 to 39 (# 20 to 39 on the 2nd side).
Things you'll need to achieve your (whatever) task:
Full sector read routine - preferably burst mode
A 4Kbyte buffer to hold the retrieved directory data
A optional 1K work buffer.

There are 4 official commodore CP/M formats:

C64 single sided:

using 32 tracks, 17 x 256byte sectors,
136K total, 1K allocation units
2K dir space = 64 entries,
dir start @ track 3 sector 0
the directory uses sectors 0,1,2,3,4,5,6,7
first data block starts @ track 3 sector 8 (allocation unit 2)
track 18 is skipped in CP/M and track 1 & 2 are reserved as system tracks.

C128 single sided:

using 680 of the 683 totally available sectors with a special translation scheme grouping 4 x 256bytes sectors to a pseudo 1024byte sector (skew 5),
170K total, 1K allocation units,
2K dir space = 64 entries,
dir starts @ track 1 sector 10,
the dir uses:
T1/S10;T1/S15;T1/S20;T1/S4 (alloc unit 0)
T1/S9;T1/S14;T1/S19;T1/S3 (alloc unit 1)
Sector 0 & 5 of track 1 and track 18 sector 0 are skipped in CP/M.
first datablock starts @ T1/S8;T1/S13;T1/S18;T1/S2 (alloc unit 2)

C128 double sided:

using 1360 sectors grouped the same as the single sided version,
skipping additionally T36/S0;T36/S5;T53/S0
340K total, 2K allocation units
4K dir space = 128 entries,
dir starts @ track 1 sector 10,
the dir uses:
T1/S10;T1/S15;T1/S20;T1/S4 (alloc unit 0)
T1/S8;T1/S13;T1/S18;T1/S2 (alloc unit 1)
first datablock starts @
T1/S6;T1/S11;T1/S16;T2/S0 (alloc unit 2)
CP/M distinguishes the single from the double sided format by reading the last byte from the boot sector T1/S0 -> if $00 then SS, if $FF then DS

1581 CP/M format:

the disk is accessed in it's physical format grouping two 512byte sectors to a pseudo 1024byte sector. The native format dir track is skipped T39/S1 to S10 (logical T40/S0 to S19) it holds a autostart prog. and a modified cpmldr to boot from this drive.
Using 794K total, 2K allocation units (0 to 396 -> 16bit pointers)
4K dir space = 128 entries,
dir starts @ track 1 sector 0 (using logical 256byte addr.)
the dir uses: T1/S0 to S15 (alloc unit 0 & 1)
first datablock starts @ T1/S16 to S23 (alloc unit 2)

To identify if a disk is CP/M formated, read in the dir header & ID.

This is "CP/M PLUS" "65 2A" for the gcr based disks and "CP/M PLUS" "80 3D" for the 1581. If it is one of the gcr disks, read in the sector T1/S0 and check for the "CBM" boot signature, if this is present read the last byte of the boot sector to identify c128-single or double-sided disk. If "CBM" is absent you have a C64-single sided disk.

Example CP/M dir from a 1581 disk (partially) - look below
As you can see a file can have multiple dir entries (called extends) if the size exceeds the max. allocation possible with one entry (in this case 16K/entry).
The format of each individual 32byte long entry is as follows:

0U F1 F2 F3 F4 F5 F6 F7 F8 T1 T2 T3 EX S1 S2 RC .FILENAMETYP....
AL AL AL AL AL AL AL AL AL AL AL AL AL AL AL AL ................

0U = User Number. 0-15 ($00 - $0F)
if this byte is $E5 => deleted or free entry
Fn - Filename (7bit ascii)
Tn - filetype. (7bit ascii)
Bit7 (upmost) bit has special functions:
If set in T1 -> the file is marked read-only
T2 is set -> the file is marked as system-file (hidden)
T3 is set -> archive attribute (reset when the file is modified)
EX - Extendnumber, lower byte - range 0-31
S2 - Extendnumber, upper byte.
S1 - Last record byte count (not allways used)
RC - Record count (1 Record=128 Bytes) in this extend
the total # of recs. of this file is (EX & exm) * 128 + RC.
If the number is $80 this extend (entry) is full, and the file might continue with another entry.

AL - allocation pointers, if the total alloc unit count is smaller than 256 these are 8bit pointers, else 16bit pointers to the data. 0 means unallocated (free)

Special entries:
first byte (0U) -
$10 -$1F - password entry + user #
$20 - directory label
$21 - date time entry (every 4th spot holding date/time for the former 3 files - $60,$e0...)

by LokalHorst

Now it's time to copy. Select
[B] Binary CBM -> CP/M Copy. You will be asked for the name of the CBM file (actually your CP/M file) and will need to type it in exactly.

download section you can find CPM.RAR archive which contains CP/M manual in PDF, CPMXTRA.D64 image to copy files, some programming languages for CP/M operating system and CP/M DEMO (look at screenshots below).

Here's link to some programming articles:

Back to content | Back to main menu