Advertisement
warmCabin

Mega Man 2 - Password screen input processing

Jun 5th, 2021 (edited)
2,385
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. password_runner_loop:
  2.  0D:A357: A5 27     LDA p1_buttons_pressed
  3. ; Mask for only D-pad buttons
  4.  0D:A359: 29 F0     AND #$F0
  5.  0D:A35B: D0 18     BNE arrows_pressed
  6.  0D:A35D: A5 23     LDA p1_buttons_held
  7. ; Mask for only D-pad buttons
  8.  0D:A35F: 29 F0     AND #$F0
  9.  0D:A361: F0 45     BEQ no_arrows_held
  10. ; Is this a bug?
  11. ; The intent here is to ignore inputs if at least one arrow
  12. ; was released this frame.
  13. ; p1_buttons_prev is used during the buttons pressed
  14. ; calculation, but afterwards it's always equal to the current
  15. ; frame's buttons. So this check always passes.
  16.  0D:A363: A5 25     LDA p1_buttons_held_prev
  17.  0D:A365: C5 23     CMP p1_buttons_held
  18.  0D:A367: D0 3F     BNE no_arrows_held
  19. ; An arrow is being held but was not pressed on this frame.
  20. ; Do delayed autorepeat logic.
  21.  0D:A369: E6 FE     INC password_cursor_timer
  22.  0D:A36B: A5 FE     LDA password_cursor_timer
  23.  0D:A36D: C9 18     CMP #$18
  24.  0D:A36F: 90 3B     BCC check_AB
  25. ; Write back a higher value so the subsequent autorepeats are
  26. ; shorter than the initial delay. Pattern looks like 25, 17, 17, 17...
  27.  0D:A371: A9 08     LDA #$08
  28.  0D:A373: 85 FE     STA password_cursor_timer
  29. arrows_pressed:
  30.  0D:A375: A9 2F     LDA #$2F
  31.  0D:A377: 20 51 C0  JSR add_sfx_to_queue
  32.  0D:A37A: AE A0 06  LDX password_cursor_position
  33. ; Check if left or right is pressed, with a bit of a bug.
  34. ; We know an arrow was PRESSED, but we're looking
  35. ; at all the ones that are HELD to determine which one.
  36. ; It's subtle, but it allows you to convert
  37. ; an arrow press into another direction,
  38. ; with the following priorities: right > left > up > down
  39. ; e.g. if you are holding right and press down, it counts as
  40. ; an extra right press.
  41. ; You might think the fix is to use p1_buttons_pressed here,
  42. ; but this logic is used for delayed autorepeat as well, so
  43. ; that won't work.
  44.  0D:A37D: A5 23     LDA p1_buttons_held
  45.  0D:A37F: 29 C0     AND #$C0
  46.  0D:A381: F0 10     BEQ up_down_check
  47. ; $80 = right
  48.  0D:A383: 29 80     AND #$80
  49.  0D:A385: F0 06     BEQ left_pressed
  50.  0D:A387: BD 46 AF  LDA cursor_right_pos,X
  51.  0D:A38A: 4C A2 A3  JMP move_cursor
  52. left_pressed:
  53.  0D:A38D: BD 5F AF  LDA cursor_left_pos,X
  54.  0D:A390: 4C A2 A3  JMP move_cursor
  55. up_down_check:
  56. ;  The same quirk applies here.
  57.  0D:A393: A5 23     LDA p1_buttons_held
  58. ; $10 = up
  59.  0D:A395: 29 10     AND #$10
  60.  0D:A397: F0 06     BEQ down_pressed
  61.  0D:A399: BD 78 AF  LDA cursor_up_pos,X
  62.  0D:A39C: 4C A2 A3  JMP move_cursor
  63. down_pressed:
  64.  0D:A39F: BD 91 AF  LDA cursor_down_pos,X
  65. move_cursor:
  66. ; A = pos for cursor to move to
  67.  0D:A3A2: 8D A0 06  STA password_cursor_position
  68.  0D:A3A5: 4C AC A3  JMP check_AB
  69. no_arrows_held:
  70. ; Reset autorepeat timer
  71.  0D:A3A8: A9 00     LDA #$00
  72.  0D:A3AA: 85 FE     STA password_cursor_timer
  73. check_AB:
  74.  0D:A3AC: A5 27     LDA p1_buttons_pressed
  75. ; Mask for A and B
  76.  0D:A3AE: 29 03     AND #$03
  77.  0D:A3B0: F0 28     BEQ wait_for_next_frame
  78.  ; No autorepeat for A/B, so no problems here.
  79.  0D:A3B2: A5 27     LDA p1_buttons_pressed
  80.  0D:A3B4: AE A0 06  LDX password_cursor_position
  81. ; 1 = A button
  82.  0D:A3B7: 29 01     AND #$01
  83.  0D:A3B9: F0 14     BEQ $A3CF b_pressed
  84. ; A was pressed.
  85. ; Sprite flags are used to indicate whether the slot is full or empty.
  86.  0D:A3BB: BD 20 04  LDA sprite_flags,X
  87.  0D:A3BE: D0 1A     BNE wait_for_next_frame
  88.  0D:A3C0: A9 42     LDA #$42
  89.  0D:A3C2: 20 51 C0  JSR add_sfx_to_queue
  90.  0D:A3C5: FE 20 04  INC sprite_flags,X
  91.  0D:A3C8: CE 80 06  DEC balls_remaining
  92.  0D:A3CB: F0 16     BEQ read_password
  93.  0D:A3CD: D0 0B     BNE wait_for_next_frame
  94. b_pressed:
  95.  0D:A3CF: BD 20 04  LDA sprite_flags,X
  96.  0D:A3D2: F0 06     BEQ wait_for_next_frame
  97.  0D:A3D4: DE 20 04  DEC sprite_flags,X
  98.  0D:A3D7: EE 80 06  INC balls_remaining
  99. wait_for_next_frame:
  100.  0D:A3DA: 20 E9 A8  JSR update_password_graphics
  101.  0D:A3DD: 20 AB C0  JSR menu_wait_routine
  102.  0D:A3E0: 4C 57 A3  JMP password_runner_loop
  103. read_password:
  104.  ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement