+  RHDN Forum Archive
|-+  Romhacking
| |-+  General Romhacking
| | |-+  SNES WRAM registers. Why bother?
Pages: [1]
Author Topic: SNES WRAM registers. Why bother?  (Read 1 times)
KingMike
Guest
« on: May 29, 2008, 01:45:54 pm »

I've kinda wondered, what's the point of the WRAM read and write registers?
Like, why should you use them over direct access?

I got this code:
Code:
LDA $2183
ORA #$01
STA $2183
REP #$20
TYA
STA $2181
SEP #$20
LDA $0FB1
STA $2180
Any reason I shouldn't replace it with
Code:
;A at the start contains $7F
PHB
PHA
PLB
SEP #$20
LDA $000FB1
STA $0000,Y
PLB
creaothceann
Guest
« Reply #1 on: May 29, 2008, 02:33:52 pm »

DMA? :huh:
Nightcrawler
Guest
« Reply #2 on: May 29, 2008, 03:08:27 pm »

1. No creaothceann, DMA does not work to or from the WRAM registers. Check Anomie's doc.

2. WTF? KingMike, $2181,$2182,and $2183 are write only. Reads will result in open bus.

3. The point of using the WRAM registers as far as I know would be to have an auto incrementing WRAM buffer. Your loop would be a few instructions smaller thus saving a few bytes.

I haven't seen any other benefits. I've actually only seen one game I can remember that actually used those registers. It used them as a decompression buffer when decompressing a block of text.
KingMike
Guest
« Reply #3 on: May 29, 2008, 03:59:21 pm »

That code is original code from a commercial game, part of its graphics decompression code.
If I am reading it right that only the low bit of the write to $2183 matters (highest bit of RAM address), then I guess it doesn't matter what is read, by the ORA #$01 statement, the low bit of A will always be 1 (thus always accessing bank $7F)
(and this game is only writing one byte through each iteration)
Just bad programming, I take it. Grin
byuu
Guest
« Reply #4 on: May 29, 2008, 04:32:37 pm »

EA is $7e0000 + ($2181-$2183) & 0x01ffff. Top seven bits of $2183 are irrelevent. It wraps around to 0x000000.

Yes, you can use $2180 for DMA. You just can't use it to perform WRAM->WRAM transfers. You could use it to transfer ROM data into WRAM, or WRAM data into SRAM. Lots of programmers use it to do a fixed DMA transfer from ROM to flush WRAM to 0x00 much quicker than with a loop.

Sorry to nitpick.
creaothceann
Guest
« Reply #5 on: May 29, 2008, 05:10:20 pm »

You live and learn...
Kejardon
Guest
« Reply #6 on: May 30, 2008, 10:22:15 am »

Quote from: byuu on May 29, 2008, 04:32:37 pm
Yes, you can use $2180 for DMA. You just can't use it to perform WRAM->WRAM transfers. You could use it to transfer ROM data into WRAM, or WRAM data into SRAM. Lots of programmers use it to do a fixed DMA transfer from ROM to flush WRAM to 0x00 much quicker than with a loop.
I was going to say this too. MathOnNapkins also uses it to clear the sprite OAM every frame in LttP. I use it for a few things too.
It's far from useless. Tongue Although, if it's only working on a single byte, you might be better off overwriting it. I'd use the X register instead though, it has a STA long,x, and it's a bit silly to switch the databank byte for a single offset.
MathOnNapkins
Guest
« Reply #7 on: May 30, 2008, 12:23:15 pm »

And of course we found out that trying to do DMA while HDMA is running can lead to tragedy on 1/1/1 SNES systems, right Byuu? DMA on $2180 may be powerful but it can also potentially crash first generation SNESes when used during the frame (but only if HDMA is enabled). Course, this is written in the official dev manual as a warning but who reads warnings before it's too late  Lips sealed
byuu
Guest
« Reply #8 on: May 30, 2008, 01:46:54 pm »

Quote
And of course we found out that trying to do DMA while HDMA is running can lead to tragedy on 1/1/1 SNES systems, right Byuu?

I've been trying to keep track of the known things I don't emulate. I'd suggest anyone programming for the SNES and relying only on bsnes (or really, any emulator) for testing to read over it:
http://byuu.cinnamonpirate.com/bsnes/errata/

And of course, I really need to go back and add some form of support for the more serious stuff. Better to be too cautious and crash more frequently to alert developers of this problem. But then I don't want that in the official release, so I need a config panel option to select the 1/1/1 hardware.
Pages: [1]  


Powered by SMF 1.1.4 | SMF © 2006-2007, Simple Machines LLC