+
+
+; FSR2 is used as outgoing message buffer pointer (reading),
+; ie private to this file
+;
+; FSR1 is used as pointer to where to add bytes of message
+
+max_messages equ 4
+
+ udata_acs
+ scana res 1
+ scanb res 1
+ scanc res 1
+ scand res 1
+ scane res 1
+ buf0 res 1
+ message_buffer res max_messages
+
+ udata
+ outgoing_buffer res max_messages+2
+
+ ; 80 40 20 10 08 04 02 01
+ ; 7 6 5 4 3 2 1 0
+
+;----------------------------------------------------------------------
+; detectors
+
+ ; A xx 19 09 12 15 18 xx xx
+ ; B xx xx xx 04 20 17 xx xx
+ ; C xx xx 05 xx xx 10 13 16
+ ; D 02 11 14 xx 08 xx 01 07
+ ; E xx xx xx xx xx 03 00 06
+
+ ; buf0 MM zz B2 B1 zz zz zz zz
+
+ ; 1: ; _<A 19 09 12 15 18 xx xx xx
+ ; >>B xx xx xx xx xx 04 20 17
+
+ ; 2: ; _>E 06 xx xx xx xx xx 03 00
+ ; [*D xx 01 07 02 11 14 xx ?? C=08
+
+ ; 0: ; [_C xx 05 xx xx 10 13 16 08
+
+det_scanloop_detectors
+ rr_fw PORTB ; W xx xx xx xx 04 20 17 xx (now)
+ ior_wff scanb ; b xx xx xx xx 04 20 17 xx (cumulative)
+ rl_fw PORTA ; W 19 09 12 15 18 xx xx xx (now)
+ ior_wff scana ; a 19 09 12 15 18 xx xx xx (cumulative)
+
+ rr_fw PORTE ; W 06 xx xx xx xx xx 03 00 (now)
+ ior_wff scane ; e 06 xx xx xx xx xx 03 00 (cumulative)
+ swap_fw PORTD ; W 08 xx 01 07 02 11 14 xx (now)
+ ior_wff scand ; d 08 xx 01 07 02 11 14 xx (cumulative)
+
+ mov_fw PORTC ; W xx xx 05 xx xx 10 13 16 (now)
+ ior_wff scanc ; c xx xx 05 xx xx 10 13 16 (cumulative)
+
+ bra det_scanloop_detectors
+
+;---------- ; buf0 MM zz zz zz zz zz zz zz
+det_read_start_detectors
+ ; detection byte 1
+ mov_lw 0xf8 ; W yy yy yy yy yy zz zz zz
+ and_wff scana ; scana 19 09 12 15 18 zz zz zz
+
+ rr_fw scanb ; W xx xx xx xx xx 04 20 17
+ and_lw 0x07 ; W zz zz zz zz zz 04 20 17
+ ior_wff scana ; scana 19 09 12 15 18 04 20 17
+
+ mov_fw scana
+ cmp_wf_ifne last1
+ bs_f buf0,4 ; buf0 MM zz zz B1 zz zz zz zz
+
+ ; detection byte 2
+ mov_lw 0x83 ; W yy zz zz zz zz zz yy yy
+ and_wff scane ; scane 06 zz zz zz zz zz 03 00
+
+ rlc_wf scand ; W xx 01 07 02 11 14 xx xx C=08
+ and_lw 0x7c ; W zz 01 07 02 11 14 zz zz C=08
+ ior_wff scane ; scane 06 01 07 02 11 14 03 00 C=08
+
+ mov_fw scane
+ cmp_wf_ifne last2
+ bs_f buf0,5 ; buf0 MM zz B2 B1 zz zz zz zz
+
+; detection and lead byte, 0
+ rlc_wf scanc ; W xx 05 xx xx 10 13 16 08
+ and_lw 0x4f ; W zz 05 zz zz 10 13 16 08
+ ior_wfw buf0 ; W MM 05 B2 B1 10 13 16 08
+
+ call i2cs_read_data
+
+ mov_lfsr outgoing_buffer, 2
+
+ mov_fw scana
+ bt_f_if1 buf0,5
+ mov_wf POSTINC2
+ mov_wf last1
+
+ mov_fw scane
+ bt_f_if1 buf0,4
+ mov_wf POSTINC2
+ mov_wf last2
+
+ clr_f scanb
+ clr_f scanc
+ clr_f scane
+
+;...
+;----------------------------------------------------------------------
+; both detectors and reversers
+;
+both_startread_tail
+ clr_f scana
+ clr_f scand
+
+ mov_lfsr message_buffer, 1
+msg_copy_loop
+ mov_fw POSTINC1
+ mov_wf POSTINC2
+ bra_n msg_copy_loop
+
+ mov_lfsr message_buffer, 1
+ clr_f buf0
+ return
+
+;----------------------------------------------------------------------
+; reversers
+ ; A xx 01 xx 03 xx xx xx xx
+ ; B xx xx xx xx xx xx xx xx
+ ; 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
+det_scanloop_reversers
+ rr_fw PORTA ; W xx xx 01 xx 03 xx xx xx (now)
+ ior_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)
+ ior_wff scand ; d xx xx xx xx xx xx 04 05 (cumulative)
+ bt_f_if1 PORTC,2 ; 00 (now)
+ bs_f buf0,2 ; buf0 MM zz zz ss zz 00 zz zz (cumulative)
+ bt_f_if1 PORTE,2 ; 02 (now)
+ bs_f buf0,4 ; buf0 MM zz zz 02 zz ss zz zz (cumulative)
+ bra det_scanloop_reversers
+
+;---------- ; buf0 MM zz zz 02 zz 00 zz zz
+det_read_start_reversers
+ mov_wf 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_wf 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
+
+ call i2cs_read_data
+
+ mov_lfsr outgoing_buffer, 2
+
+ bra both_startread_tail
+
+
+
+ clr_f scana
+ clr_f scand
+ bra
+
+
+ ; a -- 01 -- 03 -- -- -- --
+ ; c -- -- -- -- -- 00 -- --
+ ; d -- -- -- -- -- -- 04 05
+ ; e -- -- -- -- -- 02 -- --
+
+ mov_fw scana
+ and_lw 0x50 ; W zz 01 zz 03 zz zz zz zz
+ or_wf buf0 ; buf0 zz 01 MD 03 MM zz zz zz
+ mov_fw scand
+ and_lw 0x03 ; d -- -- -- -- -- -- 04 05
+ ior_wff buf0 ; buf0 -- 01 -- 03 -- -- 04 05
+
+ bt_f_if1 scanc,2; s5=04
+ bs_f buf0,5 ; buf0 05 -- 04 -- 03 -- 01 04
+ bt_f_if1 scane,2
+ bs_f buf0,3 ; s0=08
+
+
+
+
+ cmp_fw_ifne last1
+ bs_f buf0,6 ; buf0 MM D1 zz zz zz zz zz zz
+
+ mov_
+
+
+ rr_fw scanb ; W 04 20 17 xx xx xx xx xx
+ and_lw 0xe0 ; W 04 20 17 zz zz zz zz zz
+ ior_wf buf0 ; buf0 04 20 17 zz MD MM zz zz
+
+ rrc_fw scanc ; W xx xx xx 05 xx xx 10 13 C=16
+ and_lw 0x13 ; W zz zz zz 05 zz zz 10 13 C=16
+ ior_wf buf0 ; buf0 04 20 17 05 MD MM 10 13 C=16
+
+ rrc_fw scand ; d 16 08 xx 01 07 02 11 14
+ mov_wf buf1 ; buf1 16 08 xx 01 07 02 11 14
+
+
+ ; b -- -- -- 04 20 17 -- --
+ ; *b 20 17 -- -- -- -- -- 04
+ ; >*b 04 20 17 -- -- -- -- --
+
+
+
+ ; a -- 19 09 12 15 18 -- --
+
+ ; e -- -- -- -- -- 03 00 06
+
+
+
+
+
+
+
+ ; <Ce -- -- -- -- 03 00 06 16
+
+
+ ; b -- -- -- 04 20 17 -- --
+ ; a -- 19 09 12 15 18 -- --
+
+
+ ; >a -- -- 19 09 12 15 18 --
+ ; >Ce -- -- -- -- -- -- 03 00 C=06
+
+
+
+ ; *b 20 17 -- -- -- -- -- 04
+
+
+
+ ; *b 20 17 -- -- -- -- -- 04
+ ; >Cc XX -- -- 05 -- -- 10 13 C=16
+ ; >Cb
+
+
+ ; >b -- -- -- -- 04 20 17 --
+ ; <c -- 05 -- -- 10 13 16 --
+
+ ; <b -- -- 04 20 17 -- -- --
+ ; >c 16 -- -- 05 -- -- 10 13
+
+ ; *c -- 10 13 16 -- -- 05 --
+
+ ; >C*b XX 20 17 -- -- -- -- -- C=04
+ ; *c -- 10 13 16 -- -- 05 --
+
+ ; c -- -- 05 -- -- 10 13 16
+ ; b -- -- -- 04 20 17 -- --
+
+ ; buf0 -- -- md -- mm -- -- --
+ rl_fw scand ; W 11 14 -- 08 -- 01 07 02
+ and_lw 0xeb ;
+ or_wf buf0 ; buf0 02 11 14 md 08 mm 01 07
+
+ rr_f buf0 ; buf0 05 -- 01 -- 03 -- -- 04
+ ; d 02 11 14 -- 08 -- 01 07
+
+ ; e -- -- -- -- -- 03 00 06
+ ; a -- 19 09 12 15 18 -- --
+
+ ; c -- -- 05 -- -- 10 13 16
+ ; b -- -- -- 04 20 17 -- --
+
+
+[yy]= '0,-- -- -- -- -- 18 -- --';
+[yy]= '0,-- -- -- -- 15 -- -- --';
+[yy]= '0,-- -- -- 12 -- -- -- --';
+[yy]= '0,-- -- 09 -- -- -- -- --';
+[yy]= '0,-- 19 -- -- -- -- -- --';
+
+[yy]= '1,-- -- -- -- -- 17 -- --';
+[yy]= '1,-- -- -- -- 20 -- -- --';
+[yy]= '1,-- -- -- 04 -- -- -- --';
+
+[yy]= '2,-- -- -- -- -- -- -- 16';
+[yy]= '2,-- -- -- -- -- -- 13 --';
+[yy]= '2,-- -- -- -- -- 10 -- --';
+[yy]= '2,-- -- 05 -- -- -- -- --';
+
+[yy]= '3,-- -- -- -- -- -- -- 07';
+[yy]= '3,-- -- -- -- -- -- 01 --';
+[yy]= '3,-- -- -- -- 08 -- -- --';
+[yy]= '3,-- -- 14 -- -- -- -- --';
+[yy]= '3,-- 11 -- -- -- -- -- --';
+[yy]= '3,02 -- -- -- -- -- -- --';
+
+[yy]= '4,-- -- -- -- -- -- -- 06';
+[yy]= '4,-- -- -- -- -- -- 00 --';
+[yy]= '4,-- -- -- -- -- 03 -- --';
+
+
+ ; d 02 11 14 -- 08 -- 01 07
+ mov_lw
+
+ ; a -- 19 09 12 15 18 -- --
+ ; e -- -- -- -- -- 03 00 06
+
+ ; b -- -- -- 04 20 17 -- --
+ ; c -- -- 05 -- -- 10 13 16
+
+
+
+
+
+
+
+
+ ; d 02 11 14 -- 08 -- 01 07
+
+ ; a -- -- 09 12 15 18 -- --
+ ; c -- -- 05 -- -- 10 13 16
+
+ ; b -- -- -- 04 20 17 -- --
+ ; e -- -- -- -- -- 03 00 06
+
+
+
+
+
+
+
+ ; d 02 11 14 -- 08 -- 01 07
+ ; b -- -- -- 04 20 17 -- --
+ ; 02 11 14 04 20 17 01 07 (d&0xe3) | (b&0x1c)
+ ; missing 08
+
+ ; a -- -- 09 12 15 18 -- --
+ ; b -- -- -- 04 20 17 -- --
+ ; b 20 17 -- -- -- -- -- 04
+
+
+ ; a -- -- 09 12 15 18 -- --
+ ; c -- -- 05 -- -- 10 13 16
+ ; e -- -- -- -- -- 03 00 06
+
+
+ mov_lw scanc;2
+ and_lw 0x27 ; s5=0:20, s10=0:04, s13=0:02, s16=0:01
+ mov_wf buf0
+ mov_lw scand;3
+
+
+
+
+ mov_fw PORTB
+ mov_lw scana
+ mov_fw PORTC
+ mov_lw scana
+ mov_fw PORTD
+ mov_lw scana
+
+
+
include common.inc
extern informative_panic