;
; group t, test 1
;
; trapo

m4_include(..\tmacros.h)

INIT_TEST(t,0x01)

; declare symbols here
SYM(trap_addr)
SYM(do_overflow)
SYM(resume_addr)
SYM(fail0)

SUBTEST(1)
    ld.16   a,do_overflow
    ld.16   b,v_overflo
    st.16   0(b),a
    ld.16   a,0x7000
    copy    sp,a
    ld.16   a,0x8000
    add.16  a,a
    ld.16   a,0x1111
    copy    dp,a
    ld.16   b,0x2222
    ld.16   c,0x3333
    ld.16   a,0x4444
trap_addr:
    trapo
    halt

fail0:
    FAIL

do_overflow:
  
    ld.16    a,0(sp)
    cmpb.ne.16	a,0x1111,fail0
    ld.16   a,2(sp)
    cmpb.ne.16	a,0x3333,fail0
    ld.16   a,4(sp)
    cmpb.ne.16	a,0x2222,fail0
    ld.16   a,6(sp)
    cmpb.ne.16	a,0x4444,fail0
    ld.16   a,8(sp)
    cmpb.ne.16	a,trap_addr,fail0
    ld.16   a,10(sp)
    and.16  a,0x000f
    cmpb.ne.16	a,11,fail0
    ld.16   a,12(sp)
    cmpb.ne.16	a,0x7000,fail0

    ld.16   a,8(sp)
    add.16  a,(resume_addr-trap_addr)
    st.16   8(sp),a
    reti
    FAIL

resume_addr:

;   Finally, when done branch to pass
    END_TEST
