diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-07-10 12:24:02 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-07-10 12:24:02 +0100 |
commit | 3cbf9660974ead3fd8eb2b7398af293576896ec9 (patch) | |
tree | f103f300adebc25c6d43ed620dbba67185907a74 /src/vga.c | |
parent | fcde38e508cd381ad17e0f73946fa551ac683c81 (diff) | |
download | gold-mine-run-3cbf9660974ead3fd8eb2b7398af293576896ec9.tar.gz gold-mine-run-3cbf9660974ead3fd8eb2b7398af293576896ec9.zip |
Further optimisation
Diffstat (limited to 'src/vga.c')
-rw-r--r-- | src/vga.c | 93 |
1 files changed, 54 insertions, 39 deletions
@@ -122,58 +122,73 @@ void blit(const uint8_t *sprite, const Rect *dst) void blit_c(const uint8_t *sprite, const Rect *dst, uint8_t c) { - uint8_t b; uint8_t *dtarget = target + dst->x + dst->y * 320; - const uint16_t inc = 320 - dst->w; - - for (uint16_t j = dst->h; j > 0; j--) - { - for (uint16_t i = dst->w; i > 0; i--) - { - b = *sprite++; - /* transparent */ - if (b == TRANSPARENT) - { - dtarget++; - continue; - } + asm volatile ( + "movl $320, %%ebp\n\t" + "subl %%ecx, %%ebp\n\t" + "blit_c_w:\n\t" + "movl %%ecx, %%eax\n\t" + "blit_c_w_loop:\n\t" + "movb (%%esi), %%ah\n\t" + "cmpb $%p5, %%ah\n\t" + "je blitrc_tr\n\t" + "orb %%ah, %%ah\n\t" + "je blit_c_store\n\t" + "movb %%dl, %%ah\n\t" + "blit_c_store:\n\t" + "movb %%ah, (%%edi)\n\t" + "blit_c_tr:\n\t" + "incl %%esi\n\t" + "incl %%edi\n\t" + "decb %%al\n\t" + "jne blit_c_w_loop\n\t" + "addl %%ebp, %%edi\n\t" + "decl %%ebx\n\t" + "jne blit_c_w\n\t" + : /*no output */ + : "S" (sprite), "D" (dtarget), + "b" ((uint32_t)dst->h), "d" ((uint32_t)c), + "c" ((uint32_t)dst->w), "i" (TRANSPARENT) + : "eax", "ebp" + ); - *dtarget++ = b ? c : b; - } - dtarget += inc; - } } void blitrc(const uint8_t *sprite, const Rect *src, const Rect *dst) { - uint8_t b; uint8_t *dtarget = target + dst->x + dst->y * 320; - const uint16_t inc1 = src->w - dst->w; - const uint16_t inc2 = 320 - dst->w; sprite += src->x + src->y * src->w; - for (uint16_t j = dst->h; j > 0; j--) - { - for (uint16_t i = dst->w; i > 0; i--) - { - b = *sprite++; - - /* transparent */ - if (b == TRANSPARENT) - { - dtarget++; - continue; - } - - *dtarget++ = b; - } - sprite += inc1; - dtarget += inc2; - } + asm volatile ( + "movl $320, %%ebp\n\t" + "subl %%ecx, %%ebp\n\t" + "blitrc_w:\n\t" + "movl %%ecx, %%eax\n\t" + "blitrc_w_loop:\n\t" + "movb (%%esi), %%ah\n\t" + "cmpb $%p5, %%ah\n\t" + "je blitrc_tr\n\t" + "movb %%ah, (%%edi)\n\t" + "blitrc_tr:\n\t" + "incl %%esi\n\t" + "incl %%edi\n\t" + "decb %%al\n\t" + "jne blitrc_w_loop\n\t" + "addl %%edx, %%esi\n\t" + "addl %%ebp, %%edi\n\t" + "decl %%ebx\n\t" + "jne blitrc_w\n\t" + : /*no output */ + : "S" (sprite), "D" (dtarget), + "b" ((uint32_t)dst->h), "d" ((uint32_t)(src->w - dst->w)), + "c" ((uint32_t)dst->w), "i" (TRANSPARENT) + : "eax", "ebp" + ); } + void blit_erase(uint8_t c) { memset(target, c, 320 * 200); |