Last active
March 20, 2021 20:28
-
-
Save babasbot/e004adebf302ba3fa135f1fbebbb369e to your computer and use it in GitHub Desktop.
NES APU demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.include "constants.inc" | |
.include "header.inc" | |
.segment "CODE" | |
.proc irq_handler | |
RTI | |
.endproc | |
.proc nmi_handler | |
RTI | |
.endproc | |
.import reset_handler | |
.export main | |
.proc main | |
; enables square-1 channel | |
LDA #%00000001 | |
STA APUFLAGS | |
; sets duty cycle to 50% and max volume | |
LDA #%10111111 | |
STA SQ1_ENV | |
; plays a C# note | |
LDA #$C9 | |
STA SQ1_LO | |
LDA #$00 | |
STA SQ1_HI | |
forever: | |
JMP forever | |
.endproc | |
.segment "VECTORS" | |
.addr nmi_handler, reset_handler, irq_handler | |
.segment "CHARS" | |
.res 8192 | |
.segment "STARTUP" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.include "constants.inc" | |
.include "header.inc" | |
.segment "CODE" | |
.proc irq_handler | |
RTI | |
.endproc | |
.proc nmi_handler | |
RTI | |
.endproc | |
.import reset_handler | |
.export main | |
.proc main | |
; enables the square 1, square 2 and triangle channels | |
LDA #%00000111 | |
STA APUFLAGS | |
; sets the square channel 1 duty cycle to 50% and max volume | |
LDA #%10111111 | |
STA SQ1_ENV | |
; plays a C# note on the square channel | |
LDA #$C9 | |
STA SQ1_LO | |
LDA #$00 | |
STA SQ1_HI | |
; sets the square channel 2 duty cycle to 50% and max volume | |
LDA #%10111111 | |
STA SQ2_ENV | |
; plays an E note on the square channel 2 | |
LDA #$A9 | |
STA SQ2_LO | |
LDA #$00 | |
STA SQ2_HI | |
; disable triangle channel internal controllers and turns | |
; on the channel | |
LDA #%10000001 | |
STA TRI_CTRL | |
; plays a G# note on the triangle channel | |
LDA #$42 | |
STA TRI_LO | |
LDA #$00 | |
STA TRI_HIGH | |
forever: | |
JMP forever | |
.endproc | |
.segment "VECTORS" | |
.addr nmi_handler, reset_handler, irq_handler | |
.segment "CHARS" | |
.res 8192 | |
.segment "STARTUP" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.include "constants.inc" | |
.include "header.inc" | |
.segment "CODE" | |
.proc irq_handler | |
RTI | |
.endproc | |
.proc nmi_handler | |
RTI | |
.endproc | |
.import reset_handler | |
.export main | |
.proc main | |
; enables square-2 channel | |
LDA #%00000010 | |
STA APUFLAGS | |
; sets duty cycle to 50% and max volume | |
LDA #%10111111 | |
STA SQ2_ENV | |
; plays an E note | |
LDA #$A9 | |
STA SQ2_LO | |
LDA #$00 | |
STA SQ2_HI | |
forever: | |
JMP forever | |
.endproc | |
.segment "VECTORS" | |
.addr nmi_handler, reset_handler, irq_handler | |
.segment "CHARS" | |
.res 8192 | |
.segment "STARTUP" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.include "constants.inc" | |
.include "header.inc" | |
.segment "CODE" | |
.proc irq_handler | |
RTI | |
.endproc | |
.proc nmi_handler | |
RTI | |
.endproc | |
.import reset_handler | |
.export main | |
.proc main | |
; enables the triangle channel | |
LDA #%00000100 | |
STA APUFLAGS | |
; disable triangle channel internal controllers and turn | |
; on the channel | |
LDA #%10000001 | |
STA TRI_CTRL | |
; plays a G# note | |
LDA #$42 | |
STA TRI_LO | |
LDA #$00 | |
STA TRI_HIGH | |
forever: | |
JMP forever | |
.endproc | |
.segment "VECTORS" | |
.addr nmi_handler, reset_handler, irq_handler | |
.segment "CHARS" | |
.res 8192 | |
.segment "STARTUP" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment