AppleWin/source/SynchronousEventManager.h
TomCh 6125c2b12d
Support for synchronous events (PR #841)
Switched Mockingboard/6522 Timer interrupts & Mousecard's VBlank interrupt to use synchronous events.
This is a linked-list of ordered timer-based event, where only the head of the list needs updating after every opcode.
2020-10-11 16:08:05 +01:00

51 lines
917 B
C++

#pragma once
class SyncEvent;
class SynchronousEventManager
{
public:
SynchronousEventManager() : m_syncEventHead(NULL)
{}
~SynchronousEventManager(){}
SyncEvent* GetHead(void) { return m_syncEventHead; }
void SetHead(SyncEvent* head) { m_syncEventHead = head; }
void Insert(SyncEvent* pNewEvent);
bool Remove(int id);
void Update(int cycles, ULONG uExecutedCycles);
void Reset(void) { m_syncEventHead = NULL; }
private:
SyncEvent* m_syncEventHead;
};
//
typedef int (*syncEventCB)(int id, int cycles, ULONG uExecutedCycles);
class SyncEvent
{
public:
SyncEvent(int id, int initCycles, syncEventCB callback)
: m_id(id),
m_cyclesRemaining(initCycles),
m_active(false),
m_callback(callback),
m_next(NULL)
{}
~SyncEvent(){}
void SetCycles(int cycles)
{
m_cyclesRemaining = cycles;
}
int m_id;
int m_cyclesRemaining;
bool m_active;
syncEventCB m_callback;
SyncEvent* m_next;
};