;----------------------------------------------------------- ; ; MiniBioMuse-II (1) : July 1999 ; ;----------------------------------------------------------- ;##### 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 pbddr .equ h'0fffd4 pbdr .equ h'0fffd6 addrah .equ h'0fffe0 addrbh .equ h'0fffe2 adcsr .equ h'0fffe8 adcr .equ h'0fffe9 iprb .equ h'0ffff8 ;##### Vector Defines ##### .section vector,data,locate=h'000000 .data.l start ;##### Work RAM Data Defines ##### .section ram,data,locate=h'0fef10 timer1 .res.w 1 tx_top .res.w 1 tx_end .res.w 1 ad_0 .res.w 1 ad_1 .res.w 1 counter .res.b 1 led .res.b 1 ad_no_0 .res.b 1 ad_no_1 .res.b 1 ad_sel .res.b 1 .org h'0ff400 tx_fifo .res.b 1024 ;***** Reset --> Initialize --> Main Loop ***** .section program,code,locate=h'000100 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'00000000,r0l mov.b r0l,@adcsr ; A/D setting bclr.b #7,@adcr ; TRGE = 0 mov.b #b'11111111,r0l mov.b r0l,@pbddr ; set : Port[B] all output jsr @wait_500msec mov.w #0,r0 mov.b r0l,@ad_sel mov.w r0,@ad_0 mov.w r0,@ad_1 mov.b r0l,@ad_no_0 mov.b #100,r0l mov.b r0l,@ad_no_1 mov.b #b'00100000,r0l mov.b r0l,@adcsr ; A/D(0) start ! mov.b #b'01110000,r0l ; tx/rx start ! mov.b r0l,@scr loop: jsr @ad_check jsr @timer_check jsr @tx_midi_check jmp @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 timer_check: mov.w @timer1,r1 inc.w #1,r1 mov.w r1,@timer1 beq _timer_1 rts _timer_1: mov.b @counter,r0l inc.b r0l mov.b r0l,@counter mov.b @led,r0l bnot #7,r0l mov.b r0l,@led mov.b r0l,@pbdr ; write to Port[B] rts ;***** A/D Check Routine ***** ad_check: btst.b #7,@adcsr ; A/D conv end ? bne _ad_go rts _ad_go: mov.b @ad_sel,r0l cmp.b #0,r0l bne _ad_1_calc _ad_0_calc: mov.b #1,r0l mov.b r0l,@ad_sel bclr.b #7,@adcsr ; ADF clear mov.b @addrah,r3l mov.b #b'00100001,r0l mov.b r0l,@adcsr ; A/D(1) start ! jsr @ad_add_0 rts _ad_1_calc: mov.b #0,r0l mov.b r0l,@ad_sel bclr.b #7,@adcsr ; ADF clear mov.b @addrbh,r3l mov.b #b'00100000,r0l mov.b r0l,@adcsr ; A/D(0) start ! jsr @ad_add_1 rts ad_cut: btst.b #7,r3l beq _cut_low bclr.b #7,r3l rts _cut_low: mov.b #0,r3l rts ad_add_0: mov.b #5,r0l ; ##### add.b r0l,r3l jsr @ad_cut mov.w @ad_0,r2 mov.b #0,r3h add.w r3,r2 mov.w r2,@ad_0 mov.b @ad_no_0,r0l inc.b r0l mov.b r0l,@ad_no_0 cmp.b #200,r0l beq _add_0_hit rts _add_0_hit: mov.w @ad_0,r3 shll.w r3 shll.w r3 shll.w r3 mov.b #h'de,r0h jsr @tx_fifo_set mov.b #30,r0l ; ##### add.b r0l,r3h mov.b r3h,r0h jsr @tx_fifo_set mov.w #0,r0 mov.w r0,@ad_0 mov.b r0l,@ad_no_0 rts ad_add_1: mov.b #9,r0l ; ##### add.b r0l,r3l jsr @ad_cut mov.w @ad_1,r2 mov.b #0,r3h add.w r3,r2 mov.w r2,@ad_1 mov.b @ad_no_1,r0l inc.b r0l mov.b r0l,@ad_no_1 cmp.b #220,r0l beq _add_1_hit rts _add_1_hit: mov.w @ad_1,r3 shll.w r3 shll.w r3 shll.w r3 mov.b #h'df,r0h jsr @tx_fifo_set mov.b r3h,r0h jsr @tx_fifo_set mov.w #0,r0 mov.w r0,@ad_1 mov.b r0l,@ad_no_1 rts .end