From 2f50827c3d2bb48e79f202cd084de08b5ad65732 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sat, 6 May 2023 12:06:02 +0100 Subject: Implement hardware blitter --- tr8vm.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) (limited to 'tr8vm.c') diff --git a/tr8vm.c b/tr8vm.c index d4adb67..59d08b7 100644 --- a/tr8vm.c +++ b/tr8vm.c @@ -102,7 +102,7 @@ static void update_fb() void write_m(uint16_t addr, uint8_t b) { - if (addr >= VIDEO_RAM && addr < (VIDEO_RAM + 16384)) + if (addr >= VIDEO_RAM && addr < VIDEO_RAM + 16384) fb_data[addr - VIDEO_RAM] = palette[b & 15]; ram[addr] = b; @@ -113,6 +113,60 @@ uint8_t read_m(uint16_t addr) return ram[addr]; } +uint8_t blt_set = 0; +uint8_t blt_paramc = 0; +uint8_t blt_param[6] = { 0 }; + +uint8_t port(uint8_t p, uint8_t v) +{ + switch (p) + { + case 0xb0: + if (v & 128) + { + blt_set = 1; + blt_paramc = 0; + return p; + } + if (v & 1) + { + blt_set = 0; + + if (blt_paramc != 6) + return 0xff; + + /* draw */ + 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); + } + + return p; + } + return 0xff; + + case 0xb1: + if (!blt_set || blt_paramc > 5) + return 0xff; + + blt_param[blt_paramc++] = v; + return p; + + default: + return 0xff; + } +} + int main(int argc, char *argv[]) { FILE *fd; @@ -188,7 +242,7 @@ int main(int argc, char *argv[]) SDL_RenderPresent(renderer); Tr8 vm; - tr8_init(&vm, write_m, read_m); + tr8_init(&vm, write_m, read_m, port); int pitch = 0; uint8_t rc; -- cgit v1.2.3