ch res 1
mode res 1
mode_readhex equ 0
+mode_crashread res 1
readwrite res 1
; ff means we're writing or going to write, FSR1
; buffer is 0x200 onwards
; FSR0 is buffer pointer
; FSR2 is the write cursor
+; FSR1 is the crash readout protocol cursor
+; (and may be trashed by non-crash-readout things)
master
clr_f mode
+ call bitnum2bit_init
+ call points_local_init
+ call polarity_local_init
+ call detect_local_init
+
call serial_setup
call i2cm_init
call led_green
mov_lw ~0x1f
and_wfw ch
- bra_z m_ch_bad
+ bra_z m_ch_readown
+
+ ; digit ?
+ mov_fw ch
+ add_lw -('9'+1)
+ bra_nn m_ch_notdigit
+ add_lw ('9'+1) - '0'
+ bra_z m_ch_0
+ bra_nn m_ch_digit
+
+m_ch_notdigit
+
+ bt_f_if1 mode, mode_crashread
+ bra m_ch_crashsetown
mov_lw ','
xor_wfw ch
xor_wfw ch
bra_z m_ch_dollar
- mov_fw ch
- add_lw -('9'+1)
- bra_nn m_ch_notdigit
- add_lw ('9'+1) - '0'
- bra_z m_ch_0
- bra_nn m_ch_digit
-
-m_ch_notdigit
mov_fw ch
mov_wf POSTINC0
clr_f INDF0
;----------
m_ch_setreadwrite
mov_fw ch
+ bra_z m_ch_startcrashread
mov_wf readwrite
return
+;----------
+m_ch_crashsetown
+ mov_fw ch
+ goto panic_crashread_setpointer
+
+;----------
+m_ch_readown
+ bc_f ch, 4 ; ch is now our byte counter
+m_ch_readown_loop
+ mov_fw POSTINC1
+ call serial_write_char
+ dec_f_ifnz ch
+ bra m_ch_readown_loop
+ return
+
+;----------
+m_ch_startcrashread
+ bs_f mode,mode_crashread
+ mov_lfsr 0x0,1
+ return
+
;----------
m_ch_comma
goto i2cm_read_another