diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-06-06 22:58:48 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-06-06 22:58:48 +0100 |
commit | 1c1e91bd8bf4e9d08cd4d8ee41568e3d25ee8256 (patch) | |
tree | 9f556e4cf692f83938ec772342b4cd6bb89323d8 /src | |
parent | 960db500527928e88bfb3787c9861a8b09f44749 (diff) | |
download | gold-mine-run-1c1e91bd8bf4e9d08cd4d8ee41568e3d25ee8256.tar.gz gold-mine-run-1c1e91bd8bf4e9d08cd4d8ee41568e3d25ee8256.zip |
First stab at the sw blitter
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 45 | ||||
-rw-r--r-- | src/vga.c | 42 | ||||
-rw-r--r-- | src/vga.h | 9 |
3 files changed, 82 insertions, 14 deletions
@@ -1,7 +1,7 @@ #include <stdint.h> -#include <stdio.h> #include <string.h> #include <stdlib.h> +#include <stdio.h> #include <crt0.h> #include "keyb.h" @@ -29,25 +29,50 @@ int main(int argc, char *argv[]) set_palette(binary_palette_start); - uint8_t *screen = open_framebuffer(); - if (!screen) + if (!open_framebuffer()) { set_mode(3); fprintf(stderr, "ERROR: failed to open the framebuffer\n"); return 1; } - int i = 0; + blit_erase(0); + + uint8_t bg[24 * 24] = { 0 }; + uint16_t x = 10, y = 10; + int8_t ix = 1, iy = 1; + uint8_t c = 0; + while (!keys[KEY_ESC]) { - wait_vsync(); + // erase + blit(bg, x, y, 24, 24); - memset(screen, i, 320 * 200); - i++; - if (i > 15) - i = 0; + x += ix; + y += iy; + + if (x >= 320 - 24 || x == 0) + { + ix *= -1; + c = (c + 1) % 15; + blit_erase(c); + memset(bg, c, 24 * 24); + } + if (y >= 200 - 24 || y == 0) + { + iy *= -1; + c = (c + 1) % 15; + blit_erase(c); + memset(bg, c, 24 * 24); + } + + // draw + blit(binary_sprites_start, x, y, 24, 24); + + wait_vsync(); + blit_update(); - timer_wait(1); + //timer_wait(1); } set_mode(3); @@ -1,15 +1,22 @@ #include <stdlib.h> +#include <string.h> #include <stdint.h> #include <dpmi.h> #include <sys/nearptr.h> #include <pc.h> -uint8_t *open_framebuffer() +#include "vga.h" + +static uint8_t buffer[320 * 200]; +static uint8_t *screen = NULL; + +uint8_t open_framebuffer() { if (__djgpp_nearptr_enable() == 0) - return NULL; + return 0; - return (uint8_t *)(0xa0000 + __djgpp_conventional_base); + screen = (uint8_t *)(0xa0000 + __djgpp_conventional_base); + return 1; } void close_framebuffer() @@ -36,3 +43,32 @@ void set_palette(const uint8_t *palette) for (int i = 0; i < 768; i++) outportb(0x3c9, palette[i] >> 2); } + +void blit(const uint8_t *src, uint16_t x, uint16_t y, uint16_t w, uint16_t h) +{ + for (int32_t j = y; j < y + h; j++) + for (int32_t i = x; i < x + w; i++) + { + uint8_t b = *src++; + + /* transparent */ + if (b == TRANSPARENT) + continue; + + /* clipping */ + if (i < 0 || i >= 320 || j < 0 || j >= 200) + continue; + + buffer[i + j * 320] = b; + } +} + +void blit_erase(uint8_t c) +{ + memset(buffer, c, 320 * 200); +} + +void blit_update() +{ + memcpy(screen, buffer, 320 * 200); +} @@ -1,7 +1,10 @@ #ifndef _VGA_H #define _VGA_H -uint8_t *open_framebuffer(); +/* palette index to be used as transparent color */ +#define TRANSPARENT 16 + +uint8_t open_framebuffer(); void close_framebuffer(); void set_mode(uint8_t mode); @@ -10,4 +13,8 @@ void wait_vsync(); /* the palette is expected to be 8 bit per color, and will be converted to VGA's 6 bit per color */ void set_palette(const uint8_t *palette); +void blit(const uint8_t *src, uint16_t x, uint16_t y, uint16_t w, uint16_t h); +void blit_erase(uint8_t c); +void blit_update(); + #endif /* _VGA_H */ |