DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
include/callback.h
00001 /*
00002  *  Copyright (C) 2002-2015  The DOSBox Team
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 
00020 #ifndef DOSBOX_CALLBACK_H
00021 #define DOSBOX_CALLBACK_H
00022 
00023 #ifndef DOSBOX_MEM_H
00024 #include "mem.h"
00025 #endif 
00026 
00027 typedef Bitu (*CallBack_Handler)(void);
00028 extern CallBack_Handler CallBack_Handlers[];
00029 
00030 enum { CB_RETN,CB_RETF,CB_RETF8,CB_IRET,CB_IRETD,CB_IRET_STI,CB_IRET_EOI_PIC1,
00031                 CB_IRQ0,CB_IRQ1,CB_IRQ1_BREAK,CB_IRQ9,CB_IRQ12,CB_IRQ12_RET,CB_IRQ6_PCJR,CB_MOUSE,
00032                 /*CB_INT28,*/CB_INT29,CB_INT16,CB_HOOKABLE,CB_TDE_IRET,CB_IPXESR,CB_IPXESR_RET,
00033                 CB_INT21,CB_INT13,CB_VESA_START,CB_IRET_EOI_PIC2,CB_CPM };
00034 
00035 /* NTS: Cannot make runtime configurable, because CB_MAX is used to define an array */
00036 #define CB_MAX          128U
00037 #define CB_SIZE         32U
00038 
00039 /* we can make THESE configurable though! */
00040 //#define CB_SEG        0xF000
00041 //#define CB_SOFFSET    0x1000
00042 extern Bit16u CB_SEG,CB_SOFFSET;
00043 
00044 enum {  
00045         CBRET_NONE=0,CBRET_STOP=1
00046 };
00047 
00048 extern Bit8u lastint;
00049 
00050 static INLINE RealPt CALLBACK_RealPointer(Bitu callback) {
00051         return RealMake(CB_SEG,(Bit16u)(CB_SOFFSET+callback*CB_SIZE));
00052 }
00053 static INLINE PhysPt CALLBACK_PhysPointer(Bitu callback) {
00054         return PhysMake(CB_SEG,(Bit16u)(CB_SOFFSET+callback*CB_SIZE));
00055 }
00056 
00057 static inline PhysPt CALLBACK_GetBase(void) {
00058         return (PhysPt)(((PhysPt)CB_SEG << (PhysPt)4U) + (PhysPt)CB_SOFFSET);
00059 }
00060 
00061 Bitu CALLBACK_Allocate();
00062 
00063 void CALLBACK_Idle(void);
00064 
00065 
00066 void CALLBACK_RunRealInt(Bit8u intnum);
00067 void CALLBACK_RunRealFar(Bit16u seg,Bit16u off);
00068 void CALLBACK_RunRealFarInt(Bit16u seg,Bit16u off);
00069 
00070 bool CALLBACK_Setup(Bitu callback,CallBack_Handler handler,Bitu type,const char* descr);
00071 Bitu CALLBACK_Setup(Bitu callback,CallBack_Handler handler,Bitu type,PhysPt addr,const char* descr);
00072 
00073 void CALLBACK_SetDescription(Bitu nr, const char* descr);
00074 const char* CALLBACK_GetDescription(Bitu callback);
00075 bool CALLBACK_Free(Bitu callback);
00076 
00077 void CALLBACK_SCF(bool val);
00078 void CALLBACK_SZF(bool val);
00079 void CALLBACK_SIF(bool val);
00080 
00081 extern Bitu call_priv_io;
00082 
00083 
00084 class CALLBACK_HandlerObject{
00085 private:
00086         bool installed;
00087         Bitu m_callback;
00088         enum {NONE,SETUP,SETUPAT} m_type;
00089     struct {    
00090                 RealPt old_vector;
00091                 Bit8u interrupt;
00092                 bool installed;
00093         } vectorhandler;
00094 public:
00095         CALLBACK_HandlerObject():installed(false),m_type(NONE) {
00096                 vectorhandler.installed=false;
00097         }
00098         ~CALLBACK_HandlerObject();
00099 
00100         //Install and allocate a callback.
00101         void Install(CallBack_Handler handler,Bitu type,const char* description);
00102         void Install(CallBack_Handler handler,Bitu type,PhysPt addr,const char* description);
00103 
00104         void Uninstall();
00105 
00106         //Only allocate a callback number
00107         void Allocate(CallBack_Handler handler,const char* description=0);
00108         Bit16u Get_callback() {
00109                 return (Bit16u)m_callback;
00110         }
00111         RealPt Get_RealPointer() {
00112                 return CALLBACK_RealPointer(m_callback);
00113         }
00114         void Set_RealVec(Bit8u vec,bool reinstall=false);
00115 };
00116 #endif