Page 1 of 1

SRAM n00b

Posted: Wed Feb 02, 2011 12:21 pm
by Pascal
Hello all,

i'm playing with sram, i'm able to save , but i'm unable to reload the byte written , i got some garbage. Anyone got an idea what i'm doing wrong ?

thanks in advance

pascal

Code: Select all

  68K_DisableINT	
*** Save game****************************************************************


  lea   $A130F1,a0       
  lea   $200000,a1
       
	move.b #1,(a0)

	move.b #3,1(a1)
	
	; change de bank
	move.b #2,(a0)     ; sram write protected
	
** reload***********************************************************************
  clr.l d0

  move.b #3,(a0)
	
	move.b 1(a1),d0
	andi.l #$0003,d0    ; result in d0
		
	move.b #2,(a0)
	
	
	68K_EnableINT	

Posted: Wed Feb 02, 2011 1:20 pm
by HardWareMan
If your SRAM connected to VD0-VD7 you must use odd addresses.
lea $200001,a1

Posted: Wed Feb 02, 2011 2:48 pm
by sega16
Mabey you should check you this guide:(it worked for me)
http://sonicresearch.org/forums/index.p ... topic=2233
Also try movep instead of move
http://68k.hax.com/MOVEP

Posted: Wed Feb 02, 2011 3:12 pm
by Pascal
HardWareMan wrote:If your SRAM connected to VD0-VD7 you must use odd addresses.
lea $200001,a1
i'm already using odd address

Code: Select all

move.b #3,1(a0)
Mabey you should check you this guide:(it worked for me)
http://sonicresearch.org/forums/index.p ... topic=2233
Also try movep instead of move
http://68k.hax.com/MOVEP
thanks sega16, i'll check those links

Posted: Wed Feb 02, 2011 3:15 pm
by Pascal
Pascal wrote:
HardWareMan wrote:If your SRAM connected to VD0-VD7 you must use odd addresses.
lea $200001,a1
i'm already using odd address

Code: Select all

move.b #3,1(a1)
Mabey you should check you this guide:(it worked for me)
http://sonicresearch.org/forums/index.p ... topic=2233
Also try movep instead of move
http://68k.hax.com/MOVEP
thanks sega16, i'll check those links

Posted: Wed Feb 02, 2011 4:47 pm
by Eke
I am not sure to follow, are you talking about problem running this program on emulators or real hardware ?

- On most emulators, you must have a proper ROM header to tell the emulator you are using SRAM ("RA"). which address, which size, etc... Others will handle SRAM access by default when you write the cartridge area ($000000-$3fffff) or above the ROM size area since theorically SRAM can be mapped anywhere. On most emulators, you can write to odd or even address then read back without problems, you can also use word access. Afaik, the ROM header format have additional bits to indicate the type of SRAM used, not sure if any emulators use that but probably not .

On real hardware, it obviously depends how SRAM is mapped in the cartridge. I don't see why you could not have SRAM using the even address and high bits of the data bus, you could even use 16-bit SRAM chip if you want to.

- $A130F1 banking stuff is implemented by cartridge hardware, not the console itself. On emulators, it is only necessary if your ROM program size overlaps SRAM area. Most official games using SRAM never write this address as they have SRAM mapped outside ROM area ($200000-$3fffff, $300000-$3fffff, ...). I don't even think any of the few games that use banking for SRAM implement the SRAM write-protection bit anyway

So basically, the "How to work with SRAM" guide above does not make much sense, it entirely depends on the way SRAM is build in cartridge hardware or handled by the emulator you are using.

Posted: Thu Feb 03, 2011 3:26 am
by HardWareMan
Eke wrote:Afaik, the ROM header format have additional bits to indicate the type of SRAM used, not sure if any emulators use that but probably not .
Yes.

Code: Select all

   1B0H   dc.b       ‘RA’
   1B2H   dc.b       %1x1yz000
   1B3H   dc.b       %00100000
       x : 1 backuped by battery, 0 simple RAM
    y,z : 10 for even addresses (D8-D15), 11 for odd addresses (D0-D7)
           00 for all addresses (16 bit RAM)
   1B4H   dc.l       $XXXXXX : RAM start
   1B8H   dc.l       $XXXXXX : RAM end
Your K.O. :3

Posted: Thu Feb 03, 2011 12:13 pm
by Pascal
thanks all , i got it working in fusion , my rom is 2.5mo for now, so i used banking. Test on hardware later , once i'm back home (love my work :D)