;
; group m, test 2
;
; cmp.16
;

m4_include(..\tmacros.h)

INIT_TEST(m,0x02)

; declare symbols here
SYM(hop)
SYM(d1)
SYM(d2)
SYM(d3)
SYM(d4)
SYM(d5)
SYM(d6)
SYM(d7)
SYM(next0)
SYM(next1)
SYM(next2)
SYM(next3)
SYM(next4)
SYM(next5)
SYM(next6)
SYM(next7)
SYM(next8)
SYM(next9)
SYM(next10)
SYM(next11)
SYM(next12)
SYM(next13)
SYM(next14)
SYM(next15)
SYM(next16)
SYM(next17)

    br	hop

    ; Declare data here.  Format is:
    ;	op1
    ;	op2
    ;	expected a result
    ;	expected flags result V S C Z

d1:
    defw    0xff00
    defw    0x0100
    defw    0xfe00
    defw    0x0006
d2:
    defw    0x0000
    defw    0x0000
    defw    0x0000
    defw    0x0100
d3:
    defw    0xf000
    defw    0x0f00
    defw    0xe100
    defw    0x0006
d4:
    defw    0x8000
    defw    0x0100
    defw    0x7f00
    defw    0x000a

hop:
; Begin test here

SUBTEST(1)
;   <op>.16  a,u16(dp)
    ld.16   a,d1
    lea	    a,-555(a)
    copy    dp,a
    ld.16    a,555(dp)
    cmp.16   a,555+2(dp)
    push    msw
    cmpb.eq.16	a,555(dp),next0
    FAIL
next0:
    pop	    a
    and.16   a,0xf
    cmpb.eq.16	a,555+6(dp),next1
    FAIL
next1:

SUBTEST(2)
;   <op>.16  a,u8(sp) # Don't forget to reset SP!
    ld.16   a,d2
    lea	    a,-55(a)
    copy    sp,a
    ld.16    a,55(sp)
    cmp.16   a,55+2(sp)
    cmpb.eq.16	a,55(sp),next2
    FAIL
next2:
next3:
    ld.16   a,0x7000
    copy    sp,a

SUBTEST(3)
;   <op>.16  a,u8(b)
    ld.16   a,d3
    lea	    b,-5(a)
    ld.16    a,5(b)
    cmp.16   a,5+2(b)
    push    msw
    cmpb.eq.16	a,5(b),next4
    FAIL
next4:
    pop	    a
    and.16   a,0xf
    cmpb.eq.16	a,5+6(b),next5
    FAIL
next5:

SUBTEST(4)
;   <op>.16  a,u16
    ld.16   a,d4
    lea	    b,-15(a)
    ld.16    a,15(b)
    cmp.16   a,0x0100
    push    msw
    cmpb.eq.16	a,15(b),next6
    FAIL
next6:
    pop	    a
    and.16   a,0xf
    cmpb.eq.16	a,15+6(b),next7
    FAIL
next7:

SUBTEST(6)
;   <op>.8  a,0
    ld.16    a,0
    cmp.16   a,0
    push    msw
    cmpb.eq.16	a,0,next10
    FAIL
next10:
    pop	a
    and.16   a,0xf
    cmpb.eq.16	a,3,next11
    FAIL
next11:

SUBTEST(7)
;   <op>.16  a,a
    ld.16    a,-5
    ld.16    b,-5
    cmp.16   a,b
    push    msw
    cmpb.eq.16	a,-5,next12
    FAIL
next12:
    pop	a
    and.16   a,0xf
    cmpb.eq.16	a,3,next13
    FAIL
next13:

SUBTEST(8)
;   <op>.16  a,b
    ld.16    a,-6
    ld.16    b,10
    cmp.16   a,b
    push    msw
    cmpb.eq.16	a,-6,next14
    FAIL
next14:
    pop	a
    and.16   a,0xf
    cmpb.eq.16	a,6,next15
    FAIL
next15:

SUBTEST(9)
;   <op>.8  a,1
    ld.16    a,1
    cmp.16   a,1
    push    msw
    cmpb.ne.16	a,0,next16
    FAIL
next16:
    pop	a
    and.16   a,0xf
    cmpb.eq.16	a,3,next17
    FAIL
next17:

;   Finally, when done branch to pass
    END_TEST
