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

Wrong behavior for sram with hirom #286

Open
alekmaul opened this issue Jun 11, 2024 · 1 comment
Open

Wrong behavior for sram with hirom #286

alekmaul opened this issue Jun 11, 2024 · 1 comment

Comments

@alekmaul
Copy link
Owner

SRAM mapping in hirom is a bit more complicated in then in lowram LoROM (unless SRAM is < 8KiByte when SRAM is > 8KiB in size)
https://snes.nesdev.org/wiki/Memory_map#HiROM
SNESdev Wiki
Memory map
The SNES natively provides access to RAM and I/O at specific locations. The cartridge is free to provide whatever it wants in the remaining space, and there are specific address ranges that are conventionally used to add access to additional hardware such as extra RAM or a coprocessor. Different address ranges are accessed at different speeds, a...
For HIROM, you would want to change
BANK_SRAM to $30
The sta 0,y in line 190 to sta $6000,y
The lda 0,y in line 236 to lda $6000,y
And that would get consoleCopySram() and consoleLoadSram() temporarily working for HIROM if SRAM size <= 8KiByte
(I think)
A proper fix would use ifdefs and use defines for SRAM bank, starting address and bank size.

@DigiDwrf
Copy link
Contributor

Indeed. That's why I came up with a solution:

the HiRom header looks like this:

.MEMORYMAP                      ; Begin describing the system architecture.
  SLOTSIZE $10000               ; The slot is $10000 bytes in size. More details on slots later.
  DEFAULTSLOT 0                 ; There's only 1 slot in SNES, there are more in other consoles.
  SLOT 0 $0000                  ; Defines Slot 0's starting address.
  SLOT 1 $0 $2000               ; Used for low RAM allocation
  SLOT 2 $2000 $E000            ; Used for RAM allocation
  SLOT 3 $0 $10000              ; Used for global RAM allocation
  SLOT 4 $6000                  ; Used for SRAM storage. <---- JUST HERE!!
.ENDME                          ; End MemoryMap definition

So, SLOT 4 is used for SRAM storage. A RAM secton can be added inside an ASM file like this:

.RAMSECTION ".save_file" BANK $30 SLOT 4
    save_file        DSB  2048            ; There's a size limit of 2048 bytes for HiRom
.ENDS

At last, an extern variable inside any .c or .h file has to be declared in order to access data:

typedef struct
{
    u32 var1;
    u16 var2;
    u8 var3;
    // etc...
} custom_savefie_struct;

extern custom_savefie_struct save_file[3]; // you can declare an array if you use more that one save file inside your program.

This is just an example, data can be declared an modified in any other way of course. And that's it! any modification to that variable, will automatically write SRAM data, and no fuction is needed.

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

2 participants