Skip to content

Commit

Permalink
gpulib: adjust masking
Browse files Browse the repository at this point in the history
no idea if anything uses this, but tested on hw
  • Loading branch information
notaz committed Aug 16, 2024
1 parent 5f71e0d commit 31a12b0
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions plugins/gpulib/gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,29 +370,39 @@ const unsigned char cmd_lengths[256] =

#define VRAM_MEM_XY(x, y) &gpu.vram[(y) * 1024 + (x)]

static void cpy_msb(uint16_t *dst, const uint16_t *src, int l, uint16_t msb)
// this isn't very useful so should be rare
static void cpy_mask(uint16_t *dst, const uint16_t *src, int l, uint32_t r6)
{
int i;
for (i = 0; i < l; i++)
dst[i] = src[i] | msb;
if (r6 == 1) {
for (i = 0; i < l; i++)
dst[i] = src[i] | 0x8000;
}
else {
uint16_t msb = r6 << 15;
for (i = 0; i < l; i++) {
uint16_t mask = (int16_t)dst[i] >> 15;
dst[i] = (dst[i] & mask) | ((src[i] | msb) & ~mask);
}
}
}

static inline void do_vram_line(int x, int y, uint16_t *mem, int l,
int is_read, uint16_t msb)
int is_read, uint32_t r6)
{
uint16_t *vram = VRAM_MEM_XY(x, y);
if (unlikely(is_read))
memcpy(mem, vram, l * 2);
else if (unlikely(msb))
cpy_msb(vram, mem, l, msb);
else if (unlikely(r6))
cpy_mask(vram, mem, l, r6);
else
memcpy(vram, mem, l * 2);
}

static int do_vram_io(uint32_t *data, int count, int is_read)
{
int count_initial = count;
uint16_t msb = gpu.ex_regs[6] << 15;
uint32_t r6 = gpu.ex_regs[6] & 3;
uint16_t *sdata = (uint16_t *)data;
int x = gpu.dma.x, y = gpu.dma.y;
int w = gpu.dma.w, h = gpu.dma.h;
Expand All @@ -405,7 +415,7 @@ static int do_vram_io(uint32_t *data, int count, int is_read)
if (count < l)
l = count;

do_vram_line(x + o, y, sdata, l, is_read, msb);
do_vram_line(x + o, y, sdata, l, is_read, r6);

if (o + l < w)
o += l;
Expand All @@ -420,13 +430,13 @@ static int do_vram_io(uint32_t *data, int count, int is_read)

for (; h > 0 && count >= w; sdata += w, count -= w, y++, h--) {
y &= 511;
do_vram_line(x, y, sdata, w, is_read, msb);
do_vram_line(x, y, sdata, w, is_read, r6);
}

if (h > 0) {
if (count > 0) {
y &= 511;
do_vram_line(x, y, sdata, count, is_read, msb);
do_vram_line(x, y, sdata, count, is_read, r6);
o = count;
count = 0;
}
Expand Down

0 comments on commit 31a12b0

Please sign in to comment.