DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
include/pic.h
00001 /*
00002  *  Copyright (C) 2002-2020  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 along
00015  *  with this program; if not, write to the Free Software Foundation, Inc.,
00016  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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=(1u<<0u)         // 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 unsigned int PIC_IRQ_hax[16];
00043 
00044 void PIC_Set_IRQ_hack(int IRQ,unsigned int hack);
00045 unsigned int 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 pic_tickindex_t PIC_GetCurrentEventTime(void);
00053 
00054 static INLINE pic_tickindex_t PIC_TickIndex(void) {
00055         return ((pic_tickindex_t)(CPU_CycleMax-CPU_CycleLeft-CPU_Cycles)) / ((pic_tickindex_t)CPU_CycleMax);
00056 }
00057 
00058 static INLINE Bits PIC_TickIndexND(void) {
00059         return CPU_CycleMax-CPU_CycleLeft-CPU_Cycles;
00060 }
00061 
00062 static INLINE Bits PIC_MakeCycles(const pic_tickindex_t amount) {
00063         return (Bits)((pic_tickindex_t)CPU_CycleMax * amount);
00064 }
00065 
00066 static INLINE pic_tickindex_t PIC_FullIndex(void) {
00067         return (pic_tickindex_t)PIC_Ticks + PIC_TickIndex();
00068 }
00069 
00070 void PIC_ActivateIRQ(Bitu irq);
00071 void PIC_DeActivateIRQ(Bitu irq);
00072 
00073 void PIC_runIRQs(void);
00074 bool PIC_RunQueue(void);
00075 
00076 //Delay in milliseconds
00077 void PIC_AddEvent(PIC_EventHandler handler,pic_tickindex_t delay,Bitu val=0);
00078 void PIC_RemoveEvents(PIC_EventHandler handler);
00079 void PIC_RemoveSpecificEvents(PIC_EventHandler handler, Bitu val);
00080 
00081 void PIC_SetIRQMask(Bitu irq, bool masked);
00082 #endif