How to tell if a disk sector was overwritten by a CBM drive

The question about whether or not a disk sector was overwritten is relevant when assessing whether or not an original disk was modified, e.g. for saving a hi-score table.

In fact, while researching the Vorpal disk loader used by California Games, I stumbled across two versions, one of which had been modified: the game had saved an updated hi-score table to t/s 18/10.

How does a sector overwrite look like exactly? That’s a job for CBM Flux Studio 🙂

Here are comparative images that should shed some light on the subject:

CBM Flux Studio: Unaltered t/s 18/10 in California Games by Luigi Di Fraia
CBM Flux Studio: Unaltered t/s 18/10 in California Games
CBM Flux Studio: Overwritten t/s 18/10 in California Games by Luigi Di Fraia
CBM Flux Studio: Overwritten t/s 18/10 in California Games

As you can see, there are a few clear clear indications that the sector highlighted in yellow was overwritten in the second image:

  • the beginning of the original block-sync for the data block is still visible, immediately before the new one, which was written as part of the overwrite operation
  • there’s an evident region without flux reversals in between original and new block-sync, probably due to the erase coil
  • the framing from the block header is lost in the block data (although that’s not an issue because the drive code always looks for a block-sync after it reads in a block header and before it reads GCR bytes from the corresponding block data)

BTW, once I will get some more time, I will write a track diff tool to visualize tracks by one another, in order to better appreciate this sort of differences.

My guess is that KryoFlux’s DTC looks for this sort of patterns to tell if a sector was overwritten.

Let’s now delve into the drive code itself, in order to reconcile what has been observed so far in the field.

If you check the index for the 1541 ROM on AAY, what you find out is that there are a number of references to “write block” routines.
In the end, any code that writes a block to disk invokes the data block write routine at $F575.

$F575/62837:   Write data block to disk

F589: 20 10 F5  JSR $F510       ; find block header

F58C: A2 09     LDX #$09        ; wait for 9 bytes to pass by
F58E: 50 FE     BVC $F58E       ; byte ready?
F590: B8        CLV
F591: CA        DEX
F592: D0 FA     BNE $F58E

F594: A9 FF     LDA #$FF
F596: 8D 03 1C  STA $1C03       ; switch port A pins to outputs

F599: AD 0C 1C  LDA $1C0C
F59C: 29 1F     AND #$1F
F59E: 09 C0     ORA #$C0        ; change PCR (read/write head) to output
F5A0: 8D 0C 1C  STA $1C0C

F5A3: A9 FF     LDA #$FF
F5A5: A2 05     LDX #$05
F5A7: 8D 01 1C  STA $1C01       ; write $FF to disk 5 times
F5AA: B8        CLV
F5AB: 50 FE     BVC $F5AB       ; as SYNC characters
F5AD: B8        CLV
F5AE: CA        DEX
F5AF: D0 FA     BNE $F5AB

; All GCR data is written to disk at this point (code removed for brevity)

F5CC: AD 0C 1C  LDA $1C0C
F5CF: 09 E0     ORA #$E0        ; PCR (read/write head) to input again
F5D1: 8D 0C 1C  STA $1C0C

F5D4: A9 00     LDA #$00
F5D6: 8D 03 1C  STA $1C03       ; switch port A pins to inputs

The comments about port A and PCR are mixed up in AAY, but everything else is taken almost verbatim from it.


  • the initial loop that waits for 9 bytes before switching port A to output and switching the read/write head to writing is what causes the new block-sync to appear after the original one for the data block
  • by the time port A and the read/write head state are switched, the framing from the block header is lost

Stay tuned for more!

About Luigi Di Fraia

I am a Senior DevOps Engineer so I get to work with the latest technologies and open-source software. However, in my private time I enjoy retro-computing.
This entry was posted in Retrocomputing, Reverse Engineering, Technical and tagged , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s