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
18 ;----------------------------------------------------------------------
19 slavetable_section udata 0x400
22 ; each entry is a number of bytes, at these offsets:
23 ste_slave equ 0 ; slave number
24 ste_flags equ 1 ; flags (stf_...) cslot normally points here
25 ste_detbasel equ 2 ; added to 11111bbb to make 0SSSSSSS; ie first-0xf8
26 ste_lastd0 equ 3 ; } [o0]* ie every bit is either 0 (for an
27 ste_lastd1 equ 4 ; } irrelevant bit) or o, meaning the
28 ste_lastd2 equ 5 ; } previously seen detection data bit
29 ste_detmsgh equ 7 ; 1 001 1 000 being 1 001 Y SSS
30 ste_size equ (1<<ste_szln2)
31 slavetable res maxpics * ste_size
36 ;======================================================================
37 ; HANDLING OF I2C EVENTS
39 ;----------------------------------------
41 ; handles i2c interrupt using i2cm_interrupt[_definite],
42 ; according to the rules for <something>_intrl.
45 call i2cm_interrupt_definite
48 ;----------------------------------------
49 i2cmu_done panic morse_MD
51 ;----------------------------------------
55 ;======================================================================
56 ; PROCESSING OF INCOMING BYTES
58 ;----------------------------------------
61 ; State Reading Reading-Wait
64 ; See detect.asm head comment for protocol info, in particular
65 ; the meaning of these bytes.
67 mov_wf b ; W = b = received byte
69 mov_lfsr slavetable, 1
70 mov_ff cslot, FSR1L ; FSR1 -> slave's flags
74 ; this is a first (head) byte:
76 bt_f_if0 POSTINC1, stf_detect ; FSR1 -> detbasel
77 bra read_got_first_reversers
78 read_got_first_detectors ; b = MdBBdddd
79 and_lw 0xb0 ; W = M0BB0000
80 mov_wf cbyte ; cbyte = M0BB0000
81 mov_lw 0x4f ; W = 01001111
82 and_wff b ; b = 0d00dddd
83 mov_fw POSTINC1 ; W = detbasel; FSR1 -> lastd0
84 rcall read_got_detectbyte_prep ; b = 0d00dddd
86 bt_f_if1 b, 6 ; b bit .d......
87 bs_f b, 4 ; b = 0d0ddddd
88 ; ^ ^ copies of same bit
89 ; u = (still) 0C00CCCC
90 ; or, using detection segment bit numbers:
96 read_got_first_reversers
98 bra read_got_bad_first_reversers
99 and_lw 0x80 ; W = M0000000
100 mov_wf cbyte ; cbyte = M0000000
101 bc_f b, 7 ; b = 00dddddd
102 mov_fw POSTINC1 ; W = detbasel; FSR1 -> lastd0
103 rcall read_got_detectbyte_prep
107 read_got_bad_first_reversers panic morse_MR
110 read_got_detectors_b1 ; b = dddddddd
111 bc_f cbyte, 4 ; cbyte = M0B00000
112 mov_fw POSTINC1 ; W = detbasel; FSR1 -> lastd0
113 inc_f FSR1L ; FSR1 -> lastd1
114 add_lw 5 ; W = detbasel+8
115 rcall read_got_detectbyte_prep
119 read_got_detectors_b2 ; b = dddddddd
120 bc_f cbyte,5 ; cbyte = M0000000
121 mov_fw POSTDEC1 ; W = detbasel; FSR1 -> flags
122 bs_f FSR1L, 2 ; FSR1L -> lastd2
123 add_lw 13 ; W = detbasel+16
124 rcall read_got_detectbyte_prep
128 read_got_detectbyte_prep_ifsomething
130 ; This is a branch of read_got_detectbyte_prep, called if we're doing
131 ; `return' rather than `pop+return'. For conditions on return, see
132 ; read_got_detectbyte_prep; these are supposed to be (basically) the
133 ; same as the entry conditions for addmsgs_<kind>.
144 xor_wfw INDF1 ; lastd<n> = [d0]*
146 ior_wff FSR1L ; FSR1L -> detmsgh
147 return ; to addmsgs_<something>, very shortly
149 ;----------------------------------------
152 bra read_got_detectors_b1
154 bra read_got_detectors_b2
155 ; it must be an extra byte
157 bt_f_if0 b, 7 ; any more ?
160 rcall process_got_extra
161 bra i2c_arrange_next_byte
163 ;----------------------------------------
176 read_got_detectbyte_prep
178 ; Sees if anything has changed. If no changes pops one return address
179 ; and branches to i2c_arrange_next_byte; if some changes, returns to
182 ; So, caller should be i2cmu_read_got_byte, and next stuff
183 ; should basically be a call to addmsg_<something> (perhaps preceded
184 ; by a bit of fiddling of b). addmsg_<something> will finish
185 ; by branching to i2c_arrange_next_byte.
187 ; call return pop+return
188 ; W adjdetbasel preserved undefined
189 ; b [d0]* preserved preserved
190 ; FSR1 -> lastd<n> detmsgh preserved
191 ; cbyte set for next read etc. preserved preserved
192 ; u undefined [C0]* preserved
193 ; lastd<n> [o0]* [d0]* preserved = [d0]*
195 ; TOS -> (optionally, fiddle b, and then:) goto addmsgs_<something>
196 ; NOS return address for i2cmu_read_got_byte
198 mov_wf t ; t = adjdetbasel
200 xor_wfw INDF1 ; W = [C0]*, Z iff same
201 ; where C set iff change to that detection segment
202 bra_nz read_got_detectbyte_prep_ifsomething
203 ; there's nothing to do
206 ;----------------------------------------
207 i2c_arrange_next_byte
209 goto i2cm_read_another
211 ;======================================================================
212 ; DECIDING WHICH SLAVE TO ADDRESS
214 i2c_arrange_something
215 ; figure out what to do next - which pic to address, etc.
218 ;======================================================================
219 ; GENERATION OF DETECTION MESSAGES FOR HOST - MAD BT_F_IF1 TABLES
221 addmsg_testbit macro bit
226 addmsg_return macro dummy_bit
227 goto i2c_arrange_next_byte
230 addmsg_ignore macro dummy_bit
235 addmsg_padding macro dummy_bit
240 ;----------------------------------------
243 ; on entry after first addmsg_one, or when done
244 ; W, STATUS, v, FSR0 undefined trashed
245 ; t adjdetbasel not modified by addmsgs_<kind> or _one
246 ; u [C0]* not modified by addmsgs_<kind> or _one
247 ; b [d0]* not modified by addmsgs_<kind> or _one
248 ; lastd<n> [d0]* (new) not modified by addmsgs_<kind> or _one
249 ; FSR1 -> detmsgh not modified by addmsgs_<kind> or _one
250 ; outbuf, outmsg_* not full, updated appropriately
251 ; all others any not interfered with
253 ; (this is all set up by read_prep_detectbyte and
254 ; read_got_detectbyte_prep_ifsomething)
255 ; when done, branches to i2c_arrange_next_byte, rather than returning
257 addmsgs_section code ( 7 )*4 + 0x2100
260 ; |- PCL bbb value after macro - number in this
261 ; V column should increment 1 each line
263 addmsgs_revhead addmsg_testbit 0
271 addmsgs_all addmsg_testbit 7
281 addmsgs_dethead addmsg_testbit 0
285 addmsg_testbit 6 ; bit 6 was copied to 4 but only in b, not u
290 ; TOS - 4 -> bt_f_if1 w, b'bbb'
292 ; other conditions on entry and exit as for entry to addmsgs_<kind>, above
293 rr_fw TOSL ; W = 0???bbb0
295 ior_wfw 0xf8 ; W = 11111bbb
296 mov_wf FSR0L ; FSR0L = 11111bbb
297 clr_f FSR0H ; FSR0 -> bitnum2bit[bbb]
298 add_wfw t ; W = adjdetbasel + 11111bbb
299 ; ie = 0 SSSSSSS (det msg low byte)
300 mov_wf v ; v = 0 SSSSSSS (det msg low byte)
303 and_wfw INDF0 ; train: W = 0x00, Z=1; none: W = 0*d0*, Z=0
305 mov_lw 0x08 ; train: W = 0 000 0 000; none: W = 0 000 1 000
306 xor_wfw INDF1 ; W = 1 001 Y SSS (det msg high byte)
309 mov_fw v ; W = 0 SSSSSSS (det msg low byte)
310 goto serial_addbyte_another
312 ;======================================================================