From f15e55b960e1aa4d63c29f85d5db931342b617d9 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Wed, 10 May 2023 20:34:07 +0100 Subject: Avoid magic number and fix in trasparent reading from VRAM --- tr8vm.c | 13 ++++++++----- vm.h | 1 + 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/tr8vm.c b/tr8vm.c index fdede7c..f553614 100644 --- a/tr8vm.c +++ b/tr8vm.c @@ -96,13 +96,13 @@ uint32_t *fb_data = NULL; static void update_fb() { - for (uint16_t addr = 0; addr < 16384; addr++) + for (uint16_t addr = 0; addr < VIDEO_RAM_LEN; addr++) fb_data[addr] = palette[ram[VIDEO_RAM + addr] & 15]; } void write_m(uint16_t addr, uint8_t b) { - if (addr >= VIDEO_RAM && addr < VIDEO_RAM + 16384) + if (addr >= VIDEO_RAM && addr < VIDEO_RAM + VIDEO_RAM_LEN) fb_data[addr - VIDEO_RAM] = palette[b & 15]; ram[addr] = b; @@ -159,7 +159,7 @@ static void update_ctl(SDL_Event *ev) uint8_t blt_set = 0; uint8_t blt_paramc = 0; -uint8_t blt_param[6] = { 0 }; +int8_t blt_param[6] = { 0 }; uint8_t port(uint8_t p, uint8_t v) { @@ -191,7 +191,7 @@ uint8_t port(uint8_t p, uint8_t v) if (v & 1) { uint16_t src = blt_param[0] | (blt_param[1] << 8); - uint16_t dst = VIDEO_RAM + blt_param[2] + blt_param[3] * 128; + uint16_t dst = VIDEO_RAM + blt_param[2] + blt_param[3] * TR8_W; for (uint8_t y = 0; y < blt_param[5]; y++) for (uint8_t x = 0; x < blt_param[4]; x++) @@ -208,7 +208,7 @@ uint8_t port(uint8_t p, uint8_t v) /* read from vram */ else { - uint16_t src = VIDEO_RAM + blt_param[2] + blt_param[3] * 128; + uint16_t src = VIDEO_RAM + blt_param[2] + blt_param[3] * TR8_W; uint16_t dst = blt_param[0] | (blt_param[1] << 8); for (uint8_t y = 0; y < blt_param[5]; y++) @@ -218,7 +218,10 @@ uint8_t port(uint8_t p, uint8_t v) /* skip transparent if transparent flag is set */ if ((v & 2) && (b & 128)) + { + dst++; continue; + } write_m(dst++, b); } diff --git a/vm.h b/vm.h index 118ea25..9ba93ed 100644 --- a/vm.h +++ b/vm.h @@ -26,6 +26,7 @@ #define _TR8_H #define VIDEO_RAM 0xbf00 +#define VIDEO_RAM_LEN 16384 #define FRAME_INT_VECT 0xff00 typedef struct -- cgit v1.2.3