Log In  

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 ?

P#28924 2016-09-21 00:48 ( Edited 2016-09-24 02:37)

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?

P#29003 2016-09-22 00:14 ( Edited 2016-09-22 04:14)

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.

P#29005 2016-09-22 00:36 ( Edited 2016-09-22 04:36)

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.

P#29008 2016-09-22 01:05 ( Edited 2016-09-22 05:07)

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.

P#29027 2016-09-22 09:10 ( Edited 2016-09-22 13:10)

Rytrasmi, I'm wondering if it will work if I post it as a cart in the BBS here.

P#29033 2016-09-22 12:31 ( Edited 2016-09-22 16:31)

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.

P#29043 2016-09-22 13:04 ( Edited 2016-09-22 17:04)

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. :)

P#29049 2016-09-22 13:20 ( Edited 2016-09-22 17:20)

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:

https://www.lexaloffle.com/bbs/?tid=27731

P#29207 2016-09-23 22:37 ( Edited 2016-09-24 03:05)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 15:06:00 | 0.008s | Q:21