From 3cbf9660974ead3fd8eb2b7398af293576896ec9 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Mon, 10 Jul 2023 12:24:02 +0100 Subject: Further optimisation --- README.md | 2 +- src/vga.c | 93 ++++++++++++++++++++++++++++++++++++--------------------------- 2 files changed, 55 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index e2e6dc6..c9792a4 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Running the game: - MS/DOS or compatible - A DOS Protected Mode Interface, e.g. [CWSDPMI](http://sandmann.dotster.com/cwsdpmi/) -- 386DX with VGA or better +- 386DX 33MHz (or better) with VGA - At least 4MB of RAM - Sound Blaster (or no sound) diff --git a/src/vga.c b/src/vga.c index a82fca9..1dc77db 100644 --- a/src/vga.c +++ b/src/vga.c @@ -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); -- cgit v1.2.3