Disk Format

40 track, 16 sectors (128 or 256 bytes, depends on the floppy controller)

directory is at track 20, structured as follow :

sector 1 : reserved (on TO this holds the disk label, 8 ASCII chars, space-padded)

sector 2 : FAT

sector 3-16 : directory

FAT: occupation map unit is 8 sectors, so you get 2 blocks per track (1KB in SD, 2KB in DD)

each byte in the FAT represents a block. but byte 0 is not used. Possible values are:

Catalog format : each entry uses 32 bytes, so you can store up to 112 files per disk. (actually per side, each side is handled as an independant drive).

There is a trick when reading the FAT from a DD disk : as the FAT is 256 bytes, to point with it with a single pointer andan 8-bit offset, the two halves of the FAT are swapped and the pointer put in the middle. This way you can use offsets directly, the 6809 will count them as signed and this will compensate for the swap. Of course everything is put back in order when writing to disk.

On SD disks this does not happen as the FAT isonly 128 bytes long.

Standard process for handling files


Save file without erasing

Save file without erasing

erasing a file

File header

Binary files use a chunk based format. You need to follow this if you want the file to be loadable with LOADM. the format is :

There may be as many chunks as you want in a single binary file. To end the file, the latest chunk is:

This allows for some tricks. You can have small chunks changing the screen border by writing to the PIA directly, for example.

Floppy controller

There are 3 different floppy disk extensions, each with his own controller. They are all of the WD279x family.

This part only talks about the CD90-640, whichis the only controller I have. It is apparently a WD1770 based one.

There are 4 registers to communicate with the FDC. Writing to the command register starts a command, you may need to set parameters in the ther registers before that. While the command runs, there may be a daa phase where you get/send data in the data register.

Here are some useful documents :

There is no interrupt wired on the MO5 (as usual). This means when reading or writing, you have to do do everything by polling. With the 1MHz 6809, it can get tricky to do it right.


Nothing special to say about them, just look at the docs above.

There is an additionnal register at A7D8, this one allows to select the drive and side you want to work with. Bit 0 selects the side, bit 2 and 3 act as drive select bits (one for each drive). Bit 7 allows to switch to single density mode when it is set.

Simple routines

These are the basics to get started with FDC programming.

Waiting for the controller

Since the floppy drive is a slow device, you need to wait for your commands to be done. It is a good idea to do that after any of the other commands.

wready	LDA	,X
	BITA	#$1
	BNE	wready

Seeking to a track

This routine assumes that the track register is up to date. Either you write the current track to this register, or you start with a RESTORE command to get the head on track 0.

Input : register A holds track to seek to. X points to the FDC (A7D0)

seek	STA	3,X	* A is stored in the DATA register 
	LDA	#$10	* SEEK command


restor	CLRA


Input : U points to data to write, D holds track number and sector ID

write	ORCC	#$50	* Disable all interrupts, our timing is critical
	STD	1,X	* Send Track and Sector IDs
	LEAY	3,X	* Y points to data register (we need fast access to it)
	LDA	#$A8	* Write command with motor spinup delay
	BSR	delay	* Wait for the FDC to handlethe command
	BRA	do 
load	STA	,Y	* Write one byte 
do	LDA 	,U+	* Get one byte from memory
wai	LDB	,X	* Read status 
	BITB	#2	* Do we need to write one byte now ?
	BNE	load 
	BITB	#1	* Is the command done ?
	BNE	wai	* If not, we need to wait for previous byte to be handled 
	ANDCC	#$AF	* Allow interrupts again

delay	BSR hop		* Just waste some time (35 cycles) jumping around
	BSR hop
	BSR hop
	BSR hop
	BSR hop
hop	RTS


Input : U points to destination, D holds track number and sector ID. Head should already be on the right track and drive selected.

read	STD	1,X
	LDB	#$88	* Read command, motor on
	BSR	delay
rloop	LDB	,X
	BITB	#2
	BEQ	done 
	LDA	3,X
	STA	,U+
	BRA	rloop
done	BITB	#1
	BNE	rloop