From ef6a41652e0d3ee5b1745286fefa6d8f57509a23 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Mon, 8 May 2023 23:34:33 +0100 Subject: Fix reading from vram --- tr8vm.c | 50 +++++++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 19 deletions(-) (limited to 'tr8vm.c') diff --git a/tr8vm.c b/tr8vm.c index 69a0123..f5b2098 100644 --- a/tr8vm.c +++ b/tr8vm.c @@ -143,30 +143,42 @@ uint8_t port(uint8_t p, uint8_t v) if (blt_paramc != 6) return 0xff; - /* 1: write into vram */ - uint16_t src = blt_param[0] | (blt_param[1] << 8); - uint16_t dst = VIDEO_RAM + blt_param[2] + blt_param[3] * 128; - - /* 4: read from vram */ - if (v & 4) + /* write into vram */ + if (v & 1) { - /* swap */ - uint16_t t = dst; - dst = src; - src = t; + uint16_t src = blt_param[0] | (blt_param[1] << 8); + uint16_t dst = VIDEO_RAM + blt_param[2] + blt_param[3] * 128; + + for (uint8_t y = 0; y < blt_param[5]; y++) + for (uint8_t x = 0; x < blt_param[4]; x++) + { + uint8_t b = read_m(src++); + + /* skip transparent if transparent flag is set */ + if ((v & 2) && (b & 128)) + continue; + + write_m(dst + x + y * 128, b); + } } + /* read from vram */ + else + { + uint16_t src = VIDEO_RAM + blt_param[2] + blt_param[3] * 128; + 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++) - { - uint8_t b = read_m(src++); + for (uint8_t y = 0; y < blt_param[5]; y++) + for (uint8_t x = 0; x < blt_param[4]; x++) + { + uint8_t b = read_m(src + x + y * 128); - /* skip transparent if transparent flag is set */ - if ((v & 2) && (b & 128)) - continue; + /* skip transparent if transparent flag is set */ + if ((v & 2) && (b & 128)) + continue; - write_m(dst + x + y * 128, b); - } + write_m(dst++, b); + } + } return p; } -- cgit v1.2.3