This repository was archived by the owner on Mar 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregdump.c
93 lines (76 loc) · 1.86 KB
/
regdump.c
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "regdump.h"
#include <assert.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
void regdump_init(
struct regdump_status* status
)
{
assert(status);
status->events = NULL;
status->length = 0;
status->index = 0;
status->delay = 0;
}
void regdump_load(
struct regdump_status* status,
const void* data,
size_t size
)
{
uint8_t* ptr = (uint8_t*)data;
uint32_t length_by_size;
assert(status);
status->events = NULL;
status->length = 0;
regdump_restart(status);
length_by_size = (uint32_t)size;
length_by_size /= sizeof(struct regdump_event);
status->length = length_by_size;
status->events = (const struct regdump_event*)(const void*)&ptr[0];
}
void regdump_restart(
struct regdump_status* status
)
{
assert(status);
status->index = 0;
status->delay = 0;
}
const struct regdump_cmd regdump_opl_tick(
struct regdump_status* status
)
{
const struct regdump_event* event = NULL;
struct regdump_cmd cmd = { 0, 0, 1 };
uint32_t delay;
assert(status);
assert(status->events);
if (status->delay) {
status->delay--;
}
if (!status->delay) {
if (status->index < status->length) {
event = &status->events[status->index++];
if (event->address_hi & 0x80) {
delay = (((uint32_t)(event->address_hi & 0x7F) << 16) |
((uint32_t)event->address_lo << 8) | event->value);
status->delay = delay;
cmd.delaying = (uint8_t)(delay > 0);
}
else {
cmd.address = (((uint16_t)event->address_hi << 8) | event->address_lo);
cmd.value = event->value;
}
}
else {
cmd.delaying = 2; // EOF
}
}
return cmd;
}
#ifdef __cplusplus
} // extern "C"
#endif