... | ... |
@@ -23,12 +23,12 @@ static Uint32 advances[12] = { |
23 | 23 |
0xb504f, 0xbfc88, 0xcb2ff, 0xd7450, 0xe411f, 0xf1a1c |
24 | 24 |
}; |
25 | 25 |
|
26 |
-Audio audio[POLYPHONY]; |
|
26 |
+UxnAudio uxn_audio[POLYPHONY]; |
|
27 | 27 |
|
28 | 28 |
/* clang-format on */ |
29 | 29 |
|
30 | 30 |
static Sint32 |
31 |
-envelope(Audio *c, Uint32 age) |
|
31 |
+envelope(UxnAudio *c, Uint32 age) |
|
32 | 32 |
{ |
33 | 33 |
if(!c->r) return 0x0888; |
34 | 34 |
if(age < c->a) return 0x0888 * age / c->a; |
... | ... |
@@ -40,7 +40,7 @@ envelope(Audio *c, Uint32 age) |
40 | 40 |
} |
41 | 41 |
|
42 | 42 |
int |
43 |
-audio_render(Audio *c, Sint16 *sample, Sint16 *end) |
|
43 |
+audio_render(UxnAudio *c, Sint16 *sample, Sint16 *end) |
|
44 | 44 |
{ |
45 | 45 |
Sint32 s; |
46 | 46 |
if(!c->advance || !c->period) return 0; |
... | ... |
@@ -64,7 +64,7 @@ audio_render(Audio *c, Sint16 *sample, Sint16 *end) |
64 | 64 |
} |
65 | 65 |
|
66 | 66 |
void |
67 |
-audio_start(Audio *c, Uint16 adsr, Uint8 pitch) |
|
67 |
+audio_start(UxnAudio *c, Uint16 adsr, Uint8 pitch) |
|
68 | 68 |
{ |
69 | 69 |
if(pitch < 108 && c->len) |
70 | 70 |
c->advance = advances[pitch % 12] >> (8 - pitch / 12); |
... | ... |
@@ -85,7 +85,7 @@ audio_start(Audio *c, Uint16 adsr, Uint8 pitch) |
85 | 85 |
} |
86 | 86 |
|
87 | 87 |
Uint8 |
88 |
-audio_get_vu(Audio *c) |
|
88 |
+audio_get_vu(UxnAudio *c) |
|
89 | 89 |
{ |
90 | 90 |
int i; |
91 | 91 |
Sint32 sum[2] = {0, 0}; |
... | ... |
@@ -21,11 +21,11 @@ typedef struct { |
21 | 21 |
Uint16 i, len; |
22 | 22 |
Sint8 volume[2]; |
23 | 23 |
Uint8 pitch, repeat; |
24 |
-} Audio; |
|
24 |
+} UxnAudio; |
|
25 | 25 |
|
26 |
-extern Audio audio[POLYPHONY]; |
|
26 |
+extern UxnAudio uxn_audio[POLYPHONY]; |
|
27 | 27 |
|
28 |
-Uint8 audio_get_vu(Audio *c); |
|
29 |
-int audio_render(Audio *c, Sint16 *sample, Sint16 *end); |
|
30 |
-void audio_start(Audio *c, Uint16 adsr, Uint8 pitch); |
|
31 |
-void audio_finished_handler(Audio *c); |
|
32 | 28 |
\ No newline at end of file |
29 |
+Uint8 audio_get_vu(UxnAudio *c); |
|
30 |
+int audio_render(UxnAudio *c, Sint16 *sample, Sint16 *end); |
|
31 |
+void audio_start(UxnAudio *c, Uint16 adsr, Uint8 pitch); |
|
32 |
+void audio_finished_handler(UxnAudio *c); |
|
33 | 33 |
\ No newline at end of file |
... | ... |
@@ -13,7 +13,7 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
13 | 13 |
WITH REGARD TO THIS SOFTWARE. |
14 | 14 |
*/ |
15 | 15 |
|
16 |
-Screen screen; |
|
16 |
+UxnScreen uxn_screen; |
|
17 | 17 |
|
18 | 18 |
static Uint8 blending[5][16] = { |
19 | 19 |
{0, 0, 0, 0, 1, 0, 1, 1, 2, 2, 0, 2, 3, 3, 3, 0}, |
... | ... |
@@ -41,7 +41,7 @@ static Uint8 font[][8] = { |
41 | 41 |
{0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x80, 0x80}}; |
42 | 42 |
|
43 | 43 |
static void |
44 |
-screen_write(Screen *p, Layer *layer, Uint16 x, Uint16 y, Uint8 color) |
|
44 |
+screen_write(UxnScreen *p, Layer *layer, Uint16 x, Uint16 y, Uint8 color) |
|
45 | 45 |
{ |
46 | 46 |
if(x < p->width && y < p->height) { |
47 | 47 |
Uint32 i = x + y * p->width; |
... | ... |
@@ -53,7 +53,7 @@ screen_write(Screen *p, Layer *layer, Uint16 x, Uint16 y, Uint8 color) |
53 | 53 |
} |
54 | 54 |
|
55 | 55 |
static void |
56 |
-screen_blit(Screen *p, Layer *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy, Uint8 twobpp) |
|
56 |
+screen_blit(UxnScreen *p, Layer *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy, Uint8 twobpp) |
|
57 | 57 |
{ |
58 | 58 |
int v, h, opaque = blending[4][color]; |
59 | 59 |
for(v = 0; v < 8; ++v) { |
... | ... |
@@ -71,7 +71,7 @@ screen_blit(Screen *p, Layer *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 co |
71 | 71 |
} |
72 | 72 |
|
73 | 73 |
void |
74 |
-screen_palette(Screen *p, Uint8 *addr) |
|
74 |
+screen_palette(UxnScreen *p, Uint8 *addr) |
|
75 | 75 |
{ |
76 | 76 |
int i, shift; |
77 | 77 |
for(i = 0, shift = 4; i < 4; ++i, shift ^= 4) { |
... | ... |
@@ -86,7 +86,7 @@ screen_palette(Screen *p, Uint8 *addr) |
86 | 86 |
} |
87 | 87 |
|
88 | 88 |
void |
89 |
-screen_resize(Screen *p, Uint16 width, Uint16 height) |
|
89 |
+screen_resize(UxnScreen *p, Uint16 width, Uint16 height) |
|
90 | 90 |
{ |
91 | 91 |
Uint8 |
92 | 92 |
*bg = realloc(p->bg.pixels, width * height), |
... | ... |
@@ -106,7 +106,7 @@ screen_resize(Screen *p, Uint16 width, Uint16 height) |
106 | 106 |
} |
107 | 107 |
|
108 | 108 |
void |
109 |
-screen_clear(Screen *p, Layer *layer) |
|
109 |
+screen_clear(UxnScreen *p, Layer *layer) |
|
110 | 110 |
{ |
111 | 111 |
Uint32 i, size = p->width * p->height; |
112 | 112 |
for(i = 0; i < size; ++i) |
... | ... |
@@ -115,7 +115,7 @@ screen_clear(Screen *p, Layer *layer) |
115 | 115 |
} |
116 | 116 |
|
117 | 117 |
void |
118 |
-screen_redraw(Screen *p, Uint32 *pixels) |
|
118 |
+screen_redraw(UxnScreen *p, Uint32 *pixels) |
|
119 | 119 |
{ |
120 | 120 |
Uint32 i, size = p->width * p->height, palette[16]; |
121 | 121 |
for(i = 0; i < 16; ++i) |
... | ... |
@@ -126,7 +126,7 @@ screen_redraw(Screen *p, Uint32 *pixels) |
126 | 126 |
} |
127 | 127 |
|
128 | 128 |
void |
129 |
-screen_debug(Screen *p, Uint8 *stack, Uint8 wptr, Uint8 rptr, Uint8 *memory) |
|
129 |
+screen_debug(UxnScreen *p, Uint8 *stack, Uint8 wptr, Uint8 rptr, Uint8 *memory) |
|
130 | 130 |
{ |
131 | 131 |
Uint8 i, x, y, b; |
132 | 132 |
for(i = 0; i < 0x20; ++i) { |
... | ... |
@@ -160,10 +160,10 @@ Uint8 |
160 | 160 |
screen_dei(Device *d, Uint8 port) |
161 | 161 |
{ |
162 | 162 |
switch(port) { |
163 |
- case 0x2: return screen.width >> 8; |
|
164 |
- case 0x3: return screen.width; |
|
165 |
- case 0x4: return screen.height >> 8; |
|
166 |
- case 0x5: return screen.height; |
|
163 |
+ case 0x2: return uxn_screen.width >> 8; |
|
164 |
+ case 0x3: return uxn_screen.width; |
|
165 |
+ case 0x4: return uxn_screen.height >> 8; |
|
166 |
+ case 0x5: return uxn_screen.height; |
|
167 | 167 |
default: return d->dat[port]; |
168 | 168 |
} |
169 | 169 |
} |
... | ... |
@@ -180,7 +180,7 @@ screen_deo(Device *d, Uint8 port) |
180 | 180 |
Uint16 x = peek16(d->dat, 0x8); |
181 | 181 |
Uint16 y = peek16(d->dat, 0xa); |
182 | 182 |
Uint8 layer = d->dat[0xe] & 0x40; |
183 |
- screen_write(&screen, layer ? &screen.fg : &screen.bg, x, y, d->dat[0xe] & 0x3); |
|
183 |
+ screen_write(&uxn_screen, layer ? &uxn_screen.fg : &uxn_screen.bg, x, y, d->dat[0xe] & 0x3); |
|
184 | 184 |
if(d->dat[0x6] & 0x01) poke16(d->dat, 0x8, x + 1); /* auto x+1 */ |
185 | 185 |
if(d->dat[0x6] & 0x02) poke16(d->dat, 0xa, y + 1); /* auto y+1 */ |
186 | 186 |
break; |
... | ... |
@@ -188,10 +188,10 @@ screen_deo(Device *d, Uint8 port) |
188 | 188 |
case 0xf: { |
189 | 189 |
Uint16 x = peek16(d->dat, 0x8); |
190 | 190 |
Uint16 y = peek16(d->dat, 0xa); |
191 |
- Layer *layer = (d->dat[0xf] & 0x40) ? &screen.fg : &screen.bg; |
|
191 |
+ Layer *layer = (d->dat[0xf] & 0x40) ? &uxn_screen.fg : &uxn_screen.bg; |
|
192 | 192 |
Uint8 *addr = &d->mem[peek16(d->dat, 0xc)]; |
193 | 193 |
Uint8 twobpp = !!(d->dat[0xf] & 0x80); |
194 |
- screen_blit(&screen, layer, x, y, addr, d->dat[0xf] & 0xf, d->dat[0xf] & 0x10, d->dat[0xf] & 0x20, twobpp); |
|
194 |
+ screen_blit(&uxn_screen, layer, x, y, addr, d->dat[0xf] & 0xf, d->dat[0xf] & 0x10, d->dat[0xf] & 0x20, twobpp); |
|
195 | 195 |
if(d->dat[0x6] & 0x04) poke16(d->dat, 0xc, peek16(d->dat, 0xc) + 8 + twobpp * 8); /* auto addr+8 / auto addr+16 */ |
196 | 196 |
if(d->dat[0x6] & 0x01) poke16(d->dat, 0x8, x + 8); /* auto x+8 */ |
197 | 197 |
if(d->dat[0x6] & 0x02) poke16(d->dat, 0xa, y + 8); /* auto y+8 */ |
... | ... |
@@ -19,22 +19,22 @@ typedef struct Layer { |
19 | 19 |
Uint8 changed; |
20 | 20 |
} Layer; |
21 | 21 |
|
22 |
-typedef struct Screen { |
|
22 |
+typedef struct UxnScreen { |
|
23 | 23 |
Uint32 palette[4], *pixels; |
24 | 24 |
Uint16 width, height; |
25 | 25 |
Layer fg, bg; |
26 |
-} Screen; |
|
26 |
+} UxnScreen; |
|
27 | 27 |
|
28 |
-extern Screen screen; |
|
28 |
+extern UxnScreen uxn_screen; |
|
29 | 29 |
|
30 | 30 |
/* this should probably be done differently */ |
31 | 31 |
int set_size(Uint16 width, Uint16 height, int is_resize); |
32 | 32 |
|
33 |
-void screen_palette(Screen *p, Uint8 *addr); |
|
34 |
-void screen_resize(Screen *p, Uint16 width, Uint16 height); |
|
35 |
-void screen_clear(Screen *p, Layer *layer); |
|
36 |
-void screen_redraw(Screen *p, Uint32 *pixels); |
|
37 |
-void screen_debug(Screen *p, Uint8 *stack, Uint8 wptr, Uint8 rptr, Uint8 *memory); |
|
33 |
+void screen_palette(UxnScreen *p, Uint8 *addr); |
|
34 |
+void screen_resize(UxnScreen *p, Uint16 width, Uint16 height); |
|
35 |
+void screen_clear(UxnScreen *p, Layer *layer); |
|
36 |
+void screen_redraw(UxnScreen *p, Uint32 *pixels); |
|
37 |
+void screen_debug(UxnScreen *p, Uint8 *stack, Uint8 wptr, Uint8 rptr, Uint8 *memory); |
|
38 | 38 |
|
39 | 39 |
Uint8 screen_dei(Device *d, Uint8 port); |
40 | 40 |
void screen_deo(Device *d, Uint8 port); |
41 | 41 |
\ No newline at end of file |
... | ... |
@@ -246,9 +246,12 @@ parse(char *w, FILE *f) |
246 | 246 |
if(slen(w) != 1) fprintf(stderr, "-- Malformed comment: %s\n", w); |
247 | 247 |
i = 1; /* track nested comment depth */ |
248 | 248 |
while(fscanf(f, "%63s", word) == 1) { |
249 |
- if(slen(word) != 1) continue; |
|
250 |
- else if(word[0] == '(') i++; |
|
251 |
- else if(word[0] == ')' && --i < 1) break; |
|
249 |
+ if(slen(word) != 1) |
|
250 |
+ continue; |
|
251 |
+ else if(word[0] == '(') |
|
252 |
+ i++; |
|
253 |
+ else if(word[0] == ')' && --i < 1) |
|
254 |
+ break; |
|
252 | 255 |
} |
253 | 256 |
break; |
254 | 257 |
case '~': /* include */ |
... | ... |
@@ -66,17 +66,17 @@ audio_callback(void *u, Uint8 *stream, int len) |
66 | 66 |
Sint16 *samples = (Sint16 *)stream; |
67 | 67 |
SDL_memset(stream, 0, len); |
68 | 68 |
for(i = 0; i < POLYPHONY; ++i) |
69 |
- running += audio_render(&audio[i], samples, samples + len / 2); |
|
69 |
+ running += audio_render(&uxn_audio[i], samples, samples + len / 2); |
|
70 | 70 |
if(!running) |
71 | 71 |
SDL_PauseAudioDevice(audio_id, 1); |
72 | 72 |
(void)u; |
73 | 73 |
} |
74 | 74 |
|
75 | 75 |
void |
76 |
-audio_finished_handler(Audio *c) |
|
76 |
+audio_finished_handler(UxnAudio *c) |
|
77 | 77 |
{ |
78 | 78 |
SDL_Event event; |
79 |
- event.type = audio0_event + (c - audio); |
|
79 |
+ event.type = audio0_event + (c - uxn_audio); |
|
80 | 80 |
SDL_PushEvent(&event); |
81 | 81 |
} |
82 | 82 |
|
... | ... |
@@ -104,20 +104,20 @@ set_window_size(SDL_Window *window, int w, int h) |
104 | 104 |
int |
105 | 105 |
set_size(Uint16 width, Uint16 height, int is_resize) |
106 | 106 |
{ |
107 |
- screen_resize(&screen, width, height); |
|
107 |
+ screen_resize(&uxn_screen, width, height); |
|
108 | 108 |
gRect.x = PAD; |
109 | 109 |
gRect.y = PAD; |
110 |
- gRect.w = screen.width; |
|
111 |
- gRect.h = screen.height; |
|
110 |
+ gRect.w = uxn_screen.width; |
|
111 |
+ gRect.h = uxn_screen.height; |
|
112 | 112 |
if(gTexture != NULL) SDL_DestroyTexture(gTexture); |
113 |
- SDL_RenderSetLogicalSize(gRenderer, screen.width + PAD * 2, screen.height + PAD * 2); |
|
114 |
- gTexture = SDL_CreateTexture(gRenderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, screen.width + PAD * 2, screen.height + PAD * 2); |
|
113 |
+ SDL_RenderSetLogicalSize(gRenderer, uxn_screen.width + PAD * 2, uxn_screen.height + PAD * 2); |
|
114 |
+ gTexture = SDL_CreateTexture(gRenderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, uxn_screen.width + PAD * 2, uxn_screen.height + PAD * 2); |
|
115 | 115 |
if(gTexture == NULL || SDL_SetTextureBlendMode(gTexture, SDL_BLENDMODE_NONE)) |
116 | 116 |
return error("gTexture", SDL_GetError()); |
117 |
- if(SDL_UpdateTexture(gTexture, NULL, screen.pixels, sizeof(Uint32)) != 0) |
|
117 |
+ if(SDL_UpdateTexture(gTexture, NULL, uxn_screen.pixels, sizeof(Uint32)) != 0) |
|
118 | 118 |
return error("SDL_UpdateTexture", SDL_GetError()); |
119 | 119 |
if(is_resize) |
120 |
- set_window_size(gWindow, (screen.width + PAD * 2) * zoom, (screen.height + PAD * 2) * zoom); |
|
120 |
+ set_window_size(gWindow, (uxn_screen.width + PAD * 2) * zoom, (uxn_screen.height + PAD * 2) * zoom); |
|
121 | 121 |
return 1; |
122 | 122 |
} |
123 | 123 |
|
... | ... |
@@ -125,9 +125,9 @@ static void |
125 | 125 |
redraw(Uxn *u) |
126 | 126 |
{ |
127 | 127 |
if(devsystem->dat[0xe]) |
128 |
- screen_debug(&screen, u->wst.dat, u->wst.ptr, u->rst.ptr, u->ram.dat); |
|
129 |
- screen_redraw(&screen, screen.pixels); |
|
130 |
- if(SDL_UpdateTexture(gTexture, &gRect, screen.pixels, screen.width * sizeof(Uint32)) != 0) |
|
128 |
+ screen_debug(&uxn_screen, u->wst.dat, u->wst.ptr, u->rst.ptr, u->ram.dat); |
|
129 |
+ screen_redraw(&uxn_screen, uxn_screen.pixels); |
|
130 |
+ if(SDL_UpdateTexture(gTexture, &gRect, uxn_screen.pixels, uxn_screen.width * sizeof(Uint32)) != 0) |
|
131 | 131 |
error("SDL_UpdateTexture", SDL_GetError()); |
132 | 132 |
SDL_RenderClear(gRenderer); |
133 | 133 |
SDL_RenderCopy(gRenderer, gTexture, NULL, NULL); |
... | ... |
@@ -188,7 +188,7 @@ system_deo(Device *d, Uint8 port) |
188 | 188 |
case 0x3: d->u->rst.ptr = d->dat[port]; break; |
189 | 189 |
} |
190 | 190 |
if(port > 0x7 && port < 0xe) |
191 |
- screen_palette(&screen, &d->dat[0x8]); |
|
191 |
+ screen_palette(&uxn_screen, &d->dat[0x8]); |
|
192 | 192 |
} |
193 | 193 |
|
194 | 194 |
static void |
... | ... |
@@ -203,7 +203,7 @@ console_deo(Device *d, Uint8 port) |
203 | 203 |
static Uint8 |
204 | 204 |
audio_dei(Device *d, Uint8 port) |
205 | 205 |
{ |
206 |
- Audio *c = &audio[d - devaudio0]; |
|
206 |
+ UxnAudio *c = &uxn_audio[d - devaudio0]; |
|
207 | 207 |
if(!audio_id) return d->dat[port]; |
208 | 208 |
switch(port) { |
209 | 209 |
case 0x4: return audio_get_vu(c); |
... | ... |
@@ -215,7 +215,7 @@ audio_dei(Device *d, Uint8 port) |
215 | 215 |
static void |
216 | 216 |
audio_deo(Device *d, Uint8 port) |
217 | 217 |
{ |
218 |
- Audio *c = &audio[d - devaudio0]; |
|
218 |
+ UxnAudio *c = &uxn_audio[d - devaudio0]; |
|
219 | 219 |
if(!audio_id) return; |
220 | 220 |
if(port == 0xf) { |
221 | 221 |
SDL_LockAudioDevice(audio_id); |
... | ... |
@@ -317,14 +317,14 @@ static void |
317 | 317 |
set_zoom(Uint8 scale) |
318 | 318 |
{ |
319 | 319 |
zoom = clamp(scale, 1, 3); |
320 |
- set_window_size(gWindow, (screen.width + PAD * 2) * zoom, (screen.height + PAD * 2) * zoom); |
|
320 |
+ set_window_size(gWindow, (uxn_screen.width + PAD * 2) * zoom, (uxn_screen.height + PAD * 2) * zoom); |
|
321 | 321 |
} |
322 | 322 |
|
323 | 323 |
static void |
324 | 324 |
toggle_debugger(void) |
325 | 325 |
{ |
326 | 326 |
devsystem->dat[0xe] = !devsystem->dat[0xe]; |
327 |
- screen_clear(&screen, &screen.fg); |
|
327 |
+ screen_clear(&uxn_screen, &uxn_screen.fg); |
|
328 | 328 |
} |
329 | 329 |
|
330 | 330 |
static void |
... | ... |
@@ -449,8 +449,8 @@ run(Uxn *u) |
449 | 449 |
/* Mouse */ |
450 | 450 |
else if(event.type == SDL_MOUSEMOTION) |
451 | 451 |
mouse_pos(devmouse, |
452 |
- clamp(event.motion.x - PAD, 0, screen.width - 1), |
|
453 |
- clamp(event.motion.y - PAD, 0, screen.height - 1)); |
|
452 |
+ clamp(event.motion.x - PAD, 0, uxn_screen.width - 1), |
|
453 |
+ clamp(event.motion.y - PAD, 0, uxn_screen.height - 1)); |
|
454 | 454 |
else if(event.type == SDL_MOUSEBUTTONUP) |
455 | 455 |
mouse_up(devmouse, 0x1 << (event.button.button - 1)); |
456 | 456 |
else if(event.type == SDL_MOUSEBUTTONDOWN) |
... | ... |
@@ -484,7 +484,7 @@ run(Uxn *u) |
484 | 484 |
console_input(u, event.cbutton.button); |
485 | 485 |
} |
486 | 486 |
uxn_eval(u, devscreen->vector); |
487 |
- if(screen.fg.changed || screen.bg.changed || devsystem->dat[0xe]) |
|
487 |
+ if(uxn_screen.fg.changed || uxn_screen.bg.changed || devsystem->dat[0xe]) |
|
488 | 488 |
redraw(u); |
489 | 489 |
if(!BENCH) { |
490 | 490 |
elapsed = (SDL_GetPerformanceCounter() - begin) / (double)SDL_GetPerformanceFrequency() * 1000.0f; |