News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: How to add sram saving to a MMC3 NES game? PUNES incompatibility (update:fixed!)  (Read 2110 times)

nesrocks

  • Hero Member
  • *****
  • Posts: 608
    • View Profile
    • nesrocks.com
So, I have added sram saving to my super pitfall hack and it is working on fceux, nestopia and nintendulator. But it it isn't working on punes. I've sent the rom to protomank and he tested on an everdrive v8 and it isn't saving there either. So I figured my saving implementation is incomplete.

What is the correct process to succesfully add saving feature to a game? I've eddited the header using NESHEAD, clicked the sram checkbox and saved the rom with the new header. Then I simply added code that reads / writes to $6000-$7FFF memory range whenever I needed. On the three mentioned emulators it saves perfectly, I can close them and it keeps all of the save.

But on punes it doesn't keep the save even when I do a soft reset, so I think my writes and reads to $6000-$7FFF are doing nothing at all, ever. I have tested wario's woods, a mmc3 game with save, and it is saving correctly on punes.

I save at any time during the game. Here's how I'm writting (it's as simple as it gets):
LDA $B2
STA $60B2
... many other addresses

And I load everytime I load the main menu:
LDA $60B2
STA $00B2
... many other addresses

My header settings, according to NESHEAD:
Mapper: 4
PRG 16K Count: 8
CHR 8K Count: 0
8K RAM-banks: 0
Mirroring: Vertical
SRAM: yes
Trainer: no
PAL: no
4-screen: no
VS Unisystem: no
Clean out possible garbage: yes

In other words:
   .db  $4E
   .db  $45
   .db  $53
   .db  $1A
   .db  $08
   .db  $00
   .db  $43
   .db  $00
   .db  $00
   .db  $00
   .db  $00
   .db  $00
   .db  $00
   .db  $00
   .db  $00
   .db  $00

If this is all there is to it then is it possible that it is a problem with my mmc3 conversion? The game is originally UNROM.

Thoughts?
« Last Edit: August 29, 2016, 02:47:58 pm by nesrocks »

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 6927
  • *sigh* A changed avatar. Big deal.
    • View Profile
Re: How to add sram saving to a MMC3 NES game
« Reply #1 on: August 29, 2016, 11:09:36 am »
I'm not sure whether punes by default emulates WRAM write-lock or not. (some MMC3 variations had write-lock I think, and some didn't)
Does it require the PRG-RAM size to be correct?
(does it save games for other games? I know that wasn't in the original iNES specification, and a value of 0 is supposed to be treated the same as 1 for compatibility)
"My watch says 30 chickens" Google, 2018

nesrocks

  • Hero Member
  • *****
  • Posts: 608
    • View Profile
    • nesrocks.com
Re: How to add sram saving to a MMC3 NES game
« Reply #2 on: August 29, 2016, 11:42:26 am »
Does it require the PRG-RAM size to be correct?
Sorry, I don't really understand the question. I set 8K RAM-banks to 1 and it still doesn't save.

(does it save games for other games? I know that wasn't in the original iNES specification, and a value of 0 is supposed to be treated the same as 1 for compatibility)
Yes, it works with wario's woods, which is also mmc3, but its header isn't exactly the same. CHR 8K Count, 8K RAM-banks and Mirroring are different.

Looking at the nesdev wiki on the mmc3 mapper page, there's this:

PRG RAM protect ($A001-$BFFF, odd)
7  bit  0
---- ----
RWXX xxxx
||||
||++------ Nothing on the MMC3, see MMC6
|+-------- Write protection (0: allow writes; 1: deny writes)
+--------- PRG RAM chip enable (0: disable; 1: enable)
Disabling PRG RAM through bit 7 causes reads from the PRG RAM region to return open bus.
Though these bits are functional on the MMC3, their main purpose is to write-protect save RAM during power-off. Many emulators choose not to implement them as part of iNES Mapper 4 to avoid an incompatibility with the MMC6.
See iNES Mapper 004 and MMC6 below.

I'll see if this is the case.

edit: yeah, I don't understand which byte holds these bits. I'm throughly confused. I'm starting to think this is handled by the ines header so it was already eddited by NESHEAD.
« Last Edit: August 29, 2016, 12:16:08 pm by nesrocks »

Disch

  • Hero Member
  • *****
  • Posts: 2746
  • NES Junkie
    • View Profile
Re: How to add sram saving to a MMC3 NES game? PUNES incompatibility
« Reply #3 on: August 29, 2016, 12:19:45 pm »
PRG-RAM has to be enabled on the MMC3 chip during runtime.  This means you'll have to make a code change -- it can't be done just in the header.

Code: [Select]
; Add this code somewhere in the startup code -- after Reset, before you try to read/write to SRAM
LDA #$80
STA $A001

Note you only have to do that once at startup.  Slipping it in the Reset routine is fine.

nesrocks

  • Hero Member
  • *****
  • Posts: 608
    • View Profile
    • nesrocks.com
Re: How to add sram saving to a MMC3 NES game? PUNES incompatibility
« Reply #4 on: August 29, 2016, 12:34:38 pm »
PRG-RAM has to be enabled on the MMC3 chip during runtime.  This means you'll have to make a code change -- it can't be done just in the header.

Code: [Select]
; Add this code somewhere in the startup code -- after Reset, before you try to read/write to SRAM
LDA #$80
STA $A001

Note you only have to do that once at startup.  Slipping it in the Reset routine is fine.
Perfectly accurate, I just did it and it is now working on punes! Thank you!!