this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

removed tic80local struct and done some Studio refactoring

nesbox 3dc2feac 617e5b5f

+431 -549
+9 -8
include/tic80.h
··· 42 42 43 43 #define TIC80_KEY_BUFFER 4 44 44 #define TIC80_SAMPLERATE 44100 45 + #define TIC80_SAMPLETYPE s16 46 + #define TIC80_SAMPLESIZE sizeof(TIC80_SAMPLETYPE) 47 + #define TIC80_SAMPLE_CHANNELS 2 45 48 #define TIC80_FRAMERATE 60 46 49 47 50 typedef enum { ··· 57 60 { 58 61 void (*trace)(const char* text, u8 color); 59 62 void (*error)(const char* info); 60 - void (*exit)(); 63 + void (*exit)(); 61 64 } callback; 62 65 63 66 struct 64 67 { 65 - s16* samples; 68 + TIC80_SAMPLETYPE* buffer; 66 69 s32 count; 67 - } sound; 70 + } samples; 68 71 69 - u32* screen; 70 - tic80_pixel_color_format screen_format; 71 - 72 + u32 *screen; 72 73 } tic80; 73 74 74 75 typedef union ··· 154 155 155 156 } tic80_input; 156 157 157 - TIC80_API tic80* tic80_create(s32 samplerate); 158 + TIC80_API tic80* tic80_create(s32 samplerate, tic80_pixel_color_format format); 158 159 TIC80_API void tic80_load(tic80* tic, void* cart, s32 size); 159 - TIC80_API void tic80_tick(tic80* tic, const tic80_input* input); 160 + TIC80_API void tic80_tick(tic80* tic, tic80_input input); 160 161 TIC80_API void tic80_sound(tic80* tic); 161 162 TIC80_API void tic80_delete(tic80* tic); 162 163
+6 -27
src/api.h
··· 23 23 #pragma once 24 24 25 25 #include "tic.h" 26 + #include "time.h" 26 27 27 28 // convenience macros to loop languages 28 29 #define FOR_EACH_LANG(ln) for (tic_script_config** conf = Languages ; *conf != NULL; conf++ ) { tic_script_config* ln = *conf; ··· 42 43 ErrorOutput error; 43 44 ExitCallback exit; 44 45 45 - u64 (*counter)(void*); 46 - u64 (*freq)(void*); 47 - u64 start; 46 + clock_t start; 48 47 49 48 void* data; 50 49 } tic_tick_data; ··· 813 812 814 813 struct tic_mem 815 814 { 816 - tic_ram ram; 817 - tic_cartridge cart; 815 + tic80 product; 816 + tic_ram ram; 817 + tic_cartridge cart; 818 818 819 819 char saveid[TIC_SAVEID_SIZE]; 820 820 ··· 829 829 830 830 u8 data; 831 831 } input; 832 - 833 - struct 834 - { 835 - s16* buffer; 836 - s32 size; 837 - } samples; 838 - 839 - #if defined(_3DS) 840 - u32 *screen; 841 - #else 842 - u32 screen[TIC80_FULLWIDTH * TIC80_FULLHEIGHT]; 843 - #endif 844 - tic80_pixel_color_format screen_format; 845 832 }; 846 833 847 - tic_mem* tic_core_create(s32 samplerate); 834 + tic_mem* tic_core_create(s32 samplerate, tic80_pixel_color_format format); 848 835 void tic_core_close(tic_mem* memory); 849 836 void tic_core_pause(tic_mem* memory); 850 837 void tic_core_resume(tic_mem* memory); ··· 855 842 void tic_core_blit(tic_mem* tic); 856 843 void tic_core_blit_ex(tic_mem* tic, tic_blit_callback clb); 857 844 const tic_script_config* tic_core_script_config(tic_mem* memory); 858 - 859 - typedef struct 860 - { 861 - tic80 tic; 862 - tic_mem* memory; 863 - tic_tick_data tickData; 864 - u64 tick_counter; 865 - } tic80_local; 866 845 867 846 #define VBANK(tic, bank) \ 868 847 bool MACROVAR(_bank_) = tic_api_vbank(tic, bank); \
+1 -1
src/api/js.c
··· 346 346 347 347 s32 duration = duk_opt_int(duk, 2, -1); 348 348 s32 channel = duk_opt_int(duk, 3, 0); 349 - s32 volumes[TIC_STEREO_CHANNELS]; 349 + s32 volumes[TIC80_SAMPLE_CHANNELS]; 350 350 351 351 if(duk_is_array(duk, 4)) 352 352 {
+1 -1
src/api/lua.c
··· 865 865 s32 octave = -1; 866 866 s32 duration = -1; 867 867 s32 channel = 0; 868 - s32 volumes[TIC_STEREO_CHANNELS] = {MAX_VOLUME, MAX_VOLUME}; 868 + s32 volumes[TIC80_SAMPLE_CHANNELS] = {MAX_VOLUME, MAX_VOLUME}; 869 869 s32 speed = SFX_DEF_SPEED; 870 870 871 871 s32 index = getLuaNumber(lua, 1);
+3 -3
src/api/mruby.c
··· 644 644 mrb_int duration = -1; 645 645 mrb_int channel = 0; 646 646 mrb_value volume = mrb_int_value(mrb, MAX_VOLUME); 647 - mrb_int volumes[TIC_STEREO_CHANNELS]; 647 + mrb_int volumes[TIC80_SAMPLE_CHANNELS]; 648 648 mrb_int speed = SFX_DEF_SPEED; 649 649 650 650 mrb_int argc = mrb_get_args(mrb, "i|oiio!i", &index, &note_obj, &duration, &channel, &volume, &speed); ··· 653 653 654 654 if (mrb_array_p(volume)) 655 655 { 656 - for (mrb_int i = 0; i < TIC_STEREO_CHANNELS; ++i) 656 + for (mrb_int i = 0; i < TIC80_SAMPLE_CHANNELS; ++i) 657 657 { 658 658 volumes[i] = mrb_integer(mrb_ary_entry(volume, i)); 659 659 } 660 660 } 661 661 else if (mrb_fixnum_p(volume)) 662 662 { 663 - for (size_t ch = 0; ch < TIC_STEREO_CHANNELS; ++ch) 663 + for (size_t ch = 0; ch < TIC80_SAMPLE_CHANNELS; ++ch) 664 664 { 665 665 volumes[ch] = mrb_integer(volume); 666 666 }
+1 -1
src/api/squirrel.c
··· 944 944 s32 octave = -1; 945 945 s32 duration = -1; 946 946 s32 channel = 0; 947 - s32 volumes[TIC_STEREO_CHANNELS] = {MAX_VOLUME, MAX_VOLUME}; 947 + s32 volumes[TIC80_SAMPLE_CHANNELS] = {MAX_VOLUME, MAX_VOLUME}; 948 948 s32 speed = SFX_DEF_SPEED; 949 949 950 950 s32 index = getSquirrelNumber(vm, 2);
+1 -1
src/api/wren.c
··· 1094 1094 s32 octave = -1; 1095 1095 s32 duration = -1; 1096 1096 s32 channel = 0; 1097 - s32 volumes[TIC_STEREO_CHANNELS] = {MAX_VOLUME, MAX_VOLUME}; 1097 + s32 volumes[TIC80_SAMPLE_CHANNELS] = {MAX_VOLUME, MAX_VOLUME}; 1098 1098 s32 speed = SFX_DEF_SPEED; 1099 1099 1100 1100 if (index >= 0)
+47 -42
src/core/core.c
··· 204 204 double tic_api_time(tic_mem* memory) 205 205 { 206 206 tic_core* core = (tic_core*)memory; 207 - return (double)((core->data->counter(core->data->data) - core->data->start) * 1000) / core->data->freq(core->data->data); 207 + return (clock() - core->data->start) * 1000.0 / CLOCKS_PER_SEC; 208 208 } 209 209 210 210 s32 tic_api_tstamp(tic_mem* memory) ··· 275 275 } 276 276 277 277 memset(&memory->ram.registers, 0, sizeof memory->ram.registers); 278 - memset(memory->samples.buffer, 0, memory->samples.size); 278 + memset(memory->product.samples.buffer, 0, memory->product.samples.count * TIC80_SAMPLESIZE); 279 279 280 280 tic_api_music(memory, -1, 0, 0, false, false, -1, -1); 281 281 } ··· 290 290 memory->ram.vram.blit.segment = TIC_DEFAULT_BLIT_MODE; 291 291 } 292 292 293 + static void font2ram(tic_mem* memory) 294 + { 295 + memory->ram.font = (tic_font) 296 + { 297 + .regular = 298 + { 299 + .data = 300 + { 301 + #include "font.inl" 302 + }, 303 + .width = TIC_FONT_WIDTH, 304 + .height = TIC_FONT_HEIGHT, 305 + }, 306 + 307 + .alt = 308 + { 309 + .data = 310 + { 311 + #include "altfont.inl" 312 + }, 313 + .width = TIC_ALTFONT_WIDTH, 314 + .height = TIC_FONT_HEIGHT, 315 + }, 316 + }; 317 + } 318 + 293 319 void tic_api_reset(tic_mem* memory) 294 320 { 295 321 tic_core* core = (tic_core*)memory; ··· 324 350 325 351 soundClear(memory); 326 352 updateSaveid(memory); 353 + font2ram(memory); 327 354 } 328 355 329 356 static void cart2ram(tic_mem* memory) 330 357 { 331 - memory->ram.font = (tic_font) 332 - { 333 - .regular = 334 - { 335 - .data = 336 - { 337 - #include "font.inl" 338 - }, 339 - .width = TIC_FONT_WIDTH, 340 - .height = TIC_FONT_HEIGHT, 341 - }, 342 - 343 - .alt = 344 - { 345 - .data = 346 - { 347 - #include "altfont.inl" 348 - }, 349 - .width = TIC_ALTFONT_WIDTH, 350 - .height = TIC_FONT_HEIGHT, 351 - }, 352 - }; 358 + font2ram(memory); 353 359 354 360 enum 355 361 { ··· 442 448 tic->input.keyboard = 1; 443 449 else tic->input.data = -1; // default is all enabled 444 450 445 - data->start = data->counter(core->data->data); 451 + data->start = clock(); 446 452 447 453 done = tic_init_vm(core, code, config); 448 454 } ··· 473 479 if (core->data) 474 480 { 475 481 core->pause.time.start = core->data->start; 476 - core->pause.time.paused = core->data->counter(core->data->data); 482 + core->pause.time.paused = clock(); 477 483 } 478 484 } 479 485 ··· 485 491 { 486 492 memcpy(&core->state, &core->pause.state, sizeof(tic_core_state_data)); 487 493 memcpy(&memory->ram, &core->pause.ram, sizeof(tic_ram)); 488 - core->data->start = core->pause.time.start + core->data->counter(core->data->data) - core->pause.time.paused; 494 + core->data->start = core->pause.time.start + clock() - core->pause.time.paused; 489 495 } 490 496 } 491 497 ··· 500 506 blip_delete(core->blip.left); 501 507 blip_delete(core->blip.right); 502 508 503 - free(memory->samples.buffer); 509 + free(memory->product.screen); 510 + free(memory->product.samples.buffer); 504 511 free(core); 505 512 } 506 513 ··· 580 587 static inline void updpal(tic_mem* tic, tic_blitpal* pal0, tic_blitpal* pal1) 581 588 { 582 589 tic_core* core = (tic_core*)tic; 583 - *pal0 = tic_tool_palette_blit(&vbank0(core)->palette, tic->screen_format); 584 - *pal1 = tic_tool_palette_blit(&vbank1(core)->palette, tic->screen_format); 590 + *pal0 = tic_tool_palette_blit(&vbank0(core)->palette, core->screen_format); 591 + *pal1 = tic_tool_palette_blit(&vbank1(core)->palette, core->screen_format); 585 592 } 586 593 587 594 static inline void updbdr(tic_mem* tic, s32 row, u32* ptr, tic_blit_callback clb, tic_blitpal* pal0, tic_blitpal* pal1) ··· 621 628 updpal(tic, &pal0, &pal1); 622 629 623 630 s32 row = 0; 624 - u32* rowPtr = tic->screen; 631 + u32* rowPtr = tic->product.screen; 625 632 626 633 #define UPDBDR() updbdr(tic, row, rowPtr, clb, &pal0, &pal1) 627 634 ··· 683 690 tic_core_blit_ex(tic, (tic_blit_callback){scanline, border, NULL}); 684 691 } 685 692 686 - tic_mem* tic_core_create(s32 samplerate) 693 + tic_mem* tic_core_create(s32 samplerate, tic80_pixel_color_format format) 687 694 { 688 695 tic_core* core = (tic_core*)malloc(sizeof(tic_core)); 689 - memset(core, 0, sizeof(tic_core)); 696 + *core = (tic_core){0}; 690 697 691 - if (core != (tic_core*)&core->memory) 692 - { 693 - free(core); 694 - return NULL; 695 - } 698 + tic80* product = &core->memory.product; 696 699 697 - core->memory.screen_format = TIC80_PIXEL_COLOR_RGBA8888; 700 + core->screen_format = format; 698 701 core->samplerate = samplerate; 699 702 #ifdef _3DS 700 703 // To feed texture data directly to the 3DS GPU, linearly allocated memory is required, which is 701 704 // not guaranteed by malloc. 702 705 // Additionally, allocate TIC80_FULLHEIGHT + 1 lines to minimize glitches in linear scaling mode. 703 - core->memory.screen = linearAlloc(TIC80_FULLWIDTH * (TIC80_FULLHEIGHT + 1) * sizeof(u32)); 706 + product->screen = linearAlloc(TIC80_FULLWIDTH * (TIC80_FULLHEIGHT + 1) * sizeof(u32)); 707 + #else 708 + product->screen = malloc(TIC80_FULLWIDTH * TIC80_FULLHEIGHT * sizeof product->screen[0]); 704 709 #endif 705 - core->memory.samples.size = samplerate * TIC_STEREO_CHANNELS / TIC80_FRAMERATE * sizeof(s16); 706 - core->memory.samples.buffer = malloc(core->memory.samples.size); 710 + product->samples.count = samplerate * TIC80_SAMPLE_CHANNELS / TIC80_FRAMERATE; 711 + product->samples.buffer = malloc(product->samples.count * TIC80_SAMPLESIZE); 707 712 708 713 core->blip.left = blip_new(samplerate / 10); 709 714 core->blip.right = blip_new(samplerate / 10);
+3 -2
src/core/core.h
··· 167 167 typedef struct 168 168 { 169 169 tic_mem memory; // it should be first 170 + tic80_pixel_color_format screen_format; 170 171 171 172 void* currentVM; 172 173 const tic_script_config* currentScript; ··· 188 189 189 190 struct 190 191 { 191 - u64 start; 192 - u64 paused; 192 + clock_t start; 193 + clock_t paused; 193 194 } time; 194 195 } pause; 195 196
+2 -2
src/core/sound.c
··· 539 539 stereo_synthesize(core, core->state.registers.left, core->blip.left, 0); 540 540 stereo_synthesize(core, core->state.registers.right, core->blip.right, 1); 541 541 542 - blip_read_samples(core->blip.left, core->memory.samples.buffer, core->samplerate / TIC80_FRAMERATE, TIC_STEREO_CHANNELS); 543 - blip_read_samples(core->blip.right, core->memory.samples.buffer + 1, core->samplerate / TIC80_FRAMERATE, TIC_STEREO_CHANNELS); 542 + blip_read_samples(core->blip.left, core->memory.product.samples.buffer, core->samplerate / TIC80_FRAMERATE, TIC80_SAMPLE_CHANNELS); 543 + blip_read_samples(core->blip.right, core->memory.product.samples.buffer + 1, core->samplerate / TIC80_FRAMERATE, TIC80_SAMPLE_CHANNELS); 544 544 545 545 // if the head has advanced, we can advance the tail too. Otherwise, we just 546 546 // keep synthesizing audio using the last known register values, so at least we don't get crackles
+1 -1
src/studio/screens/console.c
··· 2031 2031 for(s32 j = 0; j < TIC80_HEIGHT; j++) 2032 2032 for(s32 i = 0; i < TIC80_WIDTH; i++) 2033 2033 img.values[(i + c * TIC80_WIDTH) + (j + r * TIC80_HEIGHT) * Width] = 2034 - tic->screen[(i + TIC80_MARGIN_LEFT) + (j + TIC80_MARGIN_TOP) * TIC80_FULLWIDTH]; 2034 + tic->product.screen[(i + TIC80_MARGIN_LEFT) + (j + TIC80_MARGIN_TOP) * TIC80_FULLWIDTH]; 2035 2035 } 2036 2036 } 2037 2037
+12 -24
src/studio/screens/run.c
··· 96 96 strcat(run->saveid, md5); 97 97 } 98 98 99 + static void onEmptyTrace(void* data, const char* text, u8 color) {} 100 + static void onEmptyError(void* data, const char* info) {} 101 + 99 102 static void tick(Run* run) 100 103 { 101 104 if (getStudioMode() != TIC_RUN_MODE) ··· 103 106 104 107 tic_mem* tic = run->tic; 105 108 106 - tic_core_tick(tic, &run->tickData); 109 + tic_tick_data tickData = 110 + { 111 + .error = run->console ? onError : onEmptyError, 112 + .trace = run->console ? onTrace : onEmptyTrace, 113 + .exit = onExit, 114 + .data = run, 115 + }; 116 + 117 + tic_core_tick(tic, &tickData); 107 118 108 119 enum {Size = sizeof(tic_persistent)}; 109 120 ··· 117 128 setStudioMode(TIC_CONSOLE_MODE); 118 129 } 119 130 120 - static u64 getFreq(void* data) 121 - { 122 - return tic_sys_freq_get(); 123 - } 124 - 125 - static u64 getCounter(void* data) 126 - { 127 - return tic_sys_counter_get(); 128 - } 129 - 130 - static void onEmptyTrace(void* data, const char* text, u8 color) {} 131 - static void onEmptyError(void* data, const char* info) {} 132 - 133 131 void initRun(Run* run, Console* console, tic_fs* fs, tic_mem* tic) 134 132 { 135 133 *run = (Run) ··· 139 137 .fs = fs, 140 138 .tick = tick, 141 139 .exit = false, 142 - .tickData = 143 - { 144 - .error = console ? onError : onEmptyError, 145 - .trace = console ? onTrace : onEmptyTrace, 146 - .counter = getCounter, 147 - .freq = getFreq, 148 - .start = 0, 149 - .data = run, 150 - .exit = onExit, 151 - }, 152 140 }; 153 141 154 142 {
-1
src/studio/screens/run.h
··· 32 32 tic_mem* tic; 33 33 struct Console* console; 34 34 struct tic_fs* fs; 35 - tic_tick_data tickData; 36 35 37 36 bool exit; 38 37
+100 -102
src/studio/studio.c
··· 68 68 69 69 static void emptyDone(void* data) {} 70 70 71 - StudioImplementation impl = 71 + static Studio impl = 72 72 { 73 - .tic80local = NULL, 74 - 75 73 .mode = TIC_START_MODE, 76 74 .prevMode = TIC_CODE_MODE, 77 75 78 76 #if defined(BUILD_EDITORS) 79 - .cart = 80 - { 81 - .mdate = 0, 82 - }, 83 - 84 77 .menuMode = TIC_CONSOLE_MODE, 85 78 86 79 .bank = 87 80 { 88 - .show = false, 89 81 .chained = true, 90 82 }, 91 83 ··· 108 100 .text = "\0", 109 101 }, 110 102 111 - .video = 112 - { 113 - .record = false, 114 - .buffer = NULL, 115 - .frames = 0, 116 - }, 117 103 #endif 118 104 }; 119 105 ··· 157 143 #if defined(BUILD_EDITORS) 158 144 static const tic_sfx* getSfxSrc() 159 145 { 160 - tic_mem* tic = impl.studio.tic; 146 + tic_mem* tic = impl.tic; 161 147 return &tic->cart.banks[impl.bank.index.sfx].sfx; 162 148 } 163 149 164 150 static const tic_music* getMusicSrc() 165 151 { 166 - tic_mem* tic = impl.studio.tic; 152 + tic_mem* tic = impl.tic; 167 153 return &tic->cart.banks[impl.bank.index.music].music; 168 154 } 169 155 170 156 const char* studioExportSfx(s32 index, const char* filename) 171 157 { 172 - tic_mem* tic = impl.studio.tic; 158 + tic_mem* tic = impl.tic; 173 159 174 160 const char* path = tic_fs_path(impl.fs, filename); 175 161 176 162 if(wave_open( impl.samplerate, path )) 177 163 { 178 164 179 - #if TIC_STEREO_CHANNELS == 2 165 + #if TIC80_SAMPLE_CHANNELS == 2 180 166 wave_enable_stereo(); 181 167 #endif 182 168 ··· 198 184 tic_core_tick_end(tic); 199 185 tic_core_synth_sound(tic); 200 186 201 - wave_write(tic->samples.buffer, tic->samples.size / sizeof(s16)); 187 + wave_write(tic->product.samples.buffer, tic->product.samples.count); 202 188 } 203 189 204 190 sfx_stop(tic, Channel); ··· 215 201 216 202 const char* studioExportMusic(s32 track, const char* filename) 217 203 { 218 - tic_mem* tic = impl.studio.tic; 204 + tic_mem* tic = impl.tic; 219 205 220 206 const char* path = tic_fs_path(impl.fs, filename); 221 207 222 208 if(wave_open( impl.samplerate, path )) 223 209 { 224 - #if TIC_STEREO_CHANNELS == 2 210 + #if TIC80_SAMPLE_CHANNELS == 2 225 211 wave_enable_stereo(); 226 212 #endif 227 213 ··· 250 236 tic_core_tick_end(tic); 251 237 tic_core_synth_sound(tic); 252 238 253 - wave_write(tic->samples.buffer, tic->samples.size / sizeof(s16)); 239 + wave_write(tic->product.samples.buffer, tic->product.samples.count); 254 240 255 241 if(frame != state->music.frame) 256 242 { ··· 279 265 char text; 280 266 if(!tic_sys_keyboard_text(&text)) 281 267 { 282 - tic_mem* tic = impl.studio.tic; 268 + tic_mem* tic = impl.tic; 283 269 tic80_input* input = &tic->ram.input; 284 270 285 271 static const char Symbols[] = " abcdefghijklmnopqrstuvwxyz0123456789-=[]\\;'`,./ "; ··· 312 298 313 299 bool keyWasPressed(tic_key key) 314 300 { 315 - tic_mem* tic = impl.studio.tic; 301 + tic_mem* tic = impl.tic; 316 302 return tic_api_keyp(tic, key, KEYBOARD_HOLD, KEYBOARD_PERIOD); 317 303 } 318 304 319 305 bool anyKeyWasPressed() 320 306 { 321 - tic_mem* tic = impl.studio.tic; 307 + tic_mem* tic = impl.tic; 322 308 323 309 for(s32 i = 0; i < TIC80_KEY_BUFFER; i++) 324 310 { ··· 334 320 #if defined(BUILD_EDITORS) 335 321 tic_tiles* getBankTiles() 336 322 { 337 - return &impl.studio.tic->cart.banks[impl.bank.index.sprites].tiles; 323 + return &impl.tic->cart.banks[impl.bank.index.sprites].tiles; 338 324 } 339 325 340 326 tic_map* getBankMap() 341 327 { 342 - return &impl.studio.tic->cart.banks[impl.bank.index.map].map; 328 + return &impl.tic->cart.banks[impl.bank.index.map].map; 343 329 } 344 330 345 331 tic_palette* getBankPalette(bool vbank) 346 332 { 347 - tic_bank* bank = &impl.studio.tic->cart.banks[impl.bank.index.sprites]; 333 + tic_bank* bank = &impl.tic->cart.banks[impl.bank.index.sprites]; 348 334 return vbank ? &bank->palette.vbank1 : &bank->palette.vbank0; 349 335 } 350 336 351 337 tic_flags* getBankFlags() 352 338 { 353 - return &impl.studio.tic->cart.banks[impl.bank.index.sprites].flags; 339 + return &impl.tic->cart.banks[impl.bank.index.sprites].flags; 354 340 } 355 341 #endif 356 342 357 343 void playSystemSfx(s32 id) 358 344 { 359 345 const tic_sample* effect = &impl.config->cart->bank0.sfx.samples.data[id]; 360 - tic_api_sfx(impl.studio.tic, id, effect->note, effect->octave, -1, 0, MAX_VOLUME, MAX_VOLUME, effect->speed); 346 + tic_api_sfx(impl.tic, id, effect->note, effect->octave, -1, 0, MAX_VOLUME, MAX_VOLUME, effect->speed); 361 347 } 362 348 363 349 static void md5(const void* voidData, s32 length, u8 digest[MD5_HASHSIZE]) ··· 539 525 } 540 526 #endif 541 527 528 + const StudioConfig* studio_config(Studio* studio) 529 + { 530 + return &impl.config->data; 531 + } 532 + 542 533 const StudioConfig* getConfig() 543 534 { 544 - return &impl.config->data; 535 + return studio_config(&impl); 545 536 } 546 537 547 538 struct Start* getStartScreen() ··· 553 544 554 545 static void drawBankIcon(s32 x, s32 y) 555 546 { 556 - tic_mem* tic = impl.studio.tic; 547 + tic_mem* tic = impl.tic; 557 548 558 549 tic_rect rect = {x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT}; 559 550 ··· 828 819 { 829 820 enum{Width = TIC80_WIDTH, Height = TIC_FONT_HEIGHT + 1}; 830 821 831 - tic_api_rect(impl.studio.tic, 0, impl.anim.pos.popup, Width, Height, tic_color_red); 832 - tic_api_print(impl.studio.tic, impl.popup.message, 822 + tic_api_rect(impl.tic, 0, impl.anim.pos.popup, Width, Height, tic_color_red); 823 + tic_api_print(impl.tic, impl.popup.message, 833 824 (s32)(Width - strlen(impl.popup.message) * TIC_FONT_WIDTH)/2, 834 825 impl.anim.pos.popup + 1, tic_color_white, true, 1, false); 835 826 836 827 // render popup message 837 828 { 838 - tic_mem* tic = impl.studio.tic; 829 + tic_mem* tic = impl.tic; 839 830 const tic_bank* bank = &getConfig()->cart->bank0; 840 - u32* dst = tic->screen + TIC80_MARGIN_LEFT + TIC80_MARGIN_TOP * TIC80_FULLWIDTH; 831 + u32* dst = tic->product.screen + TIC80_MARGIN_LEFT + TIC80_MARGIN_TOP * TIC80_FULLWIDTH; 841 832 842 833 for(s32 i = 0, y = 0; y < (Height + impl.anim.pos.popup); y++, dst += TIC80_MARGIN_RIGHT + TIC80_MARGIN_LEFT) 843 834 for(s32 x = 0; x < Width; x++) ··· 959 950 960 951 ClipboardEvent getClipboardEvent() 961 952 { 962 - tic_mem* tic = impl.studio.tic; 953 + tic_mem* tic = impl.tic; 963 954 964 955 bool shift = tic_api_key(tic, tic_key_shift); 965 956 bool ctrl = tic_api_key(tic, tic_key_ctrl); ··· 993 984 994 985 static void exitConfirm(bool yes, void* data) 995 986 { 996 - impl.studio.quit = yes; 987 + impl.alive = yes; 997 988 } 998 989 999 - void exitStudio() 990 + void studio_exit(Studio* studio) 1000 991 { 1001 992 #if defined(BUILD_EDITORS) 1002 993 if(impl.mode != TIC_START_MODE && studioCartChanged()) ··· 1013 1004 else 1014 1005 #endif 1015 1006 exitConfirm(true, NULL); 1007 + } 1008 + 1009 + void exitStudio() 1010 + { 1011 + studio_exit(&impl); 1016 1012 } 1017 1013 1018 1014 void drawBitIcon(s32 id, s32 x, s32 y, u8 color) 1019 1015 { 1020 - tic_mem* tic = impl.studio.tic; 1016 + tic_mem* tic = impl.tic; 1021 1017 1022 1018 const tic_tile* tile = &getConfig()->cart->bank0.tiles.data[id]; 1023 1019 ··· 1042 1038 #else 1043 1039 NULL, 1044 1040 #endif 1045 - impl.fs, impl.studio.tic); 1041 + impl.fs, impl.tic); 1046 1042 } 1047 1043 1048 1044 #if defined(BUILD_EDITORS) 1049 1045 static void initWorldMap() 1050 1046 { 1051 - initWorld(impl.world, impl.studio.tic, impl.banks.map[impl.bank.index.map]); 1047 + initWorld(impl.world, impl.tic, impl.banks.map[impl.bank.index.map]); 1052 1048 } 1053 1049 1054 1050 static void initSurfMode() 1055 1051 { 1056 - initSurf(impl.surf, impl.studio.tic, impl.console); 1052 + initSurf(impl.surf, impl.tic, impl.console); 1057 1053 } 1058 1054 1059 1055 void gotoSurf() ··· 1076 1072 EditorMode prev = impl.mode; 1077 1073 1078 1074 if(prev == TIC_RUN_MODE) 1079 - tic_core_pause(impl.studio.tic); 1075 + tic_core_pause(impl.tic); 1080 1076 1081 1077 if(mode != TIC_RUN_MODE) 1082 - tic_api_reset(impl.studio.tic); 1078 + tic_api_reset(impl.tic); 1083 1079 1084 1080 switch (prev) 1085 1081 { ··· 1139 1135 1140 1136 void resumeGame() 1141 1137 { 1142 - tic_core_resume(impl.studio.tic); 1138 + tic_core_resume(impl.tic); 1143 1139 impl.mode = TIC_RUN_MODE; 1144 1140 } 1145 1141 ··· 1153 1149 1154 1150 bool checkMousePos(const tic_rect* rect) 1155 1151 { 1156 - tic_point pos = tic_api_mouse(impl.studio.tic); 1152 + tic_point pos = tic_api_mouse(impl.tic); 1157 1153 return pointInRect(&pos, rect); 1158 1154 } 1159 1155 ··· 1179 1175 1180 1176 void setCursor(tic_cursor id) 1181 1177 { 1182 - tic_mem* tic = impl.studio.tic; 1178 + tic_mem* tic = impl.tic; 1183 1179 1184 1180 VBANK(tic, 0) 1185 1181 { ··· 1199 1195 { 1200 1196 if(impl.menuMode == TIC_RUN_MODE) 1201 1197 { 1202 - tic_core_resume(impl.studio.tic); 1198 + tic_core_resume(impl.tic); 1203 1199 impl.mode = TIC_RUN_MODE; 1204 1200 } 1205 1201 else setStudioMode(impl.menuMode); ··· 1259 1255 1260 1256 static void initModules() 1261 1257 { 1262 - tic_mem* tic = impl.studio.tic; 1258 + tic_mem* tic = impl.tic; 1263 1259 1264 1260 resetBanks(); 1265 1261 1266 - initCode(impl.code, impl.studio.tic, &tic->cart.code); 1262 + initCode(impl.code, impl.tic, &tic->cart.code); 1267 1263 1268 1264 for(s32 i = 0; i < TIC_EDITOR_BANKS; i++) 1269 1265 { 1270 - initSprite(impl.banks.sprite[i], impl.studio.tic, &tic->cart.banks[i].tiles); 1271 - initMap(impl.banks.map[i], impl.studio.tic, &tic->cart.banks[i].map); 1272 - initSfx(impl.banks.sfx[i], impl.studio.tic, &tic->cart.banks[i].sfx); 1273 - initMusic(impl.banks.music[i], impl.studio.tic, &tic->cart.banks[i].music); 1266 + initSprite(impl.banks.sprite[i], impl.tic, &tic->cart.banks[i].tiles); 1267 + initMap(impl.banks.map[i], impl.tic, &tic->cart.banks[i].map); 1268 + initSfx(impl.banks.sfx[i], impl.tic, &tic->cart.banks[i].sfx); 1269 + initMusic(impl.banks.music[i], impl.tic, &tic->cart.banks[i].music); 1274 1270 } 1275 1271 1276 1272 initWorldMap(); ··· 1278 1274 1279 1275 static void updateHash() 1280 1276 { 1281 - md5(&impl.studio.tic->cart, sizeof(tic_cartridge), impl.cart.hash.data); 1277 + md5(&impl.tic->cart, sizeof(tic_cartridge), impl.cart.hash.data); 1282 1278 } 1283 1279 1284 1280 static void updateMDate() ··· 1343 1339 bool studioCartChanged() 1344 1340 { 1345 1341 CartHash hash; 1346 - md5(&impl.studio.tic->cart, sizeof(tic_cartridge), hash.data); 1342 + md5(&impl.tic->cart, sizeof(tic_cartridge), hash.data); 1347 1343 1348 1344 return memcmp(hash.data, impl.cart.hash.data, sizeof(CartHash)) != 0; 1349 1345 } ··· 1362 1358 else 1363 1359 #endif 1364 1360 { 1365 - tic_api_reset(impl.studio.tic); 1361 + tic_api_reset(impl.tic); 1366 1362 1367 1363 if(impl.mode == TIC_RUN_MODE) 1368 1364 { ··· 1422 1418 1423 1419 static void setCoverImage() 1424 1420 { 1425 - tic_mem* tic = impl.studio.tic; 1421 + tic_mem* tic = impl.tic; 1426 1422 1427 1423 if(impl.mode == TIC_RUN_MODE) 1428 1424 { ··· 1503 1499 1504 1500 static inline bool keyWasPressedOnce(s32 key) 1505 1501 { 1506 - tic_mem* tic = impl.studio.tic; 1502 + tic_mem* tic = impl.tic; 1507 1503 1508 1504 return tic_api_keyp(tic, key, -1, -1); 1509 1505 } ··· 1535 1531 { 1536 1532 if(impl.mode != TIC_MENU_MODE) 1537 1533 { 1538 - tic_core_pause(impl.studio.tic); 1539 - tic_api_reset(impl.studio.tic); 1534 + tic_core_pause(impl.tic); 1535 + tic_api_reset(impl.tic); 1540 1536 impl.mode = TIC_MENU_MODE; 1541 1537 } 1542 1538 ··· 1545 1541 1546 1542 static void processShortcuts() 1547 1543 { 1548 - tic_mem* tic = impl.studio.tic; 1544 + tic_mem* tic = impl.tic; 1549 1545 1550 1546 if(impl.mode == TIC_START_MODE) return; 1551 1547 ··· 1579 1575 } 1580 1576 else if(ctrl) 1581 1577 { 1582 - if(keyWasPressedOnce(tic_key_q)) exitStudio(NULL); 1578 + if(keyWasPressedOnce(tic_key_q)) studio_exit(&impl); 1583 1579 #if defined(BUILD_EDITORS) 1584 1580 else if(keyWasPressedOnce(tic_key_pageup)) changeStudioMode(-1); 1585 1581 else if(keyWasPressedOnce(tic_key_pagedown)) changeStudioMode(1); ··· 1743 1739 1744 1740 static void renderStudio() 1745 1741 { 1746 - tic_mem* tic = impl.studio.tic; 1742 + tic_mem* tic = impl.tic; 1747 1743 1748 1744 #if defined(BUILD_EDITORS) 1749 1745 showTooltip(""); ··· 1756 1752 switch(impl.mode) 1757 1753 { 1758 1754 case TIC_RUN_MODE: 1759 - sfx = &impl.studio.tic->ram.sfx; 1760 - music = &impl.studio.tic->ram.music; 1755 + sfx = &impl.tic->ram.sfx; 1756 + music = &impl.tic->ram.music; 1761 1757 break; 1762 1758 case TIC_START_MODE: 1763 1759 case TIC_MENU_MODE: ··· 1778 1774 1779 1775 // restore mapping in all the modes except Run mode 1780 1776 if(impl.mode != TIC_RUN_MODE) 1781 - impl.studio.tic->ram.mapping = getConfig()->options.mapping; 1777 + impl.tic->ram.mapping = getConfig()->options.mapping; 1782 1778 1783 1779 tic_core_tick_start(tic); 1784 1780 } ··· 1859 1855 1860 1856 static void updateSystemFont() 1861 1857 { 1862 - tic_mem* tic = impl.studio.tic; 1858 + tic_mem* tic = impl.tic; 1863 1859 1864 1860 impl.systemFont = (tic_font) 1865 1861 { ··· 1903 1899 for(s32 i = 0; i < COUNT_OF(impl.mouse.state); i++) 1904 1900 impl.mouse.state[i].click = false; 1905 1901 1906 - tic_mem* tic = impl.studio.tic; 1902 + tic_mem* tic = impl.tic; 1907 1903 1908 1904 tic->ram.vram.vars.cursor.sprite = tic_cursor_arrow; 1909 1905 tic->ram.vram.vars.cursor.system = true; ··· 1929 1925 1930 1926 static void blitCursor() 1931 1927 { 1932 - tic_mem* tic = impl.studio.tic; 1928 + tic_mem* tic = impl.tic; 1933 1929 tic80_mouse* m = &tic->ram.input.mouse; 1934 1930 1935 1931 if(tic->input.mouse && !m->relative && m->x < TIC80_FULLWIDTH && m->y < TIC80_FULLHEIGHT) ··· 1953 1949 const tic_tile* tile = &bank->sprites.data[tic->ram.vram.vars.cursor.sprite]; 1954 1950 1955 1951 tic_point s = {m->x - hot.x, m->y - hot.y}; 1956 - u32* dst = tic->screen + TIC80_FULLWIDTH * s.y + s.x; 1952 + u32* dst = tic->product.screen + TIC80_FULLWIDTH * s.y + s.x; 1957 1953 1958 1954 for(s32 y = s.y, endy = MIN(y + TIC_SPRITESIZE, TIC80_FULLHEIGHT), i = 0; y != endy; ++y, dst += TIC80_FULLWIDTH - TIC_SPRITESIZE) 1959 1955 for(s32 x = s.x, endx = x + TIC_SPRITESIZE; x != endx; ++x, ++i, ++dst) ··· 1966 1962 } 1967 1963 } 1968 1964 1969 - static void studioTick() 1965 + const tic_mem* studio_mem(Studio* studio) 1970 1966 { 1971 - tic_mem* tic = impl.studio.tic; 1967 + return impl.tic; 1968 + } 1969 + 1970 + void studio_tick(Studio* studio, tic80_input input) 1971 + { 1972 + tic_mem* tic = impl.tic; 1973 + tic->ram.input = input; 1972 1974 1973 1975 #if defined(BUILD_EDITORS) 1974 1976 processAnim(impl.anim.movie, &impl); ··· 2017 2019 2018 2020 #if defined(BUILD_EDITORS) 2019 2021 if(isRecordFrame()) 2020 - recordFrame(tic->screen); 2022 + recordFrame(tic->product.screen); 2021 2023 2022 2024 drawPopup(); 2023 2025 #endif ··· 2028 2030 #endif 2029 2031 } 2030 2032 2031 - static void studioSound() 2033 + void studio_sound(Studio* studio) 2032 2034 { 2033 - tic_mem* tic = impl.studio.tic; 2035 + tic_mem* tic = impl.tic; 2034 2036 tic_core_synth_sound(tic); 2035 2037 2036 2038 s32 volume = getConfig()->options.volume; 2037 2039 2038 2040 if(volume != MAX_VOLUME) 2039 2041 { 2040 - s32 size = tic->samples.size / sizeof tic->samples.buffer[0]; 2041 - for(s16* it = tic->samples.buffer, *end = it + size; it != end; ++it) 2042 + s32 size = tic->product.samples.count; 2043 + for(s16* it = tic->product.samples.buffer, *end = it + size; it != end; ++it) 2042 2044 *it = *it * volume / MAX_VOLUME; 2043 2045 } 2044 2046 } 2045 2047 2046 - static void studioLoad(const char* file) 2048 + void studio_load(Studio* studio, const char* file) 2047 2049 { 2048 2050 #if defined(BUILD_EDITORS) 2049 2051 showPopupMessage(impl.console->loadCart(impl.console, file) ··· 2064 2066 } 2065 2067 } 2066 2068 2067 - static void studioClose() 2069 + void studio_delete(Studio* studio) 2068 2070 { 2069 2071 { 2070 2072 #if defined(BUILD_EDITORS) ··· 2094 2096 studio_menu_free(impl.menu); 2095 2097 } 2096 2098 2097 - if(impl.tic80local) 2098 - tic80_delete((tic80*)impl.tic80local); 2099 + tic_core_close(impl.tic); 2099 2100 2100 2101 #if defined(BUILD_EDITORS) 2101 2102 tic_net_close(impl.net); ··· 2138 2139 2139 2140 static void setIdle(void* data) 2140 2141 { 2141 - StudioImplementation* studio = data; 2142 + Studio* studio = data; 2142 2143 studio->anim.movie = resetMovie(&studio->anim.idle); 2143 2144 } 2144 2145 2145 2146 static void setPopupWait(void* data) 2146 2147 { 2147 - StudioImplementation* studio = data; 2148 + Studio* studio = data; 2148 2149 studio->anim.movie = resetMovie(&studio->anim.wait); 2149 2150 } 2150 2151 2151 2152 static void setPopupHide(void* data) 2152 2153 { 2153 - StudioImplementation* studio = data; 2154 + Studio* studio = data; 2154 2155 studio->anim.movie = resetMovie(&studio->anim.hide); 2155 2156 } 2156 2157 2157 2158 #endif 2158 2159 2159 - Studio* studioInit(s32 argc, char **argv, s32 samplerate, const char* folder) 2160 + bool studio_alive(Studio* studio) 2161 + { 2162 + return impl.alive; 2163 + } 2164 + 2165 + Studio* studio_init(s32 argc, char **argv, s32 samplerate, tic80_pixel_color_format format, const char* folder) 2160 2166 { 2161 2167 setbuf(stdout, NULL); 2162 2168 ··· 2194 2200 } 2195 2201 } 2196 2202 2197 - impl.tic80local = (tic80_local*)tic80_create(impl.samplerate); 2198 - impl.studio.tic = impl.tic80local->memory; 2203 + impl.tic = tic_core_create(impl.samplerate, format); 2199 2204 2200 2205 { 2201 2206 ··· 2229 2234 2230 2235 impl.start = calloc(1, sizeof(Start)); 2231 2236 impl.run = calloc(1, sizeof(Run)); 2232 - impl.menu = studio_menu_create(impl.studio.tic); 2237 + impl.menu = studio_menu_create(impl.tic); 2233 2238 impl.config = calloc(1, sizeof(Config)); 2234 2239 } 2235 2240 2236 2241 tic_fs_makedir(impl.fs, TIC_LOCAL); 2237 2242 tic_fs_makedir(impl.fs, TIC_LOCAL_VERSION); 2238 2243 2239 - initConfig(impl.config, impl.studio.tic, impl.fs); 2240 - initStart(impl.start, impl.studio.tic, args.cart); 2244 + initConfig(impl.config, impl.tic, impl.fs); 2245 + initStart(impl.start, impl.tic, args.cart); 2241 2246 initRunMode(); 2242 2247 2243 2248 #if defined(BUILD_EDITORS) 2244 - initConsole(impl.console, impl.studio.tic, impl.fs, impl.net, impl.config, args); 2249 + initConsole(impl.console, impl.tic, impl.fs, impl.net, impl.config, args); 2245 2250 initSurfMode(); 2246 2251 initModules(); 2247 2252 #endif ··· 2261 2266 impl.config->data.soft |= args.soft; 2262 2267 impl.config->data.cli |= args.cli; 2263 2268 2264 - impl.studio.tick = studioTick; 2265 - impl.studio.sound = studioSound; 2266 - impl.studio.load = studioLoad; 2267 - impl.studio.close = studioClose; 2268 - impl.studio.exit = exitStudio; 2269 - impl.studio.config = getConfig; 2270 - 2271 2269 if(args.cli) 2272 2270 args.skip = true; 2273 2271 2274 2272 if(args.skip) 2275 2273 setStudioMode(TIC_CONSOLE_MODE); 2276 2274 2277 - return &impl.studio; 2275 + return &impl; 2278 2276 }
+4 -4
src/studio/studio_impl.h
··· 94 94 s32 key; 95 95 } Gamepads; 96 96 97 - typedef struct _StudioImplementation 97 + struct Studio 98 98 { 99 - Studio studio; 99 + tic_mem* tic; 100 100 101 - tic80_local* tic80local; 101 + bool alive; 102 102 103 103 EditorMode mode; 104 104 EditorMode prevMode; ··· 204 204 205 205 tic_font systemFont; 206 206 207 - } StudioImplementation; 207 + };
+10 -15
src/studio/system.h
··· 50 50 bool tic_sys_clipboard_has(); 51 51 char* tic_sys_clipboard_get(); 52 52 void tic_sys_clipboard_free(const char* text); 53 - u64 tic_sys_counter_get(); 54 - u64 tic_sys_freq_get(); 55 53 bool tic_sys_fullscreen_get(); 56 54 void tic_sys_fullscreen_set(bool value); 57 55 void tic_sys_message(const char* title, const char* message); ··· 138 136 139 137 } StudioConfig; 140 138 141 - typedef struct 142 - { 143 - tic_mem* tic; 144 - bool quit; 139 + typedef struct Studio Studio; 145 140 146 - void (*tick)(); 147 - void (*sound)(); 148 - void (*exit)(); 149 - void (*close)(); 150 - void (*load)(const char* file); 151 - const StudioConfig* (*config)(); 141 + const tic_mem* studio_mem(Studio* studio); 142 + void studio_tick(Studio* studio, tic80_input input); 143 + void studio_sound(Studio* studio); 144 + void studio_load(Studio* studio, const char* file); 145 + bool studio_alive(Studio* studio); 146 + void studio_exit(Studio* studio); 147 + void studio_delete(Studio* studio); 148 + const StudioConfig* studio_config(Studio* studio); 152 149 153 - } Studio; 154 - 155 - Studio* studioInit(s32 argc, char **argv, s32 samplerate, const char* appFolder); 150 + Studio* studio_init(s32 argc, char **argv, s32 samplerate, tic80_pixel_color_format format, const char* appFolder); 156 151 157 152 #ifdef __cplusplus 158 153 }
+13 -27
src/system/baremetalpi/kernel.cpp
··· 68 68 { 69 69 70 70 Studio* studio; 71 + tic80_input input; 71 72 72 73 struct 73 74 { ··· 104 105 free((void*)text); 105 106 } 106 107 107 - u64 tic_sys_counter_get() 108 - { 109 - return CTimer::Get()->GetTicks(); 110 - } 111 - 112 - u64 tic_sys_freq_get() 113 - { 114 - return HZ; 115 - } 116 - 117 108 void tic_sys_fullscreen_set(bool value) 118 109 { 119 110 } ··· 172 163 return false; 173 164 } 174 165 175 - void screenCopy(CScreenDevice* screen, u32* ts) 166 + void screenCopy(CScreenDevice* screen, const u32* ts) 176 167 { 177 168 u32 pitch = screen->GetPitch(); 178 169 u32* buf = screen->GetBuffer(); 179 170 for (int y = 0; y < TIC80_HEIGHT; y++) 180 171 { 181 - u32 *line = ts + ((y+TIC80_OFFSET_TOP)*(TIC80_FULLWIDTH) + TIC80_OFFSET_LEFT); 172 + const u32 *line = ts + ((y+TIC80_OFFSET_TOP)*(TIC80_FULLWIDTH) + TIC80_OFFSET_LEFT); 182 173 memcpy(buf + (pitch * y), line, TIC80_WIDTH * 4); 183 174 } 184 175 ··· 222 213 223 214 void inputToTic() 224 215 { 225 - tic_mem* tic = platform.studio->tic; 226 - 227 - tic80_input* tic_input = &tic->ram.input; 216 + tic80_input* tic_input = &platform.input; 228 217 229 218 // mouse 230 219 if (mousebuttons & 0x01) tic_input->mouse.left = true; else tic_input->mouse.left = false; ··· 395 384 char* argv[] = { &arg0[0], NULL }; 396 385 int argc = 1; 397 386 malloc(88); 398 - platform.studio = studioInit(argc, argv, 44100, "tic80"); 387 + platform.studio = studio_init(argc, argv, 44100, TIC80_PIXEL_COLOR_BGRA8888, "tic80"); 399 388 malloc(99); 400 389 401 390 } ··· 407 396 char* argv[] = { &arg0[0], &arg1[0], NULL }; 408 397 int argc = 2; 409 398 dbg("Without keyboard\n"); 410 - platform.studio = studioInit(argc, argv, 44100, "tic80"); 399 + platform.studio = studio_init(argc, argv, 44100, TIC80_PIXEL_COLOR_BGRA8888, "tic80"); 411 400 } 412 - dbg("studioInit OK\n"); 401 + dbg("studio_init OK\n"); 413 402 414 403 if( !platform.studio) 415 404 { 416 405 Die("Could not init studio"); 417 406 } 418 407 419 - // gotoSurf(); 420 - platform.studio->tic->screen_format = TIC80_PIXEL_COLOR_BGRA8888; 421 408 dbg("Studio init ok..\n"); 422 409 423 410 if (pKeyboard){ ··· 430 417 pMouse->RegisterEventHandler (mouseEventHandler); 431 418 } 432 419 433 - tic_mem* tic = platform.studio->tic; 434 - tic80_input* tic_input = &tic->ram.input; 420 + const tic80* product = &studio_mem(platform.studio)->product; 421 + tic80_input* tic_input = &platform.input; 435 422 tic_input->keyboard.data = 0; 436 - 437 423 438 424 // sound system 439 425 mSound->AllocateQueue(1000); ··· 451 437 inputToTic(); 452 438 keyspinlock.Release(); 453 439 454 - platform.studio->tick(); 455 - platform.studio->sound(); 440 + studio_tick(platform.studio, platform.input); 441 + studio_sound(platform.studio); 456 442 457 - mSound->Write(tic->samples.buffer, tic->samples.size); 443 + mSound->Write(product->samples.buffer, product->samples.count * TIC80_SAMPLESIZE); 458 444 459 445 mScreen.vsync(); 460 446 461 - screenCopy(&mScreen, platform.studio->tic->screen); 447 + screenCopy(&mScreen, product->screen); 462 448 463 449 mScheduler.Yield(); // for sound 464 450 }
+30 -29
src/system/libretro/tic80_libretro.c
··· 393 393 RETRO_API void retro_reset(void) 394 394 { 395 395 if (state != NULL && state->tic != NULL) { 396 - tic80_local* tic80 = (tic80_local*)state->tic; 397 - tic_api_reset(tic80->memory); 396 + tic_mem* tic = (tic_mem*)state->tic; 397 + tic_api_reset(tic); 398 398 } 399 399 } 400 400 ··· 723 723 /** 724 724 * Draws a software cursor on the screen where the mouse is. 725 725 */ 726 - void tic80_libretro_mousecursor(tic80_local* game, tic80_mouse* mouse, enum mouse_cursor_type cursortype) 726 + void tic80_libretro_mousecursor(tic80* game, tic80_mouse* mouse, enum mouse_cursor_type cursortype) 727 727 { 728 728 TIC_UNUSED(mouse); 729 729 // Only draw the mouse cursor if it's active. ··· 731 731 return; 732 732 } 733 733 734 + tic_mem* tic = (tic_mem*)state->tic; 735 + 734 736 // Determine which cursor to draw. 735 737 switch (cursortype) { 736 738 case MOUSE_CURSOR_NONE: 737 739 // Nothing. 738 740 break; 739 741 case MOUSE_CURSOR_DOT: 740 - tic_api_pix(game->memory, state->mouseX, state->mouseY, state->mouseCursorColor, false); 742 + tic_api_pix(tic, state->mouseX, state->mouseY, state->mouseCursorColor, false); 741 743 break; 742 744 case MOUSE_CURSOR_CROSS: 743 - tic_api_line(game->memory, state->mouseX - 4, state->mouseY, state->mouseX - 2, state->mouseY, state->mouseCursorColor); 744 - tic_api_line(game->memory, state->mouseX + 2, state->mouseY, state->mouseX + 4, state->mouseY, state->mouseCursorColor); 745 - tic_api_line(game->memory, state->mouseX, state->mouseY - 4, state->mouseX, state->mouseY - 2, state->mouseCursorColor); 746 - tic_api_line(game->memory, state->mouseX, state->mouseY + 2, state->mouseX, state->mouseY + 4, state->mouseCursorColor); 745 + tic_api_line(tic, state->mouseX - 4, state->mouseY, state->mouseX - 2, state->mouseY, state->mouseCursorColor); 746 + tic_api_line(tic, state->mouseX + 2, state->mouseY, state->mouseX + 4, state->mouseY, state->mouseCursorColor); 747 + tic_api_line(tic, state->mouseX, state->mouseY - 4, state->mouseX, state->mouseY - 2, state->mouseCursorColor); 748 + tic_api_line(tic, state->mouseX, state->mouseY + 2, state->mouseX, state->mouseY + 4, state->mouseCursorColor); 747 749 break; 748 750 case MOUSE_CURSOR_ARROW: 749 - tic_api_tri(game->memory, state->mouseX, state->mouseY, state->mouseX + 3, state->mouseY, state->mouseX, state->mouseY + 3, state->mouseCursorColor); 750 - tic_api_line(game->memory, state->mouseX + 3, state->mouseY, state->mouseX, state->mouseY + 3, tic_color_black); 751 + tic_api_tri(tic, state->mouseX, state->mouseY, state->mouseX + 3, state->mouseY, state->mouseX, state->mouseY + 3, state->mouseCursorColor); 752 + tic_api_line(tic, state->mouseX + 3, state->mouseY, state->mouseX, state->mouseY + 3, tic_color_black); 751 753 break; 752 754 } 753 755 } ··· 803 805 tic80_libretro_update_keyboard(&state->input.keyboard); 804 806 805 807 // Update the game state. 806 - tic80_tick(game, &state->input); 808 + tic80_tick(game, state->input); 807 809 tic80_sound(game); 808 810 } 809 811 ··· 813 815 void tic80_libretro_draw(tic80* game) 814 816 { 815 817 // Render the mouse cursor if needed. 816 - tic80_libretro_mousecursor((tic80_local*)game, &state->input.mouse, state->mouseCursor); 818 + tic80_libretro_mousecursor((tic80*)game, &state->input.mouse, state->mouseCursor); 817 819 818 820 // Render to the screen. 819 821 if (state->cropBorder) { ··· 832 834 void tic80_libretro_audio(tic80* game) 833 835 { 834 836 // Tell libretro about the samples. 835 - audio_batch_cb(game->sound.samples, game->sound.count / TIC_STEREO_CHANNELS); 837 + audio_batch_cb(game->samples.buffer, game->samples.count / TIC80_SAMPLE_CHANNELS); 836 838 } 837 839 838 840 /** ··· 1004 1006 } 1005 1007 1006 1008 // Set up the TIC-80 environment. 1007 - state->tic = tic80_create(TIC80_SAMPLERATE); 1009 + state->tic = tic80_create(TIC80_SAMPLERATE, TIC80_PIXEL_COLOR_BGRA8888); 1008 1010 if (state->tic == NULL) { 1009 1011 log_cb(RETRO_LOG_ERROR, "[TIC-80] Failed to initialize TIC-80 environment.\n"); 1010 1012 return false; 1011 1013 } 1012 1014 1013 1015 // Set up the environment variables. 1014 - state->tic->screen_format = TIC80_PIXEL_COLOR_BGRA8888; 1015 1016 state->tic->callback.exit = tic80_libretro_exit; 1016 1017 state->tic->callback.error = tic80_libretro_error; 1017 1018 state->tic->callback.trace = tic80_libretro_trace; ··· 1089 1090 return false; 1090 1091 } 1091 1092 1092 - tic80_local* tic80 = (tic80_local*)state->tic; 1093 + tic_mem* tic = (tic_mem*)state->tic; 1093 1094 u32* udata = (u32*)data; 1094 1095 for (u32 i = 0; i < TIC_PERSISTENT_SIZE; i++) { 1095 - udata[i] = tic80->memory->ram.persistent.data[i]; 1096 + udata[i] = tic->ram.persistent.data[i]; 1096 1097 } 1097 1098 1098 1099 return true; ··· 1107 1108 return false; 1108 1109 } 1109 1110 1110 - tic80_local* tic80 = (tic80_local*)state->tic; 1111 + tic_mem* tic = (tic_mem*)state->tic; 1111 1112 u32* uData = (u32*)data; 1112 1113 for (u32 i = 0; i < TIC_PERSISTENT_SIZE; i++) { 1113 - tic80->memory->ram.persistent.data[i] = uData[i]; 1114 + tic->ram.persistent.data[i] = uData[i]; 1114 1115 } 1115 1116 1116 1117 return true; ··· 1127 1128 return NULL; 1128 1129 } 1129 1130 1130 - tic80_local* tic80 = (tic80_local*)state->tic; 1131 + tic_mem* tic = (tic_mem*)state->tic; 1131 1132 switch (id) { 1132 1133 case RETRO_MEMORY_SAVE_RAM: 1133 - return tic80->memory->ram.persistent.data; 1134 + return tic->ram.persistent.data; 1134 1135 case RETRO_MEMORY_SYSTEM_RAM: 1135 - return tic80->memory->ram.data; 1136 + return tic->ram.data; 1136 1137 case RETRO_MEMORY_VIDEO_RAM: 1137 - return tic80->memory->ram.vram.data; 1138 + return tic->ram.vram.data; 1138 1139 default: 1139 1140 return NULL; 1140 1141 } ··· 1149 1150 return 0; 1150 1151 } 1151 1152 1152 - tic80_local* tic80 = (tic80_local*)state->tic; 1153 + tic_mem* tic = (tic_mem*)state->tic; 1153 1154 switch (id) { 1154 1155 case RETRO_MEMORY_SAVE_RAM: 1155 - return sizeof(tic80->memory->ram.persistent.data); 1156 + return sizeof(tic->ram.persistent.data); 1156 1157 case RETRO_MEMORY_SYSTEM_RAM: 1157 - return sizeof(tic80->memory->ram.data); 1158 + return sizeof(tic->ram.data); 1158 1159 case RETRO_MEMORY_VIDEO_RAM: 1159 - return sizeof(tic80->memory->ram.vram.data); 1160 + return sizeof(tic->ram.vram.data); 1160 1161 default: 1161 1162 return 0; 1162 1163 } ··· 1214 1215 } 1215 1216 1216 1217 // Finally, set each given code pair. 1217 - tic80_local* tic80 = (tic80_local*)state->tic; 1218 + tic_mem* tic = (tic_mem*)state->tic; 1218 1219 for (u32 i = 0; i < codeIndex; i = i + 2) { 1219 - tic80->memory->ram.persistent.data[codes[i]] = codes[i+1]; 1220 + tic->ram.persistent.data[codes[i]] = codes[i+1]; 1220 1221 } 1221 1222 }
+5 -5
src/system/n3ds/keyboard.c
··· 177 177 state[(tickey)] = true; \ 178 178 } 179 179 180 - void n3ds_keyboard_update(tic_n3ds_keyboard *kbd, tic_mem *tic) { 180 + void n3ds_keyboard_update(tic_n3ds_keyboard *kbd, tic80_input* input) { 181 181 u32 key_down, key_up, key_held; 182 182 touchPosition touch; 183 183 const touch_area_t* area; ··· 185 185 bool state[tic_keys_count]; 186 186 int i, j; 187 187 188 - tic80_keyboard *tic_kbd = &tic->ram.input.keyboard; 188 + tic80_keyboard *tic_kbd = &input->keyboard; 189 189 190 190 memset(&state, 0, sizeof(state)); 191 191 key_down = hidKeysDown(); ··· 278 278 } 279 279 } 280 280 281 - void n3ds_gamepad_update(tic_n3ds_keyboard *kbd, tic_mem *tic) { 282 - tic80_gamepads *tic_pad = &tic->ram.input.gamepads; 283 - tic80_mouse *tic_mouse = &tic->ram.input.mouse; 281 + void n3ds_gamepad_update(tic_n3ds_keyboard *kbd, tic80_input* input) { 282 + tic80_gamepads *tic_pad = &input->gamepads; 283 + tic80_mouse *tic_mouse = &input->mouse; 284 284 u32 key_held = hidKeysHeld(); 285 285 u64 curr_clock = svcGetSystemTick(); 286 286 circlePosition cstick;
+2 -2
src/system/n3ds/keyboard.h
··· 41 41 void n3ds_keyboard_init(tic_n3ds_keyboard *kbd); 42 42 void n3ds_keyboard_free(tic_n3ds_keyboard *kbd); 43 43 void n3ds_keyboard_draw(tic_n3ds_keyboard *kbd); 44 - void n3ds_keyboard_update(tic_n3ds_keyboard *kbd, tic_mem *tic); 45 - void n3ds_gamepad_update(tic_n3ds_keyboard *kbd, tic_mem *tic); 44 + void n3ds_keyboard_update(tic_n3ds_keyboard *kbd, tic80_input* input); 45 + void n3ds_gamepad_update(tic_n3ds_keyboard *kbd, tic80_input* input);
+17 -25
src/system/n3ds/main.c
··· 47 47 static struct 48 48 { 49 49 Studio* studio; 50 + tic80_input input; 50 51 char* clipboard; 51 52 52 53 struct ··· 178 179 void tic_sys_clipboard_free(const char* text) 179 180 { 180 181 free((void*) text); 181 - } 182 - 183 - u64 tic_sys_counter_get() 184 - { 185 - return svcGetSystemTick(); 186 - } 187 - 188 - u64 tic_sys_freq_get() 189 - { 190 - return SYSCLOCK_ARM11; 191 182 } 192 183 193 184 void tic_sys_fullscreen_set(bool value) ··· 364 355 365 356 static void n3ds_copy_frame(void) 366 357 { 367 - u32 *in = platform.studio->tic->screen; 358 + u32 *in = studio_mem(platform.studio)->product.screen; 368 359 369 360 if (platform.render.scaled >= 1) { 370 361 // pad border 1 pixel lower to minimize glitches in "linear" scaling mode ··· 389 380 390 381 static inline void n3ds_clear_border(C3D_RenderTarget *target) 391 382 { 392 - C3D_RenderTargetClear(target, C3D_CLEAR_ALL, platform.studio->tic->screen[0] >> 8, 0); 383 + C3D_RenderTargetClear(target, C3D_CLEAR_ALL, studio_mem(platform.studio)->product.screen[0] >> 8, 0); 393 384 } 394 385 395 386 static void n3ds_draw_screen(int scale_multiplier) ··· 448 439 float mix[12]; 449 440 int buffer_size; 450 441 451 - platform.audio.samples = platform.studio->tic->samples.size / (TIC_STEREO_CHANNELS * sizeof(u16)); 452 - buffer_size = platform.audio.samples * (TIC_STEREO_CHANNELS * sizeof(u16)); 442 + platform.audio.samples = studio_mem(platform.studio)->product.samples.count / TIC80_SAMPLE_CHANNELS; 443 + buffer_size = platform.audio.samples * (TIC80_SAMPLE_CHANNELS * TIC80_SAMPLESIZE); 453 444 454 445 platform.audio.buffer = linearAlloc(buffer_size * AUDIO_BLOCKS); 455 446 platform.audio.buffer_size = buffer_size; ··· 484 475 } 485 476 486 477 static void audio_update(void) { 487 - platform.studio->sound(); 478 + studio_sound(platform.studio); 488 479 489 480 ndspWaveBuf *wave_buf = &platform.audio.ndspBuf[platform.audio.curr_block]; 490 481 491 482 if (wave_buf->status == NDSP_WBUF_DONE) { 492 483 u16 *audio_ptr = wave_buf->data_pcm16; 493 - memcpy(audio_ptr, platform.studio->tic->samples.buffer, platform.audio.buffer_size); 484 + memcpy(audio_ptr, studio_mem(platform.studio)->product.samples.buffer, platform.audio.buffer_size); 494 485 DSP_FlushDataCache(audio_ptr, platform.audio.buffer_size); 495 486 496 487 ndspChnWaveBufAdd(0, wave_buf); ··· 502 493 u32 key_down = hidKeysDown(); 503 494 u32 key_held = hidKeysHeld(); 504 495 touchPosition touch; 505 - tic80_mouse *mouse = &platform.studio->tic->ram.input.mouse; 496 + 497 + tic80_input *input = &platform.input; 498 + tic80_mouse *mouse = &input->mouse; 506 499 507 500 if (key_held & KEY_TOUCH) 508 501 { ··· 532 525 static void keyboard_update(void) { 533 526 hidScanInput(); 534 527 535 - platform.studio->tic->ram.input.mouse.btns = 0; 528 + platform.input.mouse.btns = 0; 536 529 if (!platform.render.on_bottom) { 537 - n3ds_keyboard_update(&platform.keyboard, platform.studio->tic); 530 + n3ds_keyboard_update(&platform.keyboard, &platform.input); 538 531 } else { 539 532 touch_update(); 540 533 } 541 - n3ds_gamepad_update(&platform.keyboard, platform.studio->tic); 534 + n3ds_gamepad_update(&platform.keyboard, &platform.input); 542 535 543 536 u32 kup = hidKeysUp(); 544 537 if (kup & KEY_SELECT) { ··· 578 571 n3ds_draw_init(); 579 572 n3ds_keyboard_init(&platform.keyboard); 580 573 581 - platform.studio = studioInit(argc_used, (const char**)argv_used, AUDIO_FREQ, "./"); 582 - platform.studio->tic->screen_format = TIC80_PIXEL_COLOR_ABGR8888; 574 + platform.studio = studio_init(argc_used, argv_used, AUDIO_FREQ, TIC80_PIXEL_COLOR_ABGR8888, "./"); 583 575 584 576 n3ds_sound_init(AUDIO_FREQ); 585 577 586 - while (aptMainLoop() && !platform.studio->quit) { 578 + while (aptMainLoop() && !studio_alive(platform.studio)) { 587 579 u32 start_frame = C3D_FrameCounter(0); 588 580 589 581 keyboard_update(); 590 582 591 - platform.studio->tick(); 583 + studio_tick(platform.studio, platform.input); 592 584 audio_update(); 593 585 594 586 n3ds_copy_frame(); ··· 604 596 605 597 n3ds_sound_exit(); 606 598 607 - platform.studio->close(); 599 + studio_delete(platform.studio); 608 600 609 601 n3ds_keyboard_free(&platform.keyboard); 610 602 n3ds_draw_exit();
+107 -115
src/system/sdl/main.c
··· 39 39 #endif 40 40 41 41 #define TEXTURE_SIZE (TIC80_FULLWIDTH) 42 + #define SCREEN_FORMAT TIC80_PIXEL_COLOR_RGBA8888 42 43 43 44 #if defined(__TIC_WINDOWS__) 44 45 #include <windows.h> ··· 84 85 static struct 85 86 { 86 87 Studio* studio; 88 + tic80_input input; 87 89 88 90 SDL_Window* window; 89 91 ··· 183 185 static void destoryTexture(Texture texture) 184 186 { 185 187 #if defined(CRT_SHADER_SUPPORT) 186 - if(!platform.studio->config()->soft) 188 + if(!studio_config(platform.studio)->soft) 187 189 { 188 190 GPU_FreeImage(texture.gpu); 189 191 } ··· 197 199 static void destoryRenderer(Renderer renderer) 198 200 { 199 201 #if defined(CRT_SHADER_SUPPORT) 200 - if(!platform.studio->config()->soft) 202 + if(!studio_config(platform.studio)->soft) 201 203 { 202 204 GPU_CloseCurrentRenderer(); 203 205 } ··· 211 213 static void renderClear(Renderer renderer) 212 214 { 213 215 #if defined(CRT_SHADER_SUPPORT) 214 - if(!platform.studio->config()->soft) 216 + if(!studio_config(platform.studio)->soft) 215 217 { 216 218 GPU_Clear(renderer.gpu); 217 219 } ··· 225 227 static void renderPresent(Renderer renderer) 226 228 { 227 229 #if defined(CRT_SHADER_SUPPORT) 228 - if(!platform.studio->config()->soft) 230 + if(!studio_config(platform.studio)->soft) 229 231 { 230 232 GPU_Flip(renderer.gpu); 231 233 } ··· 239 241 static void renderCopy(Renderer render, Texture tex, SDL_Rect src, SDL_Rect dst) 240 242 { 241 243 #if defined(CRT_SHADER_SUPPORT) 242 - if(!platform.studio->config()->soft) 244 + if(!studio_config(platform.studio)->soft) 243 245 { 244 246 GPU_Rect gpusrc = {src.x, src.y, src.w, src.h}; 245 247 GPU_BlitScale(tex.gpu, &gpusrc, render.gpu, dst.x, dst.y, (float)dst.w / src.w, (float)dst.h / src.h); ··· 255 257 { 256 258 LOCK_MUTEX(platform.audio.mutex) 257 259 { 258 - tic_mem* tic = platform.studio->tic; 260 + const tic_mem* tic = studio_mem(platform.studio); 259 261 260 262 while(len--) 261 263 { 262 264 if (platform.audio.bufferRemaining <= 0) 263 265 { 264 - platform.studio->sound(); 265 - platform.audio.bufferRemaining = tic->samples.size; 266 + studio_sound(platform.studio); 267 + platform.audio.bufferRemaining = tic->product.samples.count * TIC80_SAMPLESIZE; 266 268 } 267 269 268 - *stream++ = ((u8*)tic->samples.buffer)[tic->samples.size - platform.audio.bufferRemaining--]; 270 + *stream++ = ((u8*)tic->product.samples.buffer)[tic->product.samples.count * TIC80_SAMPLESIZE - platform.audio.bufferRemaining--]; 269 271 } 270 272 } 271 273 } ··· 278 280 { 279 281 .freq = TIC80_SAMPLERATE, 280 282 .format = AUDIO_S16, 281 - .channels = TIC_STEREO_CHANNELS, 283 + .channels = TIC80_SAMPLE_CHANNELS, 282 284 .userdata = NULL, 283 285 .callback = audioCallback, 284 286 .samples = 1024, ··· 305 307 u32* pixels = SDL_malloc(Size * Size * sizeof(u32)); 306 308 SCOPE(SDL_free(pixels)) 307 309 { 308 - tic_blitpal pal = tic_tool_palette_blit(&platform.studio->config()->cart->bank0.palette.vbank0, platform.studio->tic->screen_format); 310 + tic_blitpal pal = tic_tool_palette_blit(&studio_config(platform.studio)->cart->bank0.palette.vbank0, SCREEN_FORMAT); 309 311 310 312 for(s32 j = 0, index = 0; j < Size; j++) 311 313 for(s32 i = 0; i < Size; i++, index++) 312 314 { 313 - u8 color = getSpritePixel(platform.studio->config()->cart->bank0.tiles.data, i/Scale, j/Scale); 315 + u8 color = getSpritePixel(studio_config(platform.studio)->cart->bank0.tiles.data, i/Scale, j/Scale); 314 316 pixels[index] = color == ColorKey ? 0 : pal.data[color]; 315 317 } 316 318 ··· 328 330 static void updateTextureBytes(Texture texture, const void* data, s32 width, s32 height) 329 331 { 330 332 #if defined(CRT_SHADER_SUPPORT) 331 - if(!platform.studio->config()->soft) 333 + if(!studio_config(platform.studio)->soft) 332 334 { 333 335 GPU_UpdateImageBytes(texture.gpu, NULL, (const u8*)data, width * sizeof(u32)); 334 336 } ··· 345 347 346 348 #if defined(TOUCH_INPUT_SUPPORT) 347 349 348 - static void drawKeyboardLabels(s32 shift) 350 + static void drawKeyboardLabels(tic_mem* tic, s32 shift) 349 351 { 350 - tic_mem* tic = platform.studio->tic; 351 - 352 352 typedef struct {const char* text; s32 x; s32 y; bool alt; const char* shift;} Label; 353 353 static const Label Labels[] = 354 354 { ··· 366 366 } 367 367 } 368 368 369 - static void map2ram() 369 + static void map2ram(tic_mem* tic) 370 370 { 371 - tic_mem* tic = platform.studio->tic; 372 - memcpy(tic->ram.map.data, &platform.studio->config()->cart->bank0.map, sizeof tic->ram.map); 373 - memcpy(tic->ram.tiles.data, &platform.studio->config()->cart->bank0.tiles, sizeof tic->ram.tiles * TIC_SPRITE_BANKS); 371 + memcpy(tic->ram.map.data, &studio_config(platform.studio)->cart->bank0.map, sizeof tic->ram.map); 372 + memcpy(tic->ram.tiles.data, &studio_config(platform.studio)->cart->bank0.tiles, sizeof tic->ram.tiles * TIC_SPRITE_BANKS); 374 373 } 375 374 376 - static void initTouchKeyboardState(Texture* texture, void** pixels, bool down) 375 + static void initTouchKeyboardState(tic_mem* tic, Texture* texture, void** pixels, bool down) 377 376 { 378 377 enum{Cols=KBD_COLS, Rows=KBD_ROWS}; 379 378 380 - tic_mem* tic = platform.studio->tic; 381 - 382 379 tic_api_map(tic, down ? Cols : 0, 0, Cols, Rows, 0, 0, 0, 0, 1, NULL, NULL); 383 - drawKeyboardLabels(down ? 2 : 0); 380 + drawKeyboardLabels(tic, down ? 2 : 0); 384 381 tic_core_blit(tic); 385 382 *pixels = SDL_malloc(TIC80_FULLWIDTH * TIC80_FULLHEIGHT * sizeof(u32)); 386 - memcpy(*pixels, tic->screen, TIC80_FULLWIDTH * TIC80_FULLHEIGHT * sizeof(u32)); 383 + memcpy(*pixels, tic->product.screen, TIC80_FULLWIDTH * TIC80_FULLHEIGHT * sizeof(u32)); 387 384 388 385 #if defined(CRT_SHADER_SUPPORT) 389 - if(!platform.studio->config()->soft) 386 + if(!studio_config(platform.studio)->soft) 390 387 { 391 388 texture->gpu = GPU_CreateImage(TIC80_FULLWIDTH, TIC80_FULLHEIGHT, GPU_FORMAT_RGBA); 392 389 GPU_SetAnchor(texture->gpu, 0, 0); ··· 403 400 404 401 static void initTouchKeyboard() 405 402 { 406 - tic_mem* tic = platform.studio->tic; 403 + tic_mem *tic = tic_core_create(TIC80_SAMPLERATE, SCREEN_FORMAT); 404 + 405 + SCOPE(tic_core_close(tic)) 406 + { 407 + memcpy(tic->ram.vram.palette.data, studio_config(platform.studio)->cart->bank0.palette.vbank0.data, sizeof(tic_palette)); 408 + tic_api_cls(tic, 0); 409 + map2ram(tic); 407 410 408 - memcpy(tic->ram.vram.palette.data, platform.studio->config()->cart->bank0.palette.vbank0.data, sizeof(tic_palette)); 409 - tic_api_cls(tic, 0); 410 - map2ram(); 411 - 412 - initTouchKeyboardState(&platform.keyboard.touch.texture.up, &platform.keyboard.touch.texture.upPixels, false); 413 - initTouchKeyboardState(&platform.keyboard.touch.texture.down, &platform.keyboard.touch.texture.downPixels, true); 411 + initTouchKeyboardState(tic, &platform.keyboard.touch.texture.up, &platform.keyboard.touch.texture.upPixels, false); 412 + initTouchKeyboardState(tic, &platform.keyboard.touch.texture.down, &platform.keyboard.touch.texture.downPixels, true); 414 413 415 - memset(tic->ram.map.data, 0, sizeof tic->ram.map); 414 + memset(tic->ram.map.data, 0, sizeof tic->ram.map); 415 + } 416 416 } 417 417 418 418 static void updateGamepadParts() ··· 452 452 { 453 453 if(!platform.gamepad.touch.pixels) 454 454 { 455 - tic_mem* tic = platform.studio->tic; 456 - const tic_bank* bank = &platform.studio->config()->cart->bank0; 457 - 455 + tic_mem* tic = tic_core_create(TIC80_SAMPLERATE, SCREEN_FORMAT); 456 + 457 + SCOPE(tic_core_close(tic)) 458 458 { 459 - memcpy(tic->ram.vram.palette.data, &bank->palette.vbank0, sizeof(tic_palette)); 460 - memcpy(tic->ram.tiles.data, &bank->tiles, sizeof(tic_tiles)); 461 - tic_api_spr(tic, 0, 0, 0, TIC_SPRITESHEET_COLS, TIC_SPRITESHEET_COLS, NULL, 0, 1, tic_no_flip, tic_no_rotate); 462 - } 459 + const tic_bank* bank = &studio_config(platform.studio)->cart->bank0; 460 + 461 + { 462 + memcpy(tic->ram.vram.palette.data, &bank->palette.vbank0, sizeof(tic_palette)); 463 + memcpy(tic->ram.tiles.data, &bank->tiles, sizeof(tic_tiles)); 464 + tic_api_spr(tic, 0, 0, 0, TIC_SPRITESHEET_COLS, TIC_SPRITESHEET_COLS, NULL, 0, 1, tic_no_flip, tic_no_rotate); 465 + } 463 466 464 - platform.gamepad.touch.pixels = SDL_malloc(TEXTURE_SIZE * TEXTURE_SIZE * sizeof(u32)); 467 + platform.gamepad.touch.pixels = SDL_malloc(TEXTURE_SIZE * TEXTURE_SIZE * sizeof(u32)); 465 468 466 - tic_core_blit(tic); 469 + tic_core_blit(tic); 467 470 468 - for(u32* pix = tic->screen, *end = pix + TIC80_FULLWIDTH * TIC80_FULLHEIGHT; pix != end; ++pix) 469 - if(*pix == tic_rgba(&bank->palette.vbank0.colors[0])) 470 - *pix = 0; 471 + for(u32* pix = tic->product.screen, *end = pix + TIC80_FULLWIDTH * TIC80_FULLHEIGHT; pix != end; ++pix) 472 + if(*pix == tic_rgba(&bank->palette.vbank0.colors[0])) 473 + *pix = 0; 471 474 472 - memcpy(platform.gamepad.touch.pixels, tic->screen, TIC80_FULLWIDTH * TIC80_FULLHEIGHT * sizeof(u32)); 475 + memcpy(platform.gamepad.touch.pixels, tic->product.screen, TIC80_FULLWIDTH * TIC80_FULLHEIGHT * sizeof(u32)); 473 476 474 - ZEROMEM(tic->ram.vram.palette); 475 - ZEROMEM(tic->ram.tiles); 477 + ZEROMEM(tic->ram.vram.palette); 478 + ZEROMEM(tic->ram.tiles); 479 + } 476 480 } 477 481 478 482 if(!platform.gamepad.touch.texture.sdl) 479 483 { 480 484 #if defined(CRT_SHADER_SUPPORT) 481 - if(!platform.studio->config()->soft) 485 + if(!studio_config(platform.studio)->soft) 482 486 { 483 487 platform.gamepad.touch.texture.gpu = GPU_CreateImage(TEXTURE_SIZE, TEXTURE_SIZE, GPU_FORMAT_RGBA); 484 488 GPU_SetAnchor(platform.gamepad.touch.texture.gpu, 0, 0); 485 489 GPU_SetImageFilter(platform.gamepad.touch.texture.gpu, GPU_FILTER_NEAREST); 486 - GPU_SetRGBA(platform.gamepad.touch.texture.gpu, 0xff, 0xff, 0xff, platform.studio->config()->theme.gamepad.touch.alpha); 490 + GPU_SetRGBA(platform.gamepad.touch.texture.gpu, 0xff, 0xff, 0xff, studio_config(platform.studio)->theme.gamepad.touch.alpha); 487 491 } 488 492 else 489 493 #endif ··· 491 495 platform.gamepad.touch.texture.sdl = SDL_CreateTexture(platform.screen.renderer.sdl, SDL_PIXELFORMAT_ABGR8888, 492 496 SDL_TEXTUREACCESS_STREAMING, TEXTURE_SIZE, TEXTURE_SIZE); 493 497 SDL_SetTextureBlendMode(platform.gamepad.touch.texture.sdl, SDL_BLENDMODE_BLEND); 494 - SDL_SetTextureAlphaMod(platform.gamepad.touch.texture.sdl, platform.studio->config()->theme.gamepad.touch.alpha); 498 + SDL_SetTextureAlphaMod(platform.gamepad.touch.texture.sdl, studio_config(platform.studio)->theme.gamepad.touch.alpha); 495 499 } 496 500 497 501 updateTextureBytes(platform.gamepad.touch.texture, platform.gamepad.touch.pixels, TEXTURE_SIZE, TEXTURE_SIZE); ··· 503 507 504 508 static void initGPU() 505 509 { 506 - bool vsync = platform.studio->config()->options.vsync; 507 - bool soft = platform.studio->config()->soft; 510 + bool vsync = studio_config(platform.studio)->options.vsync; 511 + bool soft = studio_config(platform.studio)->soft; 508 512 509 513 #if defined(CRT_SHADER_SUPPORT) 510 514 if(!soft) ··· 568 572 569 573 #if defined(CRT_SHADER_SUPPORT) 570 574 571 - if(!platform.studio->config()->soft) 575 + if(!studio_config(platform.studio)->soft) 572 576 { 573 577 if(platform.screen.shader) 574 578 { ··· 609 613 tic_point pt; 610 614 s32 mb = SDL_GetMouseState(&pt.x, &pt.y); 611 615 612 - tic_mem* tic = platform.studio->tic; 613 - tic80_mouse* mouse = &tic->ram.input.mouse; 616 + tic80_input* input = &platform.input; 614 617 615 618 if(SDL_GetRelativeMouseMode()) 616 619 { 617 620 SDL_GetRelativeMouseState(&pt.x, &pt.y); 618 621 619 - mouse->rx = pt.x; 620 - mouse->ry = pt.y; 622 + input->mouse.rx = pt.x; 623 + input->mouse.ry = pt.y; 621 624 } 622 625 else 623 626 { 624 - mouse->x = mouse->y = -1; 627 + input->mouse.x = input->mouse.y = -1; 625 628 626 629 if(platform.mouse.focus) 627 630 { ··· 637 640 else 638 641 { 639 642 SDL_ShowCursor(SDL_DISABLE); 640 - mouse->x = m.x; 641 - mouse->y = m.y; 643 + input->mouse.x = m.x; 644 + input->mouse.y = m.y; 642 645 } 643 646 } 644 647 } 645 648 } 646 649 647 650 { 648 - mouse->left = mb & SDL_BUTTON_LMASK ? 1 : 0; 649 - mouse->middle = mb & SDL_BUTTON_MMASK ? 1 : 0; 650 - mouse->right = mb & SDL_BUTTON_RMASK ? 1 : 0; 651 + input->mouse.left = mb & SDL_BUTTON_LMASK ? 1 : 0; 652 + input->mouse.middle = mb & SDL_BUTTON_MMASK ? 1 : 0; 653 + input->mouse.right = mb & SDL_BUTTON_RMASK ? 1 : 0; 651 654 } 652 655 } 653 656 654 657 static void processKeyboard() 655 658 { 656 - tic_mem* tic = platform.studio->tic; 657 - tic80_input* input = &tic->ram.input; 659 + tic80_input* input = &platform.input; 658 660 659 661 { 660 662 SDL_Keymod mod = SDL_GetModState(); ··· 725 727 726 728 static bool isGamepadVisible() 727 729 { 728 - return platform.studio->tic->input.gamepad; 730 + return studio_mem(platform.studio)->input.gamepad; 729 731 } 730 732 731 733 static bool isKbdVisible() 732 734 { 733 - if(!platform.studio->tic->input.keyboard) 735 + if(!studio_mem(platform.studio)->input.keyboard) 734 736 return false; 735 737 736 738 s32 w, h; ··· 907 909 908 910 static void processJoysticks() 909 911 { 910 - tic_mem* tic = platform.studio->tic; 911 912 platform.gamepad.joystick.data = 0; 912 913 s32 index = 0; 913 914 ··· 954 955 955 956 if(back) 956 957 { 957 - tic80_input* input = &tic->ram.input; 958 + tic80_input* input = &platform.input; 958 959 input->keyboard.keys[0] = tic_key_escape; 959 960 } 960 961 } ··· 972 973 processJoysticks(); 973 974 974 975 { 975 - tic_mem* tic = platform.studio->tic; 976 - tic80_input* input = &tic->ram.input; 976 + tic80_input* input = &platform.input; 977 977 978 978 input->gamepads.data = 0; 979 979 ··· 1027 1027 1028 1028 static void pollEvents() 1029 1029 { 1030 - tic_mem* tic = platform.studio->tic; 1031 - tic80_input* input = &tic->ram.input; 1032 - 1033 - if((bool)input->mouse.relative != (bool)SDL_GetRelativeMouseMode()) 1034 - SDL_SetRelativeMouseMode(input->mouse.relative ? SDL_TRUE : SDL_FALSE); 1030 + // check if releative mode was enabled 1031 + { 1032 + const tic_mem* tic = studio_mem(platform.studio); 1033 + if((bool)tic->ram.input.mouse.relative != (bool)SDL_GetRelativeMouseMode()) 1034 + SDL_SetRelativeMouseMode(tic->ram.input.mouse.relative ? SDL_TRUE : SDL_FALSE); 1035 + } 1035 1036 1036 - SDL_memset(input, 0, sizeof(tic80_input)); 1037 + ZEROMEM(platform.input); 1038 + tic80_input* input = &platform.input; 1037 1039 1038 1040 // keep relative mode enabled 1039 1041 input->mouse.relative = SDL_GetRelativeMouseMode() ? 1 : 0; ··· 1108 1110 { 1109 1111 1110 1112 #if defined(CRT_SHADER_SUPPORT) 1111 - if(!platform.studio->config()->soft) 1113 + if(!studio_config(platform.studio)->soft) 1112 1114 { 1113 1115 s32 w, h; 1114 1116 SDL_GetWindowSize(platform.window, &w, &h); ··· 1152 1154 platform.keyboard.text = event.text.text[0]; 1153 1155 break; 1154 1156 case SDL_DROPFILE: 1155 - platform.studio->load(event.drop.file); 1157 + studio_load(platform.studio, event.drop.file); 1156 1158 break; 1157 1159 case SDL_QUIT: 1158 - platform.studio->exit(); 1160 + studio_exit(platform.studio); 1159 1161 break; 1160 1162 default: 1161 1163 break; ··· 1204 1206 1205 1207 renderCopy(platform.screen.renderer, platform.keyboard.touch.texture.up, src, dst); 1206 1208 1207 - const tic80_input* input = &platform.studio->tic->ram.input; 1209 + const tic80_input* input = &studio_mem(platform.studio)->ram.input; 1208 1210 1209 1211 enum{Cols=KBD_COLS, Rows=KBD_ROWS}; 1210 1212 ··· 1249 1251 const s32 tileSize = platform.gamepad.touch.button.size; 1250 1252 const SDL_Point axis = platform.gamepad.touch.button.axis; 1251 1253 typedef struct { bool press; s32 x; s32 y;} Tile; 1252 - const tic80_input* input = &platform.studio->tic->ram.input; 1254 + const tic80_input* input = &studio_mem(platform.studio)->ram.input; 1253 1255 const Tile Tiles[] = 1254 1256 { 1255 1257 {input->gamepads.first.up, axis.x + 1*tileSize, axis.y + 0*tileSize}, ··· 1270 1272 const Tile* tile = Tiles + i; 1271 1273 1272 1274 #if defined(CRT_SHADER_SUPPORT) 1273 - if(!platform.studio->config()->soft) 1275 + if(!studio_config(platform.studio)->soft) 1274 1276 { 1275 1277 GPU_Rect src = { (float)i * TIC_SPRITESIZE + Left, (float)(tile->press ? TIC_SPRITESIZE : 0) + TIC80_MARGIN_TOP, (float)TIC_SPRITESIZE, (float)TIC_SPRITESIZE}; 1276 1278 GPU_Rect dest = { (float)tile->x, (float)tile->y, (float)tileSize, (float)tileSize}; ··· 1336 1338 SDL_free((void*)text); 1337 1339 } 1338 1340 1339 - u64 tic_sys_counter_get() 1340 - { 1341 - return SDL_GetPerformanceCounter(); 1342 - } 1343 - 1344 - u64 tic_sys_freq_get() 1345 - { 1346 - return SDL_GetPerformanceFrequency(); 1347 - } 1348 - 1349 1341 bool tic_sys_fullscreen_get() 1350 1342 { 1351 1343 #if defined(CRT_SHADER_SUPPORT) 1352 - if(!platform.studio->config()->soft) 1344 + if(!studio_config(platform.studio)->soft) 1353 1345 { 1354 1346 return GPU_GetFullscreen() ? true : false; 1355 1347 } ··· 1364 1356 void tic_sys_fullscreen_set(bool value) 1365 1357 { 1366 1358 #if defined(CRT_SHADER_SUPPORT) 1367 - if(!platform.studio->config()->soft) 1359 + if(!studio_config(platform.studio)->soft) 1368 1360 { 1369 1361 GPU_SetFullscreen(value ? GPU_TRUE : GPU_FALSE, true); 1370 1362 } ··· 1436 1428 1437 1429 static void loadCrtShader() 1438 1430 { 1439 - const char* vertextShader = platform.studio->config()->shader.vertex; 1440 - const char* pixelShader = platform.studio->config()->shader.pixel; 1431 + const char* vertextShader = studio_config(platform.studio)->shader.vertex; 1432 + const char* pixelShader = studio_config(platform.studio)->shader.pixel; 1441 1433 1442 1434 if(!vertextShader) 1443 1435 printf("Error: vertex shader is empty.\n"); ··· 1517 1509 1518 1510 static void gpuTick() 1519 1511 { 1520 - tic_mem* tic = platform.studio->tic; 1512 + const tic_mem* tic = studio_mem(platform.studio); 1521 1513 1522 1514 pollEvents(); 1523 1515 1524 - if(platform.studio->quit) 1516 + if(studio_alive(platform.studio)) 1525 1517 { 1526 1518 #if defined __EMSCRIPTEN__ 1527 1519 emscripten_cancel_main_loop(); ··· 1531 1523 1532 1524 LOCK_MUTEX(platform.audio.mutex) 1533 1525 { 1534 - platform.studio->tick(); 1526 + studio_tick(platform.studio, platform.input); 1535 1527 } 1536 1528 1537 1529 renderClear(platform.screen.renderer); 1538 - updateTextureBytes(platform.screen.texture, tic->screen, TIC80_FULLWIDTH, TIC80_FULLHEIGHT); 1530 + updateTextureBytes(platform.screen.texture, tic->product.screen, TIC80_FULLWIDTH, TIC80_FULLHEIGHT); 1539 1531 1540 1532 #if defined(CRT_SHADER_SUPPORT) 1541 1533 1542 - if(!platform.studio->config()->soft && platform.studio->config()->options.crt) 1534 + if(!studio_config(platform.studio)->soft && studio_config(platform.studio)->options.crt) 1543 1535 { 1544 1536 if(platform.screen.shader == 0) 1545 1537 loadCrtShader(); ··· 1603 1595 { 1604 1596 static double nextTick = -1.0; 1605 1597 1606 - bool vsync = platform.studio->config()->options.vsync; 1598 + bool vsync = studio_config(platform.studio)->options.vsync; 1607 1599 1608 1600 if(!vsync) 1609 1601 { ··· 1638 1630 static s32 start(s32 argc, char **argv, const char* folder) 1639 1631 { 1640 1632 SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK); 1641 - platform.studio = studioInit(argc, argv, TIC80_SAMPLERATE, folder); 1633 + platform.studio = studio_init(argc, argv, TIC80_SAMPLERATE, SCREEN_FORMAT, folder); 1642 1634 1643 - SCOPE(platform.studio->close()) 1635 + SCOPE(studio_delete(platform.studio)) 1644 1636 { 1645 - if (platform.studio->config()->cli) 1637 + if (studio_config(platform.studio)->cli) 1646 1638 { 1647 - while (!platform.studio->quit) 1648 - platform.studio->tick(); 1639 + while (!studio_alive(platform.studio)) 1640 + studio_tick(platform.studio, platform.input); 1649 1641 } 1650 1642 else 1651 1643 { 1652 1644 initSound(); 1653 1645 1654 1646 { 1655 - const s32 Width = TIC80_FULLWIDTH * platform.studio->config()->uiScale; 1656 - const s32 Height = TIC80_FULLHEIGHT * platform.studio->config()->uiScale; 1647 + const s32 Width = TIC80_FULLWIDTH * studio_config(platform.studio)->uiScale; 1648 + const s32 Height = TIC80_FULLHEIGHT * studio_config(platform.studio)->uiScale; 1657 1649 1658 1650 s32 flags = SDL_WINDOW_SHOWN 1659 1651 #if !defined(__EMSCRIPTEN__) && !defined(__MACOSX__) ··· 1663 1655 1664 1656 #if defined(CRT_SHADER_SUPPORT) 1665 1657 1666 - if(!platform.studio->config()->soft) 1658 + if(!studio_config(platform.studio)->soft) 1667 1659 flags |= SDL_WINDOW_OPENGL; 1668 1660 #endif 1669 1661 ··· 1672 1664 setWindowIcon(); 1673 1665 initGPU(); 1674 1666 1675 - if(platform.studio->config()->options.fullscreen) 1667 + if(studio_config(platform.studio)->options.fullscreen) 1676 1668 tic_sys_fullscreen_set(true); 1677 1669 } 1678 1670 ··· 1685 1677 const u64 Delta = SDL_GetPerformanceFrequency() / TIC80_FRAMERATE; 1686 1678 u64 nextTick = SDL_GetPerformanceCounter(); 1687 1679 1688 - while (!platform.studio->quit) 1680 + while (!studio_alive(platform.studio)) 1689 1681 { 1690 1682 gpuTick(); 1691 1683
+5 -5
src/system/sdl/player.c
··· 80 80 tic80_input input; 81 81 SDL_memset(&input, 0, sizeof input); 82 82 83 - tic80* tic = tic80_create(audioSpec.freq); 83 + tic80* tic = tic80_create(audioSpec.freq, TIC80_PIXEL_COLOR_RGBA8888); 84 84 tic->callback.exit = onExit; 85 85 tic80_load(tic, cart, size); 86 86 ··· 142 142 143 143 nextTick += Delta; 144 144 145 - tic80_tick(tic, &input); 145 + tic80_tick(tic, input); 146 146 tic80_sound(tic); 147 147 148 148 if (!audioStarted && audioDevice) ··· 151 151 SDL_PauseAudioDevice(audioDevice, 0); 152 152 153 153 { 154 - s32 size = tic->sound.count * sizeof(tic->sound.samples[0]); 154 + s32 size = tic->samples.count; 155 155 156 156 if (cvt.needed) 157 157 { 158 - SDL_memcpy(cvt.buf, tic->sound.samples, size); 158 + SDL_memcpy(cvt.buf, tic->samples.buffer, size); 159 159 SDL_ConvertAudio(&cvt); 160 160 SDL_QueueAudio(audioDevice, cvt.buf, cvt.len_cvt); 161 161 } 162 - else SDL_QueueAudio(audioDevice, tic->sound.samples, size); 162 + else SDL_QueueAudio(audioDevice, tic->samples.buffer, size); 163 163 } 164 164 165 165 SDL_RenderClear(renderer);
+6 -6
src/system/sokol/player.c
··· 33 33 if(cart) 34 34 { 35 35 printf("%s\n", "cart loaded"); 36 - tic = tic80_create(saudio_sample_rate()); 36 + tic = tic80_create(saudio_sample_rate(), TIC80_PIXEL_COLOR_RGBA8888); 37 37 38 38 if(tic) 39 39 { ··· 54 54 { 55 55 if(tic) 56 56 { 57 - tic80_tick(tic, &tic_input); 57 + tic80_tick(tic, tic_input); 58 58 tic80_sound(tic); 59 59 } 60 60 61 61 sokol_gfx_draw(tic->screen); 62 62 63 - static float floatSamples[TIC80_SAMPLERATE / TIC80_FRAMERATE * 2]; 63 + static float floatSamples[TIC80_SAMPLERATE * TIC80_SAMPLE_CHANNELS / TIC80_FRAMERATE]; 64 64 65 - for(s32 i = 0; i < tic->sound.count; i++) 66 - floatSamples[i] = (float)tic->sound.samples[i] / SHRT_MAX; 65 + for(s32 i = 0; i < tic->samples.count; i++) 66 + floatSamples[i] = (float)tic->samples.buffer[i] / SHRT_MAX; 67 67 68 - saudio_push(floatSamples, tic->sound.count / 2); 68 + saudio_push(floatSamples, tic->samples.count / TIC80_SAMPLE_CHANNELS); 69 69 } 70 70 71 71 static void app_input(const sapp_event* event)
+22 -36
src/system/sokol/sokol.c
··· 36 36 static struct 37 37 { 38 38 Studio* studio; 39 + tic80_input input; 39 40 40 41 struct 41 42 { ··· 77 78 void tic_sys_clipboard_free(const char* text) 78 79 { 79 80 free((void*)text); 80 - } 81 - 82 - u64 tic_sys_counter_get() 83 - { 84 - return stm_now(); 85 - } 86 - 87 - u64 tic_sys_freq_get() 88 - { 89 - return 1000000000; 90 81 } 91 82 92 83 void tic_sys_fullscreen_set(bool value) ··· 154 145 155 146 stm_setup(); 156 147 157 - platform.audio.samples = calloc(sizeof platform.audio.samples[0], saudio_sample_rate() / TIC80_FRAMERATE * TIC_STEREO_CHANNELS); 148 + platform.audio.samples = calloc(sizeof platform.audio.samples[0], saudio_sample_rate() / TIC80_FRAMERATE * TIC80_SAMPLE_CHANNELS); 158 149 } 159 150 160 151 static void handleKeyboard() 161 152 { 162 - tic_mem* tic = platform.studio->tic; 163 - 164 - tic80_input* input = &tic->ram.input; 153 + tic80_input* input = &platform.input; 165 154 input->keyboard.data = 0; 166 155 167 156 enum{BufSize = COUNT_OF(input->keyboard.keys)}; ··· 173 162 174 163 static void app_frame(void) 175 164 { 176 - if(platform.studio->quit) exit(0); 165 + if(studio_alive(platform.studio)) exit(0); 177 166 178 - tic_mem* tic = platform.studio->tic; 179 - tic80_input* input = &tic->ram.input; 167 + const tic80* product = &studio_mem(platform.studio)->product; 168 + tic80_input* input = &platform.input; 180 169 181 170 input->gamepads.data = 0; 182 171 handleKeyboard(); 183 - platform.studio->tick(input); 172 + studio_tick(platform.studio, platform.input); 184 173 185 - sokol_gfx_draw(platform.studio->tic->screen); 174 + sokol_gfx_draw(product->screen); 186 175 187 - platform.studio->sound(); 188 - s32 count = tic->samples.size / sizeof tic->samples.buffer[0]; 176 + studio_sound(platform.studio); 177 + s32 count = product->samples.count; 189 178 for(s32 i = 0; i < count; i++) 190 - platform.audio.samples[i] = (float)tic->samples.buffer[i] / SHRT_MAX; 179 + platform.audio.samples[i] = (float)product->samples.buffer[i] / SHRT_MAX; 191 180 192 - saudio_push(platform.audio.samples, count / 2); 181 + saudio_push(platform.audio.samples, count / TIC80_SAMPLE_CHANNELS); 193 182 194 183 input->mouse.scrollx = input->mouse.scrolly = 0; 195 184 platform.keyboard.text = '\0'; ··· 337 326 338 327 static void processMouse(sapp_mousebutton btn, s32 down) 339 328 { 340 - tic_mem* tic = platform.studio->tic; 341 - tic80_input* input = &tic->ram.input; 342 - 329 + tic80_input* input = &platform.input; 343 330 344 331 switch(btn) 345 332 { ··· 352 339 353 340 static void app_input(const sapp_event* event) 354 341 { 355 - tic_mem* tic = platform.studio->tic; 356 - tic80_input* input = &tic->ram.input; 342 + tic80_input* input = &platform.input; 357 343 358 344 switch(event->type) 359 345 { ··· 401 387 402 388 static void app_cleanup(void) 403 389 { 404 - platform.studio->close(); 390 + studio_delete(platform.studio); 405 391 free(platform.audio.samples); 406 392 } 407 393 ··· 417 403 418 404 memset(&platform, 0, sizeof platform); 419 405 420 - platform.audio.desc.num_channels = TIC_STEREO_CHANNELS; 406 + platform.audio.desc.num_channels = TIC80_SAMPLE_CHANNELS; 421 407 saudio_setup(&platform.audio.desc); 422 408 423 - platform.studio = studioInit(argc, argv, saudio_sample_rate(), "./"); 409 + platform.studio = studio_init(argc, argv, saudio_sample_rate(), TIC80_PIXEL_COLOR_RGBA8888, "./"); 424 410 425 - if(platform.studio->config()->cli) 411 + if(studio_config(platform.studio)->cli) 426 412 { 427 - while (!platform.studio->quit) 428 - platform.studio->tick(); 413 + while (!studio_alive(platform.studio)) 414 + studio_tick(platform.studio, platform.input); 429 415 430 416 exit(0); 431 417 } 432 418 433 - const s32 Width = TIC80_FULLWIDTH * platform.studio->config()->uiScale; 434 - const s32 Height = TIC80_FULLHEIGHT * platform.studio->config()->uiScale; 419 + const s32 Width = TIC80_FULLWIDTH * studio_config(platform.studio)->uiScale; 420 + const s32 Height = TIC80_FULLHEIGHT * studio_config(platform.studio)->uiScale; 435 421 436 422 return(sapp_desc) 437 423 {
+23 -63
src/tic.c
··· 52 52 tic->callback.exit(); 53 53 } 54 54 55 - static u64 getFreq(void* data) 55 + tic80* tic80_create(s32 samplerate, tic80_pixel_color_format format) 56 56 { 57 - return TIC80_FRAMERATE; 57 + return &tic_core_create(samplerate, format)->product; 58 58 } 59 59 60 - static u64 getCounter(void* data) 61 - { 62 - tic80_local* tic80 = (tic80_local*)data; 63 - return tic80->tick_counter; 64 - } 65 - 66 - tic80* tic80_create(s32 samplerate) 60 + TIC80_API void tic80_load(tic80* tic, void* cart, s32 size) 67 61 { 68 - tic80_local* tic80 = malloc(sizeof(tic80_local)); 62 + tic_mem* mem = (tic_mem*)tic; 69 63 70 - if(tic80) 71 - { 72 - memset(tic80, 0, sizeof(tic80_local)); 73 - 74 - tic80->memory = tic_core_create(samplerate); 75 - tic80->tic.screen_format = tic80->memory->screen_format; 76 - 77 - return &tic80->tic; 78 - } 79 - 80 - return NULL; 64 + tic_cart_load(&mem->cart, cart, size); 65 + tic_api_reset(mem); 81 66 } 82 67 83 - TIC80_API void tic80_load(tic80* tic, void* cart, s32 size) 68 + TIC80_API void tic80_tick(tic80* tic, tic80_input input) 84 69 { 85 - tic80_local* tic80 = (tic80_local*)tic; 70 + tic_mem* mem = (tic_mem*)tic; 86 71 87 - tic80->tic.sound.count = tic80->memory->samples.size/sizeof(s16); 88 - tic80->tic.sound.samples = tic80->memory->samples.buffer; 89 - 90 - tic80->tic.screen = tic80->memory->screen; 91 - 92 - { 93 - tic80->tickData.error = onError; 94 - tic80->tickData.trace = onTrace; 95 - tic80->tickData.exit = onExit; 96 - tic80->tickData.data = tic80; 97 - 98 - tic80->tickData.start = 0; 99 - tic80->tickData.freq = getFreq; 100 - tic80->tickData.counter = getCounter; 101 - tic80->tick_counter = 0; 102 - } 72 + mem->ram.input = input; 103 73 74 + tic_tick_data tickData = (tic_tick_data) 104 75 { 105 - tic_cart_load(&tic80->memory->cart, cart, size); 106 - tic_api_reset(tic80->memory); 107 - } 108 - } 76 + .error = onError, 77 + .trace = onTrace, 78 + .exit = onExit, 79 + .data = tic, 80 + }; 109 81 110 - TIC80_API void tic80_tick(tic80* tic, const tic80_input* input) 111 - { 112 - tic80_local* tic80 = (tic80_local*)tic; 82 + tic_core_tick_start(mem); 83 + tic_core_tick(mem, &tickData); 84 + tic_core_tick_end(mem); 113 85 114 - tic80->memory->screen_format = tic80->tic.screen_format; 115 - tic80->memory->ram.input = *input; 116 - 117 - tic_core_tick_start(tic80->memory); 118 - tic_core_tick(tic80->memory, &tic80->tickData); 119 - tic_core_tick_end(tic80->memory); 120 - 121 - tic_core_blit(tic80->memory); 122 - 123 - tic80->tick_counter++; 86 + tic_core_blit(mem); 124 87 } 125 88 126 89 TIC80_API void tic80_sound(tic80* tic) 127 90 { 128 - tic80_local* tic80 = (tic80_local*)tic; 129 - tic_core_synth_sound(tic80->memory); 91 + tic_mem* mem = (tic_mem*)tic; 92 + tic_core_synth_sound(mem); 130 93 } 131 94 132 95 TIC80_API void tic80_delete(tic80* tic) 133 96 { 134 - tic80_local* tic80 = (tic80_local*)tic; 135 - 136 - tic_core_close(tic80->memory); 137 - 138 - free(tic80); 97 + tic_mem* mem = (tic_mem*)tic; 98 + tic_core_close(mem); 139 99 }
-1
src/tic.h
··· 61 61 #define TIC_SAVEID_SIZE 64 62 62 63 63 #define TIC_SOUND_CHANNELS 4 64 - #define TIC_STEREO_CHANNELS 2 65 64 #define SFX_TICKS 30 66 65 #define SFX_COUNT_BITS 6 67 66 #define SFX_COUNT (1 << SFX_COUNT_BITS)