	Title Routine to attach an interrupt vector to a Trap channel
	Page 60,130
Comment *
	Created 11-12-1987 k. murray
	Updates:
		None.

	Usage:
		Attach IntNo%,TrapChannelNo%
*	

	; Macro to define the trap channel handlers
TrapH	Macro Ch
Trap&Ch:
	Push	Ax
	Push	Dx
if Ch LE 16
	Xor	Dx,Dx		; high order is zero
	Mov	Ax,1 Shl (Ch-1)
else
	Xor	Ax,Ax
	Mov	Dx,1 Shl (Ch-17)
endif
	Jmp	IntCom
Endm

Cseg	Segment byte public 'Code'
	Assume Cs:Cseg,Ds:nothing,Es:nothing
Comment *
	Stack Frame:
	Bp+8	Interrupt #
	Bp+6	Trap Channel # adr.
	Bp+4	Return Segment
	Bp+2	Return Offset
	Bp+0	Saved Bp
*

Start:
Attach proc far
	Push	Bp
	Mov	Bp,Sp
	Mov	Cs:SvDs,Ds		; save data segment
	Mov	Bx,[Bp+6]		; get adr. of channel #
	Mov	Bx,[Bx]			; Get the channel #
	Dec	Bx			; make relative to zero
	And	Bx,01fh			; keep only lower 5 bits
	Shl	Bx,1			; mult by 2
	Mov	Dx,Cs:[Bx+offset TrapHList]	; get adr. for desired trap #
	Mov	Bx,[Bp+8]		; get adr. of interrupt #
	Mov	Ax,[Bx]			; Get interrupt # in Al
	Mov	Ah,25h			; Ah=Set interrupt vector call
	Push	Ds
	Mov	Bx,Cs
	Mov	Ds,Bx			; Ds:Dx=pointer to interrupt handler
	Int	21h			; set vector
	Pop	Ds
	Pop	Bp
	Ret	2*2			; remove 2 parameters
Attach endp

SvDs	Dw	0
TrapHList	Dw	offset Trap1
	Dw	offset Trap2
	Dw	offset Trap3
	Dw	offset Trap4
	Dw	offset Trap5
	Dw	offset Trap6
	Dw	offset Trap7
	Dw	offset Trap8
	Dw	offset Trap9
	Dw	offset Trap10
	Dw	offset Trap11
	Dw	offset Trap12
	Dw	offset Trap13
	Dw	offset Trap14
	Dw	offset Trap15
	Dw	offset Trap16
	Dw	offset Trap17
	Dw	offset Trap18
	Dw	offset Trap19
	Dw	offset Trap20
	Dw	offset Trap21
	Dw	offset Trap22
	Dw	offset Trap23
	Dw	offset Trap24
	Dw	offset Trap25
	Dw	offset Trap26
	Dw	offset Trap27
	Dw	offset Trap28
	Dw	offset Trap29
	Dw	offset Trap30
	Dw	offset Trap31
	Dw	offset Trap32

IntCom:
	Push	Ds
	Mov	Ds,Cs:SvDs
	Or	Ds:[0],Ax
	Or	Ds:[2],Dx		; Set trap bit
	Pop	Ds
	Pop	Dx
	Pop	Ax
	Iret				; return from interrupt
TrapH	1	
TrapH	2
TrapH	3	
TrapH	4	
TrapH	5	
TrapH	6	
TrapH	7	
TrapH	8	
TrapH	9	
TrapH	10
TrapH	11
TrapH	12
TrapH	13
TrapH	14
TrapH	15
TrapH	16
TrapH	17
TrapH	18
TrapH	19
TrapH	20
TrapH	21
TrapH	22
TrapH	23
TrapH	24
TrapH	25
TrapH	26
TrapH	27
TrapH	28
TrapH	29
TrapH	30
TrapH	31
TrapH	32

Cseg	Ends
	End	Start
