Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Savegame Support #13

Open
FlorianMarsch opened this issue Feb 5, 2023 · 3 comments
Open

Savegame Support #13

FlorianMarsch opened this issue Feb 5, 2023 · 3 comments

Comments

@FlorianMarsch
Copy link

Hi, im currently doing some research on GBA Development and this Engine is by far the most user friendly I saw so far. It follows a nice approach and is far more beyond a collection of functions and all that.

What I appreciate is the Lua Layer you added to bring GBA development to more people, was also checking on the Rust Compiler and on other Engines. But what I miss in here is a support for saving your game state to cartridge :/

Is there any plan do support this? by doing so this would become far the most simple Engine I could imagine using for using for real projects :) Also do you consider to open the Engine? I think it could be worth to port some interpolator functions into c/c++ and make then accessible via a Lua function to increase performance

@evanbowman
Copy link
Owner

evanbowman commented Feb 5, 2023

Hi!

For saving, there's a section about writing to battery-backed SRAM in the readme: https://github.com/evanbowman/BPCore-Engine#ram-readwrite
Maybe I should add some examples. GBA cartridges contain a memory chip for storing save data. The engine allows you to write to an SRAM chip's memory by using any of the functions for writing values to ram. Commercial cartridges sometimes also included flash and eeprom in place of battery-backed SRAM, but I decided to only support SRAM, as it's simplest and most widely supported option (and easiest from a library user's perspective).

For adding additional functions to the engine in C/C++:
In the releases section, I attached a file called libBPCoreEngine_Ext.a. This static library implements the engine code, allowing you to compile your own version of BPCoreEngine.gba with added functionality. Then, implement bpcore_extension_main() to match the function signature found here https://github.com/evanbowman/BPCore-Engine/blob/master/source/bpcore.h, and link your program to the engine library. bpcore_entension_main(lua_State*) accepts a lua_State* as an argument, allowing you to bind natively compiled functions to variables in the lua environment.
I can make an example of adding extensions to the engine, as I haven't document the steps very well yet.

@evanbowman
Copy link
Owner

When writing engine extensions that link the static library release target (libBPCoreEngine_Ext.a), you'll need to use the correct gcc cross compiler and linker for the ARM7 architecture from devkitpro, so I'll make an example when I have some free time.

@nguyengiabach1201
Copy link

I use something like this in my project:

if btn(0) then
    poke4(_SRAM,"Saving")
end

if btn(1) then
    print(peek4(_SRAM))
end

Also, I have tested, and the maximum size for _SRAM is about 31.25KB:

poke4(_SRAM + 4 * 7999,"Saving")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants