| 9120e874 Andy McCall |
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 |
#ifndef _IO_TRACE_H_ |
| 37 |
#define _IO_TRACE_H_ |
| 38 |
|
| 39 |
#include <stdbool.h> |
| 40 |
#include <stdint.h> |
| 41 |
|
| 42 |
#ifdef __cplusplus |
| 43 |
extern "C" { |
| 44 |
#endif |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
typedef enum { |
| 50 |
IO_DEV_VIA1 = 0, |
| 51 |
IO_DEV_VIA2, |
| 52 |
IO_DEV_VERA, |
| 53 |
IO_DEV_SPI, |
| 54 |
IO_DEV_YM, |
| 55 |
IO_DEV_EMU, |
| 56 |
IO_DEV_MIDI, |
| 57 |
IO_DEV_OPENBUS, |
| 58 |
IO_DEV_SDCARD, |
| 59 |
IO_DEV_IEEE, |
| 60 |
IO_DEV_I2C, |
| 61 |
IO_DEV_JOYSTICK, |
| 62 |
IO_DEV_SERIAL, |
| 63 |
IO_DEV_COUNT |
| 64 |
} io_device_t; |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
typedef enum { |
| 72 |
IO_EVENT_ACCESS = 0, |
| 73 |
IO_EVENT_DECODED, |
| 74 |
} io_event_kind_t; |
| 75 |
|
| 76 |
#define IO_TRACE_TEXT_MAX 72 |
| 77 |
|
| 78 |
typedef struct { |
| 79 |
uint32_t seq; |
| 80 |
uint32_t cycles; |
| 81 |
uint16_t pc; |
| 82 |
uint16_t addr; |
| 83 |
uint8_t pc_bank; |
| 84 |
uint8_t value; |
| 85 |
uint8_t device; |
| 86 |
uint8_t kind; |
| 87 |
bool is_write; |
| 88 |
bool has_addr; |
| 89 |
char text[IO_TRACE_TEXT_MAX]; |
| 90 |
} io_event_t; |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
extern bool io_trace_enabled; |
| 95 |
extern uint32_t io_trace_device_mask; |
| 96 |
|
| 97 |
#define IO_TRACE_BIT(dev) (1u << (unsigned)(dev)) |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
#define IO_TRACE_MASK_DEFAULT \ |
| 102 |
(~(IO_TRACE_BIT(IO_DEV_VERA) | IO_TRACE_BIT(IO_DEV_OPENBUS))) |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
static inline bool |
| 107 |
io_trace_wants(io_device_t dev) |
| 108 |
{ |
| 109 |
return io_trace_enabled && (io_trace_device_mask & IO_TRACE_BIT(dev)) != 0; |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
typedef void (*io_trace_context_fn)(uint16_t *pc, uint8_t *pc_bank, uint32_t *cycles); |
| 116 |
void io_trace_set_context_provider(io_trace_context_fn fn); |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
bool io_trace_init(int capacity); |
| 122 |
void io_trace_shutdown(void); |
| 123 |
void io_trace_clear(void); |
| 124 |
|
| 125 |
int io_trace_capacity(void); |
| 126 |
int io_trace_count(void); |
| 127 |
uint32_t io_trace_total(void); |
| 128 |
uint32_t io_trace_dropped(void); |
| 129 |
|
| 130 |
|
| 131 |
const io_event_t *io_trace_at(int index); |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
void io_trace_access(io_device_t dev, uint16_t addr, uint8_t value, bool is_write); |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
void io_trace_event(io_device_t dev, const char *fmt, ...); |
| 144 |
|
| 145 |
|
| 146 |
void io_trace_event_at(io_device_t dev, uint16_t addr, bool is_write, const char *fmt, ...); |
| 147 |
|
| 148 |
const char *io_trace_device_name(io_device_t dev); |
| 149 |
|
| 150 |
#ifdef __cplusplus |
| 151 |
} |
| 152 |
#endif |
| 153 |
|
| 154 |
#endif |