An interesting bug appeared on MAME Testers recently. The bug linked here is really simple. OS-9 wont boot on a copy protected disk image. The solution also was simple: properly emulate the delay between issuing a write command, and the INTRQ that happens when the write protect notch is covered.
But how long of a delay should it be? The floppy disk controller chip data sheet does not specify what is normal. I wish I had an oscilloscope to measure things like this, but I don’t. So I had to get tricky.
I wrote a Color Computer program that writes to a write protected disk on purpose. Normally after you issue the command to write to a sector, you prepare to start writing and then wait until the disk is ready. But if you know the disk write will error becuase of a write protect notch, all you really have to do is count. That is what I did, initiate write and then count forever:
pragma 6809
opt cd
start
org $6000
count fcb 55
error fcb $55
begin
orcc #$50 turn off interrupts, keep motor spinning
clrb clear counter
ldx #vector_return
stx $0983 load my NMI vector routine
lda #$ff
sta $0982 Enable NMI flag to vector
lda $ff48 reset status of 1793
lda #$A0
sta $FF48 do write sector command
; disk should be write protected.
loop
incb
bra loop
vector_return
stb count
lda $ff48
sta error
andcc #$AF enable interrupts
rts
end begin
The loop will not actually count forever. When the write fails, the Floppy Disk Controller will produce an Interrupt Request signal. On the Color Computer this is tied to the Non-Maskable Interrupt line. This will stop the loop and run my NMI handler. The records the counter and status to make available to a BASIC program for further processing.
I now have two results from different Floppy Disk Controllers: 20 and 19. With a 5 cycle loop counter, this comes to a delay of about 111 microseconds. I show my work here.