1 |
nishi |
1 |
#pragma once
|
|
|
2 |
/*
|
|
|
3 |
sys_common.h
|
|
|
4 |
|
|
|
5 |
Common data types for chips system headers.
|
|
|
6 |
|
|
|
7 |
## zlib/libpng license
|
|
|
8 |
|
|
|
9 |
Copyright (c) 2018 Andre Weissflog
|
|
|
10 |
This software is provided 'as-is', without any express or implied warranty.
|
|
|
11 |
In no event will the authors be held liable for any damages arising from the
|
|
|
12 |
use of this software.
|
|
|
13 |
Permission is granted to anyone to use this software for any purpose,
|
|
|
14 |
including commercial applications, and to alter it and redistribute it
|
|
|
15 |
freely, subject to the following restrictions:
|
|
|
16 |
1. The origin of this software must not be misrepresented; you must not
|
|
|
17 |
claim that you wrote the original software. If you use this software in a
|
|
|
18 |
product, an acknowledgment in the product documentation would be
|
|
|
19 |
appreciated but is not required.
|
|
|
20 |
2. Altered source versions must be plainly marked as such, and must not
|
|
|
21 |
be misrepresented as being the original software.
|
|
|
22 |
3. This notice may not be removed or altered from any source
|
|
|
23 |
distribution.
|
|
|
24 |
*/
|
|
|
25 |
#include <stdint.h>
|
|
|
26 |
#include <stdbool.h>
|
|
|
27 |
#include <stddef.h>
|
|
|
28 |
|
|
|
29 |
#ifdef __cplusplus
|
|
|
30 |
extern "C" {
|
|
|
31 |
#endif
|
|
|
32 |
|
|
|
33 |
typedef struct {
|
|
|
34 |
void* ptr;
|
|
|
35 |
size_t size;
|
|
|
36 |
} chips_range_t;
|
|
|
37 |
|
|
|
38 |
typedef struct {
|
|
|
39 |
int width, height;
|
|
|
40 |
} chips_dim_t;
|
|
|
41 |
|
|
|
42 |
typedef struct {
|
|
|
43 |
int x, y, width, height;
|
|
|
44 |
} chips_rect_t;
|
|
|
45 |
|
|
|
46 |
typedef struct {
|
|
|
47 |
struct {
|
|
|
48 |
chips_dim_t dim; // framebuffer dimensions in pixels
|
|
|
49 |
chips_range_t buffer;
|
|
|
50 |
size_t bytes_per_pixel; // 1 or 4
|
|
|
51 |
} frame;
|
|
|
52 |
chips_rect_t screen;
|
|
|
53 |
chips_range_t palette;
|
|
|
54 |
bool portrait;
|
|
|
55 |
} chips_display_info_t;
|
|
|
56 |
|
|
|
57 |
typedef struct {
|
|
|
58 |
void (*func)(const float* samples, int num_samples, void* user_data);
|
|
|
59 |
void* user_data;
|
|
|
60 |
} chips_audio_callback_t;
|
|
|
61 |
|
|
|
62 |
typedef void (*chips_debug_func_t)(void* user_data, uint64_t pins);
|
|
|
63 |
typedef struct {
|
|
|
64 |
struct {
|
|
|
65 |
chips_debug_func_t func;
|
|
|
66 |
void* user_data;
|
|
|
67 |
} callback;
|
|
|
68 |
bool* stopped;
|
|
|
69 |
} chips_debug_t;
|
|
|
70 |
|
|
|
71 |
typedef struct {
|
|
|
72 |
chips_audio_callback_t callback;
|
|
|
73 |
int num_samples;
|
|
|
74 |
int sample_rate;
|
|
|
75 |
float volume;
|
|
|
76 |
} chips_audio_desc_t;
|
|
|
77 |
|
|
|
78 |
// prepare chips_audio_t snapshot for saving
|
|
|
79 |
void chips_audio_callback_snapshot_onsave(chips_audio_callback_t* snapshot);
|
|
|
80 |
// fixup chips_audio_t snapshot after loading
|
|
|
81 |
void chips_audio_callback_snapshot_onload(chips_audio_callback_t* snapshot, chips_audio_callback_t* sys);
|
|
|
82 |
// prepare chips_debut_t snapshot for saving
|
|
|
83 |
void chips_debug_snapshot_onsave(chips_debug_t* snapshot);
|
|
|
84 |
// fixup chips_debug_t snapshot after loading
|
|
|
85 |
void chips_debug_snapshot_onload(chips_debug_t* snapshot, chips_debug_t* sys);
|
|
|
86 |
|
|
|
87 |
#ifdef __cplusplus
|
|
|
88 |
} // extern "C"
|
|
|
89 |
#endif
|
|
|
90 |
|
|
|
91 |
/*--- IMPLEMENTATION ---------------------------------------------------------*/
|
|
|
92 |
#ifdef CHIPS_IMPL
|
|
|
93 |
|
|
|
94 |
void chips_audio_callback_snapshot_onsave(chips_audio_callback_t* snapshot) {
|
|
|
95 |
snapshot->func = 0;
|
|
|
96 |
snapshot->user_data = 0;
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
void chips_audio_callback_snapshot_onload(chips_audio_callback_t* snapshot, chips_audio_callback_t* sys) {
|
|
|
100 |
snapshot->func = sys->func;
|
|
|
101 |
snapshot->user_data = sys->user_data;
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
void chips_debug_snapshot_onsave(chips_debug_t* snapshot) {
|
|
|
105 |
snapshot->callback.func = 0;
|
|
|
106 |
snapshot->callback.user_data = 0;
|
|
|
107 |
snapshot->stopped = 0;
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
void chips_debug_snapshot_onload(chips_debug_t* snapshot, chips_debug_t* sys) {
|
|
|
111 |
snapshot->callback.func = sys->callback.func;
|
|
|
112 |
snapshot->callback.user_data = sys->callback.user_data;
|
|
|
113 |
snapshot->stopped = sys->stopped;
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
#endif // CHIPS_IMPL
|