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 16:19
TWW

Registered: Jul 2009
Posts: 378
KERNAL disk formatting

Hiho.

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

FormatDisk:
    sei
    lda $01
    pha
    lda #$36
    sta $01
    lda #$00
    sta $d01a
    lda #$01
    sta $d019
    jsr $ff8a    // Restore Vectors
    lda #$0f
    tay 
    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
    pla
    sta $01
    cli
    rts

FormatName:
    .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
Groepaz

Registered: Dec 2001
Posts: 7971
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
Frantic

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

https://codebase64.org/doku.php?id=base:dos_examples

Also see:

https://codebase64.org/doku.php?id=base:formatting_disks
2016-10-15 17:45
tlr

Registered: Sep 2003
Posts: 1118
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
TWW

Registered: Jul 2009
Posts: 378
@GPZ:
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

    FormatDisk:
        lda $01
        pha
        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
        dex
        bpl !-

        jsr $ffc0            // OPEN
        lda #$0f
        jsr $ffc3            // CLOSE
        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"

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:

OPEN 15,8,15,"N:DISKNAME,ID":CLOSE 15

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:

LOAD"$",8

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
Moloch

Registered: Jan 2002
Posts: 1527
boot VICE
attach d64
open15,8,15,"n0:diskname,jm":close15
disk formats
check directory
worked

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

Registered: Jul 2009
Posts: 378
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
soci

Registered: Sep 2003
Posts: 323
TWW:

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
TWW

Registered: Jul 2009
Posts: 378
@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
Flavioweb

Registered: Nov 2011
Posts: 329
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
Advanced
Users Online
V-12/Tropyx
Martin Piper
Matt
Mch/Genesis Project
TheRyk/MYD
Powerslave/Tronix
Nafcom/P.o.L.
redback
Almighty God/L64/Ons..
Guests online: 56
Top Demos
1 Uncensored  (9.7)
2 Edge of Disgrace  (9.7)
3 The Shores of Reflec..  (9.7)
4 Coma Light 13  (9.6)
5 Lunatico  (9.6)
6 Comaland 100%  (9.6)
7 Incoherent Nightmare  (9.5)
8 Wonderland XII  (9.5)
9 Comaland  (9.5)
10 Wonderland XIII  (9.5)
Top onefile Demos
1 Dawnfall V1.1  (9.5)
2 Daah, Those Acid Pil..  (9.4)
3 SidRok  (9.4)
4 Treu Love [reu]  (9.4)
5 Tunnel Vision  (9.3)
6 Dawnfall  (9.3)
7 One-Der  (9.2)
8 Globe 2016 [reu]  (9.2)
9 Hardware Accelerated..  (9.2)
10 Safe VSP  (9.1)
Top Groups
1 Booze Design  (9.4)
2 Oxyron  (9.4)
3 Censor Design  (9.3)
4 Crest  (9.3)
5 Camelot  (9.2)
Top Mega Swappers
1 Nightshade  (9.4)
2 Aslive  (9.3)
3 Calypso  (9.2)
4 Dishy  (9.0)
5 R.C.S.  (8.8)

Home - Disclaimer
Copyright © No Name 2001-2017
Page generated in: 0.522 sec.