;----------------------------------------------------------- ; ; 5 * [sensor+LED] : July 2006 ; ; for 22-Tora Iwami Aya ; ;----------------------------------------------------------- ;##### Port Defines ##### paddr .equ h'0fffd1 padr .equ h'0fffd3 pbddr .equ h'0fffd4 pbdr .equ h'0fffd6 ;##### Vector Defines ##### .section vector,data,locate=h'000000 .data.l start ;##### Work RAM Data Defines ##### .section ram,data,locate=h'0fef10 timer .res.w 1 mode .res.b 8 speed .res.b 8 sp_cnt .res.b 8 level .res.b 8 phase .res.b 8 counter .res.b 8 flag .res.b 1 led .res.b 1 check .res.b 1 mask .res.b 1 old .res.b 1 new .res.b 1 ;***** Constant Table Defines ***** .section rom,data,locate=h'001000 table: .data.b 1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3,3 ; 21 .data.b 4,4,4,4,4,5,5,5,5,5 ; +10=31 .data.b 6,6,6,6,7,7,7,7,8,8,8,9,9,9 ; +14=45 .data.b 10,10,11,11,12,12,13,13,14,14,15,15,16,16 ; +14=59 .data.b 17,17,18,18,19,20 ; +6=65 .data.b 21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36 ; +16=81 .data.b 37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52 ; +16=97 .data.b 54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84 ; +16=113 .data.b 87,90,93,96,99,102,105,108,111,114,117,120,123 ; +13=126 .data.b 126,127 ; +2=128 ;***** Reset --> Initialize --> Main Loop ***** .section program,code,locate=h'002000 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 mov.b #b'00000000,r0l mov.b r0l,@pbddr ; set : Port[B] = input mov.b #b'11111111,r0l mov.b r0l,@paddr ; set : Port[A] = output mov.b #b'00000000,r0l mov.b r0l,@led jsr @led_write mov.b #3,r0l mov.b r0l,@speed+0 mov.b #4,r0l mov.b r0l,@speed+1 mov.b #5,r0l mov.b r0l,@speed+2 mov.b #6,r0l mov.b r0l,@speed+3 mov.b #7,r0l mov.b r0l,@speed+4 jsr @wait_500msec loop: jsr @timer_check bra loop ;***** 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.b @timer,r0l inc.b r0l mov.b r0l,@timer cmp.b #50,r0l ; ### sensor check speed ! bne _timer_event jsr @sensor_check mov.b #0,r0l mov.b r0l,@timer rts _timer_event: mov.b #0,r0l mov.b r0l,@check mov.b #b'00000001,r0l mov.b r0l,@mask _timer_loop: jsr @led_check mov.b @mask,r0l shll.b r0l mov.b r0l,@mask mov @check,r0l inc.b r0l mov.b r0l,@check cmp.b #5,r0l bne _timer_loop rts off_off: mov.b @led,r1l xor.b #b'00011111,r2l and.b r2l,r1l mov.b r1l,@led bra led_write on_on: mov.b @led,r1l or.b r2l,r1l mov.b r1l,@led led_write: mov.b @led,r0l xor.b #b'00011111,r0l mov.b r0l,@padr rts led_check: mov.b @check,r2h ; R2H = check No. (0-4) mov.b @mask,r2l ; R2L = bit mask : 00001-10000 mov.w #0,e6 mov.b #0,r6h mov.b r2h,r6l ; ER6 = addressing pointer mov.b @(mode,er6),r0l cmp.b #2,r0l beq _mode_2 cmp.b #3,r0l beq _mode_3 _mode_0: mov.b @(counter,er6),r3h mov.b @(level,er6),r4h cmp.b r3h,r4h ; level - counter bpl _on_light _off_light: jsr @off_off bra _mix_light _on_light: jsr @on_on _mix_light: mov.b @(counter,er6),r0l inc.b r0l and.b #b'01111111,r0l mov.b r0l,@(counter,er6) cmp.b #0,r0l beq _mode_0_1 rts _mode_0_1: mov.b @(sp_cnt,er6),r0l inc.b r0l mov.b r0l,@(sp_cnt,er6) mov.b @(speed,er6),r1l cmp.b r0l,r1l beq _mode_0_2 rts _mode_0_2: mov.b #0,r0l mov.b r0l,@(sp_cnt,er6) mov.b @(mode,er6),r0l cmp.b #0,r0l beq _mode_0_3 cmp.b #1,r0l beq _mode_1_5 rts _mode_0_3: mov.b @(phase,er6),r0l cmp.b #127,r0l beq _mode_1_4 inc.b r0l _mode_0_mix: and.b #b'01111111,r0l mov.b r0l,@(phase,er6) mov.b #0,r0h mov.w #0,e0 mov.b @(table,er0),r1l ; new level mov.b r1l,@(level,er6) rts _mode_1_4: mov.b #1,r0l mov.b r0l,@(mode,er6) rts _mode_1_5: mov.b @(phase,er6),r0l cmp.b #0,r0l beq _mode_0_6 dec.b r0l bra _mode_0_mix _mode_0_6: mov.b #0,r0l mov.b r0l,@(mode,er6) rts _mode_2: jsr @on_on mov.b @(counter,er6),r0l inc.b r0l and.b #b'01111111,r0l mov.b r0l,@(counter,er6) cmp.b #0,r0l beq _mode_2_1 rts _mode_2_1: mov.b @(phase,er6),r0l inc.b r0l and.b #b'01111111,r0l mov.b r0l,@(phase,er6) cmp.b #0,r0l beq _mode_2_2 rts _mode_2_2: jsr @off_off mov.b #3,r0l mov.b r0l,@(mode,er6) mov.b #0,r0l mov.b r0l,@(counter,er6) mov.b r0l,@(phase,er6) mov.b r0l,@(sp_cnt,er6) rts _mode_3: jsr @off_off mov.b @(counter,er6),r0l inc.b r0l and.b #b'01111111,r0l mov.b r0l,@(counter,er6) cmp.b #0,r0l beq _mode_3_1 rts _mode_3_1: mov.b @(phase,er6),r0l inc.b r0l and.b #b'01111111,r0l mov.b r0l,@(phase,er6) cmp.b #0,r0l beq _mode_3_2 rts _mode_3_2: jsr @on_on mov.b #2,r0l mov.b r0l,@(mode,er6) mov.b #0,r0l mov.b r0l,@(counter,er6) mov.b r0l,@(phase,er6) mov.b r0l,@(sp_cnt,er6) rts sensor_check: mov.b @pbdr,r3h and.b #b'00011111,r3h mov.b r3h,@new ; R3H = current data mov.b @old,r3l xor.b r3h,r3l ; R3L = event bit bne _sensor_event rts _sensor_event: mov.b #0,r2h ; R2H = check No. (0-4) mov.b #b'00000001,r2l ; R2L = bit mask : 00001-10000 _sensor_loop: jsr @sensor_chk shll.b r2l inc.b r2h cmp.b #5,r2h bne _sensor_loop mov.b r3h,@old rts sensor_chk: mov.b r3l,r1l and.b r2l,r1l bne _bit_hit rts _bit_hit: mov.b r3h,r0l and.b r2l,r0l beq _hit_to_0 _hit_to_2: mov.b #2,r0l bra _hit_mix _hit_to_0: mov.b #0,r0l _hit_mix: mov.w #0,e6 mov.b #0,r6h mov.b r2h,r6l ; ER6 = addressing pointer mov.b r0l,@(mode,er6) mov.b #0,r0l mov.b r0l,@(counter,er6) mov.b r0l,@(phase,er6) mov.b r0l,@(sp_cnt,er6) rts .end