; WriteBankAtomic Example ; ----------------------- ; Requires Extended mode. ; Build a tiny binary save header in a Bank: ; 4 magic bytes "SAVE", then a version Int, then the gold amount bank=CreateBank(12) PokeByte bank,0,Asc("S") PokeByte bank,1,Asc("A") PokeByte bank,2,Asc("V") PokeByte bank,3,Asc("E") PokeInt bank,4,3 ; Save format version PokeInt bank,8,1250 ; Gold ; WriteBankAtomic publishes the exact bytes atomically - a crash ; mid-write can never leave a truncated save on disk If WriteBankAtomic("savegame_example.bin",bank)=0 Then RuntimeError FilesystemError() Print "Wrote savegame_example.bin ("+FileSize("savegame_example.bin")+" bytes)" Print "" ; Read the file back to prove the bytes are untransformed file=ReadFile("savegame_example.bin") magic$=Chr(ReadByte(file))+Chr(ReadByte(file))+Chr(ReadByte(file))+Chr(ReadByte(file)) version=ReadInt(file) gold=ReadInt(file) CloseFile file Print "Read back - magic: "+magic+" version: "+version+" gold: "+gold FreeBank bank ; Clean up the file this example created DeleteFile "savegame_example.bin" Print "" Print "Press any key to close the example" WaitKey End