📄 run.asm
字号:
;****************************************************************;
; Set Rules
;
; Function: set some limits to the movement rules
;
; Written by: Kelvin Yuan
; Date: 2004-03-02
;20040710:when received the broadcast sign,the mouse will go ahead to the barrier.
;****************************************************************;
;================================================================;
;Constant Area
;================================================================;
c_mtr_tab_row equ #28 ;motor move status totoal number range is 0~c_mtr_tab_row+1
c_rnd_range_f equ #5 ;random number range is 8
c_offset_f_ini equ #0
c_flg_left equ #0
c_flg_right equ #1
c_flg_backup equ #2
c_flg_ahead equ #3
;//04-04-13// add
c_flg_stop equ #4
c_rnd_range_not_stop equ #26
;end add //04-04-13//
c_flg_l_rcved equ #2
c_flg_r_rcved equ #3
c_flg_f_l_rcved equ #4
c_flg_f_r_rcved equ #5
c_rnd_range_1 equ #1 ;random number range is 1
;c_rnd_range_2 equ #2 ;random number range is 2
;c_rnd_range_3 equ #3 ;random number range is 3
;c_rnd_range_4 equ #4 ;random number range is 4
;c_rnd_range_5 equ #5 ;random number range is 5
;c_rnd_range_6 equ #6 ;random number range is 6
;c_rnd_range_8 equ #8 ;random number range is 8
;c_offset_f equ #0
;;--------------------------------------以下为左转的开始偏移
c_offset_l_20 equ #72 ;=9(row)*8(column) left 20 degree
;c_offset_l_40 equ #80 ;=10(row)*8(column) left 40 degree
;c_offset_l_60 equ #88 ;=11(row)*8(column) left 60 degree
;c_offset_l_80 equ #96 ;=12(row)*8(column) left 80 degree
;c_offset_l_100 equ #104 ;=13(row)*8(column) left 100 degree
;c_offset_l_120 equ #112 ;=14(row)*8(column) left 120 degree
;;--------------------------------------以下为右转的开始偏移
c_offset_r_20 equ #144 ;=18(row)*8(column) right 20 degree
;c_offset_r_40 equ #152 ;=19(row)*8(column) right 40 degree
;c_offset_r_60 equ #160 ;=20(row)*8(column) right 60 degree
;c_offset_r_80 equ #168 ;=21(row)*8(column) right 80 degree
;c_offset_r_100 equ #176 ;=22(row)*8(column) right 100 degree
;c_offset_r_120 equ #184 ;=23(row)*8(column) right 120 degree
;;;-------------------------------------以下为红外左右转表的开始偏移
;;//04-03-17// add for swerve when detceting the obstacles
c_offset_l_20_ir equ #240 ;=30(row)*8(column) left 20 degree
c_offset_l_40_ir equ #248 ;=31(row)*8(column) left 40 degree
;c_offset_l_60_ir equ #256 ;=32(row)*8(column) left 60 degree
c_offset_r_20_ir equ #312 ;=39(row)*8(column) right 20 degree
c_offset_r_40_ir equ #320 ;=40(row)*8(column) right 40 degree
;c_offset_r_60_ir equ #328 ;=41(row)*8(column) right 60 degree
c_offset_backup equ #384 ;=48(row)*8(column) right 60 degree
;;end adding //04-03-17//
;================================================================;
;Data Area
;================================================================;
.area set_rules_var(data)
temp_flg_ir_received:: .ds 1 ;store the last flg_ir_received value
flg_last_barrier:: .ds 1 ;there is barrier at the last time
;================================================================;
;Code Area
;================================================================;
.area Rules_code(code)
Run::
lda flg_touched_key
cmpe #2
brnz No_touched_key
ret
No_touched_key:
lda flg_rcv_broadcast ;received the broadcast sign
cmpe #0
brnz Run_with_broadcast
lda flg_rcv_barrier ;Is there any barrier sign ahead?
cmpe #1
brz front_barrier
lda flg_new_random ;there isn't barrier
cmpe #0
brnz Run_next_status ;the last status finished(flg_new_random=1 or 2)
;--------------------------------------------------------------------------------
;no barrier at this times,the last status isn't finished
lda flg_last_barrier
cmpe #1
brz last_barrier_ahead ;if the last barrier,will go ahead
ret ;no barrier at this times and last times ,the last status isn't finished,no change,go on the current status
last_barrier_ahead:
lda #0 ;no barrier at this times,barrier at last times,last status isn't finished
sta flg_last_barrier ;go ahead
br next_status_ahead
;------------------------------------------------------------------------------------
;no barrier at this time,the last status has be finished
Run_next_status:
lda flg_last_barrier ;the last status has be finished
cmpe #0
brz Run_random_status ;there isn't barrier in the previous status,will random except backup
br last_barrier_ahead ;no barrier at this time,barrier at last time,current status finished,go ahead
Run_random_status:
lda #3 ;no barrier at this time and last time,last status finished
sta m_rnd_range
br next_status_l_r_ahead ;the next status will be left,right,(backup),ahead
;------------------------------------------------------------------------------------------
;barrier at the front
front_barrier:
lda #1
sta flg_last_barrier
broadcast_no_barrier: ;broadcast,no barrier(no cheese,seek it)
lda flg_motor_status ;if the previous status is turning left or right, the next status is left or right too.
cmpe #c_flg_ahead
brz next_status_l_r_b ;the next status is a random except ahead
lda flg_new_random
cmpe #0
brz pre_status_continue ;if the previous status is going on,no change director and continue the last status
lda flg_motor_status
cmpe #c_flg_left
brz next_status_left ;repeat the last status
cmpe #c_flg_right
brz next_status_right ;repeat the last status
cmpe #c_flg_backup ;the previous status is backup
brz next_status_backup ;repeat backup
cmpe #c_flg_stop ;if the previous status is stop, not stop next.
brz next_status_left ;turn left(assume),may turn right
ret
pre_status_continue:
; lda #0 ;go on the last status till it is finished(flg_new_random=1)
; sta flg_rcv_barrier
ret
next_status_l_r_b:
lda flg_rcv_broadcast
cmpe #1
brz next_status_l_r
lda #2 ;0 will turn left,1 will turn right,2 will turn backup
sta m_rnd_range
br next_status_l_r_ahead
next_status_l_r:
lda #1 ;no cheese,only turn left and turn right
sta m_rnd_range
next_status_l_r_ahead:
lda #0
sta rnd_num
call read_random
lda rnd_num
cmpe #c_flg_left
brz next_status_left
cmpe #c_flg_right
brz next_status_right
cmpe #c_flg_backup
brz next_status_backup
cmpe #c_flg_ahead
brz next_status_ahead
ret
next_status_backup:
lda flg_rcv_barrier
cmpe #0
brz Run_random_status ;read random again,cann't backup
Run_backup::
lda #>c_offset_backup
sta m_offset_ini_h
lda #<c_offset_backup
sta m_offset_ini
lda #0
sta rnd_num ;random data is 0,just only a selection
call Lookup
lda #0
sta flg_new_random
ret
next_status_ahead:
lda #>c_offset_f_ini
sta m_offset_ini_h
lda #<c_offset_f_ini
sta m_offset_ini
lda #c_rnd_range_f
br next_status_set_end1
next_status_right: ;右转
lda #>c_offset_r_20
sta m_offset_ini_h
lda #<c_offset_r_20
sta m_offset_ini
br next_status_set_end
next_status_left: ;左转
lda #>c_offset_l_20
sta m_offset_ini_h
lda #<c_offset_l_20
sta m_offset_ini
next_status_set_end:
lda #c_rnd_range_1
next_status_set_end1:
sta m_rnd_range
call Read_Random
call Lookup
lda #0
sta flg_new_random
ret
Run_with_broadcast:
lda flg_rcv_barrier ;Is there any barrier sign ahead?
cmpe #1
brz front_barrier_bc ;there is barrier,go ahead
br broadcast_no_barrier ;no cheese,shall turn left or right
front_barrier_bc:
lda #>c_offset_f_ini ;assume the cheese is at the front of mouse
sta m_offset_ini_h ;go ahead
lda #<c_offset_f_ini
sta m_offset_ini
lda #2
br next_status_set_end1
;set_rules::
; ;lda flg_new_random
; cmpe #1
;; brnz set_rules_end
; brnz rules_for_ir ;if the flg_new_random is 2, set some rules for run when received ir.
;
;;-------------------------------------这是flg_new_random==1时的设置一些规则,即是没有障碍物的情况下。
;rules_for_free_run: ;
; lda flg_motor_status ;if the previous status is turning left or right, the next move status is straight forward.
; cmpe #c_flg_stop ;if the previous status is stop, not stop next.
; brz next_status_not_stop ;前一运行状态是停止
; cmpe #c_flg_left
; brz next_status_forward ;前一运行状态是向左,则下一个是向前
; cmpe #c_flg_right
; brz next_status_forward ;前一运行状态是向右,则下一个是向前
;next_status_random: ;if not, the next status is selected from the whole move status.
; lda #0
; sta m_offset_ini ;add the high 8bit of the offset register
; sta m_offset_ini_h
; lda #c_mtr_tab_row
; sta m_rnd_range
; br set_rules_end
;next_status_forward: ;revise for adding the high 8bit of the offset register
; lda #>c_offset_f_ini
; sta m_offset_ini_h
; lda #<c_offset_f_ini
; sta m_offset_ini
; lda #c_rnd_range_f
; sta m_rnd_range
; br set_rules_end
;next_status_not_stop: ;add the rules for not stop continuously
; lda #>c_offset_f_ini
; sta m_offset_ini_h
; lda #<c_offset_f_ini
; sta m_offset_ini
; lda #c_rnd_range_not_stop
; sta m_rnd_range
; br set_rules_end
;;--------------------------------------这是flg_new_random==2时的设置一些规则,即是有障碍物的情况下。
;rules_for_ir:
; lda temp_flg_ir_received ;上一次的红外状态
; cmpe #c_flg_l_rcved ;前一个是左边有障碍物
; brz $1
; cmpe #c_flg_f_l_rcved
; brz $1
; cmpe #c_flg_r_rcved
; brz $2
; cmpe #c_flg_f_r_rcved
; brz $2
; br set_rules_end
;$1:
; lda flg_ir_received ;对照今次的红外状态
; cmpe #c_flg_r_rcved
; brz next_status_forward
; cmpe #c_flg_f_r_rcved
; brz next_status_forward
; br set_rules_end
;$2:
; lda flg_ir_received
; cmpe #c_flg_l_rcved
; brz next_status_forward
; cmpe #c_flg_f_l_rcved
; brz next_status_forward
;
;set_rules_end:
; lda #0
; sta flg_new_random
; lda flg_ir_received
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -