Users browsing this thread: 1 Guest(s)
SRAM Expansion

#1
Posts: 3,969
Threads: 279
Thanks Received: 236
Thanks Given: 57
Joined: Oct 2011
Reputation: 65
Status
Tissue-aware
I think I got all the code for a SRAM Expansion. Instead of a toal of 8kb, I was able to expand to 128kb. There are limits on real hardware because of the carts but I think an emulator is only governed on this level by the SRAM byte and type of mapping. So basically there are 16 blocks of $2000 bytes each.

The hack is what FF6 T-Edition and FF6-G have, 3x $2000 bytes per save slot plus some all purpose SRAM that can be used as general RAM even. The code and some commentaries are not from me, I've only sorted this out and redirected the code to the US ROM equivalent routines. I'm not sure it works at 100%, but I had trouble until I changed the $C0 bank SRAM byte, then saving and loading was normal. I cannot test it outside this without more hacking but it's the same code as in FF6-G version 2016. Enjoy!

Code:
;-----------------------------------------------------------------------
; SRAM Expansion 1.0
;
; Slot 1 expanded to: $306000, $316000, $326000. $336000 is common SRAM.
; Slot 2 expanded to: $346000, $356000, $366000. $376000 is common SRAM.
; Slot 3 expanded to: $386000, $396000, $3A6000. $3B6000 is common SRAM.
;   SRAM expanded to: $3C6000, $3D6000, $3E6000. $3F6000 is common SRAM.
;-----------------------------------------------------------------------

org $C0FFD8
db #$07                                 ;SRAM size

LAB_C37083 equ $C37083                  ; Used for branches
LAB_C37047 equ $C37047

org $C3016F
    LDA $3F6001                         ; RNG index in SRAM (formely $307FF1)   
    INC                                 ; RNG index +1          
    STA $3F6001                         ; Save changes

org $C3151F
    STA $3F6000                         ; Set last altered file number (formley $307FF0)

org $C3154D
    JSL SAVE_GAME
    JMP LAB_C37083                      ; Mark all files

org $C31577
    JSL LOAD_GAME
    RTS

org $C31D36
    LDA $3F6000                         ; Last altered file

org $C33AAA                             ; Skins and skin colors
    LDA $32674E                         ; $30674E

org $C33AC6
    LDA $36674E                         ; $31674E

org $C33AE2
    LDA $3A674E                         ; $32674E

org $C33AF9
    LDA $32674E                         ; $30674E

org $C33B0D
    LDA $36674E                         ; $31674E

org $C33B21
    LDA $3A674E                         ; $32674E

org $C37028
    CMP $3F6008                         ; In file A?
    BEQ LAB_C37047                      ; Okay if so            
    CMP $3F600A                         ; In file B?    
    BEQ LAB_C37047                      ; Okay if so                
    CMP $3F600C                         ; In file C?    
    BEQ LAB_C37047                      ; Okay if so                
    CMP $3F600E                         ; In file D?...
    BEQ LAB_C37047                      ; Okay if so

org $C3704B
    JSL INIT_SRAM       
    RTS
    
org $C37088
    STA $3F6008                         ; Mark file A (formely $307FF8)
    STA $3F600A                         ; Mark file B (formely $307FFA)
    STA $3F600C                         ; Mark file C (formely $307FFC)
    STA $3F600E                         ; No file D.. (formely $307FFE)
    
;=======================================
; Extra Code
;=======================================
org $F30000
SAVE_GAME:
    CPX #$1400                          ; Is it slot 3?             
    BEQ LAB_BR_SAVE386000               ; Branch if so              
    CPX #$0A00                          ; Is it slot 2?             
    BEQ LAB_BR_SAVE346000               ; Branch if so
;=======================================
; Slot 1
;=======================================    
    TDC                                 ;               
    TAX                                 ;               
LAB_LP_SAVE326000:
    LDA $1600,y                         ; RAM to be saved   
    STA $326000,x                       ; Store in expanded SRAM
    INX                                 ; X++           
    INY                                 ; Y++           
    CPX #$0A00                          ;
    BNE LAB_LP_SAVE326000               ; Loop until we copied 2560 bytes   
    TDC                                 ;   
    TAX                                 ;       

LAB_LP_SAVE326A00:
    LDA $3E6000,x                       ; Copy all purpose SRAM to Slot 1               
    STA $326A00,x                       ;               
    INX                                 ;           
    CPX #$1600                          ;
    BNE LAB_LP_SAVE326A00               ;   
    TDC                                 ;               
    TAX                                 ;               

LAB_LP_SAVE306000:
    LDA $3C6000,x                       ; Copy all purpose SRAM to Slot 1               
    STA $306000,x                       ;               
    LDA $3D6000,x                       ;               
    STA $316000,x                       ;               
    INX                                 ;           
    CPX #$2000                          ;
    BNE LAB_LP_SAVE306000               ;               
    LDA #$00                            ;               
    STA $3F6002                         ; Some sort of slot index not used anywhere else (would be $307FF2)             
    JMP LAB_BR_SAVE___END               ; Exit              


LAB_BR_SAVE386000:
    JMP LAB_JP_SAVE386000               ; Jump to Slot 3 saving (Original BEQ out of reach)
;=======================================
; Slot 2
;=======================================
LAB_BR_SAVE346000:
    TDC                                 ;               
    TAX                                 ;               
LAB_LP_SAVE366000:
    LDA $1600,y                         ; RAM to be saved   
    STA $366000,x                       ; Store in SRAM
    INX                                 ; X++           
    INY                                 ; Y++           
    CPX #$0A00                          ;   
    BNE LAB_LP_SAVE366000               ; Loop until we copied 2560 bytes               
    TDC                                 ;               
    TAX                                 ;               

LAB_LP_SAVE366A00:
    LDA $3E6000,x                       ; Copy all purpose SRAM to Slot 2               
    STA $366A00,x                       ;               
    INX                                 ;       
    CPX #$1600                          ;   
    BNE LAB_LP_SAVE366A00               ;               
    TDC                                 ;               
    TAX                                 ;               

LAB_LP_SAVE346000:
    LDA $3C6000,x                       ; Copy all purpose SRAM to Slot 2               
    STA $346000,x                       ;               
    LDA $3D6000,x                       ;               
    STA $356000,x                       ;               
    INX                                 ;           
    CPX #$2000                          ;   
    BNE LAB_LP_SAVE346000               ;               
    LDA #$01                            ; Some sort of slot index not used anywhere else (would be $307FF2)                             
    STA $3F6002                         ;               
    JMP LAB_BR_SAVE___END               ; Exit              
;=======================================
; Slot 3
;=======================================
LAB_JP_SAVE386000:
    TDC                                 ;               
    TAX                                 ;               
LAB_LP_SAVE3A6000:
    LDA $1600,y                         ; RAM to be saved       
    STA $3A6000,x                       ; Store in SRAM
    INX                                 ; X++           
    INY                                 ; Y++           
    CPX #$0A00                          ;   
    BNE LAB_LP_SAVE3A6000               ; Loop until we copied 2560 bytes               
    TDC                                 ;               
    TAX                                 ;               

LAB_LP_SAVE3A6A00:
    LDA $3E6000,x                       ; Copy all purpose SRAM to Slot 3               
    STA $3A6A00,x                       ;               
    INX                                 ;           
    CPX #$1600                          ;   
    BNE LAB_LP_SAVE3A6A00               ;               
    TDC                                 ;               
    TAX                                 ;               

LAB_LP_SAVE386000:
    LDA $3C6000,x                       ; Copy all purpose SRAM to Slot 3               
    STA $386000,x                       ;               
    LDA $3D6000,x                       ;               
    STA $396000,x                       ;               
    INX                                 ;           
    CPX #$2000                          ;
    BNE LAB_LP_SAVE386000               ;               
    LDA #$02                            ;               
    STA $3F6002                         ; Some sort of slot index not used anywhere else (would be $307FF2)                 

LAB_BR_SAVE___END:
    RTL                                 ; Exit              

;=======================================
; SRAM Loading
;=======================================
LOAD_GAME:
    CPX #$1400                          ; Check if slot 3               
    BEQ LAB_BR_LOAD386000               ; Branch if so              
    CPX #$0A00                          ; Check if slot 2               
    BEQ LAB_BR_LOAD346000               ; Branch if so              
    TDC                                 ;               
    TAX     
;=======================================
; Slot 1
;=======================================                    
LAB_LP_LOAD326000:
    LDA $326000,x                       ; Load original SRAM    
    STA $1600,y                         ;   
    INX                                 ;           
    INY                                 ;           
    CPX #$0A00                          ;   
    BNE LAB_LP_LOAD326000               ;               
    TDC                                 ;               
    TAX                                 ;               

LAB_LP_LOAD326A00:
    LDA $326A00,x                       ; Load All Purpose SRAM             
    STA $3E6000,x                       ;               
    INX                                 ;           
    CPX #$1600                          ;   
    BNE LAB_LP_LOAD326A00               ;               
    TDC                                 ;               
    TAX                                 ;               

LAB_LP_LOAD306000:
    LDA $306000,x                       ; Load All Purpose SRAM             
    STA $3C6000,x                       ;               
    LDA $316000,x                       ;               
    STA $3D6000,x                       ;               
    INX                                 ;           
    CPX #$2000                          ;   
    BNE LAB_LP_LOAD306000               ;               
    JMP LAB_BR_LOAD___END               ; Exit              
;=======================================
; Slot 2
;=======================================
LAB_BR_LOAD346000:
    TDC                                 ;               
    TAX                                 ;               
LAB_LP_LOAD366000:
    LDA $366000,x                       ; Load original SRAM
    STA $1600,y                         ;   
    INX                                 ;           
    INY                                 ;           
    CPX #$0A00                          ;   
    BNE LAB_LP_LOAD366000               ;               
    TDC                                 ;               
    TAX                                 ;               

LAB_LP_LOAD366A00:
    LDA $366A00,x                       ; Load All Purpose SRAM             
    STA $3E6000,x                       ;               
    INX                                 ;           
    CPX #$1600                          ;   
    BNE LAB_LP_LOAD366A00               ;               
    TDC                                 ;               
    TAX                                 ;               

LAB_LP_LOAD346000:
    LDA $346000,x                       ; Load All Purpose SRAM             
    STA $3C6000,x                       ;               
    LDA $356000,x                       ;               
    STA $3D6000,x                       ;               
    INX                                 ;           
    CPX #$2000                          ;   
    BNE LAB_LP_LOAD346000               ;               
    JMP LAB_BR_LOAD___END               ; Exit              
;=======================================
; Slot 3
;=======================================
LAB_BR_LOAD386000:
    TDC                                 ;               
    TAX                                 ;               
LAB_LP_LOAD3A6000:
    LDA $3A6000,x                       ; Load original SRAM    
    STA $1600,y                         ;   
    INX                                 ;           
    INY                                 ;           
    CPX #$0A00                          ;   
    BNE LAB_LP_LOAD3A6000               ;               
    TDC                                 ;               
    TAX                                 ;               

LAB_LP_LOAD3A6A00:
    LDA $3A6A00,x                       ; Load All Purpose SRAM             
    STA $3E6000,x                       ;               
    INX                                 ;           
    CPX #$1600                          ;   
    BNE LAB_LP_LOAD3A6A00               ;               
    TDC                                 ;               
    TAX                                 ;               

LAB_LP_LOAD386000:
    LDA $386000,x                       ; Load All Purpose SRAM             
    STA $3C6000,x                       ;               
    LDA $396000,x                       ;               
    STA $3D6000,x                       ;               
    INX                                 ;           
    CPX #$2000                          ;   
    BNE LAB_LP_LOAD386000               ;               

LAB_BR_LOAD___END:
    RTL                                 ; Exit              

;=======================================
; SRAM Init
;=======================================
INIT_SRAM:
    TDC                                 ;       
    TAX                                 ;       
LAB_LP_INIT306000:
    STA $306000,x                       ; $306000,x = 0
    STA $316000,x                       ; $316000,x = 0
    STA $326000,x                       ; $326000,x = 0
    STA $336000,x                       ; $336000,x = 0
    STA $346000,x                       ; $346000,x = 0
    STA $356000,x                       ; $356000,x = 0
    STA $366000,x                       ; $366000,x = 0
    STA $376000,x                       ; $376000,x = 0
    STA $386000,x                       ; $386000,x = 0
    STA $396000,x                       ; $396000,x = 0
    STA $3A6000,x                       ; $3A6000,x = 0
    STA $3B6000,x                       ; $3B6000,x = 0
    STA $3C6000,x                       ; New line added (see below)
    STA $3D6000,x                       ; $3D6000,x = 0
    STA $3E6000,x                       ; $3E6000,x = 0
    STA $3F6000,x                       ; $3F6000,x = 0
    INX                                 ;           
    CPX #$2000                          ;   
    BNE LAB_LP_INIT306000               ;               

;   TDC                                 ; This code is some sort of item init, I leave it as reference.         
;   TAX                                 ;           
;   DEC                                 ;               
;   REP #$20                            ;               
;   LDA #$02FF                          ;               
;LAB_LP_INIT3C6000:
;   STA $3C6000,x                       ;   
;   INX                                 ;           
;   INX                                 ;           
;   CPX #$0600                          ;   
;   BNE LAB_LP_INIT3C6000               ;               

;   TDC                                 ;           
;LAB_LP_INIT3C6600:
;   STA $3C6000,x                       ;
;   INX                                 ;       
;   CPX #$2000                          ;
;   BNE LAB_LP_INIT3C6600               ;               
;   SEP #$20                            ;               
    RTL  
  Find
Quote  
[-] The following 2 users say Thank You to madsiur for this post:
  • B-Run (12-19-2016), Gi Nattak (12-19-2016)

#2
Posts: 1,633
Threads: 56
Thanks Received: 13
Thanks Given: 84
Joined: Apr 2014
Reputation: 12
Status
Atma
so you already made it work?

maybe it's not much useful, but here's some line of random conversation among me and Everything about SRAM expansion:
--------------------------------
In an FF3 cartridge, the SRAM chip is only 8192 bytes (from $30/6000 to $30/7FFF) but in other game cartridges 
the SRAM can be larger.

Emulators and ROMs don't have hardware limitations like cartridges though. If you wanted to enlarge the SRAM 
for a ROM I believe it would be as simple as adjusting the ROM header byte at $C0/FFD8. The value for the 
original FF3 ROM is $03, which indicates a 64K Bit SRAM (8192 bytes). If you change this value to $05, the 
emulator should automatically increase the SRAM size to 256K Bit. According to the SNES Dev Manual, the 
additional SRAM will be available from $31/6000 to $31/7FFF, $32/6000 to $32/7FFF, and $33/6000 to $33/7FFF.

You can read and write SRAM any time you want. Check out the way the game does it at C3/151D (save game) 
and C3/1566 (load game).
-------------------------------

PS: i don't even remember how we ended up talking about SRAM expansion...  Tongue


THE GREATEST CHALLENGE OF ALL TIMES AWAITS:
http://www.ff6hacking.com/forums/showthr...p?tid=2593
DO YOU HAVE WHAT IT TAKES TO SLAY A GOD?
------------------------------------------------------------------------
Tenkarider's project #2 is started: FF6 Curse of the Madsiur Joke (CotMJ)
http://www.ff6hacking.com/forums/showthr...p?tid=2755
What happens when Madsiur tweaks your account? This full game hack will show that!
  Find
Quote  

#3
Posts: 281
Threads: 18
Thanks Received: 13
Thanks Given: 8
Joined: Mar 2014
Reputation: 8
Status
None
Hooray! This is the first step towards many interesting possibilities such as expansion of spells, items, chests, event bits. Not to mention the incredible utility of having lots of free general-purpose RAM available for battle functions.
  Find
Quote  

#4
Posts: 3,969
Threads: 279
Thanks Received: 236
Thanks Given: 57
Joined: Oct 2011
Reputation: 65
Status
Tissue-aware
(12-17-2016, 06:00 AM)Tenkarider Wrote: Emulators and ROMs don't have hardware limitations like cartridges though. If you wanted to enlarge the SRAM 
for a ROM I believe it would be as simple as adjusting the ROM header byte at $C0/FFD8. The value for the 
original FF3 ROM is $03, which indicates a 64K Bit SRAM (8192 bytes). If you change this value to $05, the 
emulator should automatically increase the SRAM size to 256K.

It seems setting the byte to #$07 gives 128kb. Maybe 256kb would be #$0F, I'm not sure. As this post state, if your game has 8kb of SRAM, it would be mirrored among all the banks. A SRAM hack is also a good way to keep repros guys away, as I'm not sure if carts with 128kb or 256kb of SRAM are found easily.

(12-17-2016, 09:16 AM)seibaby Wrote: Hooray! This is the first step towards many interesting possibilities such as expansion of spells, items, chests, event bits. Not to mention the incredible utility of having lots of free general-purpose RAM available for battle functions.

Yes! FF6-G and FF6 T-Edition use it for item expansion among other things like more rare items. We could even have a bestiary with each monster having a bit set to show his entry or more rages. There's a lot of possibilities.
  Find
Quote  

#5
Posts: 763
Threads: 83
Thanks Received: 55
Thanks Given: 7
Joined: Apr 2015
Reputation: 22
Status
Obliviscence
After I went through ALL THAT WORK setting up Magic 2.0 you're telling me we can just expand SRAM now and go back to 1 byte per spell!?!

Ok, I can't even get mad, that's really cool...

I guess Magic 2.2 will be a thing one day... reverting to one byte per spell but keeping all my additional functionality and flexibility.
  Find
Quote  

#6
Posts: 281
Threads: 18
Thanks Received: 13
Thanks Given: 8
Joined: Mar 2014
Reputation: 8
Status
None
Just you wait, in a few years we'll have filled out that SRAM with cool expansions and your old version will again be sought after! Tongue

I'm eyeing some of it myself to use as WRAM for extra battle timers/counters/multipliers/cooldowns.
  Find
Quote  



Forum Jump:

Users browsing this thread: 1 Guest(s)


Theme by Madsiur2017Custom Graphics by JamesWhite