Page 1 of 1

Problem with accessing SRAM

Posted: Thu Dec 07, 2006 9:16 am
by TmEE co.(TM)
I'm writing a game for MD (Glass Braker MD) which is uses SRAM, but I have trouble accessing it.

MOVE.L #$00010001, A0 ; load SRAM start addess
MOVE.B #230, (A0) ; write byte
MOVE.B (A0), D0 ; read byte

Trouble is that the read byte is not 230 but 0. SRAM gets saved with 230 in *.SRM file. What needs to be done first to read SRAM ???
My cartridge design allows this kind of memory access.

Posted: Thu Dec 07, 2006 9:31 am
by Stef
You have some banking control bit in the IO area of Genesis mem map.
The 0xA130F1 port control SRAM :
bit 0 : SRAM Enabled
bit 1 : SRAM ReadOnly

So take care of writing $01 to 0xA130F1 before writing to your SRAM.
$03 enable SRAM but in ReadOnly Mode
$00 desactive SRAM

Posted: Thu Dec 07, 2006 9:49 am
by ob1
I'm not sure to have understood everything.
Let me sum it up.
You want to save something in Save RAM, or static RAM, which should be present on a cartrige with a backup, don't you ? Reading SRAM, I thought you were refering to Vertical Scroll RAM or Scroll RAM !!!

Is SRAM a feature of the genesis ? Looking at Gens, I only found SRAM on SegaCD.

On the Genesis, @00010001 is ROM Cartrige memory, so read-only. When I run this code, the value was FF, and remains FF. Importing to me, that's a normal behaviour : you shoudln't be able to write values on this address.

I've read some times ago that Save RAM did exist, and maybe near this address, but I don't remember anything.

Nevertheless, have you tried accessing memory by word, and not by byte ?

Code: Select all

	MOVE.L #$00010000, A0 ; load SRAM start addess
	MOVE.W #230, (A0) ; write word
	MOVE.W (A0), D0 ; read word 
[/code]

Posted: Thu Dec 07, 2006 4:04 pm
by TmEE co.(TM)
The STATIC RAM on the cartridge. The cartridge works like this :
any access below 10000h enables ROM and access above enables RAM,
If you write something, the 68K pulls !LDSW (or !UDSW) low and that signal is used as WriteEnable on RAM. I did such thing with my pirate Sonic3 cartridge which doesn't have RAM (now it has) and everything works as intended.
I'll check that I/O reg as soon as I get behind my PC.

Posted: Fri Dec 08, 2006 1:41 pm
by TmEE co.(TM)
That I/O reg didn't work, still cannot read what is stored :(

Posted: Fri Dec 08, 2006 10:25 pm
by Stef
Strange.. are you doing byte access to the IO reg port ? then are you waiting some cycles (doing 6 or 7 nop) before doing your write and your read ? the hardware takes sometime to "acknowledge" your command.

Posted: Sat Dec 09, 2006 11:18 am
by TmEE co.(TM)
No byte access, I used long word. I want my game to work in emulators too not only on real hardware (and that method works on real HW). I'll try NOPping.
As far as I know, there is no rom/ram banking mechanisms in MD, if you want such thing you need to develope it on a cartridge. I believe that reg changes the state on the of some signal on the cart slot which the cart uses to change banks. My method is much simpler, but that has not been practiced by any commercial games and no emulator supports this. At least I think so...

Posted: Sat Dec 09, 2006 1:56 pm
by Stef
Yeah, the IO reg acts on some ROM port pin's so the cart has to wired them somewhere... Almost emulator expect the SRAM to be located at 0x200000. The SRAM location in rom header is sometime wrong and emulator can't rely only on that. Anyway i believe Gens does use it so it should work in our case.

Posted: Mon Dec 11, 2006 2:05 pm
by TmEE co.(TM)
Damn, I forgot to check if NOPs work, I was too busy testing my games and stuff on real hardware. My method definately works on real HW.

Posted: Thu Dec 14, 2006 6:34 am
by TmEE co.(TM)
Ok, i've tried that reg in any possible way, before, after, byte, word and long access (latter to on even addresses of course). Still nothing, I have no idea what I'm doing wrong(?).

I'm typing this by heart so there might be errors:

Code: Select all

Codestart:
 MOVE.L #$100001, A0  ; load address
 MOVE.B #1, ($A130F1) ; enable SRAM
 MOVE.B #123, (A0)    ; write byte
 MOVE.B (A0), D0      ; read byte
 MOVE.B #0, ($A130F1) ; disable SRAM
 CMPI.B #123, D0      ; compare the values
 BNE    Codestart     ; if not equal then loop

Posted: Sat Dec 16, 2006 11:16 am
by TmEE co.(TM)
I got it working !!! SRAM must be located @ 200000h. Thanks Stef !!!
Do you want your name into the credits list ??? I even draw "é" into the char set.