Advertisement
warmCabin

Mega Man 2 nonlooping animation bug

Jan 7th, 2022
1,030
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. draw_player_sprite:
  2. ; Player sprites include Mega Man, his weapons,
  3. ; and "metaballs" when he explodes.
  4. ; Aside from a different location for graphics data and some
  5. ; special cases for Mega Man and bosses, this is largely the same
  6. ; as draw_enemy_sprites.
  7.  0F:CDE4: A6 2B     LDX current_sprite_index
  8.  0F:CDE6: BD 20 04  LDA sprite_flags,X
  9.  0F:CDE9: 30 02     BMI +
  10. ; Sprite is inactive. Return.
  11.  0F:CDEB: 18        CLC
  12.  0F:CDEC: 60        RTS -----------------------------------------
  13. +:
  14. ; Get main data pointer
  15.  0F:CDED: BC 00 04  LDY sprite_ids[0],X
  16.  0F:CDF0: B9 00 F9  LDA player_main_gfx_ptrs_lo,Y
  17.  0F:CDF3: 85 08     STA $08
  18.  0F:CDF5: B9 00 FA  LDA player_main_gfx_ptrs_hi,Y
  19.  0F:CDF8: 85 09     STA $09
  20. ; Increment animation timer
  21.  0F:CDFA: BD A0 06  LDA sprite_cel_nums[0],X
  22.  0F:CDFD: 48        PHA
  23.  0F:CDFE: FE 80 06  INC sprite_anim_timers[0],X
  24.  0F:CE01: A0 01     LDY #$01
  25.  0F:CE03: B1 08     LDA ($08),Y
  26.  0F:CE05: DD 80 06  CMP sprite_anim_timers[0],X
  27.  0F:CE08: B0 15     BCS +
  28. ; Timer expired, increment to next cel
  29.  0F:CE0A: A9 00     LDA #$00
  30.  0F:CE0C: 9D 80 06  STA sprite_anim_timers[0],X
  31.  0F:CE0F: FE A0 06  INC sprite_cel_nums[0],X
  32. ; Check if we've passed the end of the animation
  33.  0F:CE12: 88        DEY
  34.  0F:CE13: B1 08     LDA ($08),Y
  35.  0F:CE15: DD A0 06  CMP sprite_cel_nums[0],X
  36.  0F:CE18: B0 05     BCS +
  37. ; End of animation. Loop it.
  38.  0F:CE1A: A9 00     LDA #$00
  39.  0F:CE1C: 9D A0 06  STA sprite_cel_nums[0],X
  40. +:
  41. ; Start loading gfx data
  42. ; A = cel number
  43. ; Fetch cel ID from animation_data[cel_number + 2 ]
  44.  0F:CE1F: 68        PLA
  45.  0F:CE20: 18        CLC
  46.  0F:CE21: 69 02     ADC #$02
  47.  0F:CE23: A8        TAY
  48.  0F:CE24: B1 08     LDA ($08),Y
  49.  0F:CE26: D0 04     BNE +
  50. ; Cel 0 == end of nonlooping animation.
  51. ; Kill sprite.
  52. ;
  53. ; There's a bug here! If the flags bit 0 is set (which indicates
  54. ; the sprite collides with Mega Man), it will be shifted into the
  55. ; carry flag, giving an erroneous return value from this routine.
  56. ; This will make the main gfx routine return early.
  57.  0F:CE28: 5E 20 04  LSR sprite_flags,X
  58.  0F:CE2B: 60        RTS -----------------------------------------
  59.  
Advertisement
RAW Paste Data Copied
Advertisement