From 710c64fc02390e41ec29667c7a0d32115bf313ec Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Wed, 10 May 2023 20:51:15 +0100 Subject: Do clipping in the blitter --- tr8vm.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'tr8vm.c') diff --git a/tr8vm.c b/tr8vm.c index f553614..ca2452e 100644 --- a/tr8vm.c +++ b/tr8vm.c @@ -191,10 +191,9 @@ 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] * TR8_W; - for (uint8_t y = 0; y < blt_param[5]; y++) - for (uint8_t x = 0; x < blt_param[4]; x++) + for (int16_t y = blt_param[3]; y < blt_param[3] + blt_param[5]; y++) + for (int16_t x = blt_param[2]; x < blt_param[2] + blt_param[4]; x++) { uint8_t b = read_m(src++); @@ -202,26 +201,28 @@ uint8_t port(uint8_t p, uint8_t v) if ((v & 2) && (b & 128)) continue; - write_m(dst + x + y * 128, b); + /* clipping */ + if (x < 0 || x >= TR8_W || y < 0 || y >= TR8_H) + continue; + + write_m((uint16_t)(VIDEO_RAM + x + y * 128), b); } } /* read from vram */ else { - 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++) - for (uint8_t x = 0; x < blt_param[4]; x++) + for (int16_t y = blt_param[3]; y < blt_param[3] + blt_param[5]; y++) + for (int16_t x = blt_param[2]; x < blt_param[2] + blt_param[4]; x++) { - uint8_t b = read_m(src + x + y * 128); + uint8_t b = 0; - /* skip transparent if transparent flag is set */ - if ((v & 2) && (b & 128)) - { - dst++; - continue; - } + /* clipping */ + if (x >= 0 && x < TR8_W && y >= 0 && y < TR8_H) + /* skip transparent if transparent flag is set */ + if (!((v & 2) && (b & 128))) + b = read_m(VIDEO_RAM + x + y * 128); write_m(dst++, b); } -- cgit v1.2.3