summaryrefslogtreecommitdiff
path: root/src/TRK_MINNOW_DOLPHIN/Portable/dispatch.c
blob: 5b2dcf167a05ca88e77ad35fb62c2c143c50752a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
 * dispatch.c
 * Description:
 */

#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/dispatch.h"
#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/msgbuf.h"
#include "TRK_MINNOW_DOLPHIN/utils/common/MWTrace.h"

u32 gTRKDispatchTableSize;

struct DispatchEntry {
	int (*fn)(TRKBuffer*);
};

extern int TRKDoUnsupported(TRKBuffer*);
extern int TRKDoConnect(TRKBuffer*);
extern int TRKDoDisconnect(TRKBuffer*);
extern int TRKDoReset(TRKBuffer*);
extern int TRKDoVersions(TRKBuffer*);
extern int TRKDoSupportMask(TRKBuffer*);
extern int TRKDoCPUType(TRKBuffer*);
extern int TRKDoReadMemory(TRKBuffer*);
extern int TRKDoWriteMemory(TRKBuffer*);
extern int TRKDoReadRegisters(TRKBuffer*);
extern int TRKDoWriteRegisters(TRKBuffer*);
extern int TRKDoFlushCache(TRKBuffer*);
extern int TRKDoContinue(TRKBuffer*);
extern int TRKDoStep(TRKBuffer*);
extern int TRKDoStop(TRKBuffer*);

struct DispatchEntry gTRKDispatchTable[33] = {
	{ &TRKDoUnsupported },   { &TRKDoConnect },        { &TRKDoDisconnect },
	{ &TRKDoReset },         { &TRKDoVersions },       { &TRKDoSupportMask },
	{ &TRKDoCPUType },       { &TRKDoUnsupported },    { &TRKDoUnsupported },
	{ &TRKDoUnsupported },   { &TRKDoUnsupported },    { &TRKDoUnsupported },
	{ &TRKDoUnsupported },   { &TRKDoUnsupported },    { &TRKDoUnsupported },
	{ &TRKDoUnsupported },   { &TRKDoReadMemory },     { &TRKDoWriteMemory },
	{ &TRKDoReadRegisters }, { &TRKDoWriteRegisters }, { &TRKDoUnsupported },
	{ &TRKDoUnsupported },   { &TRKDoFlushCache },     { &TRKDoUnsupported },
	{ &TRKDoContinue },      { &TRKDoStep },           { &TRKDoStop },
	{ &TRKDoUnsupported },   { &TRKDoUnsupported },    { &TRKDoUnsupported },
	{ &TRKDoUnsupported },   { &TRKDoUnsupported },
};

DSError TRKInitializeDispatcher() {
	gTRKDispatchTableSize = 32;
    return DS_NoError;
}

BOOL TRKDispatchMessage(TRKBuffer* buffer) {
    DSError error;
	u8 command;

	error = DS_DispatchError;
	TRKSetBufferPosition(buffer, 0);
	TRKReadBuffer1_ui8(buffer, &command);
	if (command < gTRKDispatchTableSize) {
		error = gTRKDispatchTable[command].fn(buffer);
	}
	return error;
}