News:

Don't forget to visit the main site! There's lots of helpful docs, patches, and more!

Main Menu

[SM] The Layer 3 Code Sample Page!

Started by monktroid, April 20, 2017, 07:19:22 PM

Previous topic - Next topic

monktroid

-- BACKGROUND HAZE BEHIND LAYER 2 --



I've written a pretty stable way of injecting an HDMA haze onto the subscreen behind layer 2 within a room.  This is based to a large extent on the SMW "Comprehensive HDMA Tutorial": https://www.smwcentral.net/?p=viewthread&t=27054

What this essentially means is you can have a fixed 256 colour haze behind your background giving extra depth.  I've designed this code to be easy to play around with for non-hackers;  specifically it works extremely well with the fades you can design in Super Mario World Effect Tool. you can more or less copy haze tables you build in that program straight into the Red Green and Blue tables below. Be aware that Super Metroid has a thick black menu bar at the top and SMW does not!!!

As it is, the haze I have setup is a cartoony blue colour. 

Instructions for use:
1) compile the code below using ASAR (it's way better than XKAS in my humble opinion, it will probably compile fine in XKAS mind you; i just haven't tested it).
2) open a room with a layer 2 background/set a room to use a layer 2 background
3) set some of the layer background to air (ie. transparent) tiles.
4) set the FX layer type to "0E - Unused"
5) set FX Transparency 1 to "Normal" or "dark palette".  Most other palettes will result in only some of your background loading.  If you wanna change this you'll have to do some homebrew channel jostling via hex/asm.
6) Set FX Transparency 2 to "06 - L3 over L1 / L2, behind Sa..." or "02 - L3 over L1 / L2/ behind Sa..."
7) Save FX Data and Run the game
8) Hail Monktroid for being a dude and put a line in your credits ;)

Notes:
Q. Why does the background blink on after transition rather than fading in?
A. I haven't written a routine for fading the background in during transitions as yet. Accounting for different depths of fade will require the data to be injected into RAM and tested. Furthermore, because I don't know what you're gonna put in the tables that could end up being memory expensive to program because I'll have to test against stuff

Q. Why do I get weird results from stuff like the Dark Green Palette?
The HDMA Table takes up 3 HDMA channels. The palettes get precedence so - effectively - not all of the channels are available.

Q. Can't you set the results to take up fewer channels?
yep, but then it wouldn't be so easy for newbies

Q. if used in an instance where Power bomb explosions happen/eye thingies scan samus/mother brain's health-drain attack happens then the FX don't work properly.  What's that about?
Yeah, I know. It's a colour math/HDMA (and possibly subscreen) thing. I need to look at that.  It doesn't break the game though so hopefully not too big a deal.

lorom
org $809B8B
JSR INIT ; initialised from Samus' main health routine

org $80CDA0
INIT:
print pc
  LDA $7E0A79 ; test if Xray is in action
  CMP #$0000 : BEQ + : LDA $09C2 : RTS
+
  LDA $7E0CEC ; test if power bomb has been triggered
  CMP #$0000 : BEQ + : LDA $09C2 : RTS
+
  LDA $7E196E ; test if FX Layer type = $0E
  CMP #$000E : BEQ + : LDA $09C2 : RTS
+
  LDA $099C ; test if samus is leaving our haze room
  CMP #$E2DB : BNE + : LDA $09C2 : RTS
+
  LDA $0998   ; test game state.
  CMP #$0008 : BEQ + : LDA $09C2 : RTS
+
  REP #$20
  LDA #$1300 : STA $7E006A

  SEP #$20
  LDA #$02 : STA $7E006F ; add subscreen instead of fixed color to BG2 $2130
  LDA #$02 : STA $7E0072 ; $2131

  REP #$30
LDA #$3200 ; $43X0 = 00
STA $4330 ; $43x1 = 32
LDA #RED ; get pointer to red color table
STA $4332 ; store it to low and high byte pointer
LDY #$0080 : STY $4334 ; store to bank pointer byte, thus giving you the WHOLE address for DMA transfer (ie. 4332, 4333, 4334)
LDA #$3200 ; $43X0 = 00
STA $4350 ; $43x1 = 32
LDA #GREEN ; get pointer to red color table
STA $4352 ; store it to low and high byte pointer
LDY #$0080 : STY $4354 ; store to bank pointer byte
LDA #$3200 ; $43X0 = 00
STA $4360 ; $43x1 = 32
LDA #BLUE ; get pointer to red color table
STA $4362 ; store it to low and high byte pointer
LDY #$0080 : STY $4364 ; store to bank pointer byte
SEP #$20
  print pc
  LDA #$68 : TSB $0085 ; Enable HDMA on channels 3 4 and 5
  REP #$20
  LDA $09C2
RTS ; return

RED:
db $4F,$21
db $04,$22
db $04,$24
db $04,$25
db $04,$27
db $04,$28
db $04,$2A
db $04,$2B
db $04,$2D
db $04,$2E
db $04,$30
db $00

GREEN:
db $4F,$50
db $04,$51
db $04,$52
db $04,$53
db $04,$54
db $04,$55
db $04,$56
db $04,$57
db $04,$58
db $04,$59
db $04,$5A
db $00

BLUE:
db $4F,$99
db $08,$9A
db $08,$9B
db $08,$9D
db $08,$9E
db $08,$9F
db $00




-- CERES HAZE COLOR ALTERATION --

The following code changes the colour of the ceres haze to Green.  Or to red if the room has FX1 Pointer 80F0. 

lorom
org $88DE10 : JSR chooseColor ; Ceres Haze colour offset
org $88EE32
chooseColor:
LDA $07CD : CMP #$80F0 : BEQ + : LDA #$0040 : RTS ;test Layer3 pointer, set to green by default ...
+
LDA #$0020 ; ... or red if the room has FX1 pointer $80F0
RTS


the actual shading is performed againt the values stored in table $88DF03 - $88DF33.  Obviously you can tailor these as you see fit (or, indeed, inject indirect behaviour should you see fit)

some palette numbers to be aware of for said table:
$20-3F = Red
$40-5F = Green
$80-9F = Blue
$60-7F = Red & Green
$A0-BF = Red & Blue
$C0-DF = Green & Blue
$E0-FF = Red, Green & Blue
$00-1F = nothing

so, for example, since I set the value of the offset to 40.  the table value #$02 will actually become: #$42 (IOW a shade of green)

monktroid

#1
[DEPRECATED] USE THE SAMPLE IN THE OP

I've managed to get a haze to sit behind a layer 2 background! WOOOO :D
A lot of stuff just clicked today after days of endlessly banging my head against the keyboard!

So, this is a big dumb blue haze from super mario, feel free to swap it for more broody colours!  the beauty is that it is fixed so you can get cool kind of pseudo parallax FX as a result.

lorom

org $809B8B : JSR HDMA_test
org $80CDA0
HDMA_test: 
  LDA $0998 : CMP #$0008 : BEQ + : LDA $09C2 : RTS
  +
REP #$20 ; 16 bit A
  LDA #$1300 : STA $7E006A ; 212C = 0D, 212D  =02 enable subscreen on BG2
 
  SEP #$20 ; 8 bit A
  LDA #$02 : STA $7E006F ; add subscreen instead of fixed color to BG2 $2130
  LDA #$02 : STA $7E0072 ; $2131
 
  REP #$30
LDA #$3200 ; $43X0 = 00
STA $4330 ; $43x1 = 32
LDA #LVL1RED ; get pointer to red color table
STA $4332 ; store it to low and high byte pointer
LDY #$0080 : STY $4334 ; store to bank pointer byte, thus giving you the WHOLE address for DMA transfer (ie. 4332, 4333, 4334)
LDA #$3200 ; $43X0 = 00
STA $4340 ; $43x1 = 32
LDA #LVL1GREEN ; get pointer to red color table
STA $4342 ; store it to low and high byte pointer
LDY #$0080 : STY $4344 ; store to bank pointer byte
LDA #$3200 ; $43X0 = 00
STA $4350 ; $43x1 = 32
LDA #LVL1BLUE ; get pointer to red color table
STA $4352 ; store it to low and high byte pointer
LDY #$0080 : STY $4354 ; store to bank pointer byte
SEP #$20 ; 8 bit A
  LDA #$38 : TSB $0085 ; Enable HDMA on channels 3 4 and 5
  REP #$20
RTS ; return

LVL1RED:
db $4F,$21
db $04,$22
db $04,$24
db $04,$25
db $04,$27
db $04,$28
db $04,$2A
db $04,$2B
db $04,$2D
db $04,$2E
db $04,$30
db $00

LVL1GREEN:
db $4F,$50
db $04,$51
db $04,$52
db $04,$53
db $04,$54
db $04,$55
db $04,$56
db $04,$57
db $04,$58
db $04,$59
db $04,$5A
db $00

LVL1BLUE:
db $4F,$99
db $08,$9A
db $08,$9B
db $08,$9D
db $08,$9E
db $08,$9F
db $00


I hasten to add that the above heavily cites the SMW Comprehensive HDMA tutorial:
https://www.smwcentral.net/?p=viewthread&t=27054

I'm planning to make mine a bit more interesting with indirect tables now I get the gist of how it works.

benox50

#2
Thank you alot for that, I will make test and have fun with it as soon as I can.
Keep sharing Dude, gonna make those hacks shine with colors  :bounce:

benox50

The first bug I found is that it will black out the screen if you use a negative layer 3 blending. but it works with layer 3 positive blending (color math)
See FX1 B => 02 in smile setting.

I think taht is why your screen black out the first time

monktroid

Oh the above definitely comes with caveats! I'll wrote something more stable up when it's ready!

monktroid

Just To keep people up-to-date, I'm currently writing what I hope will be a more sophisticated alternative to the common-or-garden Ceres Haze. I'm using a fairly complex bunch of stuff in bank $88 (this is fairly important because it looks after room transitions and generally helps keep it stable). Ideally it'll sit at the end of bank $88 and people will be able to translate tables from the SMW Effect Tool into something they can use in SM. It's going pretty well so far. Slightly worried it's gonna take up quite a lot of space though. Getting it stable is  more fiddly than I'd expected :P

monktroid

#6
This is a bump to let you know that I've managed to write a stable BG colour haze stub. See the opening post of this thread for details!