Advertisement
FoxCunning

CheesySong.asm

Apr 7th, 2021
2,209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; -----------------------------------------------------------------------------
  2. ;
  3. ; The available notes are:
  4. ; G3, A4, B4, C4, D4, E4, F4, G4, A5, B5, C5, D5
  5. ;
  6. ; Low byte of note frequencies
  7. *=  $FE7C
  8. .byte $3A, $FB, $C3, $AA, $7B, $52, $3F, $1C
  9. .byte $FD, $E1, $D4, $BD
  10.  
  11. ; High 3 bits of note frequencies plus (fixed) length counter
  12. *=  $FE88
  13. .byte $CA, $C9, $C9, $C9, $C9, $C9, $C9, $C9
  14. .byte $C8, $C8, $C8, $C8
  15.  
  16. ; Cheesy song
  17. ; Uses 4-bit packing, each nibble is the index of the next note to play
  18. ; for each of the two pulse channels
  19. ; The index is 1-based, and 0 means don't play a note
  20. ; Also, this is played backwards: from the last byte to the first
  21. *=  $FE94
  22. .byte $00, $00, $00, $46, $00, $35, $68, $57
  23. .byte $00, $46, $00, $68, $79, $8A, $46, $68
  24. .byte $00, $79, $00, $8B, $46, $57, $68, $46
  25. .byte $00, $13, $00, $57, $46, $57, $68, $46
  26. .byte $00, $13, $00, $35, $24, $35, $46, $57
  27. .byte $00, $00, $00, $58, $00, $00, $00, $58
  28. .byte $00, $46, $00, $68, $79, $8B, $9C, $8B
  29. .byte $00, $00, $00, $8B, $00, $00, $00, $8B
  30. .byte $00, $00, $00, $46, $35, $57, $68, $57
  31. .byte $00, $46, $00, $68, $79, $8A, $79, $68
  32. .byte $00, $46, $00, $57, $68, $79, $8B, $68
  33. .byte $00, $57, $00, $57, $46, $35, $00, $35
  34. .byte $00, $14, $00, $25, $46, $57, $68, $57
  35. .byte $00, $46, $00, $57, $68, $8B, $00, $68
  36. .byte $00, $40, $00, $50, $60, $70, $00, $70
  37. .byte $00, $60, $00, $60, $50, $40, $00, $10
  38.  
  39. ; -----------------------------------------------------------------------------
  40. ;
  41. *=  $FE14
  42. StartMusic:
  43.     lda #$03    ; Enable pulse channels only
  44.     sta ApuStatus_4015
  45.     lda #$01    ; Starting index (0 means end reached)
  46.     sta MusicIndex
  47.     rts
  48.  
  49. ; -----------------------------------------------------------------------------
  50. ;
  51. *=  $FE1E
  52. PlayMusic:
  53.     lda $39     ; This is sometimes set to #$FF to stop the music
  54.     beq _Play
  55.    
  56.     ; Music "paused"
  57.     lda #$7F
  58.     sta MusicCounter
  59.     jmp _Done
  60.    
  61. _Play:
  62.     ldx MusicIndex
  63.     dex
  64.     bne _ReadNext
  65.     ; End reached: loop
  66.     ldx #$80
  67.    
  68. _ReadNext:
  69.     stx MusicIndex
  70.     lda $FE93,X     ; Read one byte of data
  71.    
  72.     pha
  73.     ldy #$00    ; Channel 0
  74.     lsr A       ; Left nibble
  75.     lsr A
  76.     lsr A
  77.     lsr A
  78.     jsr _PlayNote
  79.    
  80.     pla
  81.     ldy #$04    ; Channel 1
  82.     and #$0F    ; Right nibble
  83.    
  84. ; --------sub start--------
  85. _PlayNote:
  86.     beq _NoteEnd
  87.     tax
  88.     lda #$17    ; Fixed duty and volume
  89.     sta Sq0Duty_4000,Y
  90.    
  91.     lda $FE7B,X
  92.     sta Sq0Timer_4002,Y
  93.    
  94.     lda $FE87,X
  95.     sta Sq0Length_4003,Y
  96.    
  97. _NoteEnd:
  98.     lda #$08
  99.     sta MusicCounter
  100.    
  101. _Done:
  102.     rts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement