aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-06-08 08:01:02 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-06-08 08:01:02 +0100
commitf90846d5a7a82573f85a58306c7b866baef95703 (patch)
tree59e5f2c56f7d6afcac7fb69e5998da97c635817b /src
parent1cd96edcd529599b2d1a0de584bee50252cc23be (diff)
downloadgold-mine-run-f90846d5a7a82573f85a58306c7b866baef95703.tar.gz
gold-mine-run-f90846d5a7a82573f85a58306c7b866baef95703.zip
Use a rectangle struct
Diffstat (limited to 'src')
-rw-r--r--src/main.c14
-rw-r--r--src/vga.c8
-rw-r--r--src/vga.h9
3 files changed, 19 insertions, 12 deletions
diff --git a/src/main.c b/src/main.c
index 88e2e98..c0e7dc3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -33,26 +33,26 @@ int main(int argc, char *argv[])
blit_update();
uint8_t bg[24 * 24] = { 0 };
- uint16_t x = 10, y = 10;
+ Rect dst = { 10, 10, 24, 24 };
int8_t ix = 1, iy = 1;
uint8_t c = 0;
while (!keys[KEY_ESC])
{
// erase
- blit(bg, x, y, 24, 24);
+ blit(bg, &dst);
- x += ix;
- y += iy;
+ dst.x += ix;
+ dst.y += iy;
- if (x >= 320 - 24 || x == 0)
+ if (dst.x >= 320 - 24 || dst.x == 0)
{
ix *= -1;
c = (c + 1) % 15;
blit_erase(c);
memset(bg, c, 24 * 24);
}
- if (y >= 200 - 24 || y == 0)
+ if (dst.y >= 200 - 24 || dst.y == 0)
{
iy *= -1;
c = (c + 1) % 15;
@@ -61,7 +61,7 @@ int main(int argc, char *argv[])
}
// draw
- blit(binary_sprites_start, x, y, 24, 24);
+ blit(binary_sprites_start, &dst);
wait_vsync();
blit_update();
diff --git a/src/vga.c b/src/vga.c
index a408f71..6665c79 100644
--- a/src/vga.c
+++ b/src/vga.c
@@ -44,12 +44,12 @@ void set_palette(const uint8_t *palette)
outportb(0x3c9, palette[i] >> 2);
}
-void blit(const uint8_t *src, uint16_t x, uint16_t y, uint16_t w, uint16_t h)
+void blit(const uint8_t *sprite, const Rect *dst)
{
- for (int32_t j = y * 320; j < (y + h) * 320; j += 320)
- for (int16_t i = x; i < x + w; i++)
+ for (int32_t j = dst->y * 320; j < (dst->y + dst->h) * 320; j += 320)
+ for (int16_t i = dst->x; i < dst->x + dst->w; i++)
{
- uint8_t b = *src++;
+ uint8_t b = *sprite++;
/* transparent */
if (b == TRANSPARENT)
diff --git a/src/vga.h b/src/vga.h
index ef183ca..a185974 100644
--- a/src/vga.h
+++ b/src/vga.h
@@ -4,6 +4,13 @@
/* palette index to be used as transparent color */
#define TRANSPARENT 16
+typedef struct {
+ uint16_t x;
+ uint16_t y;
+ uint16_t w;
+ uint16_t h;
+} Rect;
+
uint8_t open_framebuffer();
void close_framebuffer();
@@ -13,7 +20,7 @@ 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(const uint8_t *sprite, const Rect *dst);
void blit_erase(uint8_t c);
void blit_update();