Advertisement
Guest User

SMB NSF

a guest
Dec 29th, 2011
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. .inesprg 2
  2. .ineschr 0
  3. .inesmir 0
  4. .inesmap 0
  5. .code
  6.  
  7. .bank 0
  8. .org $8000
  9. Reset_Routine:
  10. cld ; clear decimal flag
  11. sei ; disable interrupts
  12. lda #%00000000 ; disable vblank interrupts by clearing
  13. sta $2000 ; the most significant bit of $2000
  14.  
  15. ; *** WAIT 2 VBLANKS ***
  16. WaitV1:
  17. lda $2002 ; give the PPU a little time to initialize
  18. bpl WaitV1 ; by waiting for a vblank
  19. WaitV2:
  20. lda $2002 ; wait for a second vblank to be safe
  21. bpl WaitV2 ; and now the PPU should be initialized
  22.  
  23. ; *** CLEAR SOUND REGISTERS ***
  24. lda #$00 ; clear all the sound registers by setting
  25. ldx #$00 ; everything to 0 in the Clear_Sound loop
  26. Clear_Sound:
  27. sta $4000,x ; store accumulator at $4000 offset by x
  28. inx ; increment x
  29. cpx #$0F ; compare x to $0F
  30. bne Clear_Sound ; branch back to Clear_Sound if x != $0F
  31.  
  32. lda #$10 ; load accumulator with $10
  33. sta $4010 ; store accumulator in $4010
  34. lda #$00 ; load accumulator with 0
  35. sta $4011 ; clear these 3 registers that are
  36. sta $4012 ; associated with the delta modulation
  37. sta $4013 ; channel of the NES
  38.  
  39. ; *** ENABLE SOUND CHANNELS ***
  40. lda #%00001111 ; enable all sound channels except
  41. sta $4015 ; the delta modulation channel
  42.  
  43. ; *** RESET FRAME COUNTER AND CLOCK DIVIDER ***
  44. lda #$C0 ; synchronize the sound playback routine
  45. sta $4017 ; to the internal timing of the NES
  46.  
  47. ; *** SET SONG # & PAL/NTSC SETTING ***
  48. lda #$00 ; replace dashes with song number
  49. ldx #$00 ; replace with $00 for NTSC or $01 for PAL
  50. jsr $BE34 ; replace dashes with init address
  51.  
  52. ; *** ENABLE VBLANK NMI ***
  53. lda #%10000000 ; enable vblank interrupts by setting the
  54. sta $2000 ; most significant bit of $2000
  55.  
  56. loop:
  57. jmp loop
  58.  
  59. NMI_Routine:
  60. lda $2002 ; read $2002 to reset the vblank flag
  61. lda #%00000000 ; clear the first PPU control register
  62. sta $2000 ; writing 0 to it
  63. lda #%10000000 ; reenable vblank interrupts by setting
  64. sta $2000 ; the most significant bit of $2000
  65. jsr $F2D0 ; replace dashes with play address
  66. rti ; return from interrupt routine
  67.  
  68. IRQ_Routine:
  69. rti ; return from interrupt routine
  70.  
  71.  
  72. .bank 1
  73. .org $BDC4 ; replace dashes with load address MINUS $80
  74. .incbin "SMB.nsf" ; include NSF tune
  75.  
  76. .bank 3
  77. .org $FFFA ;ditto
  78. .dw NMI_Routine ; setup the NMI vector at $FFFA
  79. .dw Reset_Routine ; setup the Reset vector at $FFFC
  80. .dw IRQ_Routine ; setup the IRQ vector at $FFFE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement