1 ;======================================================================
2 ; MASTER - SCANNING ETC.
6 ;----------------------------------------------------------------------
9 b res 1 ; byte just read
10 cslot res 1 ; current slave in slave table, points to flags byte
12 ; one of the following:
13 ; 0000 0000 we're expecting the first byte
14 ; M0B1 0000 we're expecting more detection byte 1
15 ; M010 0000 we're expecting more detection byte 2
16 ; 1000 0000 we're expecting an extra byte
19 ;======================================================================
20 ; HANDLING OF I2C EVENTS
22 ;----------------------------------------
24 ; handles i2c interrupt using i2cm_interrupt[_definite],
25 ; according to the rules for <something>_intrl.
28 call i2cm_interrupt_definite
31 ;----------------------------------------
32 i2cmu_done panic morse_MD
34 ;----------------------------------------
38 ;======================================================================
39 ; PROCESSING OF INCOMING BYTES - CORE AND DETECTION
41 ;----------------------------------------
44 ; State Reading Reading-Wait
47 ; See detect.asm head comment for protocol info, in particular
48 ; the meaning of these bytes.
50 mov_wf b ; W = b = received byte
52 mov_lfsr slavetable, 1
53 mov_ff cslot, FSR1L ; FSR1 -> slave's flags
57 ; this is a first (head) byte:
59 bt_f_if0 POSTINC1, stf_detect ; FSR1 -> detbasel
60 bra read_got_first_reversers
61 read_got_first_detectors ; b = MdBBdddd
62 and_lw 0xb0 ; W = M0BB0000
63 mov_wf cbyte ; cbyte = M0BB0000
64 mov_lw 0x4f ; W = 01001111
65 and_wff b ; b = 0d00dddd
66 mov_fw POSTINC1 ; W = detbasel; FSR1 -> lastd0
67 rcall read_got_detectbyte_prep ; b = 0d00dddd
69 bt_f_if1 b, 6 ; b bit .d......
70 bs_f b, 4 ; b = 0d0ddddd
71 ; ^ ^ copies of same bit
72 ; u = (still) 0C00CCCC
73 ; or, using detection segment bit numbers:
79 read_got_first_reversers
81 bra read_got_bad_first_reversers
82 and_lw 0x80 ; W = M0000000
83 mov_wf cbyte ; cbyte = M0000000
84 bc_f b, 7 ; b = 00dddddd
85 mov_fw POSTINC1 ; W = detbasel; FSR1 -> lastd0
86 rcall read_got_detectbyte_prep
90 read_got_bad_first_reversers panic morse_MR
93 read_got_detectors_b1 ; b = dddddddd
94 bc_f cbyte, 4 ; cbyte = M0B00000
95 mov_fw POSTINC1 ; W = detbasel; FSR1 -> lastd0
96 inc_f FSR1L ; FSR1 -> lastd1
97 add_lw 5 ; W = detbasel+8
98 rcall read_got_detectbyte_prep
102 read_got_detectors_b2 ; b = dddddddd
103 bc_f cbyte,5 ; cbyte = M0000000
104 mov_fw POSTDEC1 ; W = detbasel; FSR1 -> flags
105 bs_f FSR1L, 2 ; FSR1L -> lastd2
106 add_lw 13 ; W = detbasel+16
107 rcall read_got_detectbyte_prep
111 read_got_detectbyte_prep_ifsomething
113 ; This is a branch of read_got_detectbyte_prep, called if we're doing
114 ; `return' rather than `pop+return'. For conditions on return, see
115 ; read_got_detectbyte_prep; these are supposed to be (basically) the
116 ; same as the entry conditions for addmsgs_<kind>.
127 xor_wfw INDF1 ; lastd<n> = [d0]*
129 ior_wff FSR1L ; FSR1L -> detmsgh
130 return ; to addmsgs_<something>, very shortly
132 ;----------------------------------------
135 bra read_got_detectors_b1
137 bra read_got_detectors_b2
138 ; it must be an extra byte
140 bt_f_if0 b, 7 ; any more ?
143 call process_got_extra
144 bra i2c_arrange_next_byte
147 read_got_detectbyte_prep
149 ; Sees if anything has changed. If no changes pops one return address
150 ; and branches to i2c_arrange_next_byte; if some changes, returns to
153 ; So, caller should be i2cmu_read_got_byte, and next stuff
154 ; should basically be a call to addmsg_<something> (perhaps preceded
155 ; by a bit of fiddling of b). addmsg_<something> will finish
156 ; by branching to i2c_arrange_next_byte.
158 ; call return pop+return
159 ; W adjdetbasel preserved undefined
160 ; b [d0]* preserved preserved
161 ; FSR1 -> lastd<n> detmsgh preserved
162 ; cbyte set for next read etc. preserved preserved
163 ; u undefined [C0]* preserved
164 ; lastd<n> [o0]* [d0]* preserved = [d0]*
166 ; TOS -> (optionally, fiddle b, and then:) goto addmsgs_<something>
167 ; NOS return address for i2cmu_read_got_byte
169 mov_wf t ; t = adjdetbasel
171 xor_wfw INDF1 ; W = [C0]*, Z iff same
172 ; where C set iff change to that detection segment
173 bra_nz read_got_detectbyte_prep_ifsomething
174 ; there's nothing to do
177 ;----------------------------------------
178 i2c_arrange_next_byte
180 goto i2cm_read_another
182 ;======================================================================
183 ; DECIDING WHICH SLAVE TO ADDRESS
185 i2c_arrange_something
186 ; figure out what to do next - which pic to address, etc.
189 ;======================================================================
190 ; PROCESSING OF INCOMING BYTES - EXTRA (NON-DETECTION)
193 ;----------------------------------------
205 ;======================================================================
206 ; GENERATION OF DETECTION MESSAGES FOR HOST - MAD BT_F_IF1 TABLES
208 addmsg_testbit macro bit
213 addmsg_return macro dummy_bit
214 goto i2c_arrange_next_byte
217 addmsg_ignore macro dummy_bit
222 addmsg_padding macro dummy_bit
227 ;----------------------------------------
230 ; on entry after first addmsg_one, or when done
231 ; W, STATUS, v, FSR0 undefined trashed
232 ; t adjdetbasel not modified by addmsgs_<kind> or _one
233 ; u [C0]* not modified by addmsgs_<kind> or _one
234 ; b [d0]* not modified by addmsgs_<kind> or _one
235 ; lastd<n> [d0]* (new) not modified by addmsgs_<kind> or _one
236 ; FSR1 -> detmsgh not modified by addmsgs_<kind> or _one
237 ; outbuf, outmsg_* not full, updated appropriately
238 ; all others any not interfered with
240 ; (this is all set up by read_prep_detectbyte and
241 ; read_got_detectbyte_prep_ifsomething)
242 ; when done, branches to i2c_arrange_next_byte, rather than returning
244 addmsgs_section code ( 7 )*4 + 0x2100
247 ; |- PCL bbb value after macro - number in this
248 ; V column should increment 1 each line
250 addmsgs_revhead addmsg_testbit 0
258 addmsgs_all addmsg_testbit 7
268 addmsgs_dethead addmsg_testbit 0
272 addmsg_testbit 6 ; bit 6 was copied to 4 but only in b, not u
277 ; TOS - 4 -> bt_f_if1 w, b'bbb'
279 ; other conditions on entry and exit as for entry to addmsgs_<kind>, above
280 rr_fw TOSL ; W = 0???bbb0
282 ior_wfw 0xf8 ; W = 11111bbb
283 mov_wf FSR0L ; FSR0L = 11111bbb
284 clr_f FSR0H ; FSR0 -> bitnum2bit[bbb]
285 add_wfw t ; W = adjdetbasel + 11111bbb
286 ; ie = 0 SSSSSSS (det msg low byte)
287 mov_wf v ; v = 0 SSSSSSS (det msg low byte)
290 and_wfw INDF0 ; train: W = 0x00, Z=1; none: W = 0*d0*, Z=0
292 mov_lw 0x08 ; train: W = 0 000 0 000; none: W = 0 000 1 000
293 xor_wfw INDF1 ; W = 1 001 Y SSS (det msg high byte)
296 mov_fw v ; W = 0 SSSSSSS (det msg low byte)
297 goto serial_addbyte_another
299 ;======================================================================