News:

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

Main Menu

Miscellaneous ASM Tweaks for M2

Started by RT-55J, April 29, 2023, 02:41:51 AM

Previous topic - Next topic

RT-55J

Making this thread so that random things that I post on Discord (that I'm too lazy to add to the wiki) don't get lost.




Here's an in-place ASM modification that makes it so beams use the same drawing logic as missiles (i.e. they flip depending on the direction they are fired):


            ; Check if missile
            ld a, d
            cp $08
            nop
            push af
                ; Missile case
                push hl
                    ; Load sprite tile for direction
                    ld hl, .missileSpriteTileTable
                    ld a, c
                    ld e, a
                    ld d, $00
                    add hl, de
                    ld a, [hl]
                    ldh [hSpriteId], a
                    ; Load sprite attribute for direction
                    ld hl, .missileSpriteAttributeTable
                    ld a, c
                    ld e, a
                    ld d, $00
                    add hl, de
                    ld a, [hl]
                    ldh [hSpriteAttr], a
                pop hl
            pop af
            jr z, .endIf_A
                ldh a, [hSpriteId]
                sub (152-126)
                ldh [hSpriteId], a
            nop
            nop
            nop
            nop
            nop
            nop
            .endIf_A:
            PRINT @
            ASSERT @ == $5359

(This modifies the drawProjectile function around $5300 in bank 1.)

file diff, because sure, why not:

0000014E: 58 57
0000014F: 1F DB
00005330: 20 00
00005331: 1A F5
0000534A: 18 F1
0000534B: 0D 28
0000534C: 3E 0C
0000534D: 7E F0
0000534E: E0 C6
0000534F: C6 D6
00005350: 79 1A
00005351: E6 E0
00005352: 03 C6
00005353: 20 00
00005354: 04 00
00005355: 3E 00
00005356: 7F 00
00005357: E0 00
00005358: C6 00


patch is attached. edit the graphics to your liking

Terrence7522


RT-55J

#2
By default, Spazer and Plasma share the same beam graphics, but it doesn't need to be that way!

The disassembly has several things called "gfxInfo" entries, which provide the source, destination, and size of various graphical assets. While the spazer and plasma beam techincally use the same gfxInfo entry, the author of the disassembly was thoughtful enough to give them separate labels for convenience:


gfxInfo_spazer:
gfxInfo_plasma: db BANK(gfx_beamPlasma)
    dw gfx_beamPlasma, vramDest_beam, $0020


Thus, if you wanted to add a separate set of graphics for the spazer, you could just include the graphics file literally anywhere in the ROM, make a label referencing it, and then make a simple edit like this:


gfxInfo_spazer: db BANK(gfx_beamSpazer)
    dw gfx_beamSpazer, vramDest_beam, $0020
gfxInfo_plasma: db BANK(gfx_beamPlasma)
    dw gfx_beamPlasma, vramDest_beam, $0020


Now, if you want to be lazy and hardcode these changes to an existing ROM, you could just make these hex-edits:


Address: Original - Change
; Address of gfxInfo_spazer
00382D: D6 60
00382E: 37 3F
; Address of gfxInfo_spazer
003C21: D6 60
003C22: 37 3F

; gfxInfo_spazer
; Source Bank
003F60: 00 06
; Source Address
003F61: 00 D0
003F62: 00 55
; Destination
003F63: 00 E0
003F64: 00 87
; Length
003F65: 00 20
003F66: 00 00


This would make the game load graphics for the spazer beam from immediately after the Varia suit graphics in bank 6, by putting gfxInfo_spazer at the start of Bank 0's freespace.

The one issue to this approach is that it uses the freespace at the very end of Bank 0, which (a) is quite valuable and (b) might conflict with existing .ips patches or hex tweaks. To avoid this, I recommend using the disassembly for your projects.