;----------------------------------------------------------- ; MIDI-Theremin ver.1 October 2002 ;----------------------------------------------------------- ;##### Port Defines ##### smr .equ h'0fffb0 brr .equ h'0fffb1 scr .equ h'0fffb2 tdr .equ h'0fffb3 ssr .equ h'0fffb4 rdr .equ h'0fffb5 p5ddr .equ h'0fffc8 p5dr .equ h'0fffca p6ddr .equ h'0fffc9 p6dr .equ h'0fffcb paddr .equ h'0fffd1 pbddr .equ h'0fffd4 iprb .equ h'0ffff8 tstr .equ h'0fff60 tsnc .equ h'0fff61 tmdr .equ h'0fff62 tfcr .equ h'0fff63 toer .equ h'0fff90 tocr .equ h'0fff91 tcr0 .equ h'0fff64 tior0 .equ h'0fff65 tier0 .equ h'0fff66 tsr0 .equ h'0fff67 tcnt0 .equ h'0fff68 gra0 .equ h'0fff6a tcr1 .equ h'0fff6e tior1 .equ h'0fff6f tier1 .equ h'0fff70 tsr1 .equ h'0fff71 tcnt1 .equ h'0fff72 gra1 .equ h'0fff74 tcr2 .equ h'0fff78 tior2 .equ h'0fff79 tier2 .equ h'0fff7a tsr2 .equ h'0fff7b tcnt2 .equ h'0fff7c gra2 .equ h'0fff7e tcr3 .equ h'0fff82 tior3 .equ h'0fff83 tier3 .equ h'0fff84 tsr3 .equ h'0fff85 tcnt3 .equ h'0fff86 gra3 .equ h'0fff88 tcr4 .equ h'0fff92 tior4 .equ h'0fff93 tier4 .equ h'0fff94 tsr4 .equ h'0fff95 tcnt4 .equ h'0fff96 gra4 .equ h'0fff98 ;##### Vector Defines ##### .section vector,data,locate=h'000000 .data.l start .org h'000060 .data.l int_timer0 ;##### Work RAM Data Defines ##### .section ram,data,locate=h'0fef10 tx_top .res.w 1 tx_end .res.w 1 timer0 .res.w 1 timer1 .res.w 1 timer2 .res.w 1 timer3 .res.w 1 timer4 .res.b 1 timer5 .res.b 1 flag .res.b 1 count .res.b 1 .org h'0ff400 tx_fifo .res.b 1024 ;***** Reset --> Initialize --> Main Loop ***** .section program,code,locate=h'001000 start: mov.l #h'0fff0f,er7 ; stack pointer set mov.l #h'0fef10,er2 mov.w #h'0fe0,r1 mov.b #0,r0l _ram_clear: mov.b r0l,@er2 inc.l #1,er2 dec.w #1,r1 bne _ram_clear jsr @sci0_init ; SCI initialize mov.b #b'00100011,r0l mov.b r0l,@tcr0 ; Timer0 init : 2MHz clock bclr #0,@tsr0 ; Clear IMFA bset #0,@tier0 ; timer INT set mov.w #2000,r0 ; 1msec INT mov.w r0,@gra0 mov.b #0,r0l mov.b r0l,@paddr mov.b r0l,@pbddr mov.b #b'00110100,r0l mov.b r0l,@tcr1 ; Timer1 init : TCLKA count mov.b #b'00110101,r0l mov.b r0l,@tcr2 ; Timer2 init : TCLKB count mov.b #b'00110110,r0l mov.b r0l,@tcr3 ; Timer3 init : TCLKC count mov.b #b'00110111,r0l mov.b r0l,@tcr4 ; Timer4 init : TCLKD count mov.b #b'00000100,r0l mov.b r0l,@tior1 mov.b r0l,@tior2 mov.b r0l,@tior3 mov.b r0l,@tior4 mov.b #b'11111111,r0l mov.b r0l,@p5ddr ; set : Port[5] all output mov.b r0l,@p6ddr ; set : Port[6] all output mov.b #b'00000000,r0l mov.b r0l,@p5dr mov.b r0l,@p6dr jsr @wait_500msec mov.b #b'00011111,r0l mov.b r0l,@tstr ; all timers start ! mov.b #b'00100000,r0l ; tx start ! mov.b r0l,@scr andc.b #b'01111111,ccr ; interrupt enable main_loop: jsr @timer_check jsr @tx_midi_check jmp @main_loop ;***** SCI init / MIDI Transmit Routines ***** sci0_init: mov.b #b'00000000,r0l mov.b r0l,@scr mov.b #b'00000000,r0l mov.b r0l,@smr mov.b #15,r0l mov.b r0l,@brr mov.w #500,r0 _sci0_wait: dec.w #1,r0 bne _sci0_wait mov.b @ssr,r0l ; (dummy read) mov.b #0,r0l mov.b r0l,@ssr mov.b #b'00001000,r0l mov.b r0l,@iprb ; SCI0-int priority UP ! rts tx_midi_check: mov.w @tx_top,r1 mov.w @tx_end,r6 cmp.w r1,r6 bne _tx_exist rts _tx_exist: btst #7,@ssr ; test TRDE bne _tx_seq rts _tx_seq: mov.w #0,e6 mov.b @(tx_fifo,er6),r0l mov.b r0l,@tdr bclr #7,@ssr ; Transmit ! inc.w #1,r6 bclr #2,r6h mov.w r6,@tx_end rts tx_fifo_set: mov.w @tx_top,r6 mov.w #0,e6 mov.b r0h,@(tx_fifo,er6) ; transmit data = [r0h] inc.w #1,r6 bclr #2,r6h mov.w r6,@tx_top rts ;***** Timer / Counter Routines ***** wait_500msec: mov.l #500,er1 _wait_1: jsr @wait_1msec sub.l #1,er1 bne _wait_1 rts wait_1msec: mov.l #2048,er2 _wait_2: sub.l #1,er2 bne _wait_2 rts int_timer0: push.w r0 mov.b #1,r0l mov.b r0l,@flag btst #0,@tsr0 bclr #0,@tsr0 ; Clear IMFA pop.w r0 rte timer_check: mov.b @flag,r0l cmp.b #0,r0l bne _timer_event rts _timer_event: mov.b #0,r0l mov.b r0l,@flag mov.b @timer4,r0l inc.b r0l mov.b r0l,@timer4 cmp.b #100,r0l beq t100msec rts t100msec: mov.b #0,r0l mov.b r0l,@timer4 jsr @count_check mov.b @timer5,r0l inc.b r0l mov.b r0l,@timer5 cmp.b #10,r0l beq t1000msec rts t1000msec: mov.b #0,r0l mov.b r0l,@timer5 mov.b @count,r0h inc.b r0h mov.b r0h,@count and.b #00000001,r0h shll.b r0h shll.b r0h mov.b r0h,@p6dr rts ;***** Counter Check Routines ***** count_check: bset #1,@p5dr ; caprure to GRA, clear bclr #1,@p5dr mov.w @gra1,r2 ; TCNT1 -> R2 mov.w @gra2,r3 ; TCNT2 -> R3 mov.w @gra3,r4 ; TCNT3 -> R4 mov.w @gra4,r5 ; TCNT4 -> R5 shlr.b r2l shlr.b r3l shlr.b r4l shlr.b r5l mov.b #h'e0,r0h jsr @tx_fifo_set mov.b r2l,r0h jsr @tx_fifo_set mov.b r2h,r0h jsr @tx_fifo_set mov.b #h'e1,r0h jsr @tx_fifo_set mov.b r3l,r0h jsr @tx_fifo_set mov.b r3h,r0h jsr @tx_fifo_set mov.b #h'e2,r0h jsr @tx_fifo_set mov.b r4l,r0h jsr @tx_fifo_set mov.b r4h,r0h jsr @tx_fifo_set mov.b #h'e3,r0h jsr @tx_fifo_set mov.b r5l,r0h jsr @tx_fifo_set mov.b r5h,r0h jsr @tx_fifo_set rts .end