aboutsummaryrefslogtreecommitdiff
path: root/tr8vm.c
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-05-10 20:51:15 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-05-10 20:51:15 +0100
commit710c64fc02390e41ec29667c7a0d32115bf313ec (patch)
tree5af5f6c8e300b4ace82dcb9cd9d90a14c21426be /tr8vm.c
parentf15e55b960e1aa4d63c29f85d5db931342b617d9 (diff)
downloadtr8vm-710c64fc02390e41ec29667c7a0d32115bf313ec.tar.gz
tr8vm-710c64fc02390e41ec29667c7a0d32115bf313ec.zip
Do clipping in the blitter
Diffstat (limited to 'tr8vm.c')
-rw-r--r--tr8vm.c29
1 files changed, 15 insertions, 14 deletions
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);
}