Writing to 8-bit SRAM

For anything related to cart (SRAM, SF2 mapper, audio, CD mode 1, ...)

Moderator: BigEvilCorporation

Post Reply
Jazzmarazz
Very interested
Posts: 60
Joined: Wed Mar 12, 2014 11:11 pm
Location: Michigan
Contact:

Writing to 8-bit SRAM

Post by Jazzmarazz » Thu Oct 16, 2014 3:46 am

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.

bastien
Very interested
Posts: 208
Joined: Mon Jun 25, 2007 7:19 pm
Location: Besançon,France
Contact:

Post by bastien » Thu Oct 16, 2014 4:40 am

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.

Mask of Destiny
Very interested
Posts: 615
Joined: Thu Nov 30, 2006 6:30 am

Post by Mask of Destiny » Thu Oct 16, 2014 5:56 am

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.

Count SymphoniC
Very interested
Posts: 149
Joined: Sat Nov 17, 2012 3:58 am

Post by Count SymphoniC » Thu Oct 16, 2014 9:36 pm

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.

Mask of Destiny
Very interested
Posts: 615
Joined: Thu Nov 30, 2006 6:30 am

Post by Mask of Destiny » Thu Oct 16, 2014 11:42 pm

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.

Jazzmarazz
Very interested
Posts: 60
Joined: Wed Mar 12, 2014 11:11 pm
Location: Michigan
Contact:

Post by Jazzmarazz » Thu Oct 16, 2014 11:51 pm

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

db-electronics
Very interested
Posts: 89
Joined: Mon Feb 24, 2014 6:04 pm
Location: Kapuskasing, Ontario, Canada
Contact:

Post by db-electronics » Mon Mar 02, 2015 4:59 pm

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.
What does db stand for? Well that's an excellent question...
http://www.db-electronics.ca

Post Reply