How does work SRAM on everdrive?

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

Moderator: BigEvilCorporation

User avatar
HardWareMan
Very interested
Posts: 699
Joined: Sat Dec 15, 2007 7:49 am
Location: Kazakhstan, Pavlodar

Re: How does work SRAM on everdrive?

Post by HardWareMan » Sat Aug 12, 2017 11:34 am

Miquel wrote:
Sat Aug 12, 2017 10:41 am
Then I suppose if neither CAS0, WRL or WRH is asserted an invalid address exception is launched, right?
You should use these signals only with CE0 and get desired access within $000000-$3FFFFF (first 4 Mbytes) dedicated to ROM cartridge. That's why 32MBit games use bank switching for SRAM (f.e. Story of Thor).
Miquel wrote:
Sat Aug 12, 2017 10:41 am
By the way, what I do is obtain a buffer in standard memory and with a sort of "memcpyPeripal" (which uses movep opcode) move data from/to save ram.
Then you'll get gaps belong to high byte. To avoid that you should use word wide SRAM or byte transfer routine, f.e.:

Code: Select all

Loop:
move.w (a0)+,d0
move.b d0,(a1)+
dbra   d1,Loop

Miquel
Very interested
Posts: 189
Joined: Sat Jul 30, 2016 12:33 am

Re: How does work SRAM on everdrive?

Post by Miquel » Sat Aug 12, 2017 12:46 pm

No, movep fills/jumps the gaps, that it's propose.

for example:

movep.w (a0), d0
transforms:
0x12 0x34 0x56 0x78
to:
0x12 0x56

movep.w d0, (a0)
transforms:
0x12 0x56
to:
0x12 0x?? 0x56 0x??

(I'm talking from memory...)
ruín shumi imatostenes
ruín rumi doné
(Is that correct?)

User avatar
HardWareMan
Very interested
Posts: 699
Joined: Sat Dec 15, 2007 7:49 am
Location: Kazakhstan, Pavlodar

Re: How does work SRAM on everdrive?

Post by HardWareMan » Sat Aug 12, 2017 1:30 pm

Ah, so...
Image
Image
Should work! One more reason to use low byte D7-D0.

Miquel
Very interested
Posts: 189
Joined: Sat Jul 30, 2016 12:33 am

Re: How does work SRAM on everdrive?

Post by Miquel » Sat Aug 12, 2017 2:48 pm

I have:
- "memcpyToPeripheral" done with movep.l, movep.w and move.b only.
- "memcpyFromPeripheral" yet to be done, (currently done in C with byte to byte copy)

So I assure you 50% off it does work.
ruín shumi imatostenes
ruín rumi doné
(Is that correct?)

User avatar
Sik
Very interested
Posts: 592
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: How does work SRAM on everdrive?

Post by Sik » Sat Aug 12, 2017 10:09 pm

HardWareMan wrote:
Sat Aug 12, 2017 9:56 am
Of course CAS0 asserted if any read occur: high byte, low byte or word. So, you can read your SRAM by words with postincrement (f.e. move.w (a0)+,d0) and use only lower byte, which more handy, than high byte, right?
For this stuff it's actually better to use MOVEP (it automatically will convert between every-other-byte and consecutive bytes, and can handle 4-byte values). Also MOVEP seems slow (it's not, really), but it's still much faster than doing the whole thing manually. Heck, this is literally the whole reason why MOVEP exists (to interface with 8-bit hardware).
HardWareMan wrote:
Sat Aug 12, 2017 1:30 pm
Ah, so...
http://savepic.net/9610965.png
http://savepic.net/9616085.png
Should work! One more reason to use low byte D7-D0.
MOVEP doesn't care about whether it's the high byte or the low byte (it just accesses every other byte starting from the given address). High byte accesses are actually stated earlier in the same manual.

Heck, the only real reason to use the low byte is that "it looks prettier" (since it's the low byte if a word access). This matters when using MOVEP on work RAM (it's a convenient way to build DMA commands, Sonic 3D uses this =P). As for SRAM, well one may want to use low byte just in case the flashcart doesn't save the high bytes in the SRAM. If you're making your own stuff it's free for all, though.
Sik is pronounced as "seek", not as "sick".

Miquel
Very interested
Posts: 189
Joined: Sat Jul 30, 2016 12:33 am

Re: How does work SRAM on everdrive?

Post by Miquel » Wed Aug 16, 2017 5:25 pm

@HardWareMan movep works 100% perfectly, you just have to point directly to the first valid byte.

Proof:

Code: Select all

// (field size is size of working ram, not sram)
STATIC void* memcpyFromPeripheral( void* const destination, void const* const source, u32 size )
{
	if( size > 0 )
	{
		register u8* dest = destination;
		register u8 const* src = source;
		// Align to 2bytes
		if( ((u32)dest) & 1 )
		{
			*dest++ = *src;
			src += 2;
			size--;
		}
		register u32 data;
		register s32 loops = size >> 5;
		register s32 jump = -((size << 1) & (7 << 3));
		__asm volatile(
			"	jmp (2f, %%pc, %4)\n"
			"1:	movep.l 0(%1), %0; move.l %0, (%2)+; addq.l #8, %1\n"
			"	movep.l 0(%1), %0; move.l %0, (%2)+; addq.l #8, %1\n"
			"	movep.l 0(%1), %0; move.l %0, (%2)+; addq.l #8, %1\n"
			"	movep.l 0(%1), %0; move.l %0, (%2)+; addq.l #8, %1\n"
			"	movep.l 0(%1), %0; move.l %0, (%2)+; addq.l #8, %1\n"
			"	movep.l 0(%1), %0; move.l %0, (%2)+; addq.l #8, %1\n"
			"	movep.l 0(%1), %0; move.l %0, (%2)+; addq.l #8, %1\n"
			"	movep.l 0(%1), %0; move.l %0, (%2)+; addq.l #8, %1\n"
			"2:	dbra %3, 1b"
			: "=d"(data), "=>a"(src), "=>a"(dest), "=d"(loops)
			: "d"(jump), "1"(src), "2"(dest), "3"(loops)
		);
		if( size & 2 )
		{
			__asm volatile(
				"movep.w 0(%1), %0; move.w %0, (%2)+; addq.l #4, %1\n"
				: "=d"(data), "=>a"(src), "=>a"(dest)
				: "1"(src), "2"(dest)
		);
		}
		if( size & 1 )
		{
			*dest++ = *src;
		}
	}
	return destination;
}
The main loop takes 66bytes of code to copy 32bytes of data, while a basic c function takes 8bytes of code to move 1byte of data.
ruín shumi imatostenes
ruín rumi doné
(Is that correct?)

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest