ifdef SLOW_VERSION
debug macro debugvalue
- movlw debugvalue
+ mov_lw debugvalue
call debug_serial_transmit
endm
endif
debug_serial_transmit
- movwf TXREG,0 ; move contents of W (i.e. debugvalue)
+ mov_wfa TXREG ; move contents of W (i.e. debugvalue)
; to TXREG for transmission
waitfortsr
- btfss TXSTA,1,0
+ bt_fa_if0 TXSTA,1
bra waitfortsr
return
serial_init
; serial set-up
; initial config - TXSTA register p181
- bcf TXSTA,6,0 ; p181, set 8-bit mode
- bsf TXSTA,5,0 ; transmit enable
- bcf TXSTA,4,0 ; asynchronous mode
+ bc_fa TXSTA,6 ; p181, set 8-bit mode
+ bs_fa TXSTA,5 ; transmit enable
+ bc_fa TXSTA,4 ; asynchronous mode
bsc_txsta_brgh
; initial config - RCSTA register p182
- bsf RCSTA,7,0 ; serial port enable (p182)
- bcf RCSTA,6,0 ; 8-bit reception
- bsf RCSTA,4,0 ; enable continuous receive
+ bs_fa RCSTA,7 ; serial port enable (p182)
+ bc_fa RCSTA,6 ; 8-bit reception
+ bs_fa RCSTA,4 ; enable continuous receive
; set SPBRG to get correct baud rate according to table top right p186
; (Tosc = 20MHz, desired baud rate = 9600)
;----------------------------------------------------------------------------
- bcf TRISE,4,0 ; turn off PSPMODE (Data Sheet p100/101)
+ bc_fa TRISE,4 ; turn off PSPMODE (Data Sheet p100/101)
; fixme eh ? where should this go ?
nmra_init
; timer0 initial config for NMRA timer
ifdef SLOW_VERSION
- bcf T0CON,6,0 ; p107 Timer0 -> 16bit mode (testing)
+ bc_fa T0CON,6 ; p107 Timer0 -> 16bit mode (testing)
endif
ifndef SLOW_VERSION
- bsf T0CON,6,0 ; p107 Timer0 -> 8bit mode (not-testing)
+ bs_fa T0CON,6 ; p107 Timer0 -> 8bit mode (not-testing)
endif
- bcf T0CON,5,0 ; timer0 use internal clock
- bcf T0CON,3,0 ; use prescaler
+ bc_fa T0CON,5 ; timer0 use internal clock
+ bc_fa T0CON,3 ; use prescaler
ifndef SLOW_VERSION
- bcf T0CON,2,0 ; }
- bcf T0CON,1,0 ; } prescale value 1:2
- bcf T0CON,0,0 ; } (not-testing)
+ bc_fa T0CON,2 ; }
+ bc_fa T0CON,1 ; } prescale value 1:2
+ bc_fa T0CON,0 ; } (not-testing)
endif
ifdef SLOW_VERSION
- bsf T0CON,2,0 ; }
- bcf T0CON,1,0 ; } prescale value 1:16
- bcf T0CON,0,0 ; } (testing)
+ bs_fa T0CON,2 ; }
+ bc_fa T0CON,1 ; } prescale value 1:16
+ bc_fa T0CON,0 ; } (testing)
endif
debug 'b' ; write 'b' to serial port
; initialise buffers (for BSR5, for nmra from-serial/to-track buffers)
- movlw bufferpage
- movwf BSR,0 ; set BSR to point to buffer page
+ mov_lw bufferpage
+ mov_wfa BSR ; set BSR to point to buffer page
- clrf nmractrl,0 ; for bits relevant to control of nmra stream
- clrf fromserial,0 ; for loc'n of write-from-usart ptr in buffers
- clrf totrack,0 ; for loc'n of send-to-track ptr in buffers
+ clr_fa nmractrl ; for bits relevant to control of nmra stream
+ clr_fa fromserial ; for loc'n of write-from-usart ptr in buffers
+ clr_fa totrack ; for loc'n of send-to-track ptr in buffers
; all in access bank
; initialise next action/transmit bit
- bsf nmractrl,nextaction,0
- bsf nmractrl,transmitbit,0
+ bs_fa nmractrl,nextaction
+ bs_fa nmractrl,transmitbit
; initialise totrackbit bitmask
- movlw 0x80
- movwf totrackbit,0 ; make bit mask be 1000 0000
+ mov_lw 0x80
+ mov_wfa totrackbit ; make bit mask be 1000 0000
; initialise booster direction
- bcf TRISC,0,0 ; make pin 0 (booster direction) output
- bcf PORTC,0,0 ; set low initially
+ bc_fa TRISC,0 ; make pin 0 (booster direction) output
+ bc_fa PORTC,0 ; set low initially
; set booster pwm high
- bsf PORTC,1,0 ; booster pwm high
- bcf TRISC,1,0 ; make pin 1 (booster pwm) output
+ bs_fa PORTC,1 ; booster pwm high
+ bc_fa TRISC,1 ; make pin 1 (booster pwm) output
debug 'd' ; write 'd' to serial port
;----------------------------------------------------------------------------
; interrupt set-up
; interrupt set-up for timer0 interrupt p79/80
- bsf INTCON2,2,0 ; timer0 overflow high priority
- bsf INTCON,5,0 ; enable timer0 interrupts
+ bs_fa INTCON2,2 ; timer0 overflow high priority
+ bs_fa INTCON,5 ; enable timer0 interrupts
debug 'e' ; write 'e' to serial port
; serial_receive:
; debug 'h' ; write 'h' to serial port
- btfsc RCSTA,FERR,0 ; if FERR set (= framing error), then panic
+ bt_fa_if1 RCSTA,FERR ; if FERR set (= framing error), then panic
goto panic
- btfsc RCSTA,OERR,0 ; if OERR set (= overrun error), then panic
+ bt_fa_if1 RCSTA,OERR ; if OERR set (= overrun error), then panic
goto panic
- movff fromserial,FSR0L ; set low byte of INDF0 pointer
- movlw bufferpage
- movwf FSR0H,0 ; set high byte of INDF0 pointer
+ mov_ff fromserial,FSR0L ; set low byte of INDF0 pointer
+ mov_lw bufferpage
+ mov_wfa FSR0H ; set high byte of INDF0 pointer
; debug '1'
mov_fw RCREG ; get received byte
mov_wf INDF0 ; copy to received register
; debug '3'
; If not, move to next byte
- incf fromserial,1,0 ; advance fromserial pointer by 1 byte
+ inc_fa fromserial ; advance fromserial pointer by 1 byte
; debug '4'
- bcf PIR1,RCIF,0 ; unset interrupt
+ bc_fa PIR1,RCIF ; unset interrupt
goto intrl_handled_nostack
; *** I *think* the interrupt bit is cleared by reading out of RCREG
; clear low 4 bits of fromserial and increment top 4 bits
; aaaabbbb -> bbbbaaaa -> bbbb(aaaa+1) -> 0000(aaaa+1) -> (aaaa+1)0000
debug '5'
- swapf fromserial,1,0
- incf fromserial,1,0
- movlw 0xF
- andwf fromserial,1,0
- swapf fromserial,1,0
+ swap_fa fromserial
+ inc_fa fromserial
+ mov_lw 0xF
+ and_wffa fromserial
+ swap_fa fromserial
; clear bit 6 (will set back to buffer 0 if has overflowed to 4)
debug '6'
- bcf fromserial,6,0
+ bc_fa fromserial,6
return
; timer0 interrupt
debug ',' ; write 'j' to serial port
- bcf INTCON,2,0 ; clear interrupt-set bit
+ bc_fa INTCON,2 ; clear interrupt-set bit
ifdef SLOW_VERSION
- movlw 0x01 ; (testing)
+ mov_lw 0x01 ; (testing)
endif
ifndef SLOW_VERSION
- movlw 0x73 ; (not-testing)
+ mov_lw 0x73 ; (not-testing)
endif
- movwf TMR0L,0 ; set timer0 to appropriate value (so interrupt takes 58us)
+ mov_wfa TMR0L ; set timer0 to appropriate value (so interrupt takes 58us)
debug 'k' ; write 'k' to serial port
; check next action - if 0, change to 1 and return
- btfsc nmractrl,nextaction,0
+ bt_fa_if1 nmractrl,nextaction
goto toggle_output
- bsf nmractrl,nextaction,0
+ bs_fa nmractrl,nextaction
debug '1' ; write 'k' to serial port
- retfie 1
+ retfie_r
; if next action = 1, then toggle output
toggle_output
debug 'l' ; write 'l' to serial port
- btg PORTC,0,0 ; toggle booster output pin
- btfss PORTC,0,0
+ btg_fa PORTC,0 ; toggle booster output pin
+ bt_fa_if0 PORTC,0
goto decide_next_bit
goto mid_bit
mid_bit
debug 'm' ; write 'm' to serial port
- btfsc nmractrl,transmitbit,0
- bsf nmractrl,nextaction,0
- btfss nmractrl,transmitbit,0
- bcf nmractrl,nextaction,0
+ bt_fa_if1 nmractrl,transmitbit
+ bs_fa nmractrl,nextaction
+ bt_fa_if0 nmractrl,transmitbit
+ bc_fa nmractrl,nextaction
debug '2' ; write 'k' to serial port
- retfie 1
+ retfie_r
decide_next_bit
; check whether current to-track buffer = current from-serial buffer
; if yes, transmit 1s (set transmitbit=1, nextaction=1 and return)
- movff fromserial,WREG
- xorwf totrack,0,0
- andlw 0x30
- bnz read_from_buffer
- bsf nmractrl,transmitbit,0
- bsf nmractrl,nextaction,0
+ mov_ff fromserial,WREG
+ xor_wfwa totrack
+ and_lw 0x30
+ bra_nz read_from_buffer
+ bs_fa nmractrl,transmitbit
+ bs_fa nmractrl,nextaction
debug '3'
- bsf TRISB,0,0 ; user fault Z (red)
- retfie 1
+ bs_fa TRISB,0 ; user fault Z (red)
+ retfie_r
read_from_buffer
- bcf TRISB,0,0 ; user fault L (purple)
+ bc_fa TRISB,0 ; user fault L (purple)
debug 'o'
; if currently on bit 7, want to skip to bit 6
;*** wouldn't it be easier to start on bit 6 ? :-) -iwj
- btfsc totrackbit,7,0
- rrncf totrackbit,1,0 ; rotate mask right
+ 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),
fixme save and restore FSR1
fixme check other to-be-saved stuff ??
debug 'p'
- movff totrack,FSR1L ; set low byte of IND1 pointer
- movlw bufferpage
- movwf FSR1H,0 ; set high byte of IND1 pointer
- movff INDF1,WREG
- andwf totrackbit,0,0 ; select bit to be transmitted
+ mov_ff totrack,FSR1L ; set low byte of IND1 pointer
+ mov_lw bufferpage
+ mov_wfa FSR1H ; set high byte of IND1 pointer
+ mov_ff INDF1,WREG
+ and_wfwa totrackbit ; select bit to be transmitted
- bz 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
- bcf nmractrl,transmitbit,0
- bcf nmractrl,nextaction,0
+ bc_fa nmractrl,transmitbit
+ bc_fa nmractrl,nextaction
goto 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
- bsf nmractrl,transmitbit,0
- bsf nmractrl,nextaction,0
+ bs_fa nmractrl,transmitbit
+ bs_fa nmractrl,nextaction
goto advance_bit
; rotate transmitbit to next position
debug 's' ; write 's' to serial port
- rrncf totrackbit,1,0 ; rotate mask right
+ 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
- btfsc totrackbit,7,0
+ bt_fa_if1 totrackbit,7
call advance_pointer
debug '5' ; write 's' to serial port
- retfie 1
+ retfie_r
; currently on bit 7 of the byte, after having read rest of byte to
; track; check whether it is 1 or 0
- movff totrack,FSR1L
- movlw bufferpage
- movwf FSR1H,0
+ mov_ff totrack,FSR1L
+ mov_lw bufferpage
+ mov_wfa FSR1H
; if set, move to next buffer
- btfsc INDF1,7,0
+ bt_fa_if1 INDF1,7
call 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)
- btfss INDF1,7,0
- incf totrack,1,0
+ bt_fa_if0 INDF1,7
+ inc_fa totrack
return
; 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
- swapf totrack,1,0
- incf totrack,1,0
- movlw 0xF
- andwf totrack,1,0
- swapf totrack,1,0
+ swap_fa totrack
+ inc_fa totrack
+ mov_lw 0xF
+ 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)
- bcf totrack,6,0
+ bc_fa totrack,6
debug '9' ; write 'v' to serial port
return
panic
debug 'x'
- clrf INTCON,0 ; disable all interrupts EVER
+ clr_fa INTCON ; disable all interrupts EVER
debug 'y'
- bcf PORTC,1,0 ; switch off booster
+ bc_fa PORTC,1 ; switch off booster
debug 'z'
call led_red
panic_loop