News:

11 March 2016 - Forum Rules

Main Menu

SNES HDMA from WRAM example

Started by gauveldt, March 09, 2014, 11:23:45 PM

Previous topic - Next topic

gauveldt

Edit: A FinS suggested I uploaded the sources ZIP to tinyupoload.  The file may be obtained at this link.

This is a small asm demonstrating an HDMA set up using indirect mode to accept it's values from WRAM allowing the table to be changed on the fly (most likely in a NMI handler).

What it does:
1.  Uses a ROM based table of indirect values to create an HDMA from a contiguous section of WRAM.  There are no intervening scanline count bytes interspersed with the data in the WRAM image hence why I refer to it as contiguous.

2. The HDMA is in mode 3 (two dual-write word-registers) and the target is the CGRAM pointer/data.  Yes I know 240 of the 960 values are wasted since they are used to write the index register twice.  With the CGRAM port and the available HDMA modes this cannot be helped.  You cannot just ignore the index due to it auto incrementing whenever you write a word to the data register.  Other uses of the table, such as writing to paired L/R window position registers would not waste these values.

3. The NMI handler is farily simple and does three basic things.

  • Shadows the HDMA enable register (allowing read operations of the register content),
  • Increments a 32-bit frame counter, and,
  • Scrolls up the HDMA table in WRAM then writes in the frame counter value, doing some wizardry with a sine wave table in the ROM to convert to a pleasing range of 15-bit colour values as the frames advance.
The net effect is the screen starts off black (all table values zero) then a field of gradating color is seen mvoing upward as the values in the table scroll up and the HDMA is placing the each entry of the table into CGRAM palette index 0 (the background color)
in order of the screen's scanlines (first entry in table is top of screen so the color field appears from the bottom of the screen since the table is scrolled up towards the start and the color value inserted at the last position of the table)

Some miscellany not really related to the example is some SA-1 init to get all rom banks in place (it's set up for an 8 MByte ROM boilerplate) and other register init.

Incidentally the trig table is -127 to +127, suitable for working with to set up mode 7's matrix registers.

Not sure what else to say about this small snippet other than that it should build in asar to a complete runnable ROM in zsnes, higan or whatever you use.

Looks like I'm still have only noob access and unable to post an attachment so I'm not sure how to make these files available (I currently do not have ownership of any ftp sites with write access to place it on nor my own web server).  It's a 5K zip.  This isn't permitted in the file area so not sure what to do here.

KingMike

Quote from: gauveldt on March 09, 2014, 11:23:45 PM
NB: I want to post the code for this but don't see an accepted way to do so since the forum still considers me too noob to post attachments and 'demos' aren't allowed in the file areas.
Nobody can post attachments due to server limitations.
"My watch says 30 chickens" Google, 2018

FinS

You could host it on TinyUpload.com and then provide a link to it.