FC/nes music sample program Happy Birthday Song

Source: Internet
Author: User
; Start address: $ bff0
; End address: $ FFFF
; File length: $4010


Counter = $00
Music_offset1 = $01
Music_offset2 = $02

. Org $ bff0
. DB "Nes", $ 1A, $01, $01, $00, $00
. Dw $00, $00, $00, $00
. Start $ c000
. Org $ c000
Reset:
SEI; Disable interruption
ClD
Ldx # $ ff; initialize the top pointer of the stack to $ FF
TXS

Bytes
STX counter
STX music_offset1
STX music_offset2

_ VB1:
LDA $2002
BPL _ VB1
_ VB2:
LDA $2002
BPL _ VB2

LDA #$00
Sta $2001


LDA # $ 0f; sound switching: 0000 1111, square wave #1 #2, triangle wave, noise
Sta $4015

LDA # $ 8f
Sta $4000; Apu square wave #1 control port

LDA #$00
Sta $4001; Apu square wave #1 control port

LDA # $80; Enable NMI interruption
Sta $2000

Main:
JMP main


NMI:
INC counter; increase in counters
Ldx music_offset1
LDA music1, X; obtain the Sound Length
CMP counter; Determine whether to play the video
Beq next2; playback
CMP # $ FF
Beq next1; Whether to end
JMP over; exit
Next1:
Ldx # $00; back to start
STX music_offset1
JMP over
Next2:
LDA #$00
Sta counter
LDA music_offset2
Tay
LDA music2, Y; eight low wavelength bits
CMP # $ ff; is it over?
Beq next3
Sta $4002

Iny
LDA music2, Y; high wavelength + sound length counter
CMP # $ ff; is it over?
Beq next3
Sta $4003

Iny; next note
Sty music_offset2
Bytes
STX music_offset1
JMP over
Next3:
Ldy # $00; back to start
Sty music_offset2
Over:
RRTI

Music1:
; Audio length 8*4 + 1 = 33
. DB $10, $10, $20, $20, $20, $20, $20, $10
. DB $10, $20, $20, $20, $20, $20, $20, $10
. DB $10, $20, $20, $20, $20, $20, $20, $20
. DB $20, $10, $10, $20, $20, $20, $20, $20
. DB $20, $ FF
Music2:
; Two groups, $ FF is the end of 8*8 + 2 = 66
. DB $ 1C, $09, $ 1C, $09, $ FD, $08, $ 1C, $09
. DB $ D4, $08, $ E1, $08, $00, $00, $ 1C, $09
. DB $ 1C, $ D9, $ FD, $08, $ 1C, $09, $ BD, $08
. DB $ D4, $08, $ D4, $08, $00, $00, $ 1C, $09
. DB $ 1C, $09, $ 8D, $08, $ A8, $08, $ D4, $08
. DB $ E1, $08, $ FD, $08, $ FD, $08, $ FD, $08
. DB $00, $00, $ 9f, $08, $ 9f, $08, $ A8, $08
. DB $ D4, $08, $ BD, $08, $ D4, $08, $ D4, $ D4
. DB $08, $00, $ ff, $ FF

IRQ:
RRTI


. Org $ fffa
. Dw NMI, reset, IRQ

Girl don't cry (QQ: 191035066) @ 2012-08-13 16:45:32 @ http://www.cnblogs.com/nbsofer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.