Zeldara109

6keys.asm (GBA)

Jan 31st, 2023 (edited)
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 2.39 KB | None | 0 0
  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ; Prevents keys in egg slots from being displaced if you have 6 keys           ;
  3. ;                                                                              ;
  4. ; A port of the 6 keys fix from SNES YI:                                       ;
  5. ;  https://www.smwcentral.net/?p=section&a=details&id=13207                    ;
  6. ;                                                                              ;
  7. ; Warning: Don't use 6 keys and a Super Star in the same level! If you collect ;
  8. ; a Super Star with 6 keys, the large Yoshi egg despawns and you softlock.     ;
  9. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  10.  
  11. .gba
  12. .open "sma3.gba", "sma3-6keys.gba", 0x08000000
  13.  
  14. .org 0x0804C578
  15. .area @AreaEnd-org()
  16.     ; r0: offset to sprite slot to be destroyed, from start of sprite structs
  17.     ; r4: pointer to new egg's struct
  18.     ldr r2,[0x0804C6D4] ; 0300702C: pointer to sprite structs
  19.     ldr r1,[r2]         ; 03002460: sprite structs
  20.     add r2,r1,r0        ; pointer to sprite to be destroyed
  21.     ldrh r0,[r2,0x32]   ; sprite ID, to be destroyed
  22.     cmp r0,0x27         ; 27: key
  23.     bne @@NotKey
  24.     mov r2,r4           ; if key, destroy new egg instead
  25.     @@NotKey:
  26.  
  27.     ; mostly vanilla code starting at 0804C584
  28.     ; excess instructions were removed, to avoid freespace usage
  29.     mov r1,0x0
  30.     mov r0,0x7          ;\
  31.     strh r0,[r2,0x24]   ;/ set sprite status to 7 (falling off screen)
  32.     mov r0,r2
  33.     add r0,0x5E         ; sprite+5E
  34.     strh r1,[r0]        ; clear sprite+5E
  35.     strh r1,[r0,0x1C]   ; clear sprite+7A
  36.     strh r1,[r0,0x18]   ; clear sprite+76
  37.     strh r1,[r0,0x14]   ; clear sprite+72
  38.     strh r1,[r0,0x10]   ; clear sprite+6E
  39.     strh r1,[r0,0xC]    ; clear sprite+6A
  40.     ldr r1,[0x0804C6D8] ; 08171FB0: sprite X velocities (00000100, FFFFFF00)
  41.     add r0,0x41         ; sprite+9F
  42.     ldrb r0,[r0]
  43.     lsl r0,r0,0x1       ; offset table with [sprite+9F]*2
  44.     ldr r0,[r1,r0]
  45.     str r0,[r2,0x8]     ; set sprite X velocity
  46.     ldr r0,[0x0804C6DC] ; FFFFFC00
  47.     str r0,[r2,0xC]     ; set sprite Y velocity
  48.     mov r0,0x40
  49.     str r0,[r2,0x14]    ; set sprite Y accel
  50.  
  51.     ; if new egg was destroyed, return early
  52.     cmp r2,r4
  53.     bne @AreaEnd
  54.     b 0x0804C6AC        ; return
  55.  
  56.     .fill @AreaEnd-org()
  57. .endarea
  58. .org 0x0804C5BC
  59. @AreaEnd:
  60.  
  61. .close
Add Comment
Please, Sign In to add comment