chiark / gitweb /
i2cmu_read_got_byte - main scanning loop - wip
[trains.git] / detpic / mascan.asm
1 ;======================================================================
2 ; MASTER - SCANNING ETC.
3
4  include common.inc
5
6  udata_acs
7
8 cslot   res     1       ; current slave in slave table, points to flags byte
9 main    res     1
10         ; one of the following:
11         ;       0000 0000       we're expecting the first byte
12         ;       
13         ;       M0BB 0001       we have rec
14         ;       M0BB 0001       we have rec
15
16         ;       MM zz B2 B1 zz zz zz II
17         ;
18         ;       main byte from slave
19 ; X0BB0000
20                         ; where X is 1 iff we're expecting an `extra byte'
21                         ; otherwise NN is the detection byte we're expecting
22
23 sc              res     1
24 sc_extra        equ     7 ; we're 
25
26 slavetable_section udata 0x280
27 slavetable res maxpics * 2
28         ; each entry is:
29         ;  1 byte slave number
30         ;  1 byte flags
31         ;       00DD0000        where D is 1 iff a detectors board
32
33  code
34 ;======================================================================
35
36 ;----------------------------------------
37 i2cm_intrl
38 ; handles i2c interrupt using i2cm_interrupt[_definite],
39 ; according to the rules for <something>_intrl.
40         bt_f_if0 PIR1, SSPIF
41         return
42         call    i2cm_interrupt_definite
43         intrl_handled_nostack
44
45 ;----------------------------------------
46 i2cmu_read_got_byte
47 ;               Beforehand      At call
48 ;   State       Reading         Reading-Wait
49 ;   W                           data from slave
50 ;
51 ; See detect.asm head comment for protocol info, in particular
52 ; the meaning of these bytes.
53         mov_wf  t               ; remember the byte for a moment
54         mov_lw  slavetable >> 8
55         mov_wf  FSR1H
56         mov_ff  cslot, FSR1L
57
58         tst_f_ifnz cbyte
59         bra     read_got_notfirst
60         ; this is a first (head) byte:
61
62         and_wfw POSTINC1, 
63         
64
65         bt_f_if1 cbyte, 4
66         bra     read_got_moredet1
67         bt_f_if1 cbyte, 5
68         bra     read_got_moredet2
69         
70         
71         mov_fw  cbyte
72         
73         bra_n   read_got_extra
74         bra_nz  read_got_moredet
75
76         bt_f_if1 sc, sc_extra
77         bra     got_read_extra
78
79 got_read_extra
80         panic   morse_UX
81
82 ;----------------------------------------
83 i2cmu_done
84 i2cmu_write_next_byte
85         panic   morse_UI
86
87 ;======================================================================
88  include final.inc