From 385fa44f9d77da0366d8f63569e9f13ff097869d Mon Sep 17 00:00:00 2001 From: neauoire Date: Wed, 29 Dec 2021 09:11:03 -0800 Subject: [PATCH] Prefixed globals with uxn_ --- src/devices/audio.c | 10 +++++----- src/devices/audio.h | 12 ++++++------ src/devices/screen.c | 30 +++++++++++++++--------------- src/devices/screen.h | 16 ++++++++-------- src/uxnasm.c | 9 ++++++--- src/uxnemu.c | 42 +++++++++++++++++++++--------------------- 6 files changed, 61 insertions(+), 58 deletions(-) diff --git a/src/devices/audio.c b/src/devices/audio.c index 8d71220..f3c47ee 100644 --- a/src/devices/audio.c +++ b/src/devices/audio.c @@ -23,12 +23,12 @@ static Uint32 advances[12] = { 0xb504f, 0xbfc88, 0xcb2ff, 0xd7450, 0xe411f, 0xf1a1c }; -Audio audio[POLYPHONY]; +UxnAudio uxn_audio[POLYPHONY]; /* clang-format on */ static Sint32 -envelope(Audio *c, Uint32 age) +envelope(UxnAudio *c, Uint32 age) { if(!c->r) return 0x0888; if(age < c->a) return 0x0888 * age / c->a; @@ -40,7 +40,7 @@ envelope(Audio *c, Uint32 age) } int -audio_render(Audio *c, Sint16 *sample, Sint16 *end) +audio_render(UxnAudio *c, Sint16 *sample, Sint16 *end) { Sint32 s; if(!c->advance || !c->period) return 0; @@ -64,7 +64,7 @@ audio_render(Audio *c, Sint16 *sample, Sint16 *end) } void -audio_start(Audio *c, Uint16 adsr, Uint8 pitch) +audio_start(UxnAudio *c, Uint16 adsr, Uint8 pitch) { if(pitch < 108 && c->len) c->advance = advances[pitch % 12] >> (8 - pitch / 12); @@ -85,7 +85,7 @@ audio_start(Audio *c, Uint16 adsr, Uint8 pitch) } Uint8 -audio_get_vu(Audio *c) +audio_get_vu(UxnAudio *c) { int i; Sint32 sum[2] = {0, 0}; diff --git a/src/devices/audio.h b/src/devices/audio.h index 49ca8db..f7a757c 100644 --- a/src/devices/audio.h +++ b/src/devices/audio.h @@ -21,11 +21,11 @@ typedef struct { Uint16 i, len; Sint8 volume[2]; Uint8 pitch, repeat; -} Audio; +} UxnAudio; -extern Audio audio[POLYPHONY]; +extern UxnAudio uxn_audio[POLYPHONY]; -Uint8 audio_get_vu(Audio *c); -int audio_render(Audio *c, Sint16 *sample, Sint16 *end); -void audio_start(Audio *c, Uint16 adsr, Uint8 pitch); -void audio_finished_handler(Audio *c); \ No newline at end of file +Uint8 audio_get_vu(UxnAudio *c); +int audio_render(UxnAudio *c, Sint16 *sample, Sint16 *end); +void audio_start(UxnAudio *c, Uint16 adsr, Uint8 pitch); +void audio_finished_handler(UxnAudio *c); \ No newline at end of file diff --git a/src/devices/screen.c b/src/devices/screen.c index 155eac8..f6512df 100644 --- a/src/devices/screen.c +++ b/src/devices/screen.c @@ -13,7 +13,7 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. */ -Screen screen; +UxnScreen uxn_screen; static Uint8 blending[5][16] = { {0, 0, 0, 0, 1, 0, 1, 1, 2, 2, 0, 2, 3, 3, 3, 0}, @@ -41,7 +41,7 @@ static Uint8 font[][8] = { {0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x80, 0x80}}; static void -screen_write(Screen *p, Layer *layer, Uint16 x, Uint16 y, Uint8 color) +screen_write(UxnScreen *p, Layer *layer, Uint16 x, Uint16 y, Uint8 color) { if(x < p->width && y < p->height) { Uint32 i = x + y * p->width; @@ -53,7 +53,7 @@ screen_write(Screen *p, Layer *layer, Uint16 x, Uint16 y, Uint8 color) } static void -screen_blit(Screen *p, Layer *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy, Uint8 twobpp) +screen_blit(UxnScreen *p, Layer *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy, Uint8 twobpp) { int v, h, opaque = blending[4][color]; for(v = 0; v < 8; ++v) { @@ -71,7 +71,7 @@ screen_blit(Screen *p, Layer *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 co } void -screen_palette(Screen *p, Uint8 *addr) +screen_palette(UxnScreen *p, Uint8 *addr) { int i, shift; for(i = 0, shift = 4; i < 4; ++i, shift ^= 4) { @@ -86,7 +86,7 @@ screen_palette(Screen *p, Uint8 *addr) } void -screen_resize(Screen *p, Uint16 width, Uint16 height) +screen_resize(UxnScreen *p, Uint16 width, Uint16 height) { Uint8 *bg = realloc(p->bg.pixels, width * height), @@ -106,7 +106,7 @@ screen_resize(Screen *p, Uint16 width, Uint16 height) } void -screen_clear(Screen *p, Layer *layer) +screen_clear(UxnScreen *p, Layer *layer) { Uint32 i, size = p->width * p->height; for(i = 0; i < size; ++i) @@ -115,7 +115,7 @@ screen_clear(Screen *p, Layer *layer) } void -screen_redraw(Screen *p, Uint32 *pixels) +screen_redraw(UxnScreen *p, Uint32 *pixels) { Uint32 i, size = p->width * p->height, palette[16]; for(i = 0; i < 16; ++i) @@ -126,7 +126,7 @@ screen_redraw(Screen *p, Uint32 *pixels) } void -screen_debug(Screen *p, Uint8 *stack, Uint8 wptr, Uint8 rptr, Uint8 *memory) +screen_debug(UxnScreen *p, Uint8 *stack, Uint8 wptr, Uint8 rptr, Uint8 *memory) { Uint8 i, x, y, b; for(i = 0; i < 0x20; ++i) { @@ -160,10 +160,10 @@ Uint8 screen_dei(Device *d, Uint8 port) { switch(port) { - case 0x2: return screen.width >> 8; - case 0x3: return screen.width; - case 0x4: return screen.height >> 8; - case 0x5: return screen.height; + case 0x2: return uxn_screen.width >> 8; + case 0x3: return uxn_screen.width; + case 0x4: return uxn_screen.height >> 8; + case 0x5: return uxn_screen.height; default: return d->dat[port]; } } @@ -180,7 +180,7 @@ screen_deo(Device *d, Uint8 port) Uint16 x = peek16(d->dat, 0x8); Uint16 y = peek16(d->dat, 0xa); Uint8 layer = d->dat[0xe] & 0x40; - screen_write(&screen, layer ? &screen.fg : &screen.bg, x, y, d->dat[0xe] & 0x3); + screen_write(&uxn_screen, layer ? &uxn_screen.fg : &uxn_screen.bg, x, y, d->dat[0xe] & 0x3); if(d->dat[0x6] & 0x01) poke16(d->dat, 0x8, x + 1); /* auto x+1 */ if(d->dat[0x6] & 0x02) poke16(d->dat, 0xa, y + 1); /* auto y+1 */ break; @@ -188,10 +188,10 @@ screen_deo(Device *d, Uint8 port) case 0xf: { Uint16 x = peek16(d->dat, 0x8); Uint16 y = peek16(d->dat, 0xa); - Layer *layer = (d->dat[0xf] & 0x40) ? &screen.fg : &screen.bg; + Layer *layer = (d->dat[0xf] & 0x40) ? &uxn_screen.fg : &uxn_screen.bg; Uint8 *addr = &d->mem[peek16(d->dat, 0xc)]; Uint8 twobpp = !!(d->dat[0xf] & 0x80); - screen_blit(&screen, layer, x, y, addr, d->dat[0xf] & 0xf, d->dat[0xf] & 0x10, d->dat[0xf] & 0x20, twobpp); + screen_blit(&uxn_screen, layer, x, y, addr, d->dat[0xf] & 0xf, d->dat[0xf] & 0x10, d->dat[0xf] & 0x20, twobpp); if(d->dat[0x6] & 0x04) poke16(d->dat, 0xc, peek16(d->dat, 0xc) + 8 + twobpp * 8); /* auto addr+8 / auto addr+16 */ if(d->dat[0x6] & 0x01) poke16(d->dat, 0x8, x + 8); /* auto x+8 */ if(d->dat[0x6] & 0x02) poke16(d->dat, 0xa, y + 8); /* auto y+8 */ diff --git a/src/devices/screen.h b/src/devices/screen.h index b608a80..f94985d 100644 --- a/src/devices/screen.h +++ b/src/devices/screen.h @@ -19,22 +19,22 @@ typedef struct Layer { Uint8 changed; } Layer; -typedef struct Screen { +typedef struct UxnScreen { Uint32 palette[4], *pixels; Uint16 width, height; Layer fg, bg; -} Screen; +} UxnScreen; -extern Screen screen; +extern UxnScreen uxn_screen; /* this should probably be done differently */ int set_size(Uint16 width, Uint16 height, int is_resize); -void screen_palette(Screen *p, Uint8 *addr); -void screen_resize(Screen *p, Uint16 width, Uint16 height); -void screen_clear(Screen *p, Layer *layer); -void screen_redraw(Screen *p, Uint32 *pixels); -void screen_debug(Screen *p, Uint8 *stack, Uint8 wptr, Uint8 rptr, Uint8 *memory); +void screen_palette(UxnScreen *p, Uint8 *addr); +void screen_resize(UxnScreen *p, Uint16 width, Uint16 height); +void screen_clear(UxnScreen *p, Layer *layer); +void screen_redraw(UxnScreen *p, Uint32 *pixels); +void screen_debug(UxnScreen *p, Uint8 *stack, Uint8 wptr, Uint8 rptr, Uint8 *memory); Uint8 screen_dei(Device *d, Uint8 port); void screen_deo(Device *d, Uint8 port); \ No newline at end of file diff --git a/src/uxnasm.c b/src/uxnasm.c index d7b2229..39009a7 100644 --- a/src/uxnasm.c +++ b/src/uxnasm.c @@ -246,9 +246,12 @@ parse(char *w, FILE *f) if(slen(w) != 1) fprintf(stderr, "-- Malformed comment: %s\n", w); i = 1; /* track nested comment depth */ while(fscanf(f, "%63s", word) == 1) { - if(slen(word) != 1) continue; - else if(word[0] == '(') i++; - else if(word[0] == ')' && --i < 1) break; + if(slen(word) != 1) + continue; + else if(word[0] == '(') + i++; + else if(word[0] == ')' && --i < 1) + break; } break; case '~': /* include */ diff --git a/src/uxnemu.c b/src/uxnemu.c index caefbed..b8e45a9 100644 --- a/src/uxnemu.c +++ b/src/uxnemu.c @@ -66,17 +66,17 @@ audio_callback(void *u, Uint8 *stream, int len) Sint16 *samples = (Sint16 *)stream; SDL_memset(stream, 0, len); for(i = 0; i < POLYPHONY; ++i) - running += audio_render(&audio[i], samples, samples + len / 2); + running += audio_render(&uxn_audio[i], samples, samples + len / 2); if(!running) SDL_PauseAudioDevice(audio_id, 1); (void)u; } void -audio_finished_handler(Audio *c) +audio_finished_handler(UxnAudio *c) { SDL_Event event; - event.type = audio0_event + (c - audio); + event.type = audio0_event + (c - uxn_audio); SDL_PushEvent(&event); } @@ -104,20 +104,20 @@ set_window_size(SDL_Window *window, int w, int h) int set_size(Uint16 width, Uint16 height, int is_resize) { - screen_resize(&screen, width, height); + screen_resize(&uxn_screen, width, height); gRect.x = PAD; gRect.y = PAD; - gRect.w = screen.width; - gRect.h = screen.height; + gRect.w = uxn_screen.width; + gRect.h = uxn_screen.height; if(gTexture != NULL) SDL_DestroyTexture(gTexture); - SDL_RenderSetLogicalSize(gRenderer, screen.width + PAD * 2, screen.height + PAD * 2); - gTexture = SDL_CreateTexture(gRenderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, screen.width + PAD * 2, screen.height + PAD * 2); + SDL_RenderSetLogicalSize(gRenderer, uxn_screen.width + PAD * 2, uxn_screen.height + PAD * 2); + gTexture = SDL_CreateTexture(gRenderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, uxn_screen.width + PAD * 2, uxn_screen.height + PAD * 2); if(gTexture == NULL || SDL_SetTextureBlendMode(gTexture, SDL_BLENDMODE_NONE)) return error("gTexture", SDL_GetError()); - if(SDL_UpdateTexture(gTexture, NULL, screen.pixels, sizeof(Uint32)) != 0) + if(SDL_UpdateTexture(gTexture, NULL, uxn_screen.pixels, sizeof(Uint32)) != 0) return error("SDL_UpdateTexture", SDL_GetError()); if(is_resize) - set_window_size(gWindow, (screen.width + PAD * 2) * zoom, (screen.height + PAD * 2) * zoom); + set_window_size(gWindow, (uxn_screen.width + PAD * 2) * zoom, (uxn_screen.height + PAD * 2) * zoom); return 1; } @@ -125,9 +125,9 @@ static void redraw(Uxn *u) { if(devsystem->dat[0xe]) - screen_debug(&screen, u->wst.dat, u->wst.ptr, u->rst.ptr, u->ram.dat); - screen_redraw(&screen, screen.pixels); - if(SDL_UpdateTexture(gTexture, &gRect, screen.pixels, screen.width * sizeof(Uint32)) != 0) + screen_debug(&uxn_screen, u->wst.dat, u->wst.ptr, u->rst.ptr, u->ram.dat); + screen_redraw(&uxn_screen, uxn_screen.pixels); + if(SDL_UpdateTexture(gTexture, &gRect, uxn_screen.pixels, uxn_screen.width * sizeof(Uint32)) != 0) error("SDL_UpdateTexture", SDL_GetError()); SDL_RenderClear(gRenderer); SDL_RenderCopy(gRenderer, gTexture, NULL, NULL); @@ -188,7 +188,7 @@ system_deo(Device *d, Uint8 port) case 0x3: d->u->rst.ptr = d->dat[port]; break; } if(port > 0x7 && port < 0xe) - screen_palette(&screen, &d->dat[0x8]); + screen_palette(&uxn_screen, &d->dat[0x8]); } static void @@ -203,7 +203,7 @@ console_deo(Device *d, Uint8 port) static Uint8 audio_dei(Device *d, Uint8 port) { - Audio *c = &audio[d - devaudio0]; + UxnAudio *c = &uxn_audio[d - devaudio0]; if(!audio_id) return d->dat[port]; switch(port) { case 0x4: return audio_get_vu(c); @@ -215,7 +215,7 @@ audio_dei(Device *d, Uint8 port) static void audio_deo(Device *d, Uint8 port) { - Audio *c = &audio[d - devaudio0]; + UxnAudio *c = &uxn_audio[d - devaudio0]; if(!audio_id) return; if(port == 0xf) { SDL_LockAudioDevice(audio_id); @@ -317,14 +317,14 @@ static void set_zoom(Uint8 scale) { zoom = clamp(scale, 1, 3); - set_window_size(gWindow, (screen.width + PAD * 2) * zoom, (screen.height + PAD * 2) * zoom); + set_window_size(gWindow, (uxn_screen.width + PAD * 2) * zoom, (uxn_screen.height + PAD * 2) * zoom); } static void toggle_debugger(void) { devsystem->dat[0xe] = !devsystem->dat[0xe]; - screen_clear(&screen, &screen.fg); + screen_clear(&uxn_screen, &uxn_screen.fg); } static void @@ -449,8 +449,8 @@ run(Uxn *u) /* Mouse */ else if(event.type == SDL_MOUSEMOTION) mouse_pos(devmouse, - clamp(event.motion.x - PAD, 0, screen.width - 1), - clamp(event.motion.y - PAD, 0, screen.height - 1)); + clamp(event.motion.x - PAD, 0, uxn_screen.width - 1), + clamp(event.motion.y - PAD, 0, uxn_screen.height - 1)); else if(event.type == SDL_MOUSEBUTTONUP) mouse_up(devmouse, 0x1 << (event.button.button - 1)); else if(event.type == SDL_MOUSEBUTTONDOWN) @@ -484,7 +484,7 @@ run(Uxn *u) console_input(u, event.cbutton.button); } uxn_eval(u, devscreen->vector); - if(screen.fg.changed || screen.bg.changed || devsystem->dat[0xe]) + if(uxn_screen.fg.changed || uxn_screen.bg.changed || devsystem->dat[0xe]) redraw(u); if(!BENCH) { elapsed = (SDL_GetPerformanceCounter() - begin) / (double)SDL_GetPerformanceFrequency() * 1000.0f;