Language…
2 users online: Firstnamebutt, tOaO - Guests: 182 - Bots: 361
Users: 64,795 (2,380 active)
Latest user: mathew

How to Insert Layer 3 Backgrounds

Tired of not no one else putting up a tutorial on this, I decided to teach myself how to do it and write a tutorial on it. Note that this is a rushed job since I don't have a lot of time right now. If anyone has any problems or doesn't understand something please post here and I'll try to help. Also note that this covers the Stripe Image method instead of the .bin method. The advantage to the .bin method is that it saves a bit of space, but I haven't used it enough to know exactly how it works.

What you will need:






Creating a Tilemap

1. Open the game that has your layer 3 background and create a save state when that background comes into view.
2. Open up that save state with Racing Stripe.
3. Select BG3 from the list box (or any other 4-color background if your game isn't using mode 1). You should see the background you want to rip.
4. Go to Options -> Convert 16x16 tilemap to 8x8. If this option is not available then it means your tilemap is already 8x8 and you can skip this step. At this point you can make any modifications you want to the background. Go to Window -> Tile Selector to view all the possible tiles you can insert.
5. Go to File -> Save Tilemap/Stripe As and save it in the same directory as your ROM.
6. In the dialog that appears, select $A000 as the starting address.

Inserting your Stripe

7. Open up stim.asm
8. Define your freespace, etc.
9. Look at the table named LevelTable. Each bit represents one level, if the bit is set then the level uses a layer 3 background. Set the bits for the levels you're using.
10.Scroll down to the bottom of the file. Where it says "LayerImg1: incbin stim.stim" replace LayerImg1 with some sort of a one word descriptive name for your background and replace stim.stim with your actual background filename; the .stim file you saved earlier. You can add more, just follow same pattern of "name: incbin background.stim"
11.Look at the table named LayerPointerTable. Each entry represents the background used for one level. Replace LayerImg1 for the levels you want with the label you've given your background in the previous step.

Inserting the Graphics

12.Rip the layer 3 background's graphics. The best way to do this is to open up your save state with YY-CHR, and then to find the background's tileset. Once you've found it, paste it into a 2kb ExGFX file (it MUST be 2kb, not the normal 4kb! If you need a 2kb file, export SMW's default graphics in Lunar Magic, making sure to not use joined GFX files. Files 28, 29, 2A, and 2B are all 2kb; paste the new graphics over the old and save it as an ExGFX file.).
13.Insert your ExGFX with Lunar Magic. Be sure to take note of the number you inserted it as, you'll need it in a moment.
13.Open up Layer3ExGFX.asm
14.You'll see tables like the ones you've seen before, except now there are four of them per level. For whatever level you're using you'll have to replace the default graphics with your ExGFX file you created earlier. Which table to use, though, is pretty much trial and error.
15.Patch stim.asm and layer3ExGFX.asm to your ROM.
16.If you chose the correct table, you now have a layer 3 background! If not, then try a different one. Once you've gotten it correct, read on for optional details on making it look a bit nicer.

Scrolling Issues

This will make your background scroll, as opposed to being fixed on the screen at all times. You'll need levelASM for this.

Code
REP #$20	;Make A 16 bits wide
LDA $1462		;Load the layer 1 x position
LSR		;Divide by 2.  The more times you use LSR the slower the background will scroll horizontally.
LSR		;If you use ASL (multiply by 2) instead the background will scroll faster than the foreground.
STA $22		;Store to the layer 3 x position

LDA $1464		;Load the layer 1 y position
LSR		;Same as above, but vertically.
LSR
SEC		;These two lines are for shifting your background vertically.
SBC #$0038	;If you're using a background that loops you probably won't have to use this.
STA $24		;Store to the layer 3 y position
SEP #$20	;Make A 8 bits wide


Just paste that into levelASM (both level and init) and you're good to go!

Priority Issues

If you want to place your background behind layer 2, place the following in Levelinitcode:
Code
LDA #$17
STA $212C


Alternatively, use level modes 2, 8, or 11.

Status Bar

You might have noticed that your background cuts off at the status bar line. To fix this, you'll have to use Edit's Sprite Status Bar. Just take note of its limitations.

Windowing Issues



Credit to Ripperon-X for this code:

Code
LDA.b #%00010001
STA.w $0D9D
LDA.b #%00000110
STA.w $0D9E 


This will, according to him, allow windowing effects to work properly with layer three backgrounds. Just put that in levelINIT.asm

Incorrect Background Size

If you're having trouble getting your background to align or scroll correctly and your .STIM file is abnormally large (larger than 256x256), insert this code, courtesy of Ripperon-X and Edit:
Code
LDA #$50
STA $2109 

See this post for more details.


Hopefully this helps somebody out there, if not, post here and I'll do my best to help!
Seems useful.

Layout by algorithmshark. Additional help by mockingod.

Linkable Links: Youtube Channel - If any of you want me to do hack videos, I will. I cannot guarantee sound, however.

Shadow of A Hero Progress:


Not doing much.
Holy crap! Thank you, thank you, thank you....

I haven't toyed with LM in a long while, mostly because I hit a brick wall when I tried messing with custom Layer 3 BG's and couldn't figure out up from down, but I think I'm definitely gonna give this a whirl tomorrow. Just glancing through this and it already makes so much more sense.
Originally posted by Kipernal
[...]Be sure to take not of the number you inserted it as, you'll need it in a moment.[...]

I guess that's supposed to be "note"?
Your layout has been removed.
Originally posted by Milk
Holy crap! Thank you, thank you, thank you....

I haven't toyed with LM in a long while, mostly because I hit a brick wall when I tried messing with custom Layer 3 BG's and couldn't figure out up from down, but I think I'm definitely gonna give this a whirl tomorrow. Just glancing through this and it already makes so much more sense.


No problem. I'm actually surprised that no one had created one before this...

Originally posted by Stocking
I guess that's supposed to be "note"?


You would be correct. Thank you.
I should get a new layout.

Probably won't, though.
This tutorial looks promising. What am I saying? It's fantastic. At least it doesn't involve Terra Stripe.
Oh yes, yes, yes!! You're a god, Kipernal, at last, somebody made a good tutorial for Layer 3 BGs! I was waiting months ago for this. I can't wait to have a little more time and learn this. :D
This actually works. However, I sumbled upon this:


The BG isn't placed right. It's around 8 pixels away from the top of the screen. How can that be fixed?
Edit: I have discovered another error. If I apply the code, the layer 3 BG WON'T scroll horizontally at all, no matter how many LSRs or ASLs are. Only vertically.
Edit2: The horizontal scrolling works. But even so, it's like if I don't get the right horizontal and vertical combination of that layer 3
BG, then I end up not filling that screen with the layer 3 BG entirely. There will be a few pixels distance. I've found another thing. When the layer 3 BG scrolls both horizontally and vertically, it doesn't loop. Now I know that there's a part of code that needs to be removed, if I want that to happen, but even rremoved, the BG won't loop right, because there's a 256x256 empty space that comes after and finally the layer 3 BG. The same thing happens to vertical scrolling.
Edit3: Woah I opened the savestate and I found out that the layr 3 BG isn't 256x256. It's actually 512x512. What? Apparently, my .stim file is 2 KB, rather than 25 bytes. Hmm, I savestated in other levels without a layer 3 BG and I discover that every layer 3 non-existent BG has 512x512 as size. What to do?

Finat edit: I finally got it to work right by removing that one code suggested and added 4 LSRs for vertical scrolling. I think it doesn't matter how many LSRs or ASLs are for horizontal scrolling. I have a suggestion. Perhaps you should have put a code that resizes the layer 3 tilemap to 256x256. Credit to edit for this code:
Code
LDA.b #$50         
STA.w $2109

Other than that, tutorial works just great.
@Ripperon: That's a strange glitch...I don't suppose you would mind giving me the save state file you used so that I can experiment a bit?

Also, the LSRs and the ASLs do matter, for normal backgrounds at least. I guess using 512x512 backgrounds messes something up? I'll look into it if you can get me that save state.
I should get a new layout.

Probably won't, though.
I'm sorry. I don't have it anymore. As I mentioned before. 512x512 isn't only in the level where I used your tutorial. It is everywhere in my case. Maybe other people can try this and actually give a better result than me. It's likely that I patched something in my ROM that has to do with resizing. My ROM is overly crowded with patches and I'm amazed it still works fine.
Edit: Curiosity: If I were to place Layer 3 between 1 and would changing that 212C to 212D help? Also to make Layer 3 appear over the other layers, would changing 212C to 212E do?
Nice tutorial! This should help a lot of people. I do hope you eventually add information for inserting Layer 3 backgrounds with genericuploader.asm, though.

----------------

I'm working on a hack! Check it out here. Progress: 64/95 levels.
OhmygodthankyousomuchIhatedusingothermethodsandtherewasneveratutorialonitsoicouldn'tfigureitoutandnowIcanthankyouI'lltrythistomorrow. *inhale* I mean, um... THANK YOU. I will DEFINITELY try this out with Lynne's Layer 3 Clouds tomorrow.
I have a possible guess about why does the layer 2 BG change its vertical position, depending on the amount of LSRs or ASLs. This is possibly the effect of a scrolling patch, Those usually have to do with HDMA, even though I didn;t apply HDMA is a level with a 3rd BG, but the scrollreset patch should be the problem. Even though it could be weird.
(fixes the glitch in which the BG's X-position isn't reset when the
player exits from a level with H:Variable into a level with H:None)
Edit:No. Scroll reset is fine. It's not it.
Edit2:Hdma.asm is clear, too.
Finally my layer 2 shinanigans wont have to seems so bland.
SMWC's official dentist since 2011.

YouTube - Threads - Bluesky
So today I tried this tutorial, and inserted a layer 3 background into a test ROM. I've had some problems about inserting first, but fortunately they are now solved. The only problem is, I can't get it scrolling for some reason, even though I'm using exactly the same code you posted.
I copied the code both into levelcode.asm and levelinitcode.asm.

Before applying:



After:



For some reason the status bar got copied onto the layer 3 background.
I didn't change anything in the code and didn't have anything there beside that code. Any ideas what could cause this?
I'm not sure what's causing the status bar to be copied, but to fix the vertical offset from moving the background to high, find this line:

Code
SBC #$0038 ;If you're using a background that loops you probably won't have to use this. 


And play around with it. There should be some value that will get your background working correctly (and it looks like it would also hide that extra status bar.)
I should get a new layout.

Probably won't, though.
Ah, thanks for the fast help. After a few tries, the value D3A made the background correct again. It seems, if that value is lower, the background goes higher. Probably my background was extremely high, and that status bar glitch could occur (?). Anyways, thanks again.
This thing didn't work for me at all. This is what I did:

I made a savestate of the cave level in SMAS and ripped the layer 3 BG with Racing Stripe. Saved it as "smb3cave.stim" in the same folder as my ROM. Then I opened stim.asm and set the bit for level 10A to 1. In the tables below, I did following:

dl LayerImg1, LayerImg1, LayerImg1, LayerImg1, LayerImg1, LayerImg1, LayerImg1, LayerImg1, LayerImg1, LayerImg1, smb3cave, LayerImg1, LayerImg1, LayerImg1, LayerImg1, LayerImg1 ; Levels 100-10F

smb3cave:
incbin smb3cave.stim

Then I created an ExGFX file by copying GFX28.bin, deleted all tiles and pasted the layer 3 tiles from the savestate and inserted as ExGFX81.

In Layer3ExGFX.asm, I modified following:

dw $002B,$002B,$002B,$002B,$002B,$002B,$002B,$002B,$002B,$002B,$0081,$002B,$002B,$002B,$002B,$002B ; Levels 100-10F

I tried all four tables btw. The result? No background but a glitched up status bar. What did I do wrong?

Also, how would the game know how to setup the layer 3 background if the tiles in the ExGFX file could be anywhere? I don't get it at all...

e: In case you want to take a look at the ExGFX file, I have it uploaded here.
Originally posted by Weeabuu
This thing didn't work for me at all. This is what I did:...I tried all four tables btw. The result? No background but a glitched up status bar. What did I do wrong?


I need a bit more information. Could you send me the .STIM file you used, and a savestate of your level? But first, put this in levelASM:
Code
LDA #$0038 ;Play around with this value.
STA $24 ;Store to the layer 3 y position 


And see if that changes anything.

Originally posted by Weeabuu
Also, how would the game know how to setup the layer 3 background if the tiles in the ExGFX file could be anywhere? I don't get it at all...


You have to paste them in the same relative position as the original. It's a bit tricky to explain; maybe a picture will help:



Up top is garbage, you don't need to concern yourself with that, obviously. The second half of the window, however, is the graphics. Lets say that your background was made up of those random letters down there. You'd want to just copy that entire bottom half of graphics and create your ExGFX file out of that, because it would keep the letters in the same relative position. Again, it's kind of tricky to explain, so if you still don't get it, I'll try to explain it over again.
I should get a new layout.

Probably won't, though.
I perfectly understand what you mean with the position of the tiles.

Anyway, upon pasting the code in LevelASM and applying the patch, the level crashes for me. Removing the code resolves that.

I uploaded the .stim and the savestate:
http://bin.smwcentral.net/38119/smw.zst
http://bin.smwcentral.net/38121/smb3cave.stim