this repo has no description
0
fork

Configure Feed

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

Merge pull request #1121 from asiekierka/pixel-color-format

Add pixel color format field to TIC-80 structs and blitting.

authored by

Vadim Grigoruk and committed by
GitHub
a7a9949a 94786b3e

+98 -98
+8
include/tic80.h
··· 38 38 #define TIC80_SAMPLERATE 44100 39 39 #define TIC80_FRAMERATE 60 40 40 41 + typedef enum { 42 + TIC80_PIXEL_COLOR_ARGB8888 = (1 << 8) | 32, 43 + TIC80_PIXEL_COLOR_ABGR8888 = (2 << 8) | 32, 44 + TIC80_PIXEL_COLOR_RGBA8888 = (3 << 8) | 32, 45 + TIC80_PIXEL_COLOR_BGRA8888 = (4 << 8) | 32 46 + } tic80_pixel_color_format; 47 + 41 48 typedef struct 42 49 { 43 50 struct ··· 54 61 } sound; 55 62 56 63 u32* screen; 64 + tic80_pixel_color_format screen_format; 57 65 58 66 } tic80; 59 67
+20 -9
src/studio.c
··· 1417 1417 { 1418 1418 enum {Pitch = TIC80_FULLWIDTH*sizeof(u32)}; 1419 1419 1420 - tic_core_blit(tic); 1420 + tic_core_blit(tic, TIC_PIXEL_COLOR_RGBA8888); 1421 1421 1422 1422 u32* buffer = malloc(TIC80_WIDTH * TIC80_HEIGHT * sizeof(u32)); 1423 1423 ··· 1661 1661 } 1662 1662 } 1663 1663 1664 - static void drawDesyncLabel(u32* frame) 1664 + static void drawDesyncLabel(u32* frame, tic_pixel_color_format fmt) 1665 1665 { 1666 1666 if(getConfig()->showSync && impl.missedFrame) 1667 1667 { ··· 1676 1676 1677 1677 enum{sx = TIC80_WIDTH-24, sy = 8, Cols = sizeof DesyncLabel[0]*BITS_IN_BYTE, Rows = COUNT_OF(DesyncLabel)}; 1678 1678 1679 - const u32* pal = tic_tool_palette_blit(&impl.config->cart.bank0.palette); 1679 + const u32* pal = tic_tool_palette_blit(&impl.config->cart.bank0.palette, fmt); 1680 1680 const u32* color = &pal[tic_color_6]; 1681 1681 1682 1682 for(s32 y = 0; y < Rows; y++) ··· 1690 1690 } 1691 1691 } 1692 1692 1693 + static bool isRecordFrame(void) 1694 + { 1695 + return impl.video.record; 1696 + } 1697 + 1693 1698 static void recordFrame(u32* pixels) 1694 1699 { 1695 1700 if(impl.video.record) ··· 1701 1706 1702 1707 if(impl.video.frame % TIC80_FRAMERATE < TIC80_FRAMERATE / 2) 1703 1708 { 1704 - const u32* pal = tic_tool_palette_blit(&impl.config->cart.bank0.palette); 1709 + const u32* pal = tic_tool_palette_blit(&impl.config->cart.bank0.palette, TIC_PIXEL_COLOR_RGBA8888); 1705 1710 drawRecordLabel(pixels, TIC80_WIDTH-24, 8, &pal[tic_color_2]); 1706 1711 } 1707 1712 ··· 1945 1950 memcpy(tic->ram.font.data, impl.systemFont.data, sizeof(tic_font)); 1946 1951 } 1947 1952 1948 - data 1949 - ? tic_core_blit_ex(tic, scanline, overline, data) 1950 - : tic_core_blit(tic); 1953 + if(isRecordFrame()) 1954 + { 1955 + data 1956 + ? tic_core_blit_ex(tic, TIC_PIXEL_COLOR_RGBA8888, scanline, overline, data) 1957 + : tic_core_blit(tic, TIC_PIXEL_COLOR_RGBA8888); 1958 + recordFrame(tic->screen); 1959 + } 1951 1960 1952 - recordFrame(tic->screen); 1953 - drawDesyncLabel(tic->screen); 1961 + data 1962 + ? tic_core_blit_ex(tic, tic->screen_format, scanline, overline, data) 1963 + : tic_core_blit(tic, tic->screen_format); 1964 + drawDesyncLabel(tic->screen, tic->screen_format); 1954 1965 1955 1966 } 1956 1967
+5 -16
src/system/baremetalpi/kernel.cpp
··· 181 181 .updateConfig = updateConfig, 182 182 }; 183 183 184 - u32 rgbaToBgra(u32 u){ 185 - u8 r = u & 0xFF; 186 - u8 g = (u >> 8) & 0xff; 187 - u8 b = (u >> 16) & 0xff; 188 - return (b & 0xFF) 189 - | ((g & 0xFF) << 8) 190 - | ((r & 0xFF) << 16) 191 - | (0xFF << 24); 192 - } 193 - 194 184 void screenCopy(CScreenDevice* screen, u32* ts) 195 185 { 196 186 u32 pitch = screen->GetPitch(); 197 187 u32* buf = screen->GetBuffer(); 198 - for (int y = 0; y<136;y++) 199 - for (int x = 0; x<240;x++) 188 + for (int y = 0; y < TIC80_HEIGHT; y++) 200 189 { 201 - u32 p = ts[(y+4)*(8+240+8)+(x+8)]; 202 - buf[pitch*y + x] = rgbaToBgra(p); 190 + u32 *line = ts + ((y+TIC80_OFFSET_TOP)*(TIC80_FULLWIDTH) + TIC80_OFFSET_LEFT); 191 + memcpy(buf + (pitch * y), line, TIC80_WIDTH * 4); 203 192 } 204 193 205 194 // single pixel mouse pointer, disappear after 10 seconds unmoved ··· 209 198 buf[midx]= 0xffffff; 210 199 } 211 200 212 - // memcpy(screen->GetBuffer(), tic->screen, 240*136*4); would have been too good 201 + // memcpy(screen->GetBuffer(), tic->screen, TIC80_WIDTH*TIC80_HEIGHT*4); would have been too good 213 202 } 214 203 215 204 ··· 430 419 } 431 420 432 421 // gotoSurf(); 433 - 422 + platform.studio->tic->screen_format = TIC_PIXEL_COLOR_BGRA8888; 434 423 dbg("Studio init ok..\n"); 435 424 436 425 if (pKeyboard){
-8
src/system/baremetalpi/size.h
··· 1 - #ifndef _sizes_h 2 - #define _sizes_h 3 - 4 - #define SCREEN_WIDTH 240 5 - #define SCREEN_HEIGHT 136 6 - 7 - #endif 8 -
+4 -3
src/system/baremetalpi/stdlib_app.h
··· 17 17 #include <circle/exceptionhandler.h> 18 18 #include <circle/interrupt.h> 19 19 #include "customscreen.h" 20 - #include "size.h" 20 + #include <tic80.h> 21 21 #include <circle/serial.h> 22 22 #include <circle/timer.h> 23 23 #include <circle/logger.h> ··· 34 34 #include <circle/startup.h> 35 35 36 36 #include <circle_glue.h> 37 + 38 + #include <tic80.h> 37 39 38 40 /** 39 41 * Basic Circle Stdlib application that supports GPIO access. ··· 94 96 public: 95 97 CStdlibAppScreen(const char *kernel) 96 98 : CStdlibApp (kernel), 97 - mScreen (SCREEN_WIDTH, SCREEN_HEIGHT), 98 - // mScreen (240, 136), 99 + mScreen (TIC80_WIDTH, TIC80_HEIGHT), 99 100 mSerial(&mInterrupt), 100 101 mTimer (&mInterrupt), 101 102 mLogger (LogWarning /*mOptions.GetLogLevel ()*/, &mTimer)
+3 -3
src/system/baremetalpi/syscore.h
··· 9 9 #include <circle/exceptionhandler.h> 10 10 #include <circle/interrupt.h> 11 11 #include "customscreen.h" 12 - #include "size.h" 12 + #include <tic80.h> 13 13 #include "utils.h" 14 14 #include <circle/serial.h> 15 15 #include <circle/timer.h> ··· 45 45 static CNullDevice mNullDevice; 46 46 static CExceptionHandler mExceptionHandler; 47 47 static CInterruptSystem mInterrupt; 48 - static CScreenDevice mScreen(SCREEN_WIDTH, SCREEN_HEIGHT); 48 + static CScreenDevice mScreen(TIC80_WIDTH, TIC80_HEIGHT); 49 49 static CSerialDevice mSerial(&mInterrupt); 50 50 static CTimer mTimer(&mInterrupt); 51 51 static CLogger mLogger(LogWarning /*mOptions.GetLogLevel ()*/, &mTimer); ··· 174 174 } 175 175 else 176 176 { 177 - if (!pMouse->Setup (SCREEN_WIDTH*MOUSE_SENS, SCREEN_HEIGHT*MOUSE_SENS)) 177 + if (!pMouse->Setup (TIC80_WIDTH*MOUSE_SENS, TIC80_HEIGHT*MOUSE_SENS)) 178 178 { 179 179 Die("Cannot setup mouse"); 180 180 }
+3 -39
src/system/libretro/tic80_libretro.c
··· 20 20 // How long to wait before hiding the mouse. 21 21 #define TIC_LIBRETRO_MOUSE_HIDE_TIMER_START 300 22 22 23 - static uint32_t *frame_buf = NULL; 24 23 static struct retro_log_callback logging; 25 24 static retro_log_printf_t log_cb; 26 25 static retro_video_refresh_t video_cb; ··· 91 90 */ 92 91 void retro_init(void) 93 92 { 94 - // Create the frame buffer. 95 - frame_buf = calloc(TIC80_FULLWIDTH * TIC80_FULLHEIGHT, sizeof(uint32_t)); 96 - 97 93 // Initialize the keyboard mappings. 98 94 state.keymap[RETROK_UNKNOWN] = tic_key_unknown; 99 95 state.keymap[RETROK_a] = tic_key_a; ··· 195 191 */ 196 192 void retro_deinit(void) 197 193 { 198 - // Clear out the frame buffer if it exists. 199 - if (frame_buf != NULL) { 200 - free(frame_buf); 201 - frame_buf = NULL; 202 - } 194 + 203 195 } 204 196 205 197 /** ··· 559 551 // Update the game state. 560 552 tic80_tick(game, &state.input); 561 553 } 562 - 563 - /** 564 - * Convert between argb8888 and abgr8888. 565 - * 566 - * This was copied from libretro-common's scaler.c: 567 - * https://github.com/libretro/libretro-common/blob/master/gfx/scaler/scaler.c 568 - * 569 - * @see tic80_libretro_draw() 570 - */ 571 - void tic80_libretro_conv_argb8888_abgr8888(uint32_t *output, uint32_t *input, 572 - int width, int height, 573 - int out_stride, int in_stride) 574 - { 575 - int h, w; 576 - for (h = 0; h < height; h++, output += out_stride >> 2, input += in_stride >> 2) { 577 - for (w = 0; w < width; w++) { 578 - uint32_t col = input[w]; 579 - output[w] = ((col << 16) & 0xff0000) | 580 - ((col >> 16) & 0xff) | 581 - (col & 0xff00ff00); 582 - } 583 - } 584 - } 585 - 586 554 /** 587 555 * Draw the screen. 588 556 */ ··· 591 559 // Mouse Cursor 592 560 tic80_libretro_mousecursor((tic80_local*)game, &state.input.mouse, state.mouseCursor); 593 561 594 - // TIC-80 uses ABGR8888, so we need to convert it. 595 - tic80_libretro_conv_argb8888_abgr8888(frame_buf, game->screen, 596 - TIC80_FULLWIDTH, TIC80_FULLHEIGHT, 597 - TIC80_FULLWIDTH << 2, TIC80_FULLWIDTH << 2); 598 - 599 562 // Render to the screen. 600 - video_cb(frame_buf, TIC80_FULLWIDTH, TIC80_FULLHEIGHT, TIC80_FULLWIDTH << 2); 563 + video_cb(game->screen, TIC80_FULLWIDTH, TIC80_FULLHEIGHT, TIC80_FULLWIDTH << 2); 601 564 } 602 565 603 566 /** ··· 717 680 718 681 // Set up the TIC-80 environment. 719 682 tic = tic80_create(TIC80_SAMPLERATE); 683 + tic->screen_format = TIC80_PIXEL_COLOR_BGRA8888; 720 684 tic->callback.exit = tic80_libretro_exit; 721 685 tic->callback.error = tic80_libretro_error; 722 686 tic->callback.trace = tic80_libretro_trace;
+5 -5
src/system/sdlgpu.c
··· 185 185 186 186 u32* pixels = SDL_malloc(Size * Size * sizeof(u32)); 187 187 188 - const u32* pal = tic_tool_palette_blit(&platform.studio->config()->cart->bank0.palette); 188 + const u32* pal = tic_tool_palette_blit(&platform.studio->config()->cart->bank0.palette, platform.studio->tic->screen_format); 189 189 190 190 for(s32 j = 0, index = 0; j < Size; j++) 191 191 for(s32 i = 0; i < Size; i++, index++) ··· 278 278 279 279 drawKeyboardLabels(0); 280 280 281 - tic_core_blit(tic); 281 + tic_core_blit(tic, tic->screen_format); 282 282 283 283 platform.keyboard.texture.upPixels = SDL_malloc(TIC80_FULLWIDTH * TIC80_FULLHEIGHT * sizeof(u32)); 284 284 if(platform.keyboard.texture.upPixels) ··· 303 303 304 304 drawKeyboardLabels(2); 305 305 306 - tic_core_blit(tic); 306 + tic_core_blit(tic, tic->screen_format); 307 307 308 308 platform.keyboard.texture.downPixels = SDL_malloc(TIC80_FULLWIDTH * TIC80_FULLHEIGHT * sizeof(u32)); 309 309 if(platform.keyboard.texture.downPixels) ··· 335 335 336 336 const u8* in = platform.studio->tic->ram.vram.screen.data; 337 337 const u8* end = in + sizeof(platform.studio->tic->ram.vram.screen); 338 - const u32* pal = tic_tool_palette_blit(&platform.studio->config()->cart->bank0.palette); 338 + const u32* pal = tic_tool_palette_blit(&platform.studio->config()->cart->bank0.palette, platform.studio->tic->screen_format); 339 339 const u32 Delta = ((TIC80_FULLWIDTH*sizeof(u32))/sizeof *out - TIC80_WIDTH); 340 340 341 341 s32 col = 0; ··· 1150 1150 platform.mouse.src = in; 1151 1151 1152 1152 const u8* end = in + sizeof(tic_tile); 1153 - const u32* pal = tic_tool_palette_blit(&platform.studio->tic->ram.vram.palette); 1153 + const u32* pal = tic_tool_palette_blit(&platform.studio->tic->ram.vram.palette, platform.studio->tic->screen_format); 1154 1154 static u32 data[TIC_SPRITESIZE*TIC_SPRITESIZE]; 1155 1155 u32* out = data; 1156 1156
+7 -6
src/tic.c
··· 2088 2088 #endif 2089 2089 } 2090 2090 2091 - void tic_core_blit_ex(tic_mem* tic, tic_scanline scanline, tic_overline overline, void* data) 2091 + void tic_core_blit_ex(tic_mem* tic, tic_pixel_color_format fmt, tic_scanline scanline, tic_overline overline, void* data) 2092 2092 { 2093 - const u32* pal = tic_tool_palette_blit(&tic->ram.vram.palette); 2093 + const u32* pal = tic_tool_palette_blit(&tic->ram.vram.palette, fmt); 2094 2094 2095 2095 { 2096 2096 tic_machine* machine = (tic_machine*)tic; ··· 2100 2100 if(scanline) 2101 2101 { 2102 2102 scanline(tic, 0, data); 2103 - pal = tic_tool_palette_blit(&tic->ram.vram.palette); 2103 + pal = tic_tool_palette_blit(&tic->ram.vram.palette, fmt); 2104 2104 } 2105 2105 2106 2106 enum {Top = (TIC80_FULLHEIGHT-TIC80_HEIGHT)/2, Bottom = Top}; ··· 2131 2131 if(scanline && (r < TIC80_HEIGHT-1)) 2132 2132 { 2133 2133 scanline(tic, r+1, data); 2134 - pal = tic_tool_palette_blit(&tic->ram.vram.palette); 2134 + pal = tic_tool_palette_blit(&tic->ram.vram.palette, fmt); 2135 2135 } 2136 2136 } 2137 2137 ··· 2158 2158 machine->state.ovr.callback(memory, data); 2159 2159 } 2160 2160 2161 - void tic_core_blit(tic_mem* tic) 2161 + void tic_core_blit(tic_mem* tic, tic_pixel_color_format fmt) 2162 2162 { 2163 - tic_core_blit_ex(tic, scanline, overline, NULL); 2163 + tic_core_blit_ex(tic, fmt, scanline, overline, NULL); 2164 2164 } 2165 2165 2166 2166 u8 tic_api_peek(tic_mem* memory, s32 address) ··· 2256 2256 return NULL; 2257 2257 } 2258 2258 2259 + machine->memory.screen_format = TIC_PIXEL_COLOR_RGBA8888; 2259 2260 machine->samplerate = samplerate; 2260 2261 machine->memory.samples.size = samplerate * TIC_STEREO_CHANNELS / TIC80_FRAMERATE * sizeof(s16); 2261 2262 machine->memory.samples.buffer = malloc(machine->memory.samples.size);
+9
src/tic.h
··· 611 611 tic_cursor_hand, 612 612 tic_cursor_ibeam, 613 613 } tic_cursor; 614 + 615 + typedef enum { 616 + TIC_PIXEL_COLOR_ARGB8888 = (1 << 8) | 32, 617 + TIC_PIXEL_COLOR_ABGR8888 = (2 << 8) | 32, 618 + TIC_PIXEL_COLOR_RGBA8888 = (3 << 8) | 32, 619 + TIC_PIXEL_COLOR_BGRA8888 = (4 << 8) | 32 620 + } tic_pixel_color_format; 621 + 622 + #define TIC_PIXEL_COLOR_DEPTH(fmt) ((fmt) & 0xFF)
+3 -1
src/tic80.c
··· 74 74 memset(tic80, 0, sizeof(tic80_local)); 75 75 76 76 tic80->memory = tic_core_create(samplerate); 77 + tic80->tic.screen_format = tic80->memory->screen_format; 77 78 78 79 return &tic80->tic; 79 80 } ··· 112 113 { 113 114 tic80_local* tic80 = (tic80_local*)tic; 114 115 116 + tic80->memory->screen_format = tic80->tic.screen_format; 115 117 tic80->memory->ram.input = *input; 116 118 117 119 tic_core_tick_start(tic80->memory); 118 120 tic_core_tick(tic80->memory, &tic80->tickData); 119 121 tic_core_tick_end(tic80->memory); 120 122 121 - tic_core_blit(tic80->memory); 123 + tic_core_blit(tic80->memory, tic80->memory->screen_format); 122 124 123 125 TickCounter++; 124 126 }
+3 -2
src/ticapi.h
··· 163 163 } samples; 164 164 165 165 u32 screen[TIC80_FULLWIDTH * TIC80_FULLHEIGHT]; 166 + tic_pixel_color_format screen_format; 166 167 }; 167 168 168 169 tic_mem* tic_core_create(s32 samplerate); ··· 174 175 void tic_core_tick_start(tic_mem* memory); 175 176 void tic_core_tick(tic_mem* memory, tic_tick_data* data); 176 177 void tic_core_tick_end(tic_mem* memory); 177 - void tic_core_blit(tic_mem* tic); 178 - void tic_core_blit_ex(tic_mem* tic, tic_scanline scanline, tic_overline overline, void* data); 178 + void tic_core_blit(tic_mem* tic, tic_pixel_color_format fmt); 179 + void tic_core_blit_ex(tic_mem* tic, tic_pixel_color_format fmt, tic_scanline scanline, tic_overline overline, void* data); 179 180 const tic_script_config* tic_core_script_config(tic_mem* memory); 180 181 181 182 typedef struct
+27 -5
src/tools.c
··· 91 91 return closetColor; 92 92 } 93 93 94 - u32* tic_tool_palette_blit(const tic_palette* srcpal) 94 + u32* tic_tool_palette_blit(const tic_palette* srcpal, tic_pixel_color_format fmt) 95 95 { 96 96 static u32 pal[TIC_PALETTE_SIZE]; 97 97 ··· 101 101 102 102 while(src != end) 103 103 { 104 - *dst++ = src->r; 105 - *dst++ = src->g; 106 - *dst++ = src->b; 107 - *dst++ = 0xff; 104 + switch(fmt){ 105 + case TIC_PIXEL_COLOR_BGRA8888: 106 + *dst++ = src->b; 107 + *dst++ = src->g; 108 + *dst++ = src->r; 109 + *dst++ = 0xff; 110 + break; 111 + case TIC_PIXEL_COLOR_RGBA8888: 112 + *dst++ = src->r; 113 + *dst++ = src->g; 114 + *dst++ = src->b; 115 + *dst++ = 0xff; 116 + break; 117 + case TIC_PIXEL_COLOR_ABGR8888: 118 + *dst++ = 0xff; 119 + *dst++ = src->b; 120 + *dst++ = src->g; 121 + *dst++ = src->r; 122 + break; 123 + case TIC_PIXEL_COLOR_ARGB8888: 124 + *dst++ = 0xff; 125 + *dst++ = src->r; 126 + *dst++ = src->g; 127 + *dst++ = src->b; 128 + break; 129 + } 108 130 src++; 109 131 } 110 132
+1 -1
src/tools.h
··· 75 75 s32 tic_tool_get_pattern_id(const tic_track* track, s32 frame, s32 channel); 76 76 void tic_tool_set_pattern_id(tic_track* track, s32 frame, s32 channel, s32 id); 77 77 u32 tic_tool_find_closest_color(const tic_rgb* palette, const gif_color* color); 78 - u32* tic_tool_palette_blit(const tic_palette* src); 78 + u32* tic_tool_palette_blit(const tic_palette* src, tic_pixel_color_format fmt); 79 79 bool tic_tool_has_ext(const char* name, const char* ext); 80 80 s32 tic_tool_get_track_row_sfx(const tic_track_row* row); 81 81 void tic_tool_set_track_row_sfx(tic_track_row* row, s32 sfx);