This is an old revision of the document!
Formatting a disk
As pointed out elsewhere, the CBMDOS formats disks well. To activate it we send a command via the command channel as follows:
OPEN 15, 8, 15, “N0:DISKNAME,ID”: CLOSE 15
And that's it if You're doing it from Basic. However from inside a program possibly running IRQ, Memory Configurations and even possibly run from a cartridge (meaning KERNAL is bypassed during start up) we can do it as follows:
//--------------------------- // Format the disk in Drive 8 FormatDisk: lda $01 pha // Preserve Memory Configuration lda #$36 sta $01 // BANK KERNAL+IO+RAM sei // Make sure our external IRQ don't kick in while messing with the vectors ldx #6 !: lda SetParameters,x sta $b7,x // Set SETLFS & SETNAM dex bpl !- jsr $f34a // OPEN (jumps straight to $f34a instead of $ffc0 (indirectly jumps to $f34a)) lda #$0f jsr $f291 // CLOSE (Same here, straight instead of $ffc3) pla sta $01 rts SetParameters: .byte $14 // Length of Filename .byte $0f // Logical File Number .byte $6f // Channel .byte $08 // Device .word FormatName FormatName: .text "N:DISKNAME,ID"
Make sure You have your Vectors at 0314 etc. set up correctly as they will be called since the OPEN command invokes CLI. Also if you want to maintain compatibility you will have to make sure the KERNAL RAM Vectors are set up correctly and call OPEN and CLOSE from the KERNAL Jump Table and use SETNAM / SETLFS instead of the loop-routine.
I also encountered an issue where I had to initialize the drive before formatting worked. Suspect it was an emulator issue but posting the work-around for sake of good order:
OPEN 15,8,15,“I”: CLOSE 15