;----------------------------------------------------------------------
; COMMON INCLUDES and BOILERPLATE
- include /usr/share/gputils/header/p18f458.inc
+ include p18f458.inc
radix dec
include panic.inc
include morse+auto.inc
;----------------------------------------------------------------------
; Common conventions for function register notation:
-; Master Slave
+; Master Slave
; Registers etc.
-; W Trashed Trashed
-; STATUS Trashed Trashed
-; BSR Not used Not used
-; t,u,v Low ISR Low ISR
-; TBLPTR*,TABLAT Low ISR Low ISR
-; PROD* Low ISR Low ISR
-; FSR0 Low ISR Low ISR
-; PCLATU Always set to 0 Not used
-; PCLATH Low ISR Not used
-; t_dolocal Low ISR High ISR
-; FSR1 Low ISR High ISR (detect[1])
-; FSR2 High ISR (nmra[1]) High ISR (detect[1])
-;
-; Main loop detection scan detection scan
-; High ISR NMRA output I2C service
-; Low ISRs everything else everything else
+; W Trashed Trashed
+; STATUS Trashed Trashed
+; BSR Not used Not used
+; t,u,v Low ISR Low ISR
+; TBLPTR*,TABLAT Low ISR Low ISR
+; PROD* Low ISR Low ISR
+; FSR0 Low ISR Low ISR
+; PCLATU Always set to 0 Not used
+; PCLATH Low ISR Not used
+; t_dolocal Low ISR High ISR
+; FSR1 Low ISR High ISR (detect[1])
+; FSR2 High ISR (nmra[1]) High ISR (detect[1])
+; PORTB Special read handling[2] Used normally
+;
+; Main loop detection scan detection scan
+; High ISR NMRA output I2C service
+; Low ISRs everything else everything else
;
; Trashed May be trashed by any routine anywhere. Saved
; during every ISR entry/exit.
; detect_slave_init. Likewise FSR2 is reserved exclusively
; for the NMRA output ISR after nmra_init.
;
+; [2] On the master PIC we the interrupt-on-change feature of PORTB.
+; This means that routines mustn't casually read PORTB. Instead,
+; they should call portb_read from serout.asm.
+;
; General-purpose hardware allocation:
;
; Master Slave
;
; <something>_intrl Low ISR service routine.
; Checks for any relevant interrupt.
-; If not, just returns.
+; If not, just returns
; If found, services it and then does either
; intrl_handled or intrl_handled_nostack
; neither of which return; the latter is
-; faster but implies a promise
+; faster but implies a promise
;
;----------------------------------------------------------------------
; MACROS
@ macro
endm
+;----------------------------------------
+; For adding a byte to the debug buffer.
+; Not for use in High ISR. In all cases:
+;
+; STATUS any trashed
+; all others any preserved
+
+ ifdef DEBUG
+;----------
+Dv macro ; sorry, but assembler's dw directive isn't case-sensitive
+;
+; W message byte preserved
+;
+ call debugbyte
+ endm
+
+;----------
+Dl macro debug_literal_value
+;
+; W any literal value as specified
+;
+ mov_lw debug_literal_value
+ Dv
+ endm
+
+;----------
+Df macro debug_register_file_address
+;
+; W any value from specified memory location
+;
+ mov_fw debug_register_file_address
+ Dv
+ endm
+ else
+Dv macro
+ endm
+Dl macro debug_literal_value
+ endm
+Df macro debug_register_file_address
+ endm
+ endif
+
;----------------------------------------
; For entering and leaving Low ISR, saving and restoring STATUS and W
; See above under <something>_intrl, and {master,slave}_interrupt_low
bt_f_if0 LATA + (LATB-LATA)*((pinspec-0xa) & 15), pinspec >> 4
endm
+pin_inw_ifh macro pinspec
+ bt_w_if1 pinspec >> 4
+ endm
+
+pin_inw_ifl macro pinspec
+ bt_w_if0 pinspec >> 4
+ endm
+
;----------------------------------------------------------------------