From 0194f9c3bbb460647ce5a22e4e8e7859398d8da0 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Mon, 8 May 2023 22:52:26 +0100 Subject: Support read from the screen --- README.md | 11 +++++++---- tr8vm.c | 22 ++++++++++++++++++++-- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4f70bf0..f8eb7e5 100644 --- a/README.md +++ b/README.md @@ -77,8 +77,10 @@ On a successful port call, the read value equals to the port number, so the call To draw with the blitter the following steps are required: 1. put the blitter in settings mode using control port `0xb0` -2. provide the source address, and destination coordinates (x, y, width and height) using settings port `0xb1` -3. set the blitter in one of the write modes using the control port `0xb0` +2. provide an address, and screen coordinates (x, y, width and height) using settings port `0xb1` +3. set the blitter in one of the draw modes using the control port `0xb0` + +The address will be the source data in write mode, and the destination in read mode. Step 3 can be repeated as many times as needed, the blitter will keep the settings until the control port is set in settings mode. @@ -87,9 +89,10 @@ The settings byte is as follow: | Bits | Effect | --- | --- | | `x0000000` | Set blitter in settings mode | -| `0000000x` | Write | +| `0000000x` | Write to video RAM | | `000000x0` | The source includes a transparent bit | -| `0xxxxx00` | Unused | +| `00000x00` | Read from video RAM | +| `0xxxx000` | Unused | Example: diff --git a/tr8vm.c b/tr8vm.c index 59d08b7..69a0123 100644 --- a/tr8vm.c +++ b/tr8vm.c @@ -121,24 +121,41 @@ uint8_t port(uint8_t p, uint8_t v) { switch (p) { + /* blitter control */ case 0xb0: + /* settings mode */ if (v & 128) { blt_set = 1; blt_paramc = 0; return p; } - if (v & 1) + /* draw (read or write) */ + if (v & 5) { blt_set = 0; + /* can't be both */ + if ((v & 1) && (v & 4)) + return 0xff; + + /* missing parameters */ if (blt_paramc != 6) return 0xff; - /* draw */ + /* 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) + { + /* swap */ + uint16_t t = dst; + dst = src; + src = t; + } + for (uint8_t y = 0; y < blt_param[5]; y++) for (uint8_t x = 0; x < blt_param[4]; x++) { @@ -155,6 +172,7 @@ uint8_t port(uint8_t p, uint8_t v) } return 0xff; + /* blitter settings */ case 0xb1: if (!blt_set || blt_paramc > 5) return 0xff; -- cgit v1.2.3