; We maintain the following properties, notionally:
;
; lasttelldone <= totrack <= fromserial < lasttelldone
- ;
- ; / \
- ; ' `- equal if we have nothing but
- ; equal if we have idle to trasmit
- ; told the host about our
- ; current buffer state
+ ;
+ ; / \ \
+ ; ' \ `- equal would mean overrun
+ ; equal if we have \
+ ; told the host about our `- equal if we have nothing but
+ ; current buffer state idle to trasmit
;
bufferpage equ 5
; macro to call subroutine to transmit over serial port for debugging
; takes 8-bit value, puts in W, invokes debug_serial_transmit
-
+
ifndef SLOW_VERSION
debug macro debugvalue
endm
mov_wfa TXREG ; move contents of W (i.e. debugvalue)
; to TXREG for transmission
waitfortsr
- bt_fa_if0 TXSTA,1
+ bt_fa_if0 TXSTA,1
bra waitfortsr
return
bs_fa TXSTA,5 ; transmit enable
bc_fa TXSTA,4 ; asynchronous mode
bsc_txsta_brgh
-
+
; initial config - RCSTA register p182
bs_fa RCSTA,7 ; serial port enable (p182)
bc_fa RCSTA,6 ; 8-bit reception
bc_fa T0CON,1 ; } prescale value 1:16
bc_fa T0CON,0 ; } (testing)
endif
-
+
debug 'b' ; write 'b' to serial port
;----------------------------------------------------------------------------
; initialise next action/transmit bit
- bs_fa nmractrl,nextaction
- bs_fa nmractrl,transmitbit
+ bs_fa nmractrl,nextaction
+ bs_fa nmractrl,transmitbit
; initialise totrackbit bitmask
mov_lw 0x80
bt_f_if0 INTCON,TMR0IF ; check whether timer0 interrupt set
bra master_interrupt_high_notnmra
; timer0 interrupt
-
+
debug ',' ; write 'j' to serial port
bc_fa INTCON,TMR0IF ; clear interrupt-set bit
-
+
ifdef SLOW_VERSION
mov_lw 0x01 ; (testing)
endif
debug 'k' ; write 'k' to serial port
; check next action - if 0, change to 1 and return
- bt_fa_if1 nmractrl,nextaction
+ bt_fa_if1 nmractrl,nextaction
bra toggle_output
- bs_fa nmractrl,nextaction
+ bs_fa nmractrl,nextaction
debug '1' ; write 'k' to serial port
- retfie_r
+ retfie_r
; if next action = 1, then toggle output
toggle_output
debug 'l' ; write 'l' to serial port
btg_fa PORTC,0 ; toggle booster output pin
- bt_fa_if0 PORTC,0
+ bt_fa_if0 PORTC,0
bra decide_next_bit
; we're in mid-bit:
-; if transition was 0->1 then we are mid-bit, so copy transmitbit to
+; if transition was 0->1 then we are mid-bit, so copy transmitbit to
; nextaction in preparation for 2nd half of bit and then return
debug 'm' ; write 'm' to serial port
- bc_fa nmractrl,nextaction
- bt_fa_if1 nmractrl,transmitbit
- bs_fa nmractrl,nextaction
+ bc_fa nmractrl,nextaction
+ bt_fa_if1 nmractrl,transmitbit
+ bs_fa nmractrl,nextaction
debug '2' ; write 'k' to serial port
- retfie_r
+ retfie_r
decide_next_bit
; if yes, transmit 1s (set transmitbit=1, nextaction=1 and return)
mov_fw fromserial
- xor_wfwa totrack
+ xor_wfwa totrack
and_lw 0x30
bra_nz read_from_buffer
- bs_fa nmractrl,transmitbit
- bs_fa nmractrl,nextaction
+ bs_fa nmractrl,transmitbit
+ bs_fa nmractrl,nextaction
debug '3'
bs_fa TRISB,0 ; user fault Z (red)
- retfie_r
+ retfie_r
read_from_buffer
; if currently on bit 7, want to skip to bit 6
;*** wouldn't it be easier to start on bit 6 ? :-) -iwj
- bt_fa_if1 totrackbit,7
+ bt_fa_if1 totrackbit,7
rr_fa totrackbit ; rotate mask right
-; if not on bit 7 ,
-; set na=cb=bit value, advance bit (i.e. rotate transmitbit right),
+; if not on bit 7 ,
+; set na=cb=bit value, advance bit (i.e. rotate transmitbit right),
; check if bit7, if so, advance byte, return
debug 'p'
mov_fw INDF2
and_wfwa totrackbit ; select bit to be transmitted
- bra_z zero_bit_to_track
+ bra_z zero_bit_to_track
bra one_bit_to_track
-
+
zero_bit_to_track
debug '_' ; write 'q' to serial port
debug '0' ; write 'q' to serial port
debug '_' ; write 'q' to serial port
- bc_fa nmractrl,transmitbit
- bc_fa nmractrl,nextaction
+ bc_fa nmractrl,transmitbit
+ bc_fa nmractrl,nextaction
bra advance_bit
-
+
one_bit_to_track
debug '_' ; write 'q' to serial port
debug '1' ; write 'r' to serial port
debug '_' ; write 'q' to serial port
- bs_fa nmractrl,transmitbit
- bs_fa nmractrl,nextaction
+ bs_fa nmractrl,transmitbit
+ bs_fa nmractrl,nextaction
bra advance_bit
advance_bit
-; rotate transmitbit to next position
+; rotate transmitbit to next position
debug 's' ; write 's' to serial port
rr_fa totrackbit ; rotate mask right
;*** surely rrnc (`rotate right not through carry' I assume)
;*** will leave a copy of the top bit in the N flag ? Then you
;*** can use branch if negative. -iwj
- bt_fa_if1 totrackbit,7
+ bt_fa_if1 totrackbit,7
rcall advance_pointer
debug '5' ; write 's' to serial port
- retfie_r
+ retfie_r
; track; check whether it is 1 or 0
; if set, move to next buffer
- bt_fa_if1 INDF2,7
+ bt_fa_if1 INDF2,7
rcall advance_read_buffer
; if not set, move to next byte of samebuffer (increment totrack)
; (will be on bit 7 at this point anyway so no need to change totrackbit)
- bt_fa_if0 INDF2,7
- inc_fa totrack
+ bt_fa_if0 INDF2,7
+ inc_fa totrack
return
advance_read_buffer
-; move pointer to next buffer
+; move pointer to next buffer
; clear low 4 bits of totrack and increment top 4 bits
; aaaabbbb -> bbbbaaaa -> bbbb(aaaa+1) -> 0000(aaaa+1) -> (aaaa+1)0000
debug '7' ; write 'v' to serial port
- swap_fa totrack
- inc_fa totrack
+ swap_fa totrack
+ inc_fa totrack
mov_lw 0xF
- and_wffa totrack
- swap_fa totrack
+ and_wffa totrack
+ swap_fa totrack
debug '8' ; write 'v' to serial port
-
+
; clear bit 6 (will set back to buffer 0 if has overflowed to 4)
- bc_fa totrack,6
+ bc_fa totrack,6
debug '9' ; write 'v' to serial port
bs_f flags, flags_tellnmra ; ensure we tell