Changed event and ticker handlers.
Removed the micro timers. Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@1657
This commit is contained in:
parent
3001a346b2
commit
44464a2a53
9 changed files with 51 additions and 97 deletions
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 <string.h>
|
||||
#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:
|
||||
|
|
|
@ -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)-1);
|
||||
|
@ -218,7 +218,7 @@ static void MIXER_Mix(Bitu ticks) {
|
|||
MIXER_MixData(count);
|
||||
}
|
||||
|
||||
static void MIXER_Mix_NoSound(Bitu ticks) {
|
||||
static void MIXER_Mix_NoSound(void) {
|
||||
mixer.tick_remain+=mixer.tick_add;
|
||||
Bitu count=mixer.tick_remain>>MIXER_SHIFT;
|
||||
mixer.tick_remain&=((1<<MIXER_SHIFT)-1);
|
||||
|
@ -334,16 +334,16 @@ void MIXER_Init(Section* sec) {
|
|||
if (mixer.nosound) {
|
||||
LOG_MSG("MIXER:No Sound Mode Selected.");
|
||||
mixer.tick_add=((mixer.freq) << MIXER_SHIFT)/1000;
|
||||
TIMER_RegisterTickHandler(MIXER_Mix_NoSound);
|
||||
TIMER_AddTickHandler(MIXER_Mix_NoSound);
|
||||
} else if (SDL_OpenAudio(&spec, &obtained) <0 ) {
|
||||
LOG_MSG("MIXER:Can't open audio: %s , running in nosound mode.",SDL_GetError());
|
||||
mixer.tick_add=((mixer.freq) << MIXER_SHIFT)/1000;
|
||||
TIMER_RegisterTickHandler(MIXER_Mix_NoSound);
|
||||
TIMER_AddTickHandler(MIXER_Mix_NoSound);
|
||||
} else {
|
||||
mixer.freq=obtained.freq;
|
||||
mixer.blocksize=obtained.samples;
|
||||
mixer.tick_add=((mixer.freq+100) << MIXER_SHIFT)/1000;
|
||||
TIMER_RegisterTickHandler(MIXER_Mix);
|
||||
TIMER_AddTickHandler(MIXER_Mix);
|
||||
SDL_PauseAudio(0);
|
||||
}
|
||||
KEYBOARD_AddEvent(KBD_f6,KBD_MOD_CTRL,MIXER_WaveEvent);
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/* $Id: pic.cpp,v 1.16 2004-01-10 14:03:35 qbix79 Exp $ */
|
||||
/* $Id: pic.cpp,v 1.17 2004-02-07 18:35:17 harekiet Exp $ */
|
||||
|
||||
#include <list>
|
||||
|
||||
|
@ -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<Timer *> 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<Timer *>::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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue