From 44464a2a53892cec1d3f38996cc2474ef7e3c57c Mon Sep 17 00:00:00 2001 From: Sjoerd van der Berg Date: Sat, 7 Feb 2004 18:37:16 +0000 Subject: [PATCH] Changed event and ticker handlers. Removed the micro timers. Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@1657 --- include/pic.h | 4 +- include/timer.h | 14 ++---- include/vga.h | 3 +- src/hardware/cmos.cpp | 2 +- src/hardware/keyboard.cpp | 4 +- src/hardware/mixer.cpp | 10 ++-- src/hardware/pic.cpp | 103 ++++++++++++-------------------------- src/hardware/sblaster.cpp | 4 +- src/hardware/timer.cpp | 4 +- 9 files changed, 51 insertions(+), 97 deletions(-) diff --git a/include/pic.h b/include/pic.h index 05566d77..35b0d7a8 100644 --- a/include/pic.h +++ b/include/pic.h @@ -26,7 +26,7 @@ extern Bits CPU_CycleLeft; extern Bits CPU_CycleMax; typedef void (PIC_EOIHandler) (void); -typedef void (* PIC_EventHandler)(void); +typedef void (* PIC_EventHandler)(Bitu val); #define PIC_MAXIRQ 15 @@ -59,7 +59,7 @@ void PIC_RegisterIRQ(Bitu irq,PIC_EOIHandler handler,char * name); void PIC_FreeIRQ(Bitu irq); bool PIC_RunQueue(void); -void PIC_AddEvent(PIC_EventHandler handler,Bitu delay); +void PIC_AddEvent(PIC_EventHandler handler,Bitu delay,Bitu val=0); void PIC_RemoveEvents(PIC_EventHandler handler); diff --git a/include/timer.h b/include/timer.h index aada3d51..22bcbfb0 100644 --- a/include/timer.h +++ b/include/timer.h @@ -25,19 +25,11 @@ #define GetTicks() SDL_GetTicks() -typedef void (*TIMER_TickHandler)(Bitu ticks); -typedef void (*TIMER_MicroHandler)(void); - -typedef void TIMER_Block; - +typedef void (*TIMER_TickHandler)(void); /* Register a function that gets called everytime if 1 or more ticks pass */ -TIMER_Block * TIMER_RegisterTickHandler(TIMER_TickHandler handler); -/* Register a function to be called every x microseconds */ -TIMER_Block * TIMER_RegisterMicroHandler(TIMER_MicroHandler handler,Bitu micro); - -/* Set the microseconds value to a new value */ -void TIMER_SetNewMicro(TIMER_Block * block,Bitu micro); +void TIMER_AddTickHandler(TIMER_TickHandler handler); +void TIMER_DelTickHandler(TIMER_TickHandler handler); /* This will add 1 milliscond to all timers */ void TIMER_AddTick(void); diff --git a/include/vga.h b/include/vga.h index b2186477..f836a610 100644 --- a/include/vga.h +++ b/include/vga.h @@ -94,7 +94,6 @@ typedef struct { bool drawing; Bitu width; Bitu height; - Bitu pitch; Bitu blocks; Bitu panning; Bitu address; @@ -296,7 +295,7 @@ typedef struct { void VGA_SetMode(VGAModes mode); void VGA_SetupHandlers(void); void VGA_StartResize(void); -void VGA_SetupDrawing(void); +void VGA_SetupDrawing(Bitu val); /* Some DAC/Attribute functions */ void VGA_DAC_CombineColor(Bit8u attr,Bit8u pal); diff --git a/src/hardware/cmos.cpp b/src/hardware/cmos.cpp index 47a63a30..58096871 100644 --- a/src/hardware/cmos.cpp +++ b/src/hardware/cmos.cpp @@ -43,7 +43,7 @@ static struct { bool update_ended; } cmos; -static void cmos_timerevent(void) { +static void cmos_timerevent(Bitu val) { PIC_ActivateIRQ(8); if(cmos.timer.enabled) PIC_AddEvent(cmos_timerevent,cmos.timer.micro); if (cmos.ack) { diff --git a/src/hardware/keyboard.cpp b/src/hardware/keyboard.cpp index 0fcde792..cab7daf6 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.20 2004-01-29 20:13:29 qbix79 Exp $ */ +/* $Id: keyboard.cpp,v 1.21 2004-02-07 18:35:24 harekiet Exp $ */ #include #include "dosbox.h" @@ -86,7 +86,7 @@ void KEYBOARD_ClrBuffer(void) { } /* Read an entry from the keycode buffer */ -void KEYBOARD_GetCode(void) { +void KEYBOARD_GetCode(Bitu val) { keyb.scheduled=false; switch (keyb.buf.state) { case STATE_NORMAL: diff --git a/src/hardware/mixer.cpp b/src/hardware/mixer.cpp index 2886da24..2c62ddc6 100644 --- a/src/hardware/mixer.cpp +++ b/src/hardware/mixer.cpp @@ -208,7 +208,7 @@ static void MIXER_MixData(Bit32u samples) { } } -static void MIXER_Mix(Bitu ticks) { +static void MIXER_Mix(void) { mixer.tick_remain+=mixer.tick_add; Bitu count=mixer.tick_remain>>MIXER_SHIFT; mixer.tick_remain&=((1<>MIXER_SHIFT; mixer.tick_remain&=((1< @@ -58,7 +58,7 @@ static IRQ_Block irqs[16]; static PIC_Controller pics[2]; struct PICEntry { - Bitu index; + Bitu index;Bitu value; PIC_EventHandler event; PICEntry * next; }; @@ -305,7 +305,7 @@ static void AddEntry(PICEntry * entry) { } } -void PIC_AddEvent(PIC_EventHandler handler,Bitu delay) { +void PIC_AddEvent(PIC_EventHandler handler,Bitu delay,Bitu val) { if (!pic.free_entry) { LOG(LOG_PIC,LOG_ERROR)("Event queue full"); return; @@ -314,6 +314,7 @@ void PIC_AddEvent(PIC_EventHandler handler,Bitu delay) { Bitu index=delay+PIC_Index(); entry->index=index; entry->event=handler; + entry->value=val; pic.free_entry=pic.free_entry->next; AddEntry(entry); } @@ -357,7 +358,7 @@ bool PIC_RunQueue(void) { while (pic.next_entry && pic.next_entry->index<=index) { PICEntry * entry=pic.next_entry; pic.next_entry=entry->next; - (entry->event)(); + (entry->event)(entry->value); /* Put the entry in the free list */ entry->next=pic.free_entry; pic.free_entry=entry; @@ -378,90 +379,52 @@ bool PIC_RunQueue(void) { } /* The TIMER Part */ - -enum { T_TICK,T_MICRO,T_DELAY}; - -struct Timer { - Bitu type; - union { - struct { - TIMER_TickHandler handler; - } tick; - struct{ - Bits left; - Bits total; - TIMER_MicroHandler handler; - } micro; - }; +struct TickerBlock { + TIMER_TickHandler handler; + TickerBlock * next; }; -static Timer * first_timer=0; -static std::list Timers; +static TickerBlock * firstticker=0; -TIMER_Block * TIMER_RegisterTickHandler(TIMER_TickHandler handler) { - Timer * new_timer=new(Timer); - new_timer->type=T_TICK; - new_timer->tick.handler=handler; - Timers.push_front(new_timer); - return (TIMER_Block *)new_timer; -} -TIMER_Block * TIMER_RegisterMicroHandler(TIMER_MicroHandler handler,Bitu micro) { - Timer * new_timer=new(Timer); - new_timer->type=T_MICRO; - new_timer->micro.handler=handler; - Timers.push_front(new_timer); - TIMER_SetNewMicro(new_timer,micro); - return (TIMER_Block *)new_timer; -} - -void TIMER_SetNewMicro(TIMER_Block * block,Bitu micro) { - Timer * timer=(Timer *)block; - if (timer->type!=T_MICRO) E_Exit("TIMER:Illegal handler type"); - timer->micro.total=micro; - Bitu index=PIC_Index(); - while ((1000-index)>micro) { - PIC_AddEvent(timer->micro.handler,micro); - micro+=micro; - index+=micro; +void TIMER_DelTickHandler(TIMER_TickHandler handler) { + TickerBlock * ticker=firstticker; + TickerBlock * * where=&firstticker; + while (ticker) { + if (ticker->handler==handler) { + *where=ticker->next; + return; + } + where=&ticker->next; + ticker=ticker->next; } - timer->micro.left=timer->micro.total-(1000-index); +} + +void TIMER_AddTickHandler(TIMER_TickHandler handler) { + TickerBlock * newticker=new TickerBlock; + newticker->next=firstticker; + newticker->handler=handler; + firstticker=newticker; } void TIMER_AddTick(void) { /* Setup new amount of cycles for PIC */ - CPU_CycleLeft=CPU_CycleMax; CPU_Cycles=0; PIC_Ticks++; - /* Go through the list of scheduled irq's and lower their index with 1000 */ + /* 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; else entry->index=0; entry=entry->next; } - Bits index; - /* Check if there are timer handlers that need to be called */ - std::list::iterator i; - for(i=Timers.begin(); i != Timers.end(); ++i) { - Timer * timers=(*i); - switch (timers->type) { - case T_TICK: - timers->tick.handler(1); - break; - case T_MICRO: - index=1000; - while (index>=timers->micro.left) { - PIC_AddEvent(timers->micro.handler,timers->micro.left); - index-=timers->micro.left; - timers->micro.left=timers->micro.total; - } - timers->micro.left-=index; - break; - default: - E_Exit("TIMER:Illegal handler type"); - } + /* Call our list of ticker handlers */ + TickerBlock * ticker=firstticker; + while (ticker) { + TickerBlock * nextticker=ticker->next; + ticker->handler(); + ticker=nextticker; } } diff --git a/src/hardware/sblaster.cpp b/src/hardware/sblaster.cpp index 93430fe8..7a28c284 100644 --- a/src/hardware/sblaster.cpp +++ b/src/hardware/sblaster.cpp @@ -525,7 +525,7 @@ static void GenerateSound(Bitu size) { } } -static void END_DMA_Event(void) { +static void END_DMA_Event(Bitu val) { GenerateDMASound(sb.dma.left); } @@ -551,7 +551,7 @@ static void DSP_ChangeMode(DSP_MODES mode) { sb.mode=mode; } -static void DSP_RaiseIRQEvent(void) { +static void DSP_RaiseIRQEvent(Bitu val) { SB_RaiseIRQ(SB_IRQ_8); } diff --git a/src/hardware/timer.cpp b/src/hardware/timer.cpp index 1e31770e..b60e8dd3 100644 --- a/src/hardware/timer.cpp +++ b/src/hardware/timer.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: timer.cpp,v 1.20 2004-01-10 11:43:41 qbix79 Exp $ */ +/* $Id: timer.cpp,v 1.21 2004-02-07 18:34:03 harekiet Exp $ */ #include "dosbox.h" #include "inout.h" @@ -43,7 +43,7 @@ struct PIT_Block { static PIT_Block pit[3]; -static void PIT0_Event(void) { +static void PIT0_Event(Bitu val) { PIC_ActivateIRQ(0); if (pit[0].mode!=0) PIC_AddEvent(PIT0_Event,pit[0].micro); }