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


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

Registered: Jul 2009
Posts: 545
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 15:15
chatGPZ

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

Registered: Mar 2003
Posts: 1648
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 15:45
tlr

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

Registered: Jul 2009
Posts: 545
@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 01:08
Moloch

Registered: Jan 2002
Posts: 2928
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 01:22
TWW

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

Registered: Sep 2003
Posts: 480
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 21:02
TWW

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

Registered: Nov 2011
Posts: 463
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
morphfrog
Flashback
hedning/G★P
iAN CooG/HVSC
wil
Wolk/Software of Swe..
zscs
Paladin/G★P
LightSide
St0rmfr0nt/Quantum
Guests online: 82
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 Layers  (9.6)
2 No Listen  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 Rainbow Connection  (9.5)
7 Dawnfall V1.1  (9.5)
8 Onscreen 5k  (9.5)
9 Morph  (9.5)
10 Libertongo  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Triad  (9.3)
5 Censor Design  (9.3)
Top Graphicians
1 Mirage  (9.8)
2 Archmage  (9.7)
3 Pal  (9.6)
4 Carrion  (9.6)
5 Sulevi  (9.6)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.059 sec.