;
; group h, test 1
;
; sub.8
;

m4_include(..\tmacros.h)

INIT_TEST(h,0x01)

; 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:
    defb    0xff
    defb    0x01
    defb    0xfe
    defb    0x06
d2:
    defb    0x00
    defb    0x00
    defb    0x00
    defb    0x01
d3:
    defb    0xf0
    defb    0x0f
    defb    0xe1
    defb    0x06
d4:
    defb    0x80
    defb    0x01
    defb    0x7f
    defb    0x0a

hop:
; Begin test here

SUBTEST(1)
;   <op>.8  a,u16(dp)
    ld.16   a,d1
    lea	    a,-555(a)
    copy    dp,a
    ld.8    a,555(dp)
    sub.8   a,555+1(dp)
    push    msw
    cmpb.eq.8	a,555+2(dp),next0
    FAIL
next0:
    pop	    a
    and.8   a,0xf
    cmpb.eq.8	a,555+3(dp),next1
    FAIL
next1:

SUBTEST(2)
;   <op>.8  a,u8(sp) # Don't forget to reset SP!
    ld.16   a,d2
    lea	    a,-55(a)
    copy    sp,a
    ld.8    a,55(sp)
    sub.8   a,55+1(sp)
    cmpb.eq.8	a,55+2(sp),next2
    FAIL
next2:
next3:
    ld.16   a,0x7000
    copy    sp,a

SUBTEST(3)
;   <op>.8  a,u8(b)
    ld.16   a,d3
    lea	    b,-5(a)
    ld.8    a,5(b)
    sub.8   a,5+1(b)
    push    msw
    cmpb.eq.8	a,5+2(b),next4
    FAIL
next4:
    pop	    a
    and.8   a,0xf
    cmpb.eq.8	a,5+3(b),next5
    FAIL
next5:

SUBTEST(4)
;   <op>.8  a,u8
    ld.16   a,d4
    lea	    b,-15(a)
    ld.8    a,15(b)
    sub.8   a,0x01
    push    msw
    cmpb.eq.8	a,15+2(b),next6
    FAIL
next6:
    pop	    a
    and.8   a,0xf
    cmpb.eq.8	a,15+3(b),next7
    FAIL
next7:

SUBTEST(6)
;   <op>.8  a,1
    ld.8    a,0
    sub.8   a,1
    push    msw
    cmpb.eq.8	a,0xff,next10
    FAIL
next10:
    pop	a
    and.8   a,0xf
    cmpb.eq.8	a,4,next11
    FAIL
next11:

SUBTEST(7)
;   <op>.8  a,b
    ld.8    a,-5
    ld.8    b,-5
    sub.8   a,b
    push    msw
    cmpb.eq.8	a,0,next12
    FAIL
next12:
    pop	a
    and.8   a,0xf
    cmpb.eq.8	a,3,next13
    FAIL
next13:

SUBTEST(8)
;   <op>.8  a,b
    ld.8    a,-6
    ld.8    b,10
    sub.8   a,b
    push    msw
    cmpb.eq.8	a,-16,next14
    FAIL
next14:
    pop	a
    and.8   a,0xf
    cmpb.eq.8	a,6,next15
    FAIL
next15:

SUBTEST(9)
;   <op>.8  a,11
    ld.8    a,10
    sub.8   a,11
    push    msw
    cmpb.eq.8	a,0xff,next16
    FAIL
next16:
    pop	a
    and.8   a,0xf
    cmpb.eq.8	a,4,next17
    FAIL
next17:


;   Finally, when done branch to pass
    END_TEST
