Advertisement
Bisqwit

cv2ins_sample_after

Aug 20th, 2022 (edited)
3,144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. function Add_delete_p2_input($needed = true)
  3. {
  4.   if(!$needed) return;
  5.   static $added;
  6.   if(isset($added)) return;
  7.   $added = true;
  8.   //
  9.   for($part = 1; $part <= 2; ++$part)
  10.   LoadAsmBlobWithMapAndLink(sprintf("bin/delete_p2_input_part$part.bin"));
  11. }
  12. ------------------------
  13. .include "macros.inc"
  14. .include "defines.inc"
  15. .code
  16.  
  17. ;    Frees RAM addresses F4,F6 (new buttons player2),
  18. ;                        F2,F8 (current buttons player2)
  19. ;    Change NMI_UpdateInput (C453-C4AE, 92 bytes) to to:
  20. ;             ldx #1                    ;2
  21. ;             jsr @read                 ;12+189
  22. ;             dex                   ;2
  23. ;             jsr @read                 ;12+189
  24. ;             lda $00                   ;3
  25. ;             cmp $01                   ;3
  26. ;             bne @blank (+14)              ;2
  27. ;             tay                   ;2
  28. ;             eor $F1 (Input_CurrentJoyButtonsOrig) ;3
  29. ;             and $00                   ;3
  30. ;             sta $F5 (Input_NewJoyButtonsWork)     ;3
  31. ;             sta $F3 (Input_NewJoyButtonsOrig)     ;3
  32. ;             sty $F7 (Input_CurrentJoyButtonsWork) ;3
  33. ;             sty $F1 (Input_CurrentJoyButtonsOrig) ;3
  34. ;             rts
  35. ;       @blank:
  36. ;             stx $F5                   ;3
  37. ;             stx $F3                   ;3
  38. ;             nop;nop;nop;php;plp                       ;13
  39. ;             rts
  40. ;       @read:
  41. ;             ldy #1        ;2
  42. ;             sty $4016     ;4
  43. ;             dey       ;2
  44. ;             sty $4016     ;4
  45. ;             ldy #8        ;2
  46. ;       @loop:
  47. ;             lda $4016     ;4
  48. ;             sta $04       ;3         
  49. ;             lsr a     ;2
  50. ;             ora $04       ;3
  51. ;             lsr a     ;2
  52. ;             rol $00,x     ;3
  53. ;             dey       ;2
  54. ;             bne @loop     ;3
  55. ;                       ;  (4+3+2+3+2+3+2+3)*8-1 = 175
  56. ;             rts       ; @read cost: 189 cycles + JSR+RTS
  57. ;
  58. ;    Cost (normally):     2+12+189+2+12+189+3+3+2+2+6*3 = 434 cycles
  59. ;    Cost (if DMA error): 2+12+189+2+12+189+3+3+3+6+13  = 434 cycles
  60. next_PART
  61. .if PART=::CURPART
  62. LINK_FREE_SPACE $1C453, ($1C4AF-$1C453)
  63. LINK_IN_ADDR    $1C453
  64. PUBLIC_LABEL NMI_UpdateInput
  65.     ldx #1
  66.     JSRF   NMI_ReadOneJoypad
  67.     dex
  68.     JSRF   NMI_ReadOneJoypad
  69.     lda $00
  70.     cmp $01
  71.     bne @blank
  72.     tay
  73.     eor $F1 ;Input_CurrentJoyButtonsOrig
  74.     and $00
  75.     sta $F5 ;Input_NewJoyButtonsWork
  76.     sta $F3 ;Input_NewJoyButtonsOrig
  77.     sty $F7 ;Input_CurrentJoyButtonsWork
  78.     sty $F1 ;Input_CurrentJoyButtonsOrig
  79.     rts
  80. @blank: stx $F5
  81.     stx $F3
  82.     nop
  83.     nop
  84.     nop
  85.     php
  86.     plp
  87.     rts
  88. PUBLIC_LABEL NMI_ReadOneJoypad
  89.     ldy #1
  90.     sty $4016
  91.     dey
  92.     sty $4016
  93.     ldy #8
  94. @loop:  lda $4016
  95.     sta $04
  96.     lsr
  97.     ora $04
  98.     lsr
  99.     rol $00,x
  100.     dey
  101.     bne @loop
  102.     rts
  103. .endif
  104.  
  105. next_PART
  106. .if PART=::CURPART
  107. ;    Change _func_1C5EF, which clears memory from 300..3C5,
  108. ;    to a more optimal implementation:
  109. ;           ldy #$C6
  110. ;           lda #0
  111. ;    @loop: dey
  112. ;           sta $0300,y
  113. ;           bne @loop
  114. ;           rts
  115. ;    (Also erases a couple of unused functions)
  116. LINK_FREE_SPACE $1C5EF, ($C615-$C5EF)
  117. LINK_IN_ADDR    $1C5EF
  118. PUBLIC_LABEL ReplaceC5EF
  119.     ldy #$C6
  120.     lda #0
  121. @loop:  dey
  122.     sta $0300,y
  123.     bne @loop
  124.     rts
  125. .endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement