From f27394249ef3e3b219ac73a7b2259509ab5b6dbf Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Fri, 17 Nov 2017 23:37:37 +0300 Subject: [PATCH] blit api performance optimization --- src/tic.c | 28 +++++++++++----------------- src/tools.c | 24 ++---------------------- src/tools.h | 25 +++++++++++++++++++++++-- 3 files changed, 36 insertions(+), 41 deletions(-) diff --git a/src/tic.c b/src/tic.c index 99c1a11..5e0ab7c 100644 --- a/src/tic.c +++ b/src/tic.c @@ -1647,27 +1647,21 @@ static void api_blit(tic_mem* tic, u32* out, tic_scanline scanline) memset4(&out[0 * TIC80_FULLWIDTH], pal[tic->ram.vram.vars.border], TIC80_FULLWIDTH*Top); - for(s32 r = 0; r < TIC80_HEIGHT; r++) + u32* rowPtr = out + Top*TIC80_FULLWIDTH; + + for(s32 r = 0, y = tic->ram.vram.vars.offset.y; r < TIC80_HEIGHT; r++, y++, rowPtr += TIC80_FULLWIDTH) { - memset4(&out[(r+Top) * TIC80_FULLWIDTH], pal[tic->ram.vram.vars.border], Left); - memset4(&out[(r+Top) * TIC80_FULLWIDTH + Left], pal[tic->ram.vram.vars.bg], TIC80_WIDTH); + memset4(rowPtr, pal[tic->ram.vram.vars.border], Left); + memset4(rowPtr + Left, pal[tic->ram.vram.vars.bg], TIC80_WIDTH); - { - s32 y = r + tic->ram.vram.vars.offset.y; + u32* colPtr = rowPtr + Left; - if(y < 0 || y >= TIC80_HEIGHT) continue; - - for(s32 c = 0; c < TIC80_WIDTH; c++) - { - s32 x = c + tic->ram.vram.vars.offset.x; + if(y >= 0 && y < TIC80_HEIGHT) + for(s32 c = 0, x = tic->ram.vram.vars.offset.x, index = y * TIC80_WIDTH + x; c < TIC80_WIDTH; c++, colPtr++, x++, index++) + if(x >= 0 && x < TIC80_WIDTH) + *colPtr = pal[tic_tool_peek4(tic->ram.vram.screen.data, index)]; - if(x < 0 || x >= TIC80_WIDTH) continue; - - out[(c + Left) + (r+Top) * TIC80_FULLWIDTH] = pal[tic_tool_peek4(tic->ram.vram.screen.data, x + y * TIC80_WIDTH)]; - } - } - - memset4(&out[(r+Top) * TIC80_FULLWIDTH + (TIC80_FULLWIDTH-Right)], pal[tic->ram.vram.vars.border], Right); + memset4(rowPtr + (TIC80_FULLWIDTH-Right), pal[tic->ram.vram.vars.border], Right); if(scanline && (r < TIC80_HEIGHT-1)) { diff --git a/src/tools.c b/src/tools.c index 05c7ea8..b4dab40 100644 --- a/src/tools.c +++ b/src/tools.c @@ -25,28 +25,8 @@ #include -void tic_tool_poke4(void* addr, u32 index, u8 value) -{ - u8* val = (u8*)addr + (index >> 1); - - if(index & 1) - { - *val &= 0x0f; - *val |= (value << 4); - } - else - { - *val &= 0xf0; - *val |= value & 0x0f; - } -} - -u8 tic_tool_peek4(const void* addr, u32 index) -{ - u8 val = ((u8*)addr)[index >> 1]; - - return index & 1 ? val >> 4 : val & 0xf; -} +extern void tic_tool_poke4(void* addr, u32 index, u8 value); +extern u8 tic_tool_peek4(const void* addr, u32 index); s32 tic_tool_get_pattern_id(const tic_track* track, s32 frame, s32 channel) { diff --git a/src/tools.h b/src/tools.h index bfa327b..50e5361 100644 --- a/src/tools.h +++ b/src/tools.h @@ -24,8 +24,29 @@ #include "tic.h" -void tic_tool_poke4(void* addr, u32 index, u8 value); -u8 tic_tool_peek4(const void* addr, u32 index); +inline void tic_tool_poke4(void* addr, u32 index, u8 value) +{ + u8* val = (u8*)addr + (index >> 1); + + if(index & 1) + { + *val &= 0x0f; + *val |= (value << 4); + } + else + { + *val &= 0xf0; + *val |= value & 0x0f; + } +} + +inline u8 tic_tool_peek4(const void* addr, u32 index) +{ + u8 val = ((u8*)addr)[index >> 1]; + + return index & 1 ? val >> 4 : val & 0xf; +} + bool tic_tool_parse_note(const char* noteStr, s32* note, s32* octave); s32 tic_tool_get_pattern_id(const tic_track* track, s32 frame, s32 channel); void tic_tool_set_pattern_id(tic_track* track, s32 frame, s32 channel, s32 id);