;MACROS --------------------------------------------------------------------------

; Port r[a | b | c | d | e] [in | out | pull | float | cmos | ttl] bits
;  sets the port mode and configuration for standard pins

in	EQU	$F00
out	EQU	$FFF
pull	EQU	$E00
float	EQU	$EFF
cmos	EQU	$D00
ttl	EQU	$DFF
sch	EQU	$CFF
inten	EQU	$B00
intedge	EQU	$A00
intpend EQU	$900

porthelp MACRO
	ERROR 'USAGE: port r[a,b,c,d,e] [in,out,pull,float,cmos,ttl] bits'
	ENDM

_PortMode = $1F

PortMode MACRO 1
	noexpand
; IF _PortMode <> \1 ;can't do this if you don't know how you got to this code.
IF CpuPins > 28
  _PortMode = \1 | $10
  expand
 mov w,#_PortMode
 mov m,w
  noexpand
ELSE
  _PortMode = \1
  expand
 mov	m,#_PortMode
  noexpand
ENDIF
;  ENDIF
 ENDM

port	MACRO	port, mode, mask
	noexpand
IF (port==ra) || (port==rb) 
ELSE
 IF (CpuPins > 18) && (port==rc) )
 ELSE
  IF (CpuPins > 28) && ((port==rd) || (port==re)) )
  ELSE
	porthelp
   ENDIF
  ENDIF
 ENDIF
IF port==RB && ((?mode=='sch') || (?mode=='inten') || (?mode=='intedge') || (?mode=='intpend'))
ELSE
 IF (?mode=='in') || (?mode=='out') || (?mode=='pull') || (?mode=='float') || (?mode=='cmos') || (?mode=='ttl')
 ELSE
  porthelp
  ENDIF
 ENDIF
	PortMode (mode / $100) 
	expand
 mov !port, #(mode//$100)^mask
	noexpand
	ENDM

