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


Forums > CSDb Entries > Release id #165826 : EasyFlash Saving
2018-06-28 09:41
Knight Rider

Registered: Mar 2005
Posts: 114
Release id #165826 : EasyFlash Saving

EasyFlash saving....

www.skoe.de/easyflash/files/devdocs/EasyFlash-ProgRef.pdf

It was q0w who brought this to my attention (after Sam's Journey). Not only does EAPIEraseSector take a lot of time, it actually causes chip deterioration (especially on older flash chips) as the erase cycles are finite.

The way my saver works is the following:

Save game under #$fe bytes
Assumption: Write to bank #$18 LOW

. Start at $8000 checking LH pointer, incrementing until result is not $00/$00 (the load address). (ie $8000, $8100 --> $a000/end). When data found this is the current save state.
. Delete by changing the load address to $00/$00
. Advance LOW bank address
. If $a000, then EAPIEraseSector, set LOW bank address back to $8000
. Save data (load address + data)

Save game over #$fe bytes
Assumption: Write to bank #$18 LOW

. Start at $8000 checking LH pointer, incrementing the bank until the result is not $00/$00 (the load address). (ie #$18, #$19 --> #$20/end). When data found this is the current save state.
. Delete by changing the load address to $00/$00
. Advance bank number
. If #$20, then EAPIEraseSector, set bank number back to #$18
. Save data (load address + data)

Save game over #$1ffe bytes
Assumption: Write to bank #$18 LOW & HIGH

. Start at $8000 checking LH pointer, incrementing the bank until the result is not $00/$00 (the load address). (ie #$18, #$19 --> #$20/end). When data found this is the current save state.
. Delete by changing the load address to $00/$00
. Advance bank number
. If #$20, then EAPIEraseSector <-- 2x for LOW bank & HIGH bank, set bank number back to #$18
. Save data (load address + data)
2018-06-28 11:06
JackAsser

Registered: Jun 2002
Posts: 1987
Nice, thanks. Eye of the Beholder will most probably feature flash save and those savegames are comparatively huge.
2018-06-28 11:21
Knight Rider

Registered: Mar 2005
Posts: 114
I didn't actually use the 1st example yet. Just coded it.

Tass Times in Tone Town uses the 2nd example.
Oil-Imperium [german] uses the 3rd example.

These 2 samples use inc/dec $d020 during saving. The initial value for $d020 is the actual bank number in use. This enables you to 'see' EAPIEraseSector. Generally the base screen screen is black during 'format', followed by white, red, cyan etc. See https://csdb.dk/release/?id=161988&show=notes#notes for further info.
2018-06-28 12:23
Flavioweb

Registered: Nov 2011
Posts: 442
The true problem which we have using EF save-to-flash code as HighScore/Status saver, is that each save will delete a "sector" of 64kb in flash ram.
We can't decide where a sector starts... we can just choose to use a Low or a Hi bank where to start, then format from here 64kb in Hi or Low memory "chip".
"Sectors" starts from Byte $0000 from the first $8000/$A/$E000 bank and next "sector" is exactly $10000 bytes forward.
Isn't possible to put data to be read/saved in random places on FlashRam... because when we go to save data to our "file", we need to "format" 64kb "around" it.
So, imho, the best solution is to reserve a 64kb sector just to store files for save operations...
A borderline case is, for eg GrandPrix Circuit, where we have 18 save file.
Put first file at the start of our reserved 64kb bank and saving to it, means that we delete all following files due to format operation.
And reserve 18x$10000 banks (1 for each file) is not feasible, because we need $12000 bytes just for this ($2000 too much just for saving...).
So, my solution, is to reserve a "files area" starting from a sector, where to put all saving files, making a backup/restore for each save, just changing the file that is written...
I asked to Skoe if there are other possibile solutions, but he stated:
Quote:
There is a technikal reason: That's the physical page size of (some) of the flash chips used.
2018-06-28 13:04
Knight Rider

Registered: Mar 2005
Posts: 114
You don't need to format a 64k sector for each save. You format the sector 1x and then fill it. Remember erasing a sector sets all bits to 1. When you write you can only set a bit to 0.

This means:

Erase a bank:
%11111111 x 64kb

Write a bank:
%11111111 x 64kb > something else until > %00000000 (final state)

So each file can be logically deleted.

Your file system could look like this:

Bank : EF Address : C64Load Address : File Name
$18    $8000        $1234             HS_01
$18    $8100        $4567             HS_02
.
.
.
$18    $9100        $7890             HS_18


now when you want to overwrite HS_01, you don't need to erase the sector. You logically delete it by EAPIWriteFlashInc $00 to $8000 (x2).

Taking my example #2, you simply EAPISetBank +1 to the logically deleted HS_01 and write a new one. You can do this right up to the end of memory, or keep within predefined boundaries.

this would result in:

Bank : EF Address : C64Load Address : File Name
$18    $8000        $0000             HS_01
$18    $8100        $4567             HS_02
.
.
.
$18    $9100        $7890             HS_18
$19    $8000        $1234             HS_01
2018-06-28 13:26
Knight Rider

Registered: Mar 2005
Posts: 114
See example:

;Sample Save Routine - Knight Rider Example #2
;-------------------------------------------
; Switch Bank
-       lda zpBANK      ;Some zero page address
        jsr EAPISETBANK

; Read The Destination Address From The EasyFlash
        ldy #$01
        lda (pDestL),y  ; pDestL is $8000 or whatever
        sta zpSavAH     ; H Start address during SAVE
        dey
        lda (pDestL),y  ; pDestL is $8000 or whatever
        sta zpSavAL     ; L Start address during SAVE

; If it is not ZERO then overwrite
        bne SEFJ1       ; Overwrite Old Save image
        lda zpSavAH     ; H Start address during SAVE
        bne SEFJ1       ; Overwrite Old Save image

; It is ZERO, increment the bank
        inc zpBANK      ;Some zero page address

; Loop
        bne -          ; Short JMP

;-------------------------------------------
; Overwrite Old Save image
SEFJ1

;Set The Pointer
        jsr SETPTR      ;EAPISETPTR

;Erase The Header
        txa             ;X is #$00
        jsr EAPIWRITEFLASHINC
        jsr EAPIWRITEFLASHINC

;Switch Bank
        lda zpBANK      ;Some zero page address
        clc
        adc #$01

;Check That We Are Still In Bounds
        cmp zpBANKe     ;End Bank
        bne +

;Switch Bank
        lda zpBANKs     ;Start Bank
        jsr EAPISETBANK

;Erase The Sector
        ldy pDestH      ;ie >$8000 or whatever
        jsr EAPIERASESECTOR

        jmp SEFJ2       ; Write New Save image

;Set The New Bank
+       jsr EAPISETBANK

;-------------------------------------------
; Write New Save image
SEFJ2

;Set The Pointer
        jsr SETPTR      ;EAPISETPTR

;Reset Save Start
        lda zpSavAL     ; L Start address during SAVE
        jsr EAPIWRITEFLASHINC ;Set Up The Needed Header
        lda zpSavAH     ; H Start address during SAVE
        jsr EAPIWRITEFLASHINC ;Set Up The Needed Header

;Save The Bytes
        ldy #$00
-       inc $01       ;ie $38
        lda (zpSavAL),y ; Start address during SAVE
        dec $01       ;ie $37
        jsr EAPIWRITEFLASHINC
        inc zpSavAL   ; L Start address during SAVE
        lda zpSavAL   ; L Start address during SAVE
        bne +
        inc zpSavAH   ; H Start address during SAVE
+       lda zpSavAH   ; H Check If The End Has Been Reached
        cmp zpSavEH   ; H End address for SAVE
        bne -
        lda zpSavAL   ; L Start address during SAVE
        cmp zpSavEL   ; L End address for SAVE
        bne -

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
apprentix
AMB/Level 64
Oxbow/Xenon
sebalozlepsi
iAN CooG/HVSC
Guests online: 129
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 No Bounds  (9.6)
7 Uncensored  (9.6)
8 Wonderland XIV  (9.6)
9 The Ghost  (9.6)
10 Bromance  (9.6)
Top onefile Demos
1 It's More Fun to Com..  (9.9)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 Rainbow Connection  (9.5)
6 TRSAC, Gabber & Pebe..  (9.5)
7 Onscreen 5k  (9.5)
8 Dawnfall V1.1  (9.5)
9 Quadrants  (9.5)
10 Daah, Those Acid Pil..  (9.5)
Top Groups
1 Oxyron  (9.3)
2 Nostalgia  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Swappers
1 Derbyshire Ram  (10)
2 Jerry  (9.8)
3 Violator  (9.8)
4 Acidchild  (9.7)
5 Starlight  (9.6)

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