In the last post, I managed to get a fair bit of progress on the ability to format disks in the MEGA65's internal drive.  I am now able to write

Making a C64/C65 compatible computer: Work on floppy formatting, CRC calculation and sector writing

submited by
Style Pass
2021-06-29 21:30:19

In the last post, I managed to get a fair bit of progress on the ability to format disks in the MEGA65's internal drive.  I am now able to write data and synchronisation bytes, and generally make a valid track of data... except for the CRC fields in the sector header and sector data regions.  So now I need to look for some nice simple code to implement this.  

We already have a working VHDL implementation that works on a bit-by-bit basis. But for software formatting in my test programme, we ideally need a nice simple byte-oriented algorithm.  The C65 ROM must clearly have one, so lets see how it is done in there.

The first part of this is to look at the track formatting code. The wttrk routine does the actual writing of tracks, writing out the ten sectors, including the header and initial CRCs.  The relevant part looks like this:

    ldy #4            ;Write 4 header bytes     ldx #$ff 30$    lda header-1,y 40$    bit stata     bpl wtabort        ;   oops     bvc 40$     sta data1     stx clock     dey     bne 30$     lda sec            ;Convert sector number into a     asl a            ; CRC pointer     tay     lda crc,y     ldx #$ff 50$    bit stata        ;Write 2 byte header CRC     bpl wtabort        ;   oops     bvc 50$     sta data1     stx clock     lda crc-1,y 60$    bit stata     bpl wtabort        ;   oops     bvc 60$     sta data1     stx clock     ldy #42            ;Write post ID gap 70$    lda gap1-1,y     ldx gap1clk-1,y 80$

Leave a Comment