diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-05-06 12:06:02 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-05-06 12:13:00 +0100 |
commit | 2f50827c3d2bb48e79f202cd084de08b5ad65732 (patch) | |
tree | 3027a753af4ae891d5de4baa997846f11b28f58c /tr8vm.c | |
parent | dd194bf4de0d54cef7e14aeb7576d799acb61840 (diff) | |
download | tr8vm-2f50827c3d2bb48e79f202cd084de08b5ad65732.tar.gz tr8vm-2f50827c3d2bb48e79f202cd084de08b5ad65732.zip |
Implement hardware blitter
Diffstat (limited to 'tr8vm.c')
-rw-r--r-- | tr8vm.c | 58 |
1 files changed, 56 insertions, 2 deletions
@@ -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; |