;------------------------------------------------------------------------------ ; An NES music engine that understands the binary stream outputted from my ; MIDI converter :) ;;;; ; Create an iNES header .ines {"prog": 1, "char": 0, "mapper": 0, "mirror": 0} ;;;; ; Include all the symbols in the nes library .inc ;;;; ; Let's put a data structure to control the sound engine in the zero page .org $0000 .scope sound_engine ; Where we are reading from ROM .space stream_read_ptr_lo 1 .space stream_read_ptr_hi 1 ; Where we are writing in the APU .space stream_write_ptr_lo 1 .space stream_write_ptr_hi 1 .space delta 1 . ;;;; ; Open the prog section bank 0 .segment prog 0 ;;;; ; Setup the interrupt vectors .org $FFFA .dw vblank .dw main .dw irq ;;;; ; Here is our code entry point, which we'll call main. .org $C000 .scope main ; Disable interrupts and decimal flag sei cld ; Wait for 2 vblanks wait_vb1: lda nes.ppu.status bpl wait_vb1 wait_vb2: lda nes.ppu.status bpl wait_vb2 ; Now we want to initialize the hardware to a known state lda #%00 ldx #$00 clear_segments: sta $0, x sta $100, x sta $200, x sta $300, x sta $400, x sta $500, x sta $600, x sta $700, x inx bne clear_segments ; Reset the stack pointer ldx #$FF txs ; Disable all graphics and vblank nmi lda #$00 sta nes.ppu.control sta nes.ppu.mask ; Initialize sound engine structure ; To read from $D000, and to write to $40** lda #>music_buffer sta sound_engine.stream_read_ptr_hi lda #