; C xx xx xx xx xx 00 xx xx
; D xx xx xx xx xx xx 04 05
;---------- ; E xx xx xx xx xx 02 xx xx
-backgroundloop_reversers
+backgroundloop_reversers_core macro
rr_fw PORTA ; W xx xx 01 xx 03 xx xx xx (now)
and_wff scana ; a xx xx 01 xx 03 xx xx xx (cumulative)
mov_fw PORTD ; D xx xx xx xx xx xx 04 05 (now)
bc_f buf0,2 ; buf0 MM zz zz ss zz 00 zz zz (cumulative)
bt_f_if0 PORTE,2 ; 02 (now)
bc_f buf0,4 ; buf0 MM zz zz 02 zz ss zz zz (cumulative)
+ endm
+backgroundloop_reversers
+ backgroundloop_reversers_core
backgroundloop_again backgroundloop_reversers
;---------- ; buf0 MM zz zz 02 zz 00 zz zz
-i2csu_read_begin_reversers
+read_begin_calc_buf0_reversers macro
mov_fw scana ; W xx xx 01 xx 03 xx xx xx
and_lw 0x28 ; W zz zz 01 zz 03 zz zz zz
ior_wff buf0 ; buf0 MM zz 01 02 03 00 zz zz
mov_fw scand ; W xx xx xx xx xx xx 04 05
and_lw 0x03 ; W zz zz zz zz zz zz 04 05
ior_wfw buf0 ; W MM zz 01 02 03 00 04 05
+ endm
+i2csu_read_begin_reversers
+ read_begin_calc_buf0_reversers
call i2cs_read_data
rcall new_i2c_outmsg
bra i2csu_read_begin_either_tail
+;======================================================================
+; FOR MASTER
+
+;----------
+backgroundloop_master
+ backgroundloop_reversers_core
+ bra backgroundloop_master
+
+;----------
+read_detection_head_master
+ read_begin_calc_buf0_reversers
+ bra_n read_detection_head_master_badmore
+ set_f scana
+ set_f scand
+ mov_ff buf0_startval, buf0
+ return
+
+;-----
+read_detection_head_master_badmore
+ panic morse_DM
+
;======================================================================
include final.inc
; ???? ???1 reading halted due to lack of buffer space:
cbyte_halted equ 0 ; also set briefly while we decide what to do next
-wslave res 1 ; slave we need to write to
+wslave res 1 ; slave we need to write to
+outmsg_targetlen res 1 ;
;======================================================================
; HANDLING OF I2C EVENTS
cmp_fw_ifle outmsg_targetlen
return ; target len < actual len, do not add anything
; ok, there's space, go ahead:
+ bc_f cbyte, cbyte_halted
+ mov_lw ste_size
+ add_wff cslot ; cslot -> next ste_flags
mov_lfsr slavetable, 1 ; FSR1H -> slavetable
- mov_ff cslot, FSR1L ; FSR1 -> current ste_flags
- mov_lw ste_size ; W = ste_size
-nextslave_loop
- add_wff FSR1L ; FSR1 -> next ste_flags
- bt_f_if0 INDF1, stf_present
- bra nextslave_loop
-
-nextslave_reloop_resume
- mov_ff FSR1L, cslot ; cslot -> new ste_flags
+ mov_fw cslot, FSR1L ; FSR1 -> new ste_flags
+
bt_f_if1 POSTDEC1, stf_sentinel ; FSR1 -> ste_slave
- bra nextslave_reloop
- ; no wrap around:
+ bra nextslave_looparound
+ ; Ok, we have a slave:
mov_fw INDF1 ; W = new slave number
- bc_f cbyte, cbyte_halted
goto i2cm_read_start
-nextslave_reloop
- mov_lfsr slavetable + ste_size + ste_flags
- bra nextslave_reloop_resume
+nextslave_looparound
+ ; now we do our own detection
+ mov_lw (slavetable + ste_flags) & 0xff ; select our own slot
+ mov_wf cslot
+ call read_detection_head_master
+ goto i2cmu_read_got_byte
;----------------------------------------
i2cmu_done
; INITIALISATION
mascan_init
- add_lw -maxpic/2 ; at 9600, about 1ms per char;
- ; we reckon on about 2 pics per ms. So if
- ; we have at least maxpic/2 then we won't
- ; run out before we have scanned them all
- coincidentally is about 1 pic cmp_fw_ifle
- mov_fw outmsg_end
- sub_wfw
+ mov_lw slavetable & 0xff
+ mov_wf cslot
+ clr_f cbyte
+ clr_f wslave
+
+ mov_lw 2
+ mov_lfsr slavetable, 0 ; FSR0 -> slavetable
+ load_tblptr pic2detinfo ; TBLPTR* -> pic2detinfo
+ clr_f t ; t = loop counter
+mascan_init_loop
+ tblrd_postinc_fixup ; TABLAT = EOOOOSSS
+ mov_fw TABLAT ; W = EOOOOSSS, N = E
+
+ tblrd_postinc_fixup ; TABLAT = DSSSSSSS, N (still) = E
+ bra_nn mascan_init_ifabsent
+
+ mov_ff t, POSTINC0 ; ste_slave = slave
+ mov_wf u ; u = 1OOOOSSS
+ and_lw 0x78
+ bra_nz mascan_bad_detinfo0
+ ; ok ; u = 10000SSS
+
+ mov_fw TABLAT ; W = DSSSSSSS
+ and_lw 0x80 ; W = D0000000
+ mov_wf POSTINC0 ; ste_flags = D0000000
+
+ mov_fw TABLAT ; W = DSSSSSSS
+ bc_w 7 ; W = 0SSSSSSS = first
+ add_lw -0xf8 ; W = first - 0xf8 = detbasel
+ mov_wf POSTINC0 ; detbasel
+
+ clr_f POSTINC0 ; lastd0
+ clr_f POSTINC0 ; lastd1
+ clr_f POSTINC0 ; lastd2
+ set_f POSTINC0 ; unused
+
+ mov_fw u ; W = 10000SSS
+ xor_lw b'10011000' ^ 0x80 ; W = detmsgh
+ mov_wf POSTINC0 ; detmsgh
+
+mascan_init_ifabsent
+ inc_f t ; next slave
+ bt_f_if0 t, maxpics_ln2
+ bra mascan_init_loop
+ ; we've read the whole flash table
+
+ if slavetable = 0x400
+ bt_f_if1 FSR0H, 0
+ bra mascan_bad_toomany
+ endif
+
+ clr_f POSTINC0 ; ste_slave
+ mov_lw (1<<stf_detect)|(1<<stf_sentinel)
+ mov_wf POSTINC0 ; ste_flags
+ ; rest of final entry, and rest of table, is undefined
+
+ ; at 9600, it's about 1ms per char.
+ ; we allow 1ms to scan 2 pics via i2c.
+ ; so our target len is (no of pics)/2
+ ; plus 2 bytes of slop
+ rl_fw t
+ add_lw 2
+ mov_wf outmsg_targetlen
+
+ return
+
+mascan_bad_detinfo0 panic morse_DF
+mascan_bad_toomany panic morse_DG
;======================================================================
; PROCESSING OF INCOMING BYTES - EXTRA (NON-DETECTION)