; IBM/Microsoft Confidential
;
; Copyright (c) IBM Corporation 1987, 1989
; Copyright (c) Microsoft Corporation 1987, 1989
;
; All Rights Reserved


; dbprtdef.inc - definition of DBPRT macro.



;**     DBPRT - Print debugging statement
;
;       DBPRT   n,m,<format string>, <arg list>
;
;       Where N and M are bit masks (see ?debugtest).
;
;       USES    FLAGS

DBPRT   macro   n,m,string,args
local skip,str
ifdef PMDEBUG
    CONST segment
    str: db '&string',0
    CONST ends

    pushf
;;  ?debugtst n,m       ;; 2 lines removed - save runtime code space
;;  jz    short skip
    push  ax
    push  offset str    ;; push address of string
    mov   ax,sp
    irp y,<args>
        ifidni <y>,<ax>
            xchg  ax,bp
            push  [bp+2]
            xchg  ax,bp
        else
            push  y
        endif
    endm
    if2
        ifndef DPRINTF
            extrn DPRINTF:near
        endif
    endif
    call DPRINTF
    mov   sp,ax
    pop   ax            ;; discard format string offset
    pop   ax
skip:
    popf
endif
endm



;**     DBBEG - Start debugging range
;

DBBEG   macro   n,m
local doit
    ifdef PMDEBUG
        pushf
        ?debugtst n,m
        jnz   short doit
        ?dbjmp %?dbcnt
      doit:
    endif
endm



;**     ?debugtst - Test Debug Flags
;
;       ?debugtst   n,m,a
;
;       Where N and M are bit masks.
;
;       If one or more of the bits in N is set in the high byte
;       of BUGBITS, and one or more of the bits in M is set in
;       the low byte of BUGBITS then clear the Z flag.
;
;       In other words:
;
;       If both masks show a "hit" clear 'Z' else set 'Z'
;
;       USES    FLAGS

ifdef PMDEBUG
        extrn   _dbflag:word
?debugtst macro n,m
    test  [_dbflag],n
endm
endif



;**     DBEND - Terminate debugging range
;

DBEND macro
    ifdef PMDEBUG
        ?dblab %?dbcnt
        ?dbcnt = ?dbcnt+1
        popf
    endif
endm



;**     DBJMP - Jump to a debugging label
;

?dbjmp macro n
    jmp ?dblab&n
endm



;**     DBLAB - Generate a debugging label
;

?dblab macro n
?dblab&n:
endm

  ?dbcnt = 1

