Advertisement
Bisqwit

cv2ins_sample_before

Aug 20th, 2022
829
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.83 KB | None | 0 0
  1. function DeletePlayer2Input()
  2. {
  3.   global $linker,$space;
  4.   // Frees RAM addresses F4,F6 (new buttons player2),
  5.   //                     F2,F8 (current buttons player2)
  6.   /* Change NMI_UpdateInput (C453-C4AE, 92 bytes) to to:
  7.    *          ldx #1                    ;2
  8.    *          jsr @read                 ;12+189
  9.    *          dex                   ;2
  10.    *          jsr @read                 ;12+189
  11.    *          lda $00                   ;3
  12.    *          cmp $01                   ;3
  13.    *          bne @blank (+14)              ;2
  14.    *          tay                   ;2
  15.    *          eor $F1 (Input_CurrentJoyButtonsOrig) ;3
  16.    *          and $00                   ;3
  17.    *          sta $F5 (Input_NewJoyButtonsWork)     ;3
  18.    *          sta $F3 (Input_NewJoyButtonsOrig)     ;3
  19.    *          sty $F7 (Input_CurrentJoyButtonsWork) ;3
  20.    *          sty $F1 (Input_CurrentJoyButtonsOrig) ;3
  21.    *          rts
  22.    *    @blank:
  23.    *          stx $F5                   ;3
  24.    *          stx $F3                   ;3
  25.    *          nop;nop;nop;php;plp                       ;13
  26.    *          rts
  27.    *    @read:
  28.    *          ldy #1        ;2
  29.    *          sty $4016     ;4
  30.    *          dey       ;2
  31.    *          sty $4016     ;4
  32.    *          ldy #8        ;2
  33.    *    @loop:
  34.    *          lda $4016     ;4
  35.    *          sta $04       ;3         
  36.    *          lsr a     ;2
  37.    *          ora $04       ;3
  38.    *          lsr a     ;2
  39.    *          rol $00,x     ;3
  40.    *          dey       ;2
  41.    *          bne @loop     ;3
  42.    *                    ;  (4+3+2+3+2+3+2+3)*8-1 = 175
  43.    *          rts       ; @read cost: 189 cycles + JSR+RTS
  44.    *
  45.    * Cost (normally):     2+12+189+2+12+189+3+3+2+2+6*3 = 434 cycles
  46.    * Cost (if DMA error): 2+12+189+2+12+189+3+3+3+6+13  = 434 cycles
  47.    */
  48.   $location = 0x1C453;
  49.   $space[$location] = 0x1C4AF - 0x1C453;
  50.   $b = new Blob("NMI_UpdateInput",
  51.              "\xA2\x01");
  52.   $b->AppendCallPointerTo("NMI_ReadOneJoypad");
  53.   $b->AppendRawData(
  54.              "\xCA");
  55.   $b->AppendCallPointerTo("NMI_ReadOneJoypad");
  56.   $b->AppendRawData(
  57.              "\xA5\x00\xC5\x01\xD0\x0E".
  58.              "\xA8\x45\xF1\x25\x00\x85\xF5\x85\xF3\x84\xF7\x84\xF1\x60".
  59.              "\x86\xF5\x86\xF3\xEA\xEA\xEA\x08\x28\x60");
  60.   $b->AddPublicHere("NMI_ReadOneJoypad");
  61.   $b->AppendRawData(
  62.              "\xA0\x01\x8C\x16\x40\x88\x8C\x16\x40".
  63.              "\xA0\x08".
  64.              "\xAD\x16\x40\x85\x04\x4A\x05\x04\x4A\x36\x00".
  65.              "\x88\xD0\xF2".
  66.              "\x60");
  67.   $linker->AddBlobTakeSpace($space, $b, $location);
  68.  
  69.   /* Change _func_1C5EF, which clears memory from 300..3C5,
  70.    * to a more optimal implementation:
  71.    *        ldy #$C6
  72.    *        lda #0
  73.    * @loop: dey
  74.    *        sta $0300,y
  75.    *        bne @loop
  76.    *        rts
  77.    * (Also erases a couple of unused functions)
  78.    */
  79.   $location = 0x1C5EF;
  80.   $space[$location] = 0xC615-0xC5EF;
  81.   $b = new Blob("ReplaceC5EF",
  82.       "\xA0\xC6\xA9\x00".
  83.       "\x88\x99\x00\x03".
  84.       "\xD0\xFA\x60");
  85.   $linker->AddBlobTakeSpace($space, $b, $location);
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement