base:tinymidi
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | base:tinymidi [2015-04-17 04:34] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ===== TinyMidi Source Code: ===== | ||
+ | |||
+ | < | ||
+ | ; | ||
+ | ;TinyMIDI (c) GRG/SHAPE 2007 | ||
+ | ; | ||
+ | ;This program was made for the Sequential (SCI) Interface. | ||
+ | ;It will play the notes you press on your midi keyboard | ||
+ | ;with the sid chip. | ||
+ | |||
+ | _MIDIReset | ||
+ | _MIDI16CountDiv = %00010101 ;1mhz interfaces: 16 divider | ||
+ | _MIDI64CountDIv = %00010110 ;2mhz interfaces: 64 divider | ||
+ | _IRQMIDI16 | ||
+ | _IRQMIDI64 | ||
+ | |||
+ | ;Sequential registers | ||
+ | MIDI_ControlReg = $de00 | ||
+ | MIDI_StatusReg | ||
+ | MIDI_Tx | ||
+ | MIDI_Rx | ||
+ | |||
+ | ;Adjust hardrestart to 2 for Attack Values 1-F. | ||
+ | HARDRESTART = 1 ;1 or 2 | ||
+ | |||
+ | buffnotes = $2000 ;All MIDI notes are buffered here | ||
+ | |||
+ | * = $0801 | ||
+ | .byte $0b, | ||
+ | .byte $9e | ||
+ | .text " | ||
+ | .byte 0,0,0 | ||
+ | |||
+ | lda #< | ||
+ | ldy #> | ||
+ | jsr $ab1e | ||
+ | sei | ||
+ | lda #$35 | ||
+ | sta $01 | ||
+ | lda #$03 | ||
+ | sta MIDI_ControlReg | ||
+ | lda #$95 | ||
+ | sta MIDI_ControlReg | ||
+ | jsr init_soundplayer | ||
+ | lda #<hwirq | ||
+ | sta $0314 | ||
+ | lda #>hwirq | ||
+ | sta $0315 | ||
+ | lda #<irq | ||
+ | sta $fffe | ||
+ | lda #>irq | ||
+ | sta $ffff | ||
+ | lda #<nmi | ||
+ | sta $fffa | ||
+ | sta $0318 | ||
+ | lda #>nmi | ||
+ | sta $fffb | ||
+ | sta $0319 | ||
+ | lda #$01 ;Irq on | ||
+ | sta $d01a | ||
+ | lda #$fb | ||
+ | sta $d012 | ||
+ | lda $d011 | ||
+ | and #$7f | ||
+ | sta $d011 | ||
+ | lda #$7f | ||
+ | sta $dc0d | ||
+ | bit $dc0d | ||
+ | cli | ||
+ | keyloop inc $01 ;36 | ||
+ | jsr $ffe4 | ||
+ | dec $01 ;35 | ||
+ | cmp #0 | ||
+ | beq keyloop | ||
+ | jmp keyloop | ||
+ | | ||
+ | midinote .byte 0 ;0-127 | ||
+ | ncount .byte 0 ;max 127 (max keys on keyboard) | ||
+ | countby .byte 0 ;count bytes in buffer (0-255) | ||
+ | mibcount .byte 0 ;Midi byte count (0-255) | ||
+ | |||
+ | ; | ||
+ | *= (*+$ff)& | ||
+ | ; | ||
+ | ;MIDI IRQ: | ||
+ | i80_noteoff1 sta midinote | ||
+ | lda #< | ||
+ | jmp setexirq | ||
+ | i80_noteoff2 ldx mibcount | ||
+ | lda midinote | ||
+ | ora #$80 | ||
+ | sta buffnotes,x | ||
+ | inc mibcount | ||
+ | inc ncount | ||
+ | lda #< | ||
+ | jmp setexirq | ||
+ | |||
+ | i90_noteon1 sta midinote | ||
+ | lda #< | ||
+ | jmp setexirq | ||
+ | i90_noteon2 beq i90_noteoff | ||
+ | lda #0 | ||
+ | .byte $2c | ||
+ | i90_noteoff lda #$80 | ||
+ | ldx mibcount | ||
+ | ora midinote | ||
+ | sta buffnotes,x | ||
+ | inc mibcount | ||
+ | inc ncount | ||
+ | lda #< | ||
+ | jmp setexirq | ||
+ | |||
+ | ;-------- Unused routines here | ||
+ | iC0_programchange1 | ||
+ | iA0_aftertouch1 | ||
+ | iD0_channelpress1 | ||
+ | iB0_cwheel1 | ||
+ | iE0_cwheel1 | ||
+ | lda #<exirq | ||
+ | jmp setexirq | ||
+ | | ||
+ | ;------- STATUS fetch | ||
+ | |||
+ | get_statb and #$f0 ;Allow all Midi channels | ||
+ | cmp #$e0 | ||
+ | beq stpwheel | ||
+ | cmp #$b0 | ||
+ | beq stcwheel | ||
+ | cmp #$90 | ||
+ | beq stnoteon | ||
+ | cmp #$80 | ||
+ | beq stnoteoff | ||
+ | cmp #$d0 | ||
+ | beq stchpress | ||
+ | cmp #$a0 | ||
+ | beq statouch | ||
+ | cmp #$c0 | ||
+ | beq stprchange | ||
+ | lda #<exirq | ||
+ | .byte $2c | ||
+ | stprchange lda #< | ||
+ | .byte $2c | ||
+ | statouch lda #< | ||
+ | .byte $2c | ||
+ | stchpress lda #< | ||
+ | .byte $2c | ||
+ | stnoteoff lda #< | ||
+ | .byte $2c | ||
+ | stnoteon lda #< | ||
+ | .byte $2c | ||
+ | stcwheel lda #< | ||
+ | .byte $2c | ||
+ | stpwheel lda #< | ||
+ | setexirq sta mjump+1 | ||
+ | exirq lda #0 | ||
+ | sta $d020 | ||
+ | pla | ||
+ | tay | ||
+ | pla | ||
+ | tax | ||
+ | pla | ||
+ | rti | ||
+ | |||
+ | irmid pha | ||
+ | txa | ||
+ | pha | ||
+ | tya | ||
+ | pha | ||
+ | hwirmid dec $d020 | ||
+ | lda MIDI_StatusReg | ||
+ | bpl exirq ;0-7f | ||
+ | ;bit parity | ||
+ | ;beq parok | ||
+ | ;jmp error | ||
+ | parok and #%00000001 | ||
+ | beq error | ||
+ | setMidi_Rx lda MIDI_Rx | ||
+ | bmi get_statb | ||
+ | mjump jmp exirq | ||
+ | error inc $d021 ;endless error | ||
+ | jmp error | ||
+ | |||
+ | parity .byte %01110000 ;parity error, | ||
+ | |||
+ | irq bit $d019 ; | ||
+ | bpl irmid ; | ||
+ | pha | ||
+ | txa | ||
+ | pha | ||
+ | tya | ||
+ | pha | ||
+ | jmp d019clear | ||
+ | hwirq bit $d019 ; | ||
+ | bpl hwirmid ; | ||
+ | d019clear lda #1 | ||
+ | sta $d019 | ||
+ | cli ; | ||
+ | lda #5 | ||
+ | sta $d020 | ||
+ | jsr sound_init | ||
+ | jsr sound_play | ||
+ | lda #0 | ||
+ | sta $d020 | ||
+ | lda $01 | ||
+ | pha | ||
+ | lda #$37 | ||
+ | sta $01 | ||
+ | jsr $ea87 ;C64 Keyboard scan | ||
+ | lda $dc0d | ||
+ | pla | ||
+ | sta $01 | ||
+ | pla | ||
+ | tay | ||
+ | pla | ||
+ | tax | ||
+ | pla | ||
+ | nmi rti | ||
+ | |||
+ | ; | ||
+ | |||
+ | sound_init sei | ||
+ | ; | ||
+ | ;if this routine is slow you will loose midi data | ||
+ | sinit lda ncount ; | ||
+ | beq nonote | ||
+ | ldy countby | ||
+ | lda buffnotes,y | ||
+ | bmi noteoff1 | ||
+ | keyset jsr set_concate | ||
+ | inc countby | ||
+ | dec ncount | ||
+ | jmp sinit | ||
+ | noteoff1 and #$7f | ||
+ | keyclear jsr clear_concate | ||
+ | inc countby | ||
+ | dec ncount | ||
+ | jmp sinit | ||
+ | nonote cli ; | ||
+ | rts | ||
+ | |||
+ | |||
+ | set_concate ldx chan ; | ||
+ | sta note,x | ||
+ | lda # | ||
+ | sta hreset,x | ||
+ | inx | ||
+ | cpx #3 | ||
+ | bne rer | ||
+ | ldx #0 | ||
+ | rer stx chan | ||
+ | rts | ||
+ | |||
+ | clear_concate sta tempnot2+1 | ||
+ | ldx #2 | ||
+ | tempnot2 lda #0 | ||
+ | cmp note,x | ||
+ | bne found2 | ||
+ | lda #$fe | ||
+ | sta gate, | ||
+ | sta hreset,x | ||
+ | found2 dex | ||
+ | bpl tempnot2 | ||
+ | rts | ||
+ | |||
+ | ;--------- Reset buffer counters and sid chip | ||
+ | |||
+ | init_soundplayer | ||
+ | lda #0 | ||
+ | sta ncount | ||
+ | sta countby | ||
+ | sta mibcount | ||
+ | ldx #$17 | ||
+ | ressid sta $d400,x | ||
+ | dex | ||
+ | bpl ressid | ||
+ | rts | ||
+ | |||
+ | ;---------- 3 voice music player | ||
+ | ;TinySDI Player (c) GRG/SHAPE 2007 | ||
+ | |||
+ | sound_play ldx #2 | ||
+ | mloop stx savx+1 | ||
+ | ldy sidvoice,x | ||
+ | lda hreset,x | ||
+ | bmi next_sid ; | ||
+ | pha | ||
+ | cmp # | ||
+ | bne nn | ||
+ | lda #1 | ||
+ | sta $d406, | ||
+ | lda #$0f | ||
+ | sta $d405,y | ||
+ | lda #$fe | ||
+ | sta gate, | ||
+ | nn dec hreset,x | ||
+ | pla | ||
+ | bne next_sid | ||
+ | lda #$ff | ||
+ | sta gate,x | ||
+ | sta hreset,x | ||
+ | lda note,x | ||
+ | sta note2,x | ||
+ | lda #$01 | ||
+ | sta $d405, | ||
+ | lda #$da | ||
+ | sta $d406, | ||
+ | next_sid lda note2,x | ||
+ | tax | ||
+ | lda freqlo,x | ||
+ | sta $d400,y | ||
+ | lda freqhi,x | ||
+ | sta $d401,y | ||
+ | ldx savx+1 | ||
+ | lda #$21 | ||
+ | and gate,x | ||
+ | sta $d404,y | ||
+ | savx ldx #0 | ||
+ | dex | ||
+ | bpl mloop | ||
+ | lda #$0f | ||
+ | sta $d418 | ||
+ | rts | ||
+ | |||
+ | chan .byte 0 | ||
+ | note .byte 0,0,0 | ||
+ | note2 .byte 0,0,0 | ||
+ | hreset | ||
+ | gate .byte $fe,$fe,$fe | ||
+ | sidvoice .byte 0,7,14 | ||
+ | |||
+ | ;PAL tuned frequence table: | ||
+ | freqlo | ||
+ | .byte $8a, | ||
+ | .byte $2d, | ||
+ | .byte $14, | ||
+ | .byte $5a, | ||
+ | .byte $27, | ||
+ | .byte $b4, | ||
+ | .byte $4e, | ||
+ | .byte $67, | ||
+ | .byte $9c, | ||
+ | .byte $ce, | ||
+ | .byte $39, | ||
+ | .byte $9c, | ||
+ | .byte $72, | ||
+ | .byte $39, | ||
+ | .byte $e3, | ||
+ | freqhi | ||
+ | .byte $01, | ||
+ | .byte $02, | ||
+ | .byte $03, | ||
+ | .byte $04, | ||
+ | .byte $06, | ||
+ | .byte $08, | ||
+ | .byte $0c, | ||
+ | .byte $11, | ||
+ | .byte $18, | ||
+ | .byte $22, | ||
+ | .byte $31, | ||
+ | .byte $45, | ||
+ | .byte $62, | ||
+ | .byte $8b, | ||
+ | .byte $c4, | ||
+ | |||
+ | message .byte $93,$05 | ||
+ | .text " | ||
+ | .byte 0 | ||
+ | </ |
base/tinymidi.txt · Last modified: 2015-04-17 04:34 by 127.0.0.1