diff --git a/include/pic.h b/include/pic.h index c2a8a525..43caaf40 100644 --- a/include/pic.h +++ b/include/pic.h @@ -32,21 +32,20 @@ typedef void (* PIC_EventHandler)(Bitu val); #define PIC_MAXIRQ 15 #define PIC_NOIRQ 0xFF - extern Bitu PIC_IRQCheck; extern Bitu PIC_IRQActive; extern Bitu PIC_Ticks; -INLINE Bitu PIC_Index(void) { - return ((CPU_CycleMax-CPU_CycleLeft-CPU_Cycles)*1000)/CPU_CycleMax; +INLINE float PIC_TickIndex(void) { + return (CPU_CycleMax-CPU_CycleLeft-CPU_Cycles)/(float)CPU_CycleMax; } -INLINE Bits PIC_MakeCycles(Bitu amount) { - return (CPU_CycleMax*amount)/1000; +INLINE Bits PIC_MakeCycles(double amount) { + return (Bits)(CPU_CycleMax*amount); } -INLINE Bit64u PIC_MicroCount(void) { - return PIC_Ticks*1000+PIC_Index(); +INLINE double PIC_FullIndex(void) { + return PIC_Ticks+PIC_TickIndex(); } void PIC_ActivateIRQ(Bitu irq); @@ -55,7 +54,8 @@ void PIC_DeActivateIRQ(Bitu irq); void PIC_runIRQs(void); bool PIC_RunQueue(void); -void PIC_AddEvent(PIC_EventHandler handler,Bitu delay,Bitu val=0); +//Delay in milliseconds +void PIC_AddEvent(PIC_EventHandler handler,float delay,Bitu val=0); void PIC_RemoveEvents(PIC_EventHandler handler); void PIC_SetIRQMask(Bitu irq, bool masked); diff --git a/include/vga.h b/include/vga.h index 893834db..a8814c06 100644 --- a/include/vga.h +++ b/include/vga.h @@ -89,7 +89,6 @@ typedef struct { typedef struct { bool resizing; - bool drawing; Bitu width; Bitu height; Bitu blocks; @@ -106,20 +105,21 @@ typedef struct { Bitu parts_lines; Bitu parts_left; struct { - Bitu vtotal; - Bitu vstart; - Bitu vend; - Bitu htotal; - Bitu hstart; - Bitu hend; - Bitu parts; - } micro; + float vtotal; + float vstart; + float vend; + float htotal; + float hstart; + float hend; + float parts; + } delay; bool double_scan; bool doublewidth,doubleheight; Bit8u font[64*1024]; Bit8u * font_tables[2]; Bitu blinking; struct { + Bitu address; Bit8u sline,eline; Bit8u count,delay; Bit8u enabled; diff --git a/src/hardware/adlib.cpp b/src/hardware/adlib.cpp index 10a9d690..01f62add 100644 --- a/src/hardware/adlib.cpp +++ b/src/hardware/adlib.cpp @@ -62,7 +62,7 @@ namespace OPL2 { } void TimerHandler(int channel,double interval_Sec) { if (interval_Sec==0.0) return; - PIC_AddEvent(TimerOver,(Bitu)(1000000.0*interval_Sec),channel); + PIC_AddEvent(TimerOver,1000.0f*interval_Sec,channel); } } #undef OSD_CPU_H @@ -75,7 +75,7 @@ namespace THEOPL3 { } void TimerHandler(int channel,double interval_Sec) { if (interval_Sec==0.0) return; - PIC_AddEvent(TimerOver,(Bitu)(1000000.0*interval_Sec),channel); + PIC_AddEvent(TimerOver,1000.0f*interval_Sec,channel); } } @@ -125,7 +125,7 @@ static void OPL_CallBack(Bitu len) { opl.chan->AddSamples_s16(len,(Bit16s*)MixTemp); break; } - if ((PIC_Ticks-opl.last_used)>5000) { + if ((PIC_Ticks-opl.last_used)>30000) { opl.chan->Enable(false); opl.active=false; } diff --git a/src/hardware/cmos.cpp b/src/hardware/cmos.cpp index cd878a98..59cf9eb1 100644 --- a/src/hardware/cmos.cpp +++ b/src/hardware/cmos.cpp @@ -33,34 +33,28 @@ static struct { struct { bool enabled; Bit8u div; - Bitu micro; + float delay; } timer; struct { - Bit64u timer; - Bit64u ended; - Bit64u alarm; + double timer; + double ended; + double alarm; } last; - bool ack; bool update_ended; } cmos; static void cmos_timerevent(Bitu val) { PIC_ActivateIRQ(8); - if(cmos.timer.enabled) PIC_AddEvent(cmos_timerevent,cmos.timer.micro); - if (cmos.ack) { - PIC_AddEvent(cmos_timerevent,cmos.timer.micro); - cmos.regs[0x0c]|=0x0a0; - cmos.ack=false; - } + if (cmos.timer.enabled) PIC_AddEvent(cmos_timerevent,cmos.timer.delay); } static void cmos_checktimer(void) { PIC_RemoveEvents(cmos_timerevent); if (cmos.timer.div<=2) cmos.timer.div+=7; - cmos.timer.micro=(Bitu) (1000000.0/(32768.0 / (1 << (cmos.timer.div - 1)))); + cmos.timer.delay=(1000.0f/(32768.0f / (1 << (cmos.timer.div - 1)))); if (!cmos.timer.div || !cmos.timer.enabled) return; - LOG(LOG_PIT,LOG_NORMAL)("RTC Timer at %f hz",1000000.0/cmos.timer.micro); - PIC_AddEvent(cmos_timerevent,cmos.timer.micro); + LOG(LOG_PIT,LOG_NORMAL)("RTC Timer at %.2f hz",1000.0/cmos.timer.delay); + PIC_AddEvent(cmos_timerevent,cmos.timer.delay); } void cmos_selreg(Bitu port,Bitu val,Bitu iolen) { @@ -146,7 +140,7 @@ static Bitu cmos_readreg(Bitu port,Bitu iolen) { case 0x05: /* Hours Alarm */ return cmos.regs[cmos.reg]; case 0x0a: /* Status register C */ - if (PIC_Index()<0x2) { + if (PIC_TickIndex()<0.002) { return (cmos.regs[0x0a]&0x7f) | 0x80; } else { return (cmos.regs[0x0a]&0x7f); @@ -160,12 +154,12 @@ static Bitu cmos_readreg(Bitu port,Bitu iolen) { } else { /* Give correct values at certain times */ Bit8u val=0; - Bit64u index=PIC_MicroCount(); - if (index>=(cmos.last.timer+cmos.timer.micro)) { + double index=PIC_FullIndex(); + if (index>=(cmos.last.timer+cmos.timer.delay)) { cmos.last.timer=index; val|=0x40; } - if (index>=(cmos.last.ended+1000000)) { + if (index>=(cmos.last.ended+1000)) { cmos.last.ended=index; val|=0x10; } diff --git a/src/hardware/gus.cpp b/src/hardware/gus.cpp index 40ff9785..5da73907 100644 --- a/src/hardware/gus.cpp +++ b/src/hardware/gus.cpp @@ -79,7 +79,7 @@ struct GFGus { bool raiseirq; bool masked; bool running; - Bit32u delay; + float delay; } timers[2]; Bit32u rate; Bit16u portbase; @@ -366,8 +366,8 @@ static void GUSReset(void) { myGUS.timers[0].value = 0xff; myGUS.timers[1].value = 0xff; - myGUS.timers[0].delay = 80; - myGUS.timers[1].delay = 320; + myGUS.timers[0].delay = 0.080f; + myGUS.timers[1].delay = 0.320f; myGUS.ChangeIRQDMA = false; // Stop all channels int i; @@ -471,7 +471,8 @@ static void GUS_TimerEvent(Bitu val) { myGUS.IRQStatus|=0x4 << val; GUS_CheckIRQ(); } - if (myGUS.timers[val].running) PIC_AddEvent(GUS_TimerEvent,myGUS.timers[val].delay,val); + if (myGUS.timers[val].running) + PIC_AddEvent(GUS_TimerEvent,myGUS.timers[val].delay,val); }; @@ -588,11 +589,11 @@ static void ExecuteGlobRegister(void) { break; case 0x46: // Timer 1 control myGUS.timers[0].value = (Bit8u)(myGUS.gRegData>>8); - myGUS.timers[0].delay = (0x100 - myGUS.timers[0].value) * 80; + myGUS.timers[0].delay = (0x100 - myGUS.timers[0].value) * 0.080f; break; case 0x47: // Timer 2 control myGUS.timers[1].value = (Bit8u)(myGUS.gRegData>>8); - myGUS.timers[1].delay = (0x100 - myGUS.timers[1].value) * 320; + myGUS.timers[1].delay = (0x100 - myGUS.timers[1].value) * 0.320f; break; case 0x49: // DMA sampling control register myGUS.SampControl = (Bit8u)(myGUS.gRegData>>8); diff --git a/src/hardware/keyboard.cpp b/src/hardware/keyboard.cpp index 301876c3..203d8bca 100644 --- a/src/hardware/keyboard.cpp +++ b/src/hardware/keyboard.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: keyboard.cpp,v 1.27 2004-08-04 09:12:55 qbix79 Exp $ */ +/* $Id: keyboard.cpp,v 1.28 2004-09-10 22:15:20 harekiet Exp $ */ #include #include @@ -30,7 +30,7 @@ #include "mixer.h" #define KEYBUFSIZE 32 -#define KEYDELAY 300 //Considering 20-30 khz serial clock and 11 bits/char +#define KEYDELAY 0.300f //Considering 20-30 khz serial clock and 11 bits/char enum KeyCommands { CMD_NONE, diff --git a/src/hardware/mixer.cpp b/src/hardware/mixer.cpp index e8dbc67d..f52b9c3a 100644 --- a/src/hardware/mixer.cpp +++ b/src/hardware/mixer.cpp @@ -250,12 +250,8 @@ void MixerChannel::FillUp(void) { SDL_UnlockAudio(); return; } - Bitu filled=(done-mixer.done)*1000/(mixer.needed-mixer.done); - Bitu index=PIC_Index(); - if (filled @@ -57,7 +57,8 @@ static IRQ_Block irqs[16]; static PIC_Controller pics[2]; struct PICEntry { - Bitu index;Bitu value; + float index; + Bitu value; PIC_EventHandler event; PICEntry * next; }; @@ -294,21 +295,20 @@ static void AddEntry(PICEntry * entry) { break; } } - Bits cycles=PIC_MakeCycles(pic.next_entry->index-PIC_Index()); + Bits cycles=PIC_MakeCycles(pic.next_entry->index-PIC_TickIndex()); if (cyclesindex=index; + entry->index=delay+PIC_TickIndex();; entry->event=handler; entry->value=val; pic.free_entry=pic.free_entry->next; @@ -350,7 +350,7 @@ bool PIC_RunQueue(void) { return false; } /* Check the queue for an entry */ - Bitu index=PIC_Index(); + double index=PIC_TickIndex(); while (pic.next_entry && pic.next_entry->index<=index) { PICEntry * entry=pic.next_entry; pic.next_entry=entry->next; @@ -412,7 +412,7 @@ void TIMER_AddTick(void) { /* Go through the list of scheduled events and lower their index with 1000 */ PICEntry * entry=pic.next_entry; while (entry) { - if (entry->index>1000) entry->index-=1000; + if (entry->index>=1) entry->index-=1; else entry->index=0; entry=entry->next; } diff --git a/src/hardware/sblaster.cpp b/src/hardware/sblaster.cpp index 8c43655d..32a0e35c 100644 --- a/src/hardware/sblaster.cpp +++ b/src/hardware/sblaster.cpp @@ -425,27 +425,27 @@ static void DMA_Silent_Event(Bitu val) { } if (sb.dma.left) { Bitu bigger=(sb.dma.left > sb.dma.min) ? sb.dma.min : sb.dma.left; - Bitu index=(bigger*1000000)/sb.dma.rate; - PIC_AddEvent(DMA_Silent_Event,index,bigger); + float delay=(bigger*1000.0f)/sb.dma.rate; + PIC_AddEvent(DMA_Silent_Event,delay,bigger); } } static void END_DMA_Event(Bitu val) { - GenerateDMASound(sb.dma.left); + GenerateDMASound(val); } static void CheckDMAEnd(void) { if (!sb.dma.left) return; if (!sb.speaker) { Bitu bigger=(sb.dma.left > sb.dma.min) ? sb.dma.min : sb.dma.left; - Bitu index=(bigger*1000000)/sb.dma.rate; - PIC_AddEvent(DMA_Silent_Event,index,bigger); - LOG(LOG_SB,LOG_NORMAL)("Silent DMA Transfer scheduling IRQ in %d microseconds",index); + float delay=(bigger*1000.0f)/sb.dma.rate; + PIC_AddEvent(DMA_Silent_Event,delay,bigger); + LOG(LOG_SB,LOG_NORMAL)("Silent DMA Transfer scheduling IRQ in %.3f milliseconds",delay); } else if (sb.dma.leftstart; + double index=PIC_FullIndex()-p->start; switch (p->mode) { case 0: if (p->new_mode) return false; - if (micro>p->micro) return true; + if (index>p->delay) return true; else return false; break; case 2: if (p->new_mode) return true; - micro%=p->micro; - return micro>0; + index=fmod(index,(double)p->delay); + return index>0; case 3: if (p->new_mode) return true; - micro%=p->micro; - return micro*2micro; + index=fmod(index,(double)p->delay); + return index*2delay; default: LOG(LOG_PIT,LOG_ERROR)("Illegal Mode %d for reading output",p->mode); return true; @@ -88,37 +90,32 @@ static void counter_latch(Bitu counter) { /* Fill the read_latch of the selected counter with current count */ PIT_Block * p=&pit[counter]; p->go_read_latch=false; - - Bit64s micro=PIC_MicroCount()-p->start; + double index=PIC_FullIndex()-p->start; switch (p->mode) { + case 4: /* Software Triggered Strobe */ case 0: /* Interrupt on Terminal Count */ /* Counter keeps on counting after passing terminal count */ - if (micro>p->micro) { - micro-=p->micro; - micro%=(Bit64u)(1000000/((float)PIT_TICK_RATE/(float)0x10000)); - p->read_latch=(Bit16u)(0x10000-(((double)micro/(double)p->micro)*(double)0x10000)); + if (index>p->delay) { + index-=p->delay; + index=fmod(index,(1000.0/PIT_TICK_RATE)*0x1000); + p->read_latch=(Bit16u)(0xffff-index*0xffff); } else { - p->read_latch=(Bit16u)(p->cntr-(((double)micro/(double)p->micro)*(double)p->cntr)); + p->read_latch=(Bit16u)(p->cntr-index*(PIT_TICK_RATE/1000.0)); } break; case 2: /* Rate Generator */ - micro%=p->micro; - p->read_latch=(Bit16u)(p->cntr-(((double)micro/(double)p->micro)*(double)p->cntr)); + index=fmod(index,(double)p->delay); + p->read_latch=(Bit16u)(p->cntr - (index/p->delay)*p->cntr); break; case 3: /* Square Wave Rate Generator */ - micro%=p->micro; - micro*=2; - if (micro>p->micro) micro-=p->micro; - p->read_latch=(Bit16u)(p->cntr-(((double)micro/(double)p->micro)*(double)p->cntr)); - break; - case 4: /* Software Triggered Strobe */ - if (micro>p->micro) p->read_latch=p->write_latch; - else p->read_latch=(Bit16u)(p->cntr-(((double)micro/(double)p->micro)*(double)p->cntr)); + index=fmod(index,(double)p->delay); + index*=2; + if (index>p->delay) index-=p->delay; + p->read_latch=(Bit16u)(p->cntr - (index/p->delay)*p->cntr); break; default: LOG(LOG_PIT,LOG_ERROR)("Illegal Mode %d for reading counter %d",p->mode,counter); - micro%=p->micro; - p->read_latch=(Bit16u)(p->cntr-(((double)micro/(double)p->micro)*(double)p->cntr)); + p->read_latch=0xffff; break; } } @@ -151,16 +148,15 @@ static void write_latch(Bitu port,Bitu val,Bitu iolen) { if (p->bcd == false) p->cntr = 0x10000; else p->cntr=9999; } else p->cntr = p->write_latch; - p->start=PIC_MicroCount(); - p->micro=(Bits)(1000000/((float)PIT_TICK_RATE/(float)p->cntr)); - if (!p->micro) p->micro=1; + p->start=PIC_FullIndex(); + p->delay=(1000.0f/((float)PIT_TICK_RATE/(float)p->cntr)); switch (counter) { case 0x00: /* Timer hooked to IRQ 0 */ if (p->new_mode) { p->new_mode=false; - PIC_AddEvent(PIT0_Event,p->micro); + PIC_AddEvent(PIT0_Event,p->delay); } else LOG(LOG_PIT,LOG_NORMAL)("PIT 0 Timer set without new control word"); - LOG(LOG_PIT,LOG_NORMAL)("PIT 0 Timer at %.3g Hz mode %d",PIT_TICK_RATE/(double)p->cntr,(Bit32u)p->mode); + LOG(LOG_PIT,LOG_NORMAL)("PIT 0 Timer at %.2f Hz mode %d",1000.0/p->delay,p->mode); break; case 0x02: /* Timer hooked to PC-Speaker */ // LOG(LOG_PIT,"PIT 2 Timer at %.3g Hz mode %d",PIT_TICK_RATE/(double)p->cntr,p->mode); @@ -283,10 +279,10 @@ void TIMER_Init(Section* sect) { pit[2].cntr=1320; pit[2].go_read_latch=true; - pit[0].micro=(Bits)(1000000/((float)PIT_TICK_RATE/(float)pit[0].cntr)); - pit[1].micro=(Bits)(1000000/((float)PIT_TICK_RATE/(float)pit[1].cntr)); - pit[2].micro=(Bits)(1000000/((float)PIT_TICK_RATE/(float)pit[2].cntr)); + pit[0].delay=(1000.0f/((float)PIT_TICK_RATE/(float)pit[0].cntr)); + pit[1].delay=(1000.0f/((float)PIT_TICK_RATE/(float)pit[1].cntr)); + pit[2].delay=(1000.0f/((float)PIT_TICK_RATE/(float)pit[2].cntr)); - PIC_AddEvent(PIT0_Event,pit[0].micro); + PIC_AddEvent(PIT0_Event,pit[0].delay); } diff --git a/src/hardware/vga.cpp b/src/hardware/vga.cpp index 010fe8a9..a5f6d63a 100644 --- a/src/hardware/vga.cpp +++ b/src/hardware/vga.cpp @@ -71,7 +71,7 @@ void VGA_StartResize(void) { if (!vga.draw.resizing) { vga.draw.resizing=true; /* Start a resize after 50 ms */ - PIC_AddEvent(VGA_SetupDrawing,50000); + PIC_AddEvent(VGA_SetupDrawing,50); } } diff --git a/src/hardware/vga_memory.cpp b/src/hardware/vga_memory.cpp index e3c8ced2..78846035 100644 --- a/src/hardware/vga_memory.cpp +++ b/src/hardware/vga_memory.cpp @@ -419,7 +419,7 @@ static void VGA_DoUpdateLFB(Bitu val) { void VGA_StartUpdateLFB(void) { if (!lfb_update) { lfb_update=true; - PIC_AddEvent(VGA_DoUpdateLFB,100); //100 microseconds later + PIC_AddEvent(VGA_DoUpdateLFB,0.100f); //100 microseconds later } }