1 /*
2 	_intc.c   -	Interrupt Override Handling
3 
4 	Copyright (C) 1984-2003 David L. Clark.
5 	This program is free software; you can redistribute it and/or modify it under
6 	the terms of the GNU General Public License as published by the Free Software
7 	Foundation; either version 2 of the License, or (at your option) any later
8 	version. This program is distributed in the hope that it will be useful,
9 	but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 	or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 	more details. You should have received a copy of the GNU General Public
12 	License along with this program; if not, write to the Free Software Foundation,
13 	Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
14 
15 			Author: Dave Clark
16 
17 	Modification History:
18 			84-03-15	Development
19 			85-11-06	Atari
20 			87-03-10	Microsoft compiler.
21 			2003-01-27	GNU General Public License
22 
23 	Usage:	--------------------------------------------------------
24 		_intsetup( inter, offset );
25 		int	inter, *offset;
26 
27 		replaces the vector for the specified interrupt with the
28 		IP:CS passed in as the driver address.
29 
30 		returns an index into the overridden interrupt table if
31 		successful, -1 if not.
32 		--------------------------------------------------------
33 
34 		_intreset( index )
35 		int	index;
36 
37 		resets the interrupt vector for the specified index into
38 		the interrupt table.  Returns the index passed if
39 		successful, -1 if not.
40 
41 		---------------------------------------------------
42 
43 		_intterm()
44 
45 		Call to cleanup all overridden vectors.to cleanup
46 */
47 
48 
49 #include	"std.h"
50 #define MAXINTS 10
51 
52 
53 
54 
55 struct {
56 	long	newserv;
57 	long	oldserv;
58 	int	internum;
59 }	_inttab[MAXINTS];
60 
61 
62 
63 _intsetup( inter, offset )
64 int	inter, *offset;
65 {
66 char	 *vec1, *vec2;
67 int	 _int1vec(), _int2vec();
68 long	 get_ivec();
69 register i;
70 
71 
72 	/*					   */
73 	/*	Find an empty slot in the table    */
74 	/*					   */
75 
76 	for ( i = 0; i < MAXINTS ; ++i )
77 		if ( !_inttab[i].internum )
78 			break;
79 	if ( i == MAXINTS )
80 		return( -1 );
81 	_inttab[i].internum = inter + 1;
82 
83 
84 
85 	/*					    */
86 	/*	Get old interrupt vector	    */
87 	/*	Set up new interrupt vector	    */
88 	/*					    */
89 
90 	_inttab[i].oldserv = get_ivec( inter );
91 	_inttab[i].newserv = (long) offset;
92 	vec1 = (char *)_int1vec;
93 	vec2 = (char *)_int2vec;
94 	set_ivec( inter, vec1 + (int)( vec2 - vec1 ) * i, csseg() );
95 
96 	return( i );
97 }
98 
99 
100 
101 _intreset( i )
102 int	i;
103 {
104 	/*					      */
105 	/*	Edit the index passed		      */
106 	/*					      */
107 
108 	if ( ( i < 0 ) || ( i >= MAXINTS )
109 		|| ( _inttab[i].internum == 0 ) )
110 		return( -1 );
111 
112 
113 	/*					    */
114 	/*	Reset Vector.			    */
115 	/*					    */
116 
117 	set_ivec( _inttab[i].internum - 1, _inttab[i].oldserv );
118 	_inttab[i].internum = 0;
119 
120 	return( i );
121 }
122 
123 
124 
125 _intterm()
126 {
127 register int	i;
128 
129 	for ( i = MAXINTS - 1; i >= 0; --i )
130 		if ( _inttab[i].internum )
131 			_intreset( i );
132 }
133 