evanbowman / BPCore-Engine

Lua game framework for Gameboy Advance
The Unlicense
165 stars 10 forks source link

Savegame Support #13

Open FlorianMarsch opened 1 year ago

FlorianMarsch commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 2 months ago

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")