EXCDIVZ	EQU	00H             
EXCDIVZI	EQU	0 
EXCSSI	EQU	01H             
EXCNMI	EQU	02H             
EXCBP	EQU	03H             
EXCOV	EQU	04H             
EXCOVI	EQU	1 
EXCBOUND	EQU	05H             
EXCBOUNDI	EQU	2 
EXCOP	EQU	06H             
EXCOPI	EQU	3 
EXCNOFP	EQU	07H             
EXCNOFPI	EQU	4 
EXCDED	EQU	08H             
EXCFPOVR	EQU	09H             
EXCITSS	EQU	0AH             
EXCSNP	EQU	0BH             
EXCSSONP	EQU	0CH             
EXCGP	EQU	0DH             
EXCPG	EQU	0EH             
EXCFPERR	EQU	10H             
EXCFPERRI	EQU	5 
EXCALIGN	EQU	11H             
EXCGENERIC	EQU	12H             
EXCPVW	EQU	20H             
EXCDOS	EQU	21H             
EXCDOSI	EQU	6 
EXCSW	EQU	0FFFFH           
EXCUSR	EQU	7                






















SetTrap macro   handler,sel,currtsdreg,trashreg
        .errb   <handler>                       
                .386
                push    bp
        ifnb    <currtsdreg>
                push    ss:[currtsdreg].TSDselFault
                push    ss:[currtsdreg].TSDpfnFault
                mov     ss:[currtsdreg].TSDpfnFault,handler
                ifnb    <sel>
                        mov     ss:[currtsdreg].TSDselFault,sel
                endif
        else
                ifb     <trashreg>
                        mov     bp,ss:[TKOPTDA].CurrTSD
                        push    [bp].TSDselFault
                        push    [bp].TSDpfnFault
                        mov     [bp].TSDpfnFault,handler
                        ifnb    <sel>
                                mov     [bp].TSDselFault,sel
                        endif
                        mov     bp,word ptr ss:[esp+6] 
                else
                        mov     trashreg,ss:[TKOPTDA].CurrTSD
                        push    ss:[trashreg].TSDselFault
                        push    ss:[trashreg].TSDpfnFault
                        mov     ss:[trashreg].TSDpfnFault,handler
                        ifnb    <sel>
                                mov     ss:[trashreg].TSDselFault,sel
                        endif
                endif
        endif
        CpuMode reset
        endm























PushTrap macro  clearflag,reg
    .386p
    ifnb <clearflag>
        ifdifi <clearflag>,<CLEAR>
            %out Bad clearflag <clearflag> in PushTrap
            .err
        endif
    endif
    ifb <reg>
        push    bp                      
        ifdef   TKOPTDA
            mov    bp,ss:[TKOPTDA].CurrTSD 
        else
            mov    bp,ss:CurrTSD
        endif
        push    [bp].TSDpfnFault        
        ifnb <clearflag>
            ifidni <clearflag>,<CLEAR>
                mov     [bp].TSDpfnFault,0 
            else
                %out Bad clearflag <clearflag> in PushTrap
                .err
            endif
        endif
        mov     bp,[bp].TSDselFault     
        xchg    bp,[esp+4]              
    else
        ifdef   TKOPTDA
            mov    reg,ss:[TKOPTDA].CurrTSD 
        else
            mov    reg,ss:CurrTSD
        endif
        push    ss:[reg].TSDselFault    
        push    ss:[reg].TSDpfnFault    
        ifnb <clearflag>
            mov     ss:[reg].TSDpfnFault,0 
        endif
    endif
    CpuMode reset
    endm



















PopTrap macro   reg
        .386p
        ifb     <reg>
                push    word ptr [esp+4]        
                mov     [esp+6],bp              
                ifdef   TKOPTDA
                        mov     bp,ss:[TKOPTDA].CurrTSD
                else
                        mov     bp,ss:CurrTSD   
                endif
                pop     [bp].TSDselFault        
                pop     [bp].TSDpfnFault        
                pop     bp                      
        else
                ifdef   TKOPTDA
                        mov     reg,ss:[TKOPTDA].CurrTSD
                else
                        mov     reg,ss:CurrTSD  
                endif
                pop     ss:[reg].TSDpfnFault    
                pop     ss:[reg].TSDselFault    
        endif
        CpuMode reset
        endm













ClrTrap macro   currtsdreg
        .386
        ifnb    <currtsdreg>
                pop     ss:[currtsdreg].TSDpfnFault
                pop     ss:[currtsdreg].TSDselFault
        else
                mov     bp,ss:[TKOPTDA].CurrTSD
                pop     ss:[bp].TSDpfnFault
                pop     ss:[bp].TSDselFault
        endif
        pop     bp
        CpuMode reset
        endm

