; ********************************
; Microchip-style macros for SX Key
; by Al Williams (http://www.al-williams.com/awce.htm)
; V1.1 3 March 1999

; Notes: Use _W instead of W
;        Use _OPTION instead of OPTION

;        I've only tested this a bit -- let me know if you find mistakes.
; 	 NOP, CALL, SLEEP work without change
;        For the SX-only commands, use the SX mnemonics, or port over the stuff in
;          SXDEFS.INC
;        When you debug, the "hot spot" for the line is a blank line under the
;        actual line of code (because of NOEXPAND). You get used to this pretty quick. 
;        The upper window shows the SX mnemonics which is good for double checking my macros.

;        Don't like Microchip syntax? Don't use this file. Don't complain to me!

;        Get the most current copy at http://www.al-williams.com/awce.htm
;        While you are there check out our line of coprocessors (including floating point)
;        Work great with the PIC or SX chips



; Internal use macros
uchipdf macro 3
	dw \1 + (\3 * $20 & $20) + (\2 & $1F)
	endm

uchipbf macro 3
   dw \1 + (\3 * $20 & $E0) + (\2 & $1F)
   endm


; HERE WE GO.....
addwf	macro 2
   uchipdf $1C0, \1, \2
   endm

andwf macro 2
   uchipdf $140, \1, \2
   endm

clrf macro 1
   uchipdf $060, \1, 0
   endm

clrw macro 0
   dw $40
   endm

comf macro 2
   uchipdf $240,\1,\2
   endm

decf macro 2
   uchipdf $0c0,\1,\2
   endm

decfsz macro 2
   uchipdf $2C0,\1,\2
   endm

incf macro 2
   uchipdf $280,\1,\2
   endm

incfsz macro 2
   uchipdf $3c0,\1,\2
   endm

iorwf macro 2
   uchipdf $100,\1,\2
   endm

movf macro 2
   uchipdf $200,\1,\2
   endm

movwf macro 1
   uchipdf $020,\1,0
   endm

; nop already works as-is

rlf macro 2
   uchipdf $340,\1,\2
   endm

rrf macro 2
   uchipdf $300,\1,\2
   endm

subwf macro 2
   uchipdf $080,\1,\2
   endm

swapf macro 2
   uchipdf $380,\1,\2
   endm

xorwf macro 2
   uchipdf $180,\1,\2
   endm


bcf macro 2
   uchipbf $400,\1,\2
   endm

bsf macro 2
   uchipbf $500,\1,\2
   endm

btfsc macro 2
   uchipbf $600,\1,\2
   endm

btfss macro 2
   uchipbf $700,\1,\2
   endm

andlw macro 1
    dw $E00+ (\1 & $FF)
    endm

; Call already works

clrwdt macro 0
      dw 4
       endm

goto macro 1
     jmp \1
     endm

iorlw macro 1
   dw $D00+(\1 & $FF)
    endm

movlw macro 1
   dw $C00+ (\1 & $FF)
   endm

; can't use option, so use _option if you want
_option macro 0
  dw 2
  endm

retlw  macro 1
   dw $800+(\1 & $FF)
   endm


tris macro 1
   dw \1 &$7
   endm

; Sleep already works

xorlw macro 1
   dw $F00 + (\1 & $FF)
   endm



F = 1
; a hack because Parallax uses W and won't let us use it
_W = 0
PORTA = RA
PORTB = RB
PORTC = RC

	NOEXPAND

; ******** End of UCHIP.MAC


