DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
include/pic.h
00001 /*
00002  *  Copyright (C) 2002-2013  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 #ifndef DOSBOX_PIC_H
00020 #define DOSBOX_PIC_H
00021 
00022 #include "dosbox.h"
00023 
00024 /* CPU Cycle Timing */
00025 extern cpu_cycles_count_t CPU_Cycles;
00026 extern cpu_cycles_count_t CPU_CycleLeft;
00027 extern cpu_cycles_count_t CPU_CycleMax;
00028 
00029 typedef void (PIC_EOIHandler) (void);
00030 typedef void (* PIC_EventHandler)(Bitu val);
00031 
00032 enum PIC_irq_hacks {
00033         PIC_irq_hack_none=0,            // dispatch IRQ normally
00034         PIC_irq_hack_cs_equ_ds          // do not fire IRQ unless segment registers in the CPU are DS == CS
00035                                         //    explanation: a handful of games and demos have Sound Blaster interrupt service
00036                                         //    routines that assume DS == CS and they make no attempt to reload DS to refer
00037                                         //    to local variables properly. eventually these programs crash or malfunction
00038                                         //    because sooner or later, the ISR is called with CS != DS. This hack can be
00039                                         //    used to prevent those games/demos from crashing.
00040 };
00041 
00042 extern enum PIC_irq_hacks PIC_IRQ_hax[16];
00043 
00044 void PIC_Set_IRQ_hack(int IRQ,enum PIC_irq_hacks hack);
00045 enum PIC_irq_hacks PIC_parse_IRQ_hack_string(const char *str);
00046 
00047 extern Bitu PIC_IRQCheck;
00048 extern Bitu PIC_Ticks;
00049 
00050 typedef double pic_tickindex_t;
00051 
00052 static INLINE pic_tickindex_t PIC_TickIndex(void) {
00053         return ((pic_tickindex_t)(CPU_CycleMax-CPU_CycleLeft-CPU_Cycles)) / ((pic_tickindex_t)CPU_CycleMax);
00054 }
00055 
00056 static INLINE Bits PIC_TickIndexND(void) {
00057         return CPU_CycleMax-CPU_CycleLeft-CPU_Cycles;
00058 }
00059 
00060 static INLINE Bits PIC_MakeCycles(const pic_tickindex_t amount) {
00061         return (Bits)((pic_tickindex_t)CPU_CycleMax * amount);
00062 }
00063 
00064 static INLINE pic_tickindex_t PIC_FullIndex(void) {
00065         return (pic_tickindex_t)PIC_Ticks + PIC_TickIndex();
00066 }
00067 
00068 void PIC_ActivateIRQ(Bitu irq);
00069 void PIC_DeActivateIRQ(Bitu irq);
00070 
00071 void PIC_runIRQs(void);
00072 bool PIC_RunQueue(void);
00073 
00074 //Delay in milliseconds
00075 void PIC_AddEvent(PIC_EventHandler handler,pic_tickindex_t delay,Bitu val=0);
00076 void PIC_RemoveEvents(PIC_EventHandler handler);
00077 void PIC_RemoveSpecificEvents(PIC_EventHandler handler, Bitu val);
00078 
00079 void PIC_SetIRQMask(Bitu irq, bool masked);
00080 #endif