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 save (again)
2018-10-08 13:00
JackAsser

Registered: Jun 2002
Posts: 2014
Kernal save (again)

After calling JSR $FFD8 to save a file the motor keeps spinning and the file isn't really "finalised". Works fine with Jiffy DOS, but not using the regular Kernal.

When SAVE returns I immediately throw out the kernal again and take over the system. Is there a call I need to make to "shut it down" properly or wait for it to complete the operation? Feels like some kind of race condition to me..
2018-10-08 13:03
chatGPZ

Registered: Dec 2001
Posts: 11386
  $FFE7/65511      Close All Channels And Files


it shouldnt be necessary though, SAVE alone should work
2018-10-08 13:11
JackAsser

Registered: Jun 2002
Posts: 2014
Quote:
  $FFE7/65511      Close All Channels And Files


it shouldnt be necessary though, SAVE alone should work


Exactly. I have no open files or channels... I'll try it still.

I will also add a jmp * after the save and see if the drive settles eventually. If it doesn't I guess my staged kernel environment isn't fully operational.
2018-10-08 13:16
chatGPZ

Registered: Dec 2001
Posts: 11386
wiggling dd00 a bit too much perhaps? :)
2018-10-08 13:18
JackAsser

Registered: Jun 2002
Posts: 2014
Quote: wiggling dd00 a bit too much perhaps? :)

only once every now and then to #$3c. Should be fine I suppose.
2018-10-08 13:39
Krill

Registered: Apr 2002
Posts: 2980
You're not manipulating $DD00 in an IRQ handler while saving, are you?
2018-10-08 13:57
JackAsser

Registered: Jun 2002
Posts: 2014
Quote: You're not manipulating $DD00 in an IRQ handler while saving, are you?

No, but immediatly after save returns I take over and relaunch my IRQ handlers
2018-10-08 13:59
JackAsser

Registered: Jun 2002
Posts: 2014
Prior to save I stop all IRQs (not just SEI but proper disabling all generators) Then swaps in the kernel and reinitialise io and vectors. Then I disable the timers the kernel setsup for cursor and keyscan. Then I call save.
2018-10-08 14:08
JackAsser

Registered: Jun 2002
Posts: 2014
If I do not immediately take over the kernel and instead just busy waits for a while the drive motor will stop properly and the file properly "finalised" with a correct filesize and type. If I don't wait the file will be 0 blocks big and have prg* as type.

And since all IRQ sources are disabled on the C64-side and my busy wait loop just do nothing the only explanation is that the drive must do some stuff by itself after SAVE returns which I disrupts when I take over the kernel and starts manipulating dd00 again or something along those lines.
2018-10-08 14:50
JackAsser

Registered: Jun 2002
Posts: 2014
Narrowing down. :) Totally reproducible from basic.

10 REM STUPID DRIVE

SAVE "TEST",8:POKE 56576,63

This will keep the drive motor on indefinitely.
2018-10-08 14:51
JackAsser

Registered: Jun 2002
Posts: 2014
So, follow up question. When is it safe to touch $dd00?!
2018-10-08 14:55
JackAsser

Registered: Jun 2002
Posts: 2014
Oh well, I didn't need to touch $dd00 after the SAVE anyway so I removed it and now it works. But still... weird. A good polling solution would be much appreciated.
2018-10-08 16:43
TWW

Registered: Jul 2009
Posts: 545
Hello

This from a piece of code from somewhere which might be of help:

Init:
    // ========================
    // Serial Bus Clock Pulse Output

    lda $dd00
    ora #$13
    sta $dd00

InitializeDrive:
        ldx #6
    !:  lda SetParameters,x
        sta $b7,x            // Set SETLFS & SETNAM
        dex
        bpl !-
        jsr $ffc0
        lda #$0f
        jsr $ffc3
        rts

    SetParameters:
        .byte $01            // Length of Filename
        .byte $0f            // Logical File Number
        .byte $6f            // Channel
        .byte $08            // Device
        .word FormatName
    FormatName:
        .text "I"


        //---------------------------------------------------------------------
        // Save memory to a file
        //
        // A = File Number/Pointer

    SaveFile:
        asl                            // A = File Pointer x 2
        tax                            // X = File Pointer x 2
        lda $01
        pha                            // Preserve Memory Configuration
        lda #$36
        sta $01                        // BANK KERNAL+IO+RAM
        lda $d015
        pha
        lda #$00
        sta $d015
        lda FileLocationRAM_End,x
        sta !SMC1++1                   // File Save Memory Stop LoByte
        lda FileLocationRAM_End+1,x
        sta !SMC2++1                   // File Save Memory Stop HiByte
        lda FileLocationRAM_Start,x
        sta ZP_Vector1Lo               // File Save Memory Start LoByte
        lda FileLocationRAM_Start+1,x
        sta ZP_Vector1Hi               // File Save Memory Start HiByte
        ldy FileNameList+1,x           // Pointer to Filename LoByte
        lda FileNameList,x             // Pointer to Filename HiByte
        tax
        lda #$03                       // All filenames are 3 characters long
        jsr $ffbd                      // SETNAM
        lda #$00
        tay
        ldx #$08                       // Device Number
        jsr $ffba                      // SETLFS
    !SMC1:
        ldx #$00
    !SMC2:
        ldy #$00
        lda #ZP_Vector1                // Start Address (ZP_Vector1)
        jsr $ffd8                      // SAVE
        pla
        sta $d015
        pla
        sta $01
        rts

FileLocationRAM_Start:
        .word $c000, $c000, $c000, $c000, $c000, $c000, $c000, $c000
        .word $c000, $c000, $c000, $c000, $c000, $c000, $c000, $c000
        .word $c000, $c000, $c000, $c000, $c000, $c000, $c000, $c000
        .word $c000, $c000, $c000, $c000, $c000, $c000, $c000, $c000
        .word $c000, $c000, $c000, $c000, $c000, $c000, $c000
FileLocationRAM_End:
        .word $c080, $c080, $c080, $c080, $c080, $c080, $c080, $c080
        .word $c080, $c080, $c080, $c080, $c080, $c080, $c080, $c080
        .word $c080, $c080, $c080, $c080, $c080, $c080, $c080, $c080
        .word $c080, $c080, $c080, $c080, $c080, $c080, $c080, $c080
        .word $c080, $d000, $c7b0, $c7b0, $c7b0, $c7b0, $c7b0
FileNameList:
        .word FileName00, FileName01, FileName02, FileName03, FileName04, FileName05, FileName06, FileName07
        .word FileName08, FileName09, FileName0a, FileName0b, FileName0c, FileName0d, FileName0e, FileName0f
        .word FileName10, FileName11, FileName12, FileName13, FileName14, FileName15, FileName16, FileName17
        .word FileName18, FileName19, FileName1a, FileName1b, FileName1c, FileName1d, FileName1e, FileName1f
        .word FileName20, FileName21, FileName22, FileName23, FileName24, FileName25, FileName26
FileName00:  .text "T00"
FileName01:  .text "W00"
FileName02:  .text "W01"
FileName03:  .text "W02"
FileName04:  .text "W03"
FileName05:  .text "W04"
FileName06:  .text "W05"
FileName07:  .text "W06"
FileName08:  .text "W07"
FileName09:  .text "W08"
FileName0a:  .text "W09"
FileName0b:  .text "W0A"
FileName0c:  .text "W0B"
FileName0d:  .text "W0C"
FileName0e:  .text "W0D"
FileName0f:  .text "W0E"
FileName10:  .text "W0F"
FileName11:  .text "W80"
FileName12:  .text "W81"
FileName13:  .text "W82"
FileName14:  .text "W83"
FileName15:  .text "W84"
FileName16:  .text "W85"
FileName17:  .text "W86"
FileName18:  .text "W87"
FileName19:  .text "W88"
FileName1a:  .text "W89"
FileName1b:  .text "W8A"
FileName1c:  .text "W8B"
FileName1d:  .text "W8C"
FileName1e:  .text "W8D"
FileName1f:  .text "W8E"
FileName20:  .text "W8F"
FileName21:  .text "WFF"
FileName22:  .text "R00"
FileName23:  .text "R01"
FileName24:  .text "R02"
FileName25:  .text "R03"
FileName26:  .text "R04"


Then again maybee not...
2018-10-08 17:11
JackAsser

Registered: Jun 2002
Posts: 2014
TWW: try set dd00 after the jsr to save. No, this is not helpful at all. ;) saving per se is not the problem.

The ”problem” is touching dd00 immediatly after save is not safe and imho a Kernal bug
2018-10-08 17:29
tlr

Registered: Sep 2003
Posts: 1790
Quote: TWW: try set dd00 after the jsr to save. No, this is not helpful at all. ;) saving per se is not the problem.

The ”problem” is touching dd00 immediatly after save is not safe and imho a Kernal bug


Don't expect an official patch anytime soon... ;)
2018-10-08 17:29
JackAsser

Registered: Jun 2002
Posts: 2014
Quote: Don't expect an official patch anytime soon... ;)

Hehe no. I just avoid it.
2018-10-08 17:30
cadaver

Registered: Feb 2002
Posts: 1160
Can you modify just the videobank bits, which should be safe? (ie. lda, and/or, sta). That way the ATN line is left alone, and the drive can't interpret the change as a new incoming command.
2018-10-08 17:39
JackAsser

Registered: Jun 2002
Posts: 2014
Quote: Can you modify just the videobank bits, which should be safe? (ie. lda, and/or, sta). That way the ATN line is left alone, and the drive can't interpret the change as a new incoming command.

Yes. Lda, and, ora, sta seems fine.
2018-10-08 18:15
JackAsser

Registered: Jun 2002
Posts: 2014
Quote: Yes. Lda, and, ora, sta seems fine.

Which makes it my bug.. :)
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
algorithm
wil
Guests online: 104
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 Webmasters
1 Slaygon  (9.6)
2 Perff  (9.6)
3 Sabbi  (9.5)
4 Morpheus  (9.4)
5 CreaMD  (9.1)

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