Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
 Welcome to our latest new user Skyhawk ! (Registered 2018-03-19) You are not logged in 
CSDb User Forums

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

Registered: Jul 2009
Posts: 427
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 17:15

Registered: Dec 2001
Posts: 8438
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 17:18

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


Also see:

2016-10-15 17:45

Registered: Sep 2003
Posts: 1159
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 02:43

Registered: Jul 2009
Posts: 427
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 03:08

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

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

Registered: Jul 2009
Posts: 427
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 20:53

Registered: Sep 2003
Posts: 383

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 23:02

Registered: Jul 2009
Posts: 427
@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 09:57

Registered: Nov 2011
Posts: 348
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
Guests online: 44
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 Lunatico  (9.6)
7 SSDPCM2 V3 - 16khz  (9.6)
8 Incoherent Nightmare  (9.5)
9 Wonderland XII  (9.5)
10 Wonderland XIII  (9.5)
Top onefile Demos
1 Pandemoniac Part 2 o..  (9.5)
2 Dawnfall V1.1  (9.5)
3 Synthesis  (9.5)
4 Daah, Those Acid Pil..  (9.5)
5 Treu Love [reu]  (9.5)
6 Dawnfall  (9.4)
7 Merry Xmas 2017  (9.4)
8 FMX Music Demo  (9.4)
9 Hardware Accelerated..  (9.3)
10 One-Der  (9.2)
Top Groups
1 Oxyron  (9.4)
2 Booze Design  (9.4)
3 Censor Design  (9.3)
4 Arsenic  (9.3)
5 Crest  (9.3)
Top Fullscreen Graphicians
1 Veto  (9.8)
2 Joe  (9.8)
3 Mirage  (9.7)
4 Jailbird  (9.6)
5 Hein  (9.5)

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