Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in 
CSDb User Forums

Forums > C64 Coding > KERNAL disk formatting
2016-10-15 14:19

Registered: Jul 2009
Posts: 433
KERNAL disk formatting


I am trying to format a disk inside my own program by doing this:

    lda $01
    lda #$36
    sta $01
    lda #$00
    sta $d01a
    lda #$01
    sta $d019
    jsr $ff8a    // Restore Vectors
    lda #$0f
    ldx #$08     // DRIVE
    jsr $ffba    // SETLFS
    lda #$14     // Characters
    ldx #<FormatName
    ldy #>FormatName
    jsr $ffbd    // SETNAM
    jsr $ffc0    // OPEN
    lda #$0f
    jsr $ffc3    // CLOSE
    lda #$01
    sta $d019
    sta $d01a
    sta $01

    .text "N:NAME,ID "

Outside this subroutine I am running a Raster compare IRQ and nothing else. The system is booted from a cartridge and not KERNAL. The drive spins up and led goes green but nothing get's written and it times out after a while and led starts flashing indicating error. Drive has a new D64 mounted.

I also tried running IOINIT and RESTOR but made no difference. Am I missing something?
2016-10-15 15:15

Registered: Dec 2001
Posts: 8517
i think there must be a CR ($0d) at the end of the string...

also, kernal routines will CLI, so the IRQ pointers should be valid and the SEI/CLI around this is kindof pointless
2016-10-15 15:18

Registered: Mar 2003
Posts: 1339
Maybe this could end up as an addition on codebase once you get it working? :)


Also see:

2016-10-15 15:45

Registered: Sep 2003
Posts: 1162
Can we assume that you've tried OPEN 15,8,15,"N:xxxx,yy":CLOSE15 from basic to the same disk and it worked? It seems to me that this behaviour could be most easily explained by an actual drive error.
2016-10-16 00:43

Registered: Jul 2009
Posts: 433
Yes agreed, was only making sure my IRQ wasn't interfering as I am messing with a lot of things.

@ Frantic:
Sure thing :)
        // Format the disk in Drive 8

        lda $01
        lda #$36
        sta $01

        lda #$4a
        sta $031a
        lda #$f3
        sta $031b
        lda #$91
        sta $031c
        lda #$f2
        sta $031d  // Set KERNAL RAM Vectors (Don't use $fd15 as it will mess up your IRQ Vector)

        ldx #6
    !:  lda SetParameters,x
        sta $b7,x            // Set SETLFS & SETNAM
        bpl !-

        jsr $ffc0            // OPEN
        lda #$0f
        jsr $ffc3            // CLOSE
        sta $01

        .byte $14            // Length of Filename
        .byte $0f            // Logical File Number
        .byte $6f            // Channel
        .byte $08            // Device
        .word FormatName
        .text "N:DISKNAME,ID"

As soon as I can verify it works I can paste it there.

@ TLR:
That was a good idea and now I'm even more confused here. I launch VICE, attach a disk and type in BASIC:


Same thing happens as in my program, the head goes to track zero and after some time, times out and led flashing. Now the weird part, I read the directory:


Then I run the OPEN command again and now it works... Must be some bug of sorts... Any ideas (and if someone say download build XZY of VICE I'm going to shoot myself)!
2016-10-16 01:08

Registered: Jan 2002
Posts: 1740
boot VICE
attach d64
disk formats
check directory

WinVICE 2.4.9 rev31598
true drive emulation on
2016-10-16 01:22

Registered: Jul 2009
Posts: 433
Thanks for testing Moloch.

I am running VICE 2.4.20 r29835M and TDE on.

I did however test with an Initialize command both in BASIC and inside my code and then it worked fine:

OPEN 15,8,15,"I":CLOSE 15
OPEN 15,8,15,"N:DISKNAME:ID":Close 15
2016-10-16 18:53

Registered: Sep 2003
Posts: 385

Just out of interest, why do you bother to change the vector table at all?

You could just directly call $f34a and $f291.

There's no "compatibility" either way but at least it's shorter.
2016-10-16 21:02

Registered: Jul 2009
Posts: 433
@Soci: Well, to be honest it was to maintain some degree of compatibility as I really don't know enough about it. Say f.ex. if someone has a non-standard drive ROM or fastloader relying on KERNAL calls to function but as I said, don't know enough about it. So that was the only reason really :)
2016-10-17 07:57

Registered: Nov 2011
Posts: 351
Sometimes, using my code with an ar cartridge, i solved some problems resetting the drive using first the UJ then the I command.
Seems cart drivecode causes troubles sometimes...
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Users Online
icon/The Silents, Sp..
Perff/No Name
Andy/AEG Soft
Guests online: 30
Top Demos
1 Uncensored  (9.7)
2 Edge of Disgrace  (9.7)
3 Coma Light 13  (9.6)
4 The Shores of Reflec..  (9.6)
5 Comaland 100%  (9.6)
6 We Come in Peace  (9.6)
7 Lunatico  (9.6)
8 Incoherent Nightmare  (9.5)
9 Wonderland XII  (9.5)
10 Wonderland XIII  (9.5)
Top onefile Demos
1 FMX Music Demo  (9.5)
2 Pandemoniac Part 2 o..  (9.5)
3 Daah, Those Acid Pil..  (9.5)
4 Dawnfall V1.1  (9.5)
5 Treu Love [reu]  (9.5)
6 In Memoriam BHF  (9.5)
7 Merry Xmas 2017  (9.4)
8 Dawnfall  (9.4)
9 SWiRL  (9.4)
10 Synthesis  (9.4)
Top Groups
1 Oxyron  (9.4)
2 Booze Design  (9.4)
3 Censor Design  (9.4)
4 Finnish Gold  (9.4)
5 Crest  (9.3)
Top Diskmag Editors
1 Jazzcat  (9.6)
2 Newscopy  (9.4)
3 Peter  (9.3)
4 A Life in Hell  (9.2)
5 Elwix  (9.1)

Home - Disclaimer
Copyright © No Name 2001-2018
Page generated in: 0.057 sec.