News:

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

Main Menu

[SM] [ASM] Door-Dependent FX1

Started by herald83, December 31, 2011, 01:34:02 AM

Previous topic - Next topic

herald83

So, I've been staring at Kej's sm_misc for awhile now, and something's just not clicking.  Anyone care to explain door-dependent FX1?

For reference:
[spoiler]
fx1_select

          value   | effect
          --------+-----------
          FFFF    | no FX1 (use internal defaults)
          0000    | use this FX1 entry as our FX1 entry
   active door id | use this FX1 entry as our FX1 entry
    anything else | add 10h to the room_fx1 pointer and
                  | loop back to try the next FX1 entry
[/spoiler]

I'm trying to set up something similar to the rising acid in 7B4E5.  I could just hijack and expand that room, but I feel like that's a cop out, and I should do it right from scratch.  I've been picking away at this room, and I can kind of see what's happening, but I'm not fully grasping it.  7B4E5's FX1 data when entering from room 7B585 is as follows:
[spoiler]
Code (Coming from 7B585; Acid already up) Select

99F6 00D0 FFFF 0000 00 04 02 1E 82 1F 00 00
|    |    |    |    |  |  |  |  |  |  |  |
|    |    |    |    |  |  |  |  |  |  |  |_ fx1_blend
|    |    |    |    |  |  |  |  |  |  |____ fx1_animatetile
|    |    |    |    |  |  |  |  |  |_______ fx1_palette fx
|    |    |    |    |  |  |  |  |__________ fx1_C
|    |    |    |    |  |  |  |_____________ fx1_B
|    |    |    |    |  |  |________________ fx1_A
|    |    |    |    |  |___________________ fx1_layer3type
|    |    |    |    |______________________ fx1_surface_delay
|    |    |    |___________________________ fx1_surface_speed
|    |    |________________________________ fx1_surface_new
|    |_____________________________________ fx1_surface_start
|__________________________________________ fx1_select
[/spoiler]

Coming from 7B4AD is this:
[spoiler]
Code (Coming from 7B4AD; Acid rising) Select

0000 04E8 00D0 FF80 60 04 02 1E 82 1F 02 00
|    |    |    |    |  |  |  |  |  |  |  |
|    |    |    |    |  |  |  |  |  |  |  |_ fx1_blend
|    |    |    |    |  |  |  |  |  |  |____ fx1_animatetile
|    |    |    |    |  |  |  |  |  |_______ fx1_palette fx
|    |    |    |    |  |  |  |  |__________ fx1_C
|    |    |    |    |  |  |  |_____________ fx1_B
|    |    |    |    |  |  |________________ fx1_A
|    |    |    |    |  |___________________ fx1_layer3type
|    |    |    |    |______________________ fx1_surface_delay
|    |    |    |___________________________ fx1_surface_speed
|    |    |________________________________ fx1_surface_new
|    |_____________________________________ fx1_surface_start
|__________________________________________ fx1_select
[/spoiler]

I searched for this string of hex, and it only appears at $83:884C, which is #10 bytes after the other pointer, so it looks like we have an "anything else" value.  Is this correct?  What is the "active door id" and how would you use it?

begrimed

I'm interested in this too. There're some things I'd like to do with rising water.

Metaquarius

Think you have a list of fx1 written sequentially (the first one is pointed by your room), the game iterates through them based on their door_select value.

If door_select == the door you've come through /or/ 0000, load this fx1, else, check the next fx1 (hence +10h) and so on...

herald83

Yeah, that makes sense, but I'd still like to know what the other thing is.

As a followup question, does anyone know where the FX1-handling code lives?

Qactis

All of those Acid Rising FX_1 values have RAM values for that, look in the RAM map. The game reads those values and stores them in the RAM. As far as the door code having a routine to check for this, I'm not sure about how that works. Have you checked for different bit flags on that door?

P.JBoy

#5
Here's the code that handles the FX1 header
[spoiler]

$89AB82 08          PHP
$89AB83 8B          PHB
$89AB84 C2 30       REP #$30
$89AB86 F4 00 83    PEA $8300
$89AB89 AB          PLB
$89AB8A AB          PLB
$89AB8B AE CD 07    LDX $07CD  [$7E:07CD]       ; FX1 pointer
$89AB8E D0 03       BNE $03    [$AB93]          ; Return if FX1 pointer == 0000 (never is in vanilla)
$89AB90 AB          PLB
$89AB91 28          PLP
$89AB92 6B          RTL

$89AB93 BD 00 00    LDA $0000,x[$83:A146]       ; ~sigh~
$89AB96 A0 00 00    LDY #$0000                  ; fx1 entry offset

$89AB99 BD 00 00    LDA $0000,x[$83:A146]       ; fx1_select
$89AB9C F0 1B       BEQ $1B    [$ABB9]          ; Branch for fx1_select == 0000 (unconditional FX1, if used, always last)
$89AB9E C9 FF FF    CMP #$FFFF                  ;\
$89ABA1 D0 03       BNE $03    [$ABA6]          ;} Return if fx1_select == FFFF (unconditionally no FX1, if used, always last)
$89ABA3 AB          PLB
$89ABA4 28          PLP
$89ABA5 6B          RTL

; Find fx1 entry with fx1_select == current room transition door pointer
$89ABA6 CD 8D 07    CMP $078D  [$7E:078D]       ; Door pointer for current room transition
$89ABA9 F0 0E       BEQ $0E    [$ABB9]          ; Break loop if matching door pointer
$89ABAB 8A          TXA                         ;\
$89ABAC 18          CLC                         ;|
$89ABAD 69 10 00    ADC #$0010                  ;} Next fx1 entry pointer
$89ABB0 AA          TAX                         ;/
$89ABB1 98          TYA                         ;\
$89ABB2 18          CLC                         ;|
$89ABB3 69 10 00    ADC #$0010                  ;} Next fx1 entry offset
$89ABB6 A8          TAY                         ;/
$89ABB7 80 E0       BRA $E0    [$AB99]          ; Loop infinitely

; LoadFX1:
$89ABB9 8C 68 19    STY $1968  [$7E:1968]       ; fx1 entry offset
$89ABBC 8E 66 19    STX $1966  [$7E:1966]       ; fx1 entry pointer
$89ABBF AE 66 19    LDX $1966  [$7E:1966]       ; ~sigh~
$89ABC2 BD 02 00    LDA $0002,x[$83:A148]       ;\
$89ABC5 8D 78 19    STA $1978  [$7E:1978]       ;} fx1_surface_start
$89ABC8 BD 04 00    LDA $0004,x[$83:A14A]       ;\
$89ABCB 8D 7A 19    STA $197A  [$7E:197A]       ;} fx1_surface_new
$89ABCE BD 06 00    LDA $0006,x[$83:A14C]       ;\
$89ABD1 8D 7C 19    STA $197C  [$7E:197C]       ;} fx1_surface_speed
$89ABD4 BD 08 00    LDA $0008,x[$83:A14E]       ;\
$89ABD7 29 FF 00    AND #$00FF                  ;} fx1_surface_delay
$89ABDA 8D 80 19    STA $1980  [$7E:1980]       ;/
$89ABDD BD 0A 00    LDA $000A,x[$83:A150]       ;\
$89ABE0 29 FF 00    AND #$00FF                  ;} fx1_A
$89ABE3 8D 82 19    STA $1982  [$7E:1982]       ;/
$89ABE6 BD 0B 00    LDA $000B,x[$83:A151]       ;\
$89ABE9 29 FF 00    AND #$00FF                  ;} fx1_B
$89ABEC 8D 84 19    STA $1984  [$7E:1984]       ;/
$89ABEF BD 0C 00    LDA $000C,x[$83:A152]       ;\
$89ABF2 29 FF 00    AND #$00FF                  ;} fx1_C
$89ABF5 8D 7E 19    STA $197E  [$7E:197E]       ;/
$89ABF8 BD 0F 00    LDA $000F,x[$83:A155]       ;\
$89ABFB 29 FF 00    AND #$00FF                  ;} If fx1_blend != 00:
$89ABFE F0 1B       BEQ $1B    [$AC1B]          ;/
$89AC00 AA          TAX                         ;\
$89AC01 BF 02 AA 89 LDA $89AA02,x[$89:AA24]     ;|
$89AC05 8F 32 C2 7E STA $7EC232[$7E:C232]       ;|
$89AC09 BF 04 AA 89 LDA $89AA04,x[$89:AA26]     ;} Copy three colours from $89:AA02+fx1_blend to
$89AC0D 8F 34 C2 7E STA $7EC234[$7E:C234]       ;} Target colour palette (line 1, column 9..B)
$89AC11 BF 06 AA 89 LDA $89AA06,x[$89:AA28]     ;|
$89AC15 8F 36 C2 7E STA $7EC236[$7E:C236]       ;/
$89AC19 80 07       BRA $07    [$AC22]

$89AC1B A9 00 00    LDA #$0000                  ;\ Else (fx1_blend == 00):
$89AC1E 8F 36 C2 7E STA $7EC236[$7E:C236]       ;} Clear Target colour palette (line 1, column B)

$89AC22 AE 66 19    LDX $1966  [$7E:1966]       ; Restore X index for the case of fx1_blend
$89AC25 BD 09 00    LDA $0009,x[$83:A14F]       ;\
$89AC28 29 FF 00    AND #$00FF                  ;} fx1_layer3type
$89AC2B 8D 6E 19    STA $196E  [$7E:196E]       ;/
$89AC2E F0 07       BEQ $07    [$AC37]          ; If fx1_layer3type != 00:
$89AC30 A8          TAY                         ;\
$89AC31 B9 F0 AB    LDA $ABF0,y[$83:AC1A]       ;} fx1 tilemap pointer ($83:ABF0 + fx1_layer3type)
$89AC34 8D 64 19    STA $1964  [$7E:1964]       ;/

$89AC37 AE 66 19    LDX $1966  [$7E:1966]       ;\
$89AC3A BD 09 00    LDA $0009,x[$83:A14F]       ;} ~sigh~
$89AC3D 29 FF 00    AND #$00FF                  ;} If fx1_layer3type != 00:
$89AC40 F0 12       BEQ $12    [$AC54]          ;/
$89AC42 A8          TAY                         ;\
$89AC43 A9 00 88    LDA #$8800                  ;|
$89AC46 85 13       STA $13    [$7E:0013]       ;|
$89AC48 B9 18 AC    LDA $AC18,y[$83:AC42]       ;|
$89AC4B 85 12       STA $12    [$7E:0012]       ;} Call fx1_layer3type specific code ($88:0000 + [$83:AC18 + fx1_layer3type])
$89AC4D 4B          PHK                         ;|
$89AC4E F4 53 AC    PEA $AC53                   ;|
$89AC51 DC 12 00    JML [$0012][$88:D928]       ;/

$89AC54 AE 66 19    LDX $1966  [$7E:1966]       ; Restore X for the case of fx1_layer3type specific code
$89AC57 BD 0D 00    LDA $000D,x[$83:A153]       ;\
$89AC5A 29 FF 00    AND #$00FF                  ;} Branch for fx1_palette_fx == 00
$89AC5D F0 2B       BEQ $2B    [$AC8A]          ;/
$89AC5F 8D 6A 19    STA $196A  [$7E:196A]       ; fx1_palette_fx
$89AC62 AD 9F 07    LDA $079F  [$7E:079F]       ;\
$89AC65 0A          ASL A                       ;|
$89AC66 A8          TAY                         ;} fx1_palette_fx region table ([$83:AC46 + RegionNumber*2])
$89AC67 B9 46 AC    LDA $AC46,y[$83:AC46]       ;|
$89AC6A 85 AF       STA $AF    [$7E:00AF]       ;/
$89AC6C A0 00 00    LDY #$0000                  ; (2n)th bit of fx1_palette_fx set

$89AC6F 4E 6A 19    LSR $196A  [$7E:196A]       ;\
$89AC72 B0 09       BCS $09    [$AC7D]          ;|
$89AC74 C8          INY                         ;|
$89AC75 C8          INY                         ;} For each bit set of fx1_palette_fx from bit0 to bitF:
$89AC76 C0 10 00    CPY #$0010                  ;|
$89AC79 D0 F4       BNE $F4    [$AC6F]          ;|
$89AC7B 80 0D       BRA $0D    [$AC8A]          ;/

$89AC7D B1 AF       LDA ($AF),y[$83:AC66]       ;\
$89AC7F 5A          PHY                         ;|
$89AC80 A8          TAY                         ;} Call $8D:C4E9 with Y = fx1_palette_dx region table + 2n
$89AC81 22 E9 C4 8D JSL $8DC4E9[$8D:C4E9]       ;|
$89AC85 7A          PLY                         ;/
$89AC86 C8          INY                         ;\
$89AC87 C8          INY                         ;} (Loop)
$89AC88 80 E5       BRA $E5    [$AC6F]          ;/

$89AC8A AE 66 19    LDX $1966  [$7E:1966]       ; Restore X for the case of $8D:C4E9
$89AC8D BD 0E 00    LDA $000E,x[$83:A154]       ;\
$89AC90 29 FF 00    AND #$00FF                  ;|
$89AC93 F0 2B       BEQ $2B    [$ACC0]          ;|
$89AC95 8D 6A 19    STA $196A  [$7E:196A]       ;|
$89AC98 AD 9F 07    LDA $079F  [$7E:079F]       ;|
$89AC9B 0A          ASL A                       ;|
$89AC9C A8          TAY                         ;|
$89AC9D B9 56 AC    LDA $AC56,y[$83:AC58]       ;|
$89ACA0 85 AF       STA $AF    [$7E:00AF]       ;|
$89ACA2 A0 00 00    LDY #$0000                  ;|
                                                ;|
$89ACA5 4E 6A 19    LSR $196A  [$7E:196A]       ;|
$89ACA8 B0 09       BCS $09    [$ACB3]          ;|
$89ACAA C8          INY                         ;} Same deal as above; but for fx1_animatetile, $83:AC56, and $87:8027
$89ACAB C8          INY                         ;|
$89ACAC C0 10 00    CPY #$0010                  ;|
$89ACAF D0 F4       BNE $F4    [$ACA5]          ;|
$89ACB1 80 0D       BRA $0D    [$ACC0]          ;|
                                                ;|
$89ACB3 B1 AF       LDA ($AF),y[$83:AC96]       ;|
$89ACB5 5A          PHY                         ;|
$89ACB6 A8          TAY                         ;|
$89ACB7 22 27 80 87 JSL $878027[$87:8027]       ;|
$89ACBB 7A          PLY                         ;|
$89ACBC C8          INY                         ;|
$89ACBD C8          INY                         ;|
$89ACBE 80 E5       BRA $E5    [$ACA5]          ;/

$89ACC0 AB          PLB
$89ACC1 28          PLP
$89ACC2 6B          RTL

[/spoiler]

herald83

Awesome, thanks guys!  I'll look into this when I get back from the holidays and report back if I figure anything new out.

P.JBoy

#7
Here's the palette blend table.  There's no background colour option, so I gave all the values a white glow

[spoiler]
Here's the palette blend table


$89AA04     dw 0E3F, 0D7F, 0000                                                                 ; Palette blend 02.  Tourian acid/lava rooms
$89AA0A     dw 6318,6318,0000, 6318,6318,0000, 6318,6318,0000, 6318,6318,0000, 0038
$89AA24     dw 314A, 20C6, 2008                                                                 ; Palette blend 22.  Landing site before power bombs
$89AA2A     dw 6318,6318,0000, 6318,6318,0000, 6318,6318,0000, 6318,6318,0000, 0038
$89AA44     dw 0400, 1C63, 0000                                                                 ; Palette blend 42.  Yellow Maridia
$89AA4A     dw 28E3, 1C60, 0000                                                                 ; Palette blend 48.  Water rooms
$89AA50     dw 8524,883D,0000, 8008,2004,0000, E328,601C,0000, 0038
$89AA64     dw 20A5, 1C84, 2410                                                                 ; Palette blend 62.  Fog & Rain, Crateria before Zebes awakens
$89AA6A     dw 1087,14A8,0844, 6318,6318,0000, 6318,6318,0000, 6318,6318,0000, 0038
$89AA84     dw 6318,6318,0000, 6318,6318,0000, 6318,6318,0000, 6318,6318,0000, 6318,6318,0000, 0038
$89AAA4     dw 6318,6318,0000, 6318,6318,0000, 6318,6318,0000, 6318,6318,0000, 6318,6318,0000, 0038
$89AAC4     dw 6318,6318,0000, 6318,6318,0000, 6318,6318,0000, 6318,6318,0000, 6318,6318,0000, 0038
$89AAE4     dw 0400, 18A2, 0000                                                                 ; Palette blend E2.  Lower Green/Pink Maridia
$89AAEA     dw 0020, 0C62, 0000                                                                 ; Palette blend E8.  Sandy Maridia
$89AAF0     dw 0400, 1C45, 0000                                                                 ; Palette blend EE.  Upper Green/Pink Maridia
$89AAF6     dw 6318,6318,0000, 6318,6318,0000

[/spoiler]

[spoiler="With white background"]

$89AA04     dw 0E3F, 0D7F, 0000                                                                 ; Palette blend 02.  Tourian acid/lava rooms
$89AA0A     dw 6318,6318,0000, 6318,6318,0000, 6318,6318,0000, 6318,6318,0000, 0038
$89AA24     dw 314A, 20C6, 2008                                                                 ; Palette blend 22.  Landing site before power bombs
$89AA2A     dw 6318,6318,0000, 6318,6318,0000, 6318,6318,0000, 6318,6318,0000, 0038
$89AA44     dw 0400, 1C63, 0000                                                                 ; Palette blend 42.  Yellow Maridia
$89AA4A     dw 28E3, 1C60, 0000                                                                 ; Palette blend 48.  Water rooms
$89AA50     dw 8524,883D,0000, 8008,2004,0000, E328,601C,0000, 0038
$89AA64     dw 20A5, 1C84, 2410                                                                 ; Palette blend 62.  Fog & Rain, Crateria before Zebes awakens
$89AA6A     dw 1087,14A8,0844, 6318,6318,0000, 6318,6318,0000, 6318,6318,0000, 0038
$89AA84     dw 6318,6318,0000, 6318,6318,0000, 6318,6318,0000, 6318,6318,0000, 6318,6318,0000, 0038
$89AAA4     dw 6318,6318,0000, 6318,6318,0000, 6318,6318,0000, 6318,6318,0000, 6318,6318,0000, 0038
$89AAC4     dw 6318,6318,0000, 6318,6318,0000, 6318,6318,0000, 6318,6318,0000, 6318,6318,0000, 0038
$89AAE4     dw 0400, 18A2, 0000                                                                 ; Palette blend E2.  Lower Green/Pink Maridia
$89AAEA     dw 0020, 0C62, 0000                                                                 ; Palette blend E8.  Sandy Maridia
$89AAF0     dw 0400, 1C45, 0000                                                                 ; Palette blend EE.  Upper Green/Pink Maridia
$89AAF6     dw 6318,6318,0000, 6318,6318,0000

[/spoiler]