Patater

Projects Books Links Blarg About Donate

Day 20 - Using SRAM

Mike Huber

Published: 2005-Jul-21; Updated: 2010-Dec-18

Using SRAM

First off, if this is wrong, somebody who possibly already knows about this, please correct me. The info below is my understanding of how things work, but it is quite likely that there is something that I'm not doing correctly.

SRAM

If I'm doing this correctly, it's really simple. If your cart has battery-backed up SRAM on it, then all you have to do is write to CPU memory anywhere from $6000-$8000, that's 8KB of save space. Someone was kind enough to email me the meaning of all the numbers that you can pass to .inesmir (although I didn't have a chance to email him back :( ):

0</dt
= H (Horizontal Mirroring ONLY)
1</dt
= V (Vertical Mirroring ONLY)
2</dt
= H + Bat. (Horiztonal Mirroring + Battery ON)
3</dt
= V + Bat. (Vertical Mirroring + Battery ON)
4</dt
= H + Train. (Horizontal Mirroring + Trainer ON)
5</dt
= V + Train. (Vertical Mirroring + Trainer ON)
6</dt
= H + Bat. + Train. (Horizontal Mirroring + Battery and Trainer ON)
7</dt
= V + Bat. + Train. (Vertical Mirroring + Battery and Trainer ON)
8</dt
= H + 4scr. (Horizontal Mirroring + 4 Screen VRAM ON)
9</dt
= V + 4scr. (Vertical Mirroring + 4 Screen VRAM ON)
A</dt
= H + Bat. + 4scr. (Horizontal Mirroring + Battery and 4 Screen VRAM ON)
B</dt
= V + Bat. + 4scr. (Vertical Mirroring + Battery and 4 Screen VRAM ON)
C</dt
= H + 4scr. + Train. (Horizontal Mirroring + 4 Screen VRAM and Trainer ON)
D</dt
= V + 4scr. + Train. (Vertical Mirroring + 4 Screen VRAM and Trainer ON)
E</dt
= H + Bat. + 4scr. + Train. (Horizontal Mirroring + Battery, 4 Screen VRAM, and Trainer ON)
F</dt
= V + Bat. + 4scr. + Train. (Vertical Mirroring + Battery, 4 Screen VRAM, and Trainer ON)

That is right from his email (Battery ON means the cart has SRAM). The only thing I don't understand is how you can have mirroring and still have 4 Screen VRAM or if that's a mistake or something...

An Example

Here it is:

;-- CODE START --; .inesmir 2 ; -- 2 means Horizontal mirroring and an SRAM chip; .inesmap 0 ; -- If I feel adventurous, you might see Mapper 1 next time ;) .inesprg 1 ; -- One bank of PRG-ROM .ineschr 0 ; -- no banks of CHR-ROM in this example .bank 1 .org $FFFA .dw 0 .dw START .dw 0 .bank 0 .org $C000 START: ldx #0 ; ----| loop: lda text,x ; |-- there's probably a way of doing this in less cycles.. sta $6000,x ; |-- if you figure out a way, show me and 1000 points to you.. inx ; |-- the points don't matter anyway, so I guess it doesn't matter. cmp #0 ; | bne loop ; ---|-- this routine writes a ASCIIZ string into SRAM (I hope). infin: jmp infin text: .db "Hello, NES!",0 ;-- CODE END --;

If everything goes as planned, "Hello, NES!" should be saved. If you're using FCEUltra (I recommend it.), you should see a .SAV file created, which is the same size as SRAM (8KB) and if you open it in notepad, you'll see the text. I would assume the .SAV file is just an exact copy of $6000-$8000.

This Day In Review

Now you can save your game if you couldn't before!

Have fun!,
-GbaGuy