Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; -----------------------------------------------------------------------------
- ;
- ; The available notes are:
- ; G3, A4, B4, C4, D4, E4, F4, G4, A5, B5, C5, D5
- ;
- ; Low byte of note frequencies
- *= $FE7C
- .byte $3A, $FB, $C3, $AA, $7B, $52, $3F, $1C
- .byte $FD, $E1, $D4, $BD
- ; High 3 bits of note frequencies plus (fixed) length counter
- *= $FE88
- .byte $CA, $C9, $C9, $C9, $C9, $C9, $C9, $C9
- .byte $C8, $C8, $C8, $C8
- ; Cheesy song
- ; Uses 4-bit packing, each nibble is the index of the next note to play
- ; for each of the two pulse channels
- ; The index is 1-based, and 0 means don't play a note
- ; Also, this is played backwards: from the last byte to the first
- *= $FE94
- .byte $00, $00, $00, $46, $00, $35, $68, $57
- .byte $00, $46, $00, $68, $79, $8A, $46, $68
- .byte $00, $79, $00, $8B, $46, $57, $68, $46
- .byte $00, $13, $00, $57, $46, $57, $68, $46
- .byte $00, $13, $00, $35, $24, $35, $46, $57
- .byte $00, $00, $00, $58, $00, $00, $00, $58
- .byte $00, $46, $00, $68, $79, $8B, $9C, $8B
- .byte $00, $00, $00, $8B, $00, $00, $00, $8B
- .byte $00, $00, $00, $46, $35, $57, $68, $57
- .byte $00, $46, $00, $68, $79, $8A, $79, $68
- .byte $00, $46, $00, $57, $68, $79, $8B, $68
- .byte $00, $57, $00, $57, $46, $35, $00, $35
- .byte $00, $14, $00, $25, $46, $57, $68, $57
- .byte $00, $46, $00, $57, $68, $8B, $00, $68
- .byte $00, $40, $00, $50, $60, $70, $00, $70
- .byte $00, $60, $00, $60, $50, $40, $00, $10
- ; -----------------------------------------------------------------------------
- ;
- *= $FE14
- StartMusic:
- lda #$03 ; Enable pulse channels only
- sta ApuStatus_4015
- lda #$01 ; Starting index (0 means end reached)
- sta MusicIndex
- rts
- ; -----------------------------------------------------------------------------
- ;
- *= $FE1E
- PlayMusic:
- lda $39 ; This is sometimes set to #$FF to stop the music
- beq _Play
- ; Music "paused"
- lda #$7F
- sta MusicCounter
- jmp _Done
- _Play:
- ldx MusicIndex
- dex
- bne _ReadNext
- ; End reached: loop
- ldx #$80
- _ReadNext:
- stx MusicIndex
- lda $FE93,X ; Read one byte of data
- pha
- ldy #$00 ; Channel 0
- lsr A ; Left nibble
- lsr A
- lsr A
- lsr A
- jsr _PlayNote
- pla
- ldy #$04 ; Channel 1
- and #$0F ; Right nibble
- ; --------sub start--------
- _PlayNote:
- beq _NoteEnd
- tax
- lda #$17 ; Fixed duty and volume
- sta Sq0Duty_4000,Y
- lda $FE7B,X
- sta Sq0Timer_4002,Y
- lda $FE87,X
- sta Sq0Length_4003,Y
- _NoteEnd:
- lda #$08
- sta MusicCounter
- _Done:
- rts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement