Page 1 of 1

Writing to 8-bit SRAM

Posted: Thu Oct 16, 2014 3:46 am
by Jazzmarazz
How do I write to my SRAM? As all of you know, the SRAM in official games is connected only to the Lower byte of the data bus, and writing is enabled by making the !LDSW pin go low.

My parallel SRAM is located between 0x200000 and 0x23FFFF. please help me write bytes to it.

Posted: Thu Oct 16, 2014 4:40 am
by bastien
Hi,
Maybe you should look into sram function in sgdk.
This function is written into asm directly so i think they can be included into your project easily.

Posted: Thu Oct 16, 2014 5:56 am
by Mask of Destiny
You don't need assembly to write to SRAM, unless you want to use movep. That doesn't really seem like it's worth the trouble though since SRAM access is usually not performance sensitive.

Something like this should work:

Code: Select all

char * sram = (char *)0x200001;
*sram = FIRST_BYTE;
sram += 2;
*sram = SECOND_BYTE;
Alternatively, you can tree sram like an array and only access every other location.

Posted: Thu Oct 16, 2014 9:36 pm
by Count SymphoniC
Mask of Destiny wrote:You don't need assembly to write to SRAM, unless you want to use movep. That doesn't really seem like it's worth the trouble though since SRAM access is usually not performance sensitive.

Something like this should work:

Code: Select all

char * sram = (char *)0x200001;
*sram = FIRST_BYTE;
sram += 2;
*sram = SECOND_BYTE;
Alternatively, you can tree sram like an array and only access every other location.
I'd assume that it's the same as writing to RAM in assembly anyways.

Code: Select all

SRAMADDRESS equ 0x200001

move.b              #0x3A, SRAMADDRESS
Is that really all there is to it though? He said something about "making the !LDSW pin go low" and I know squat about that.

EDIT: Oh wow. Yeah missed that movep part, time to learn a new asm instruction.

Posted: Thu Oct 16, 2014 11:42 pm
by Mask of Destiny
Count SymphoniC wrote:Is that really all there is to it though? He said something about "making the !LDSW pin go low" and I know squat about that.
!LDSW is the write strobe for the lower byte. Whenever there's a write that involves the low byte, this pin goes low (the ! indicates an active low signal). So it will go low for a word write or for a byte write to an odd address. Similarly !UDSW will be low for both word writes and byte writes to even addresses.

Posted: Thu Oct 16, 2014 11:51 pm
by Jazzmarazz
Mask of Destiny wrote:
Count SymphoniC wrote:Is that really all there is to it though? He said something about "making the !LDSW pin go low" and I know squat about that.
!LDSW is the write strobe for the lower byte. Whenever there's a write that involves the low byte, this pin goes low (the ! indicates an active low signal). So it will go low for a word write or for a byte write to an odd address. Similarly !UDSW will be low for both word writes and byte writes to even addresses.
I was hoping that was the case. Cheers

Posted: Mon Mar 02, 2015 4:59 pm
by db-electronics
I used FRAM (FM1808-70-SG) on my cartridge and it's proven to work very well with Megaman Wily Wars (SRAM hack) and Sonic 3.

!LDSW is connected to RAM #WE, the RAM is mapped to 0x200000 using a 74HC139.

The nice thing about using FM1808-70-SG is that it's pin compatible with SRAM AS6C62256-55SCN and thus you can easily make a cart which can take either FRAM or SRAM.