1 ;======================================================================
10 debug_section udata 0x100
14 ;======================================================================
15 ; GENERALLY USEFUL ROUTINES
19 ; read pic no from ID locations and return it
20 ; W undefined pic number from ID loc 0
21 ; status Z undefined 1 iff master PIC
22 ; TBLPTR* undefined points to 20001
35 ; read id locations and store in canonical place
36 ; W undefined undefined
37 ; picno undefined pic number (from 20000)
38 ; idloc1 undefined idloc1 (from 20001)
57 bra_nn init_bitnum2bit_loop
64 ; other GPRs overwritten with 0xbb
80 bra memory_erase_byteloop
85 bra_nz memory_erase_pageloop
94 ; Adds a byte to debug
95 ; W message byte preserved
97 ; all others any preserved
98 ; Not for use in High ISR
99 mov_ff FSR0L, dsave_fsr0
100 mov_ff FSR0H, dsave_fsr0+1
105 mov_ff dsave_fsr0, FSR0L
106 mov_ff dsave_fsr0+1, FSR0H
109 ;------------------------------------------------------------
110 outpins_local_init_part1 @
111 ; Initialises a table of output pins
112 ; TBLPTR picno2<thing>map (presence bitmap)
113 ; FSR0 <thing>ix2latbit - 1 (start of output table)
114 ; W max<thing>s / 8 (table sizes)
115 ; outpins_local_init_part2 @
116 ; TBLPTR bk<thing>ix2portnumbitnum (phys pins)
117 ; FSR0 <thing>ix2latbit - 1 (start of output table)
118 ; W max<thing>s (table sizes)
119 ; Caller must use both, and set variables as above on each entry.
121 ; Input table is as made by writeasm_outpin
122 ; Result table is series of 2-byte entries,
123 ; 0th byte is bottom byte of LAT* address
124 ; 1st byte is single-bit mask for the relevant pin
127 ; We do this in two stages.
128 ; Firstly, we scan the bitmap for this pic, setting
129 ; <thing>ix2latbit to 0xff,0x00 for used points and 0x00,0x00
131 ; Secondly, we scan the bk<thing>ix2portnumbitnum, adjusting
132 ; <thing>ix2latbit to have actually correct data.
133 ; Doing it like this avoids having to constantly recompute
134 ; individual TBLPTR*'s.
136 ; On entry FSR0 -> this bit and LAT*
137 ; points just at last thing we've filled in
139 mov_wf t ; t = byte counter
141 outpins_init_byte_loop
142 mov_lw 8 ; W = bit counter
143 tblrd_postinc_fixup ; TABLAT = bitmap data being processed
145 outpins_init_bit_loop
146 clr_f PREINC0 ; FSR0 -> LAT*[current] := 0
149 set_f INDF0 ; FSR0 -still-> LAT*[current] := 0xff
151 clr_f PREINC0 ; FSR0 -> bit[current] := 0
154 bra outpins_init_bit_loop
156 bra outpins_init_byte_loop
160 ; We've scanned for points used on this board;
161 ; now find the actual pins.
163 return ; caller will reset
164 outpins_local_init_part2 @ ; TBLPTR, FSR0 and W (see above)
166 bt_f_if1 idloc1,idloc1_boarddet
169 set_f FSR2H ; FSR2 -> some SFR, will point to LAT/TRIS
170 mov_lfsr bitnum2bit+7, 1 ; FSR1 -> bitnum2bit+7
172 mov_wf t ; t = loop counter
174 outpins_init_portbit_loop
175 tblrd_postinc_fixup ; TABLAT = portnum4 || bitnum4
177 bt_f_if0 PREINC0,7 ; zero?, FSR0 -> LAT*[this]
178 bra outpins_init_portbit_endif_used
180 outpins_init_portbit_if_used
182 bra_n outpins_initing_bad_object
184 ior_lw 0xf8 ; W -> bit value for bit
185 mov_wf FSR1L ; FSR1 -> bit value for bit
187 swap_fw TABLAT ; W = bitnum4 || portnum4
188 and_lw 0x0f ; W = portnum4
189 add_lw LATA & 0xff ; W = LAT*
190 mov_wf POSTINC0 ; LAT*[this] := LAT, FSR0 -> bit[this]
191 mov_wf FSR2L ; FSR2 -> LAT*
193 mov_fw INDF1 ; W = bit
194 mov_wf POSTDEC0 ; bit[this] = bit, FSR0 -> LAT*[this]
196 and_wff INDF2 ; LAT* &= ~bit, ie pin set to L (still Z)
198 pin_vh pall_pt0reverse ; but pt0 pin is backwards, set to H
199 ; (still Z, unless we've done this already)
200 ; (we don't care about doing this far too
203 add_wff FSR2L ; FSR2 -> TRIS*
204 com_fw INDF1 ; W = ~bit
205 and_wff INDF2 ; TRIS* &= ~bit, ie pin set to not Z
207 set_f FSR1L ; FSR1 -> bitnum2bit+7, again
208 outpins_init_portbit_endif_used
209 ; so now we move on to the next one
210 mov_fw POSTINC0 ; FSR0 -> bit[this]
213 bra outpins_init_portbit_loop
218 outpins_initing_bad_object