Register | Login
Views: 19364387
Main | Memberlist | Active users | ACS | Commons | Calendar | Online users
Ranks | FAQ | Color Chart | Photo album | IRC Chat
11-02-05 12:59 PM
1 user currently in Super Mario World hacking: labmaster | 3 guests
Acmlm's Board - I2 Archive - Super Mario World hacking - Implementing HDMA effects via palette hacks (code included) [ASM] | |
Pages: 1 2Add to favorites | "RSS" Feed | Next newer thread | Next older thread
User Post
BMF98567
BLACK HAS BUILT A SILLY DICE-MAZE!
GO!

Current list of BURNING FURY >8( recipients:
- Yiffy Kitten (x2)
- Xkeeper
Level: 53

Posts: 63/1261
EXP: 1094149
For next: 62970

Since: 03-15-04
From: Blobaria
Special Move: Rising Meatloaf Backhand Combo

Since last post: 21 hours
Last activity: 1 hour
Posted on 03-26-04 02:20 PM Link | Quote
WARNING: This is only for people who are experienced with ASM. It involves directly modifying game code and utilizing palette hacks.

HDMA is a powerful feature of the SNES that allows you to modify PPU registers while the screen is being drawn. A great deal of games use this to create a wide variety of special effects, such as background gradients, wavy underwater areas, and pseudo-multi-layer scrolling backgrounds (it's only one background layer, but it's split into multiple rows that scroll at different speeds). In this mini-tutorial, I'm going to show you how to create multiple levels of scrolling out of a single background layer, adding a great deal of depth to an otherwise flat background!

You'll need:
- Two files: hdmamain.bin and hdmasub.bin, both here
- SMW ROM with my Palette-Based ASM System already installed
- Hex editor
- A bit of patience

First, you'll need to patch one of SMW's main routines to set up the necessary HDMA registers. Insert hdmamain.bin into an unused part of the ROM, then modify the JSL at PC address $2495 (should be 22 00 80 7F) to point to the first byte of this new routine.

Next, insert hdmasub.bin into another unused part of the ROM (if you plan to use multiple HDMA effects, I suggest you reserve a sufficient amount of ROM space using RATS tags). This is the actual code that will control your HDMA effects. However, before you can use it, you need to make some important changes.

A few key addresses in hdmasub.bin you need to know about:

$0B: (#$07) This is the size of your HDMA table + PPU register byte, minus 1 (more on this in a bit). It specifies how many bytes will be copied into RAM. Minus the PPU register byte at the beginning and the zero byte at the end, an HDMA table's size will always be divisible by 3. Remember that.
$0D: (#$0040) This is the starting ROM address of your HDMA table + PPU register byte. The code already takes care of the bank byte, so you just need to put the lower 16 bits of the address here (but make sure the table remains in the same ROM bank as the rest of the code!).
$40: (#$0F) This is the lower byte of the PPU register that will be modified by HDMA (the upper byte is always #$21). It's set to $210F, "bg2hofs" (layer 2 horizontal offset) here by default.
$41: This is the actual HDMA table. It consists of multiple 3-byte entries and a zero byte (#$00), which marks the end of the table. The first byte of each entry specifies for how many scanlines the following two bytes will be written to the previously specified PPU register. Example:

58 50 00 7E 72 01 00

In this example, the first entry will write #$0050 to PPU register $210F for 88 (0x58) scanlines, whereas the second entry will write #$0172 for 126 (0x7E) scanlines, starting immediately on line 89. The last byte marks the end of the table (HDMA shuts off here). Make sure you don't exceed 0x80 scanlines in any single entry, as this will cause HDMA to break; if you need more lines, use two entries.

The above table would cause the first 88 lines of layer 2 to be shifted to the right by 80 pixels, and the remaining lines to be shifted by 370 pixels (even though only 126 scanlines were specified, the rest of the layer will be shifted as well, because SMW does not reset the scroll register after HDMA has finished). Now, that's all fine and dandy if you want to leave the background skewed just like that for the entire level, but what if you want the layers to actually move when the screen scrolls? That's why the table is copied to RAM: so you can modify it on-the-fly! This brings us to the hardest part of this tutorial:

$19: This is where you'll put your ASM code that will modify the HDMA table in RAM, which starts at $7FFF01 (remember this address!). Modifying the table each frame will allow you to create the illusion of multiple "layers" that scroll at different speeds. How you modify the table is entirely up to you, but I've included some code that should help get you started.

The included example code in hdmasub.bin demonstrates 4 background rows moving at 3 different speeds. It loads the 16-bit layer 2 X-scroll value from $1466 and writes it to HDMA entry #4, at $7FFF0B (this part will scroll at normal speed). It then shifts the value right by one bit, and writes it to entries #1 and #3, at $7FFF02 and $7FFF08, respectively. The value is finally shifted by one more bit, and then written to entry #2 at $7FFF05 (this part will scroll the slowest). The final result is a simulated 3-layer background, with each "layer" moving at a different rate when layer 2 scrolls left or right. (You'll need to set horizontal scrolling to "Variable" in Lunar Magic to see this effect properly.)

Once you've written your ASM code, it's time to test it out. All you have to do is link to the first byte of hdmasub.bin, wherever you inserted it in the ROM, via a palette entry in Lunar Magic (read the documentation included with the Palette-Based ASM System for detailed information on how this is done). The code will take effect immediately after your level loads.

If you want to use multiple HDMA effects (different ones for different levels), just insert more copies of hdmasub.bin and modify as needed.

That's about it! Unfortunately, there are a few side effects of using HDMA in this manner, which I haven't bothered to address yet:

- Some things will temporarily disable HDMA and cause the background to revert to normal scrolling (such as dying).
- You can't have a keyhole or goal in the same level number as your HDMA effect, otherwise the zooming keyhole or circle (after you pass the goal) will glitch up and turn the screen black. This won't lock up or crash the game, but it doesn't look good. I need to implement a way to disable custom HDMA when these events happen. I don't believe text boxes are affected by this phenomenon, and I'm not sure about layer 3 effects (like scrolling water or rocks). More testing needs to be done.
- You must set layer 2's vertical scrolling to "None" when using HDMA, otherwise the layer will scroll vertically...but the HDMA splits won't. Icky. This can be addressed with some clever programming, but I'm not even going to try to figure it out.
- Make sure any levels connected via pipes or other exits to the level with HDMA have custom palettes enabled, otherwise the HDMA effects might not shut off (since the palette entry isn't reset)!
d4s

Panser
Level: 29

Posts: 11/325
EXP: 142151
For next: 5734

Since: 03-23-04

Since last post: 13 days
Last activity: 1 day
Posted on 03-26-04 02:48 PM Link | Quote
wow, this is awesome.
arent the textboxpopups using hdma,too?
im pretty sure they do.

btw, this might be a little off-topic, but mario worlds hdma effects
glitch when you play it with pal speed.(50hz)


Luigi

Red Koopa
Level: 19

Posts: 77/126
EXP: 34570
For next: 1207

Since: 03-15-04
From: Friday the 13th

Since last post: 521 days
Last activity: 96 days
Posted on 03-26-04 04:47 PM Link | Quote
We need someone to fix them SMW HDMA glitches.
Darth Coby

Vire
Dacht je nou echt dat het over was?
Dacht je nou echt dat ik gebroken was? Nee toch?
Nou kijk eens goed op uit je ogen gast.
zonder clic heb je geen kloten tjap... bitch
Level: 55

Posts: 211/1371
EXP: 1240774
For next: 73415

Since: 03-15-04
From: Belgium

Since last post: 2 days
Last activity: 9 hours
Posted on 03-26-04 08:57 PM Link | Quote
Woah. Awesome.
mikepjr

Ninji
Level: 26

Posts: 33/242
EXP: 92006
For next: 10269

Since: 03-15-04
From: houston texas

Since last post: 4 days
Last activity: 1 hour
Posted on 03-26-04 09:32 PM Link | Quote
One question. Do you think somthing like this could ever be implamented into luner magic. Just wondering for us non asm hacking folks.
Escherial

Shyguy
Level: 17

Posts: 9/90
EXP: 20866
For next: 3877

Since: 03-15-04
From: Pasadena, CA

Since last post: 202 days
Last activity: 38 days
Posted on 03-26-04 10:27 PM Link | Quote
Thanks again, BMF, for making such a generous donation to the hacking community. It's not every day that people are willing to "surrender" their prized hacking secrets, especially in tutorial form.

Hmm, you could prospectively turn the effect off by modifying the palette entry you're using to redirect execution (if I've correctly understood how your palette ASM hack works). Actually, you could probably even do that from the patched ASM itself; just check if you're dead and replace that palette entry with whatever your code recognizes as null so the HDMA hack doesn't activate anymore *shrug*.

Of course, I very well may have no idea what I'm talking about.


(edited by Escherial on 03-26-04 01:28 PM)
Smallhacker

Green Birdo

SMW Hacking Moderator
Level: 68

Posts: 51/2273
EXP: 2647223
For next: 81577

Since: 03-15-04
From: Söderhamn, Sweden

Since last post: 10 hours
Last activity: 9 hours
Posted on 03-26-04 10:37 PM Link | Quote
Woah! Special effects! That's great, BMF!

*Messes around*
*Rom gets corrupted*
*Cries*
*Goes away to fetch some Coca-Cola, I guess*
blackhole89

LOLSEALS
Moderator of ROM hacking
EmuNET IRC network admin
Head GM of TwilightRO
Level: 47

Posts: 45/971
EXP: 739208
For next: 26995

Since: 03-15-04
From: Dresden/Germany

Since last post: 14 hours
Last activity: 12 hours
Posted on 03-27-04 12:15 AM Link | Quote
First, thx again to BMF for his incredible work...

second, I ask for a simple thing: Which PPU register holds the backdrop colour? I mean the one of the no-BG-covered area, called "back area color" by Lunar Magic. I want to make gradient backgrounds
HyperLamer
<||bass> and this was the soloution i thought of that was guarinteed to piss off the greatest amount of people

Sesshomaru
Tamaranian

Level: 118

Posts: 177/8210
EXP: 18171887
For next: 211027

Since: 03-15-04
From: Canada, w00t!
LOL FAD

Since last post: 2 hours
Last activity: 2 hours
Posted on 03-27-04 01:54 AM Link | Quote
Well it's at 7E0701 in RAM, 16 bit.


(edited by HyperHacker on 03-26-04 04:55 PM)
blackhole89

LOLSEALS
Moderator of ROM hacking
EmuNET IRC network admin
Head GM of TwilightRO
Level: 47

Posts: 49/971
EXP: 739208
For next: 26995

Since: 03-15-04
From: Dresden/Germany

Since last post: 14 hours
Last activity: 12 hours
Posted on 03-27-04 12:53 PM Link | Quote
That's what I found too (SNES9x Search for new cheats function rulezzz!), but it seems to be rather kind of RAM mirror. And BMF's routine (I guess any HDMA thingy) will write only to the PPU registers ($21xx).

GreetZ
Blacky.
BMF98567
BLACK HAS BUILT A SILLY DICE-MAZE!
GO!

Current list of BURNING FURY >8( recipients:
- Yiffy Kitten (x2)
- Xkeeper
Level: 53

Posts: 86/1261
EXP: 1094149
For next: 62970

Since: 03-15-04
From: Blobaria
Special Move: Rising Meatloaf Backhand Combo

Since last post: 21 hours
Last activity: 1 hour
Posted on 04-01-04 12:56 PM Link | Quote
So, is anyone getting any use out of this?

Err, the real reason for the bump is to let you guys know that hdmamain.bin has been updated to fix a couple of problems, namely HDMA shutting off when you die or pause the game. Turns out there's a RAM mirror of $420C at $0D9F that's not reset after each frame, so the code now writes there instead.

Message boxes, keyholes, and goals still don't properly coexist with custom HDMA, though...I should have a fix shortly.

[EDIT]
A sample of HDMA's awesome power:



(edited by BMF54123 on 04-01-04 05:28 AM)
Sendy

Shyguy
Level: 17

Posts: 9/93
EXP: 21726
For next: 3017

Since: 03-25-04
From: South of UK

Since last post: 55 days
Last activity: 53 days
Posted on 04-01-04 06:58 PM Link | Quote
Phear the wibbly backgrounds

I'd use it if I knew any ASM... Is there any chance that it could be made into a utility like BlockTool for setting it up?
blackhole89

LOLSEALS
Moderator of ROM hacking
EmuNET IRC network admin
Head GM of TwilightRO
Level: 47

Posts: 60/971
EXP: 739208
For next: 26995

Since: 03-15-04
From: Dresden/Germany

Since last post: 14 hours
Last activity: 12 hours
Posted on 04-01-04 08:38 PM Link | Quote
Sample: great idea. Somehow reminds me of RM2k's "Roster scroll" screen fadein/fadeout effect.

I actually managed to make these gradient backgrounds like in Yoshi Island. The back area colour becomes palette entry 0 on runtime. For this, I used two HDMA channels: one mode 0 channel writing 0 to $2121 (palette index selection) over and over again and one mode 2 (1 reg write twice) channel for $2122 writing the colour values.
It's still a bit buggy and therefore I won't release it yet.

EDIT*bumps* - here's the screenshot:

Still, there won't be a public release until following problems are fixed:
- Crash when Mario leaves the screen, whatever way.
- Crash when pressing any key after Mario is being damaged.
- Crash when spin-jumping on bricks.
- Backdrop area is being added (CGADSUB gone mad!?) to the background image when transparency effects turned on.

EDIT.2 - No, that is not a joke. In case everybody thinks so I'd even release a crashy SMW ALttP alpha version with that feature inside. But I better won't

GreetZ
Blacky.


(edited by blackhole89 on 04-01-04 11:01 AM)
Someguy

Buzzy Beetle
It seems as though the girl you've fallen for is also a pyromaniac.
Level: 32

Posts: 6/397
EXP: 193329
For next: 13113

Since: 03-15-04
From: I'm proud to be an American... I think...

Since last post: 1 day
Last activity: 5 hours
Posted on 04-01-04 10:31 PM Link | Quote
Can you use this hack to make layer 1 use HDMA effects too, to make YI touch fuzzy trippy effects on the area Mario plays on and not just the BG?
knuck

Hinox
Banned until 19-58-5815: trolling, flaming, spamming, being a general fucktard...
Level: 62

Posts: 156/1818
EXP: 1894574
For next: 90112

Since: 03-15-04

Since last post: 14 hours
Last activity: 9 hours
Posted on 04-01-04 10:36 PM Link | Quote
Originally posted by Someguy
Can you use this hack to make layer 1 use HDMA effects too, to make YI touch fuzzy trippy effects on the area Mario plays on and not just the BG?

Yes he can. He just need to change wich layer the HDMA will affect. (don't aske me how )
blackhole89

LOLSEALS
Moderator of ROM hacking
EmuNET IRC network admin
Head GM of TwilightRO
Level: 47

Posts: 63/971
EXP: 739208
For next: 26995

Since: 03-15-04
From: Dresden/Germany

Since last post: 14 hours
Last activity: 12 hours
Posted on 04-01-04 11:26 PM Link | Quote
No. Change the register# affected by the HDMA. Search Google for "SNES register", you'll find a lot of manuals. I think BMF well described what in particular you should change. (Exchange L2 HSCROLL with L1 HSCROLL register).

And I think YI's fuzzy effect was waving horizontally. It won't work that way unless there's something like "VDMA".

GreetZ
Blacky.
Atma X

Bandit
Level: 43

Posts: 83/801
EXP: 553639
For next: 11407

Since: 03-16-04
From: Derrière vous!!!

Since last post: 43 days
Last activity: 14 days
Posted on 04-02-04 05:10 AM Link | Quote
BMF: What are the Addresses for the Status Bar? (In Hex Address, AKA to modify in a Hex editor)

And also, how can I use Snes Ram Addresses (is there a program which modifies the Rom through Ram Addresses) to modify the Rom. (Not with PAR Codes, I mean to actually keep the changes)
Xkeeper 2.0

Hammer Brother
Local ModeratorAdministratorLocal Moderator
Again... :P
Level: 49

Posts: 22/1091
EXP: 880818
For next: 3065

Since: 03-15-04

Since last post: 5 hours
Last activity: 3 hours
Posted on 04-02-04 05:22 AM Link | Quote
Originally posted by BMF54123
So, is anyone getting any use out of this?

Err, the real reason for the bump is to let you guys know that hdmamain.bin has been updated to fix a couple of problems, namely HDMA shutting off when you die or pause the game. Turns out there's a RAM mirror of $420C at $0D9F that's not reset after each frame, so the code now writes there instead.

Message boxes, keyholes, and goals still don't properly coexist with custom HDMA, though...I should have a fix shortly.

[EDIT]
A sample of HDMA's awesome power:



Is that a real screen from SMO? Looks great!

Oh, and is it possible to do something like HDMA on sprites only? (I would use it on the last level )


(edited by skateboarder11 on 04-01-04 07:53 PM)
(edited by skateboarder11 on 04-01-04 08:02 PM)
(edited by skateboarder11 on 04-03-04 04:55 PM)
Atma X

Bandit
Level: 43

Posts: 85/801
EXP: 553639
For next: 11407

Since: 03-16-04
From: Derrière vous!!!

Since last post: 43 days
Last activity: 14 days
Posted on 04-02-04 05:46 AM Link | Quote
What is the hdmamain.bin. (Is it only useful for ASM Hackers?)

Edit: I hate when everything is capitalized, Acmlm please change it back, it's killing my eyes!


(edited by Atma X on 04-01-04 07:50 PM)
(edited by Atma X on 04-01-04 08:04 PM)
HyperLamer
<||bass> and this was the soloution i thought of that was guarinteed to piss off the greatest amount of people

Sesshomaru
Tamaranian

Level: 118

Posts: 241/8210
EXP: 18171887
For next: 211027

Since: 03-15-04
From: Canada, w00t!
LOL FAD

Since last post: 2 hours
Last activity: 2 hours
Posted on 04-02-04 10:21 AM Link | Quote
Originally posted by blackhole89
No. Change the register# affected by the HDMA. Search Google for "SNES register", you'll find a lot of manuals. I think BMF well described what in particular you should change. (Exchange L2 HSCROLL with L1 HSCROLL register).

And I think YI's fuzzy effect was waving horizontally. It won't work that way unless there's something like "VDMA".

GreetZ
Blacky.

And of course change the collision detection to match. YI used the SuperFX chip for that.
Pages: 1 2Add to favorites | "RSS" Feed | Next newer thread | Next older thread
Acmlm's Board - I2 Archive - Super Mario World hacking - Implementing HDMA effects via palette hacks (code included) [ASM] | |


ABII


AcmlmBoard vl.ol (11-01-05)
© 2000-2005 Acmlm, Emuz, et al



Page rendered in 0.022 seconds.