Bootloader API library with SDHC and FAT32

Topics related to the API, programming discussions & questions, coding tips, bugs, etc. should go here.
User avatar
D3thAdd3r
Posts: 2422
Joined: Wed Apr 29, 2009 10:00 am
Location: Minneapolis, United States

Re: Bootloader API library with SDHC and FAT32

Post by D3thAdd3r » Wed Apr 04, 2018 10:24 pm

Do you need 32 bit sector numbers? 65536*512 = 32MB

User avatar
Artcfox
Posts: 948
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: Bootloader API library with SDHC and FAT32

Post by Artcfox » Thu Apr 05, 2018 2:57 am

I finally got it working! The library works fine, I was just reading beyond the level file without knowing it, because my calculations for which sector were off. The level generator only uses valid camera positions to calculate a sector index, so when calculating the sector index based on the camera position, I had to use the restricted width in the calculations, not the full width of the level. That put me on the right track enough to fix all of the other bugs that were in both the level generator and the code that used it.

Once things progress far enough, I'll try out the writing support, and let you know how that works. Thanks!

User avatar
Jubatian
Posts: 1381
Joined: Thu Oct 01, 2015 9:44 pm
Location: Hungary
Contact:

Re: Bootloader API library with SDHC and FAT32

Post by Jubatian » Tue Apr 10, 2018 11:35 am

How the write support is going?

I think I am going to merge it in. Lee added his streaming music, now at least a new addition wouldn't make stuff more complicated for anyone else. Nobody complained, so I guess it does its job fine.

User avatar
Artcfox
Posts: 948
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: Bootloader API library with SDHC and FAT32

Post by Artcfox » Tue Apr 10, 2018 12:00 pm

Jubatian wrote:
Tue Apr 10, 2018 11:35 am
How the write support is going?

I think I am going to merge it in. Lee added his streaming music, now at least a new addition wouldn't make stuff more complicated for anyone else. Nobody complained, so I guess it does its job fine.
I haven't gotten that far yet, I'm working on splitting the SD_Read_Sector_Nr_Nc function into two functions, one that cues the read, and another that checks for the data ready and does the actual read of the 512 bytes. That way I can cue the read up, do other stuff while waiting for data ready, and then hopefully by the time I go to read the actual data (30K clocks later, after ProcessSprites gets called) the data will be immediately ready, and I can just grab it all in ~17K clocks.

I want to make the demo record how long it takes for the data ready token to appear, and then write that to a file on the SD card, so I can get a sampling of what real-world cards take, and then tweak the emulators to allow them to simulate the speed of multiple cards.

Edit: I was able to split the asm function for reading a sector into two functions, the first cues a sector (issues a CMD17 and returns), and the second can get called later (hopefully) after the card has had time to make the data ready, so you don't have to block the entire time waiting for data ready. This is awesome, I'm starting to get comfortable modifying and splitting assembly language functions!
Last edited by Artcfox on Tue Apr 10, 2018 1:20 pm, edited 1 time in total.

User avatar
Artcfox
Posts: 948
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: Bootloader API library with SDHC and FAT32

Post by Artcfox » Tue Apr 10, 2018 12:33 pm

I just made a one-off to test write support, and from what I tested in the emulator (writing, moving to the next sector, writing again) it works great! :D This will definitely come in handy for saving states that are too large for the EEPROM.

Hopefully I get a chance to test it on real hardware tonight, but my vote is to merge it into the master branch.

User avatar
D3thAdd3r
Posts: 2422
Joined: Wed Apr 29, 2009 10:00 am
Location: Minneapolis, United States

Re: Bootloader API library with SDHC and FAT32

Post by D3thAdd3r » Tue Apr 10, 2018 1:44 pm

Very nice, I needed this feature!

User avatar
nicksen782
Posts: 675
Joined: Wed Feb 01, 2012 8:23 pm
Location: Detroit, United States
Contact:

Re: Bootloader API library with SDHC and FAT32

Post by nicksen782 » Tue Apr 10, 2018 4:38 pm

Oh! Great!

My original thought was to have one big data file and the first 512 bytes be for save data. Just a raw dump from the values stored in SPIRAM.

But now, would it make sense to have a second file where one is for data and the other is for saving? I could go either way.

I still need to learn to use the new bootloader SD features. I'm ready now with my game nearly finished and requiring some music.

User avatar
Artcfox
Posts: 948
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: Bootloader API library with SDHC and FAT32

Post by Artcfox » Tue Apr 10, 2018 6:41 pm

nicksen782 wrote:
Tue Apr 10, 2018 4:38 pm
Oh! Great!

My original thought was to have one big data file and the first 512 bytes be for save data. Just a raw dump from the values stored in SPIRAM.

But now, would it make sense to have a second file where one is for data and the other is for saving? I could go either way.

I still need to learn to use the new bootloader SD features. I'm ready now with my game nearly finished and requiring some music.
I'd at least make it the second sector of the file so you can have a header with a magic number in the first sector so you can verify that the file is your particular save file (in case of conflicting games with the same filename for instance), and store an offset to the start of the real level data so in case you need more sectors for saving state in the future, older versions of the game code can read a newer level/save file and automatically skip the appropriate number of save sectors to find the level data. If you really want to make it future-proof, toss in a version number too.

User avatar
Jubatian
Posts: 1381
Joined: Thu Oct 01, 2015 9:44 pm
Location: Hungary
Contact:

Re: Bootloader API library with SDHC and FAT32

Post by Jubatian » Tue Apr 10, 2018 6:52 pm

I merged the additions and expanded the Wiki with the new functions.

By the way you could even build your .uze file to include game data and saves. Neither the old or the new bootloader checks actual file size anyhow, they flash the game by the information in the first sector. So you can add extra data beyond the game which you could access directly by filesystem functions.

Of course this is just one way to do it, might be OK for some uses, not OK for another.

User avatar
D3thAdd3r
Posts: 2422
Joined: Wed Apr 29, 2009 10:00 am
Location: Minneapolis, United States

Re: Bootloader API library with SDHC and FAT32

Post by D3thAdd3r » Tue Apr 10, 2018 8:43 pm

I really like that concept of an all in one file, I will definitely try it.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests