1 /*
2  *  Copyright (C) 2002-2010  The DOSBox Team
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  */
18 
19 /* $Id: inout.h,v 1.13 2009-05-27 09:15:41 qbix79 Exp $ */
20 
21 #ifndef DOSBOX_INOUT_H
22 #define DOSBOX_INOUT_H
23 
24 #define IO_MAX (64*1024+3)
25 
26 #define IO_MB	0x1
27 #define IO_MW	0x2
28 #define IO_MD	0x4
29 #define IO_MA	(IO_MB | IO_MW | IO_MD )
30 
31 typedef Bitu IO_ReadHandler(Bitu port,Bitu iolen);
32 typedef void IO_WriteHandler(Bitu port,Bitu val,Bitu iolen);
33 
34 extern IO_WriteHandler * io_writehandlers[3][IO_MAX];
35 extern IO_ReadHandler * io_readhandlers[3][IO_MAX];
36 
37 void IO_RegisterReadHandler(Bitu port,IO_ReadHandler * handler,Bitu mask,Bitu range=1);
38 void IO_RegisterWriteHandler(Bitu port,IO_WriteHandler * handler,Bitu mask,Bitu range=1);
39 
40 void IO_FreeReadHandler(Bitu port,Bitu mask,Bitu range=1);
41 void IO_FreeWriteHandler(Bitu port,Bitu mask,Bitu range=1);
42 
43 void IO_WriteB(Bitu port,Bitu val);
44 void IO_WriteW(Bitu port,Bitu val);
45 void IO_WriteD(Bitu port,Bitu val);
46 
47 Bitu IO_ReadB(Bitu port);
48 Bitu IO_ReadW(Bitu port);
49 Bitu IO_ReadD(Bitu port);
50 
51 /* Classes to manage the IO objects created by the various devices.
52  * The io objects will remove itself on destruction.*/
53 class IO_Base{
54 protected:
55 	bool installed;
56 	Bitu m_port, m_mask,m_range;
57 public:
IO_Base()58 	IO_Base():installed(false){};
59 };
60 class IO_ReadHandleObject: private IO_Base{
61 public:
62 	void Install(Bitu port,IO_ReadHandler * handler,Bitu mask,Bitu range=1);
63 	~IO_ReadHandleObject();
64 };
65 class IO_WriteHandleObject: private IO_Base{
66 public:
67 	void Install(Bitu port,IO_WriteHandler * handler,Bitu mask,Bitu range=1);
68 	~IO_WriteHandleObject();
69 };
70 
IO_Write(Bitu port,Bit8u val)71 static INLINE void IO_Write(Bitu port,Bit8u val) {
72 	IO_WriteB(port,val);
73 }
IO_Read(Bitu port)74 static INLINE Bit8u IO_Read(Bitu port){
75 	return (Bit8u)IO_ReadB(port);
76 }
77 
78 #endif
79