/****************************************************************************
     X-ASM MACRO DEFINITION (15.11.2005)
*****************************************************************************

 ADD - addition without carry
 SUB - subtraction
 INW - increment word
 DEW - decrement word			(MADS only)
 MVA - move byte using accumulator
 MVX - move byte using register X
 MVY - move byte using register Y
 MWA - move word using accumulator
 MWX - move word using register X
 MWY - move word using register X

*****************************************************************************/


/****************************************************************************
  ADD - addition without carry
*****************************************************************************/
add .macro ' '
 .if :0<>1
  .error 'Unexpected end of line'
 .endif

 clc
 adc :1
.endm


/*****************************************************************************
 SUB - subtraction
*****************************************************************************/
sub .macro ' '
 .if :0<>1
  .error 'Unexpected end of line'
 .endif

 sec
 sbc :1
.endm


/*****************************************************************************
 INW - increment word 
*****************************************************************************/
inw .macro ' '
 .if :0<>1
   .error 'Unexpected end of line'
 .endif

 inc :1
 bne skip
 
 inc :1+1
 
skip
.endm


/*****************************************************************************
 DEW - decrement word 
*****************************************************************************/
dew .macro ' '
 .if :0<>1
   .error 'Unexpected end of line'
 .endif

 lda :1
 bne skip

 dec :1+1

skip
 dec :1
.endm


/*****************************************************************************
 MVA, MVX, MVY - move byte using accumulator, X or Y
*****************************************************************************/
mv? .macro ' '
 .if :4<>2
   .error 'Unexpected end of line'
 .endif

 ld:3 :1
 st:3 :2
.endm


/*****************************************************************************
 MVA - move byte using accumulator
*****************************************************************************/
mva .macro ' '
 mv? :1 :2 a :0
.endm


/*****************************************************************************
 MVX - move byte using register X
*****************************************************************************/
mvx .macro ' '
 mv? :1 :2 x :0
.endm


/*****************************************************************************
 MVY - move byte using register Y
*****************************************************************************/
mvy .macro ' '
 mv? :1 :2 y :0
.endm


/*****************************************************************************
 MWA, MWX, MWY - move word using accumulator, X or Y 
*****************************************************************************/
mw? .macro ' '
  .if :3<>' ' .or :0<>5
    .error 'Illegal addresing mode'
  .endif

  .if :1='#'

    .if :2=0
      ld:5 #0
      st:5 :4
      st:5 :4+1
      .exit
    .endif

    .if :2=1
      .if 'a'<>':5' .and 'A'<>':5'
        ld:5 #:2
        st:5 :4
        de:5
        st:5 :4+1
      .else 
        lda #1
        sta :4
        lda #0
        sta :4+1
      .endif

     .exit
    .endif

    .if :2<256 .and :2>0
      ld:5 #:2
      st:5 :4
      ld:5 #0
      st:5 :4+1
    .else
      ld:5 <:2
      st:5 :4
      ld:5 >:2
      st:5 :4+1
    .endif

  .else

    ld:5 :2
    st:5 :4
    ld:5 :2+1
    st:5 :4+1

  .endif
.endm


/*****************************************************************************
 MWA - move word using accumulator
*****************************************************************************/
mwa .macro " "
 mw? :1 :2 :3 :4 a
.endm


/*****************************************************************************
 MWX - move word using register X
*****************************************************************************/
mwx .macro " "
 mw? :1 :2 :3 :4 x
.endm


/*****************************************************************************
 MWY - move word using register Y
*****************************************************************************/
mwy .macro " "
 mw? :1 :2 :3 :4 y
.endm







