Could someone please post a fully working example program making use of the CSTORE command and how to maintain user saved data even if the version changes by creating a 2nd file as the instructions hint at ?
To save persistent data in a separate cart, I assume you just memcpy it to some spare space before you save it. (since persistant data is in protected ( >= 0x4300) memory)
function backup() memcpy(0x[unused], 0x5e00, 256) cstore(0x[unused], 0x[unused], 256, "mysavedata.p8") end--backup function restore() reload(0x[unused], 0x[unused], 256, "mysavedata.p8") memcpy(0x5e00, 0x[unused], 256) end--restore |
Also have you seen zep's data compression cart?
Here's how I'd do it.
--This is the data you want to save. Each entry is a byte (0-255): msg = {1,2,3,4,5,6,7,8,9,10,255} --Store each byte of data in user RAM, which begins at 0x4300: for i=1,#msg do poke(0x4300+(i-1),msg[i]) end --Copy the relevant part of user RAM to another cart's ROM: cstore(0x0000,0x4300,#msg,"saved_data.p8") |
Load the cart called saved_data and look at the sprite sheet. There's your data.
Thanks very much, Tyroney and Rytrasmi ... I will need some time to look this over to see just what is happening.
I think I have determined one perfect area to use for temporary storage that will not affect tiles, map, audio, or music.
Rytrasmi, will your code work Online ?
Tyroney, I looked at his compression Cart, but that's not going to be effective for what I want.
It works when run as HTML locally. The cartridge "saved_data.p8" gets stored by the browser in a local file, somewhere in the browser's file system. I don't see why it wouldn't also work if the HTML was on the internet. It would be easy to test.
Feel free to post it. It might be hard to tell if it worked. You'd have to dig around your browser's local storage area looking for something called saved_data.p8. I say "something" because it may not be a file. It could be stored in a database or in a larger file. You could add some reload code to do a full load/save test. I might get around to that.
I'll make a test cart and post it Online a little later. Thanks for the initial info, Rytrasmi and Tyroney.
If it works, I think I'll be able to write a program that demonstrates how to load and save 8192 bytes of any code, even if it is later updated. 32 times the normal space of 256-bytes. :)
Guys, it's working now !
Ah ha, scratching back of head I don't know, it wasn't working earlier. Works fine now. You can find it HERE:
[Please log in to post a comment]