Gameboy Development Forum

Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)

You are not logged in.

Ads

#1 2019-04-10 06:15:23

colorful_courier
Member
Registered: 2017-03-12
Posts: 14
Website

how to .sav file?

hello
working on a new and exciting project for a cool festival smile and i want to create a save file.
i'm not finding much materials about this subject hmm
anyone knows how to do so, or can point my to a relevant link?
thanks

Offline

 

#2 2019-04-10 06:44:00

gbjosh
Member
From: KY
Registered: 2016-06-15
Posts: 51

Re: how to .sav file?

Are you using gbdk or asm?

Offline

 

#3 2019-04-10 07:02:20

colorful_courier
Member
Registered: 2017-03-12
Posts: 14
Website

Re: how to .sav file?

asm smile

Offline

 

#4 2019-04-17 04:56:49

ISSOtm
Member
From: Somewhere in Echo RAM
Registered: 2017-04-18
Posts: 160
Website

Re: how to .sav file?

I believe you've already been answered on IRC, but written reference is always good, so here goes.

For ROMs to correctly produce save files on emulators, you need to do two things.
First, make sure the MBC type in the header is set to a type that includes RAM+BATTERY. RAM means the "cartridge" contains extra RAM, BATTERY means the RAM is battery-backed, ie that it can retain data between resets. [1][2]
Second, set the SRAM size to something non-zero. [3][4]

Footnotes:
[1] ROM+RAM+BATTERY is *in theory* a valid combination, however since no commercial ROM ever made use of it, compatibility is hit-or-miss.
[2] MBC2 has a built-in RAM of 512 half-bytes (256 bytes total), which works somewhat differently. Check the wiki for more info.
[3] 2kB is possible but not recommended, according to beware. Probably due to only partially filling the SRAM space.
[4] The situation for SRAM sizes over 32kB are more complex. 64kB is only used by Pokémon Crystal JP (with a special variant of MBC3 known as MBC30). 128kB is only possible with MBC5. Compatibility with both of those is hit-or-miss too, for example Gambatte versions older than this commit didn't do 64k or 128k, nor do the original EverDrive GB models; the X series does support 64k SRAM but not 128k, due to what may be a software bug.


The French Lord Of Laziness.
Legend of Zelda and Undertale fan, I also tend to break Pokémon R/B/Y a little too much.

Twitter | Me on GCL | Discord : ISSOtm#9015 | Skype : isso.tm (I don't login anymore)

Offline

 

#5 2019-04-22 16:39:25

Mills
Member
Registered: 2012-12-21
Posts: 132

Re: how to .sav file?

Hi.

I saw the thread and I am wondering... how can you use the external RAM from the cartridge to store maps?

My goal is to store a level map in that ram, (just 8 kb is enough) so I can edit the tiles (to collect coins like in mario games).

I used the gbdk functions to test (ENABLE_RAM_MBC5; SWITCH_RAM_MBC5(0)) and also inline assembly, but it just worked for small arrays, the moment I try to store something big, it fails.

Also in BGB I can see A000, and it looks just as rom bank 1. So I'm doing something very wrong smile.


Do all flash carts have external ram?. if not, maybe using it is not a good idea...
I own an USB smart cart, and it looks like it has 128 Kb of ram. what is the bank it is using for for saves?.

EDIT: got it!.

Just assigned an address to the map array (0xA000). Once you enable the ram, and switch to relevant bank, you can always access that array.

Also The only settings that work in the linker are :

-Wl-yt27 (ROM+MBC5+RAM+BATT)

-Wl-ya4 (RAM = 128kb). You only need 8 Kb, but setting it to 128 was the only option that worked for me.

I tested it on the USB Smart Cart, and it worked ok.

Last edited by Mills (2019-04-23 07:22:17)

Offline

 

#6 2019-04-30 10:28:49

colorful_courier
Member
Registered: 2017-03-12
Posts: 14
Website

Re: how to .sav file?

thanks ISSOtm!
tidy and beautiful as always

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson