From a919803f792b795de8733258da4055dbb2f5255c Mon Sep 17 00:00:00 2001 From: George Wright Date: Mon, 9 Dec 2024 23:22:22 -0800 Subject: [PATCH] Fix LCD scanout --- WindCore/sa1100.cpp | 113 +++----------------------------------------- 1 file changed, 6 insertions(+), 107 deletions(-) diff --git a/WindCore/sa1100.cpp b/WindCore/sa1100.cpp index 8347cf6..ebbbc2a 100644 --- a/WindCore/sa1100.cpp +++ b/WindCore/sa1100.cpp @@ -1167,140 +1167,39 @@ void Emulator::readLCDIntoBuffer(uint8_t **lines, bool is32BitOutput) { uint32_t paletteBase = lcdController->get_data32(LCDController::DBAR1); // The palette is 512 bytes long uint32_t framebufferTopHalfBase = paletteBase + 512; - uint32_t framebufferBottomHalfBase = - lcdController->get_data32(LCDController::DBAR2); + uint32_t framebufferBottomHalfBase = lcdController->get_data32(LCDController::DBAR2); uint32_t test; std::vector palette; for (int i = 0; i < 128; i++) { LOAD_32LE(test, (paletteBase + (4*i)) & memoryMask, MemoryBlockC0); - palette.emplace_back(test & 0xFFFF); - palette.emplace_back(test >> 16); + palette.emplace_back(test & 0xFFF); + palette.emplace_back((test >> 16) & 0xFFF); } std::vector pixels; for (int i = 0; i < 640*240; i += 4) { LOAD_32LE(test, (framebufferTopHalfBase + (i)) & memoryMask, MemoryBlockC0); for (int j = 0; j < 4; j++) { - pixels.emplace_back(getByteIdx(test, j)); + pixels.emplace_back(getByteIdx(test, 3-j)); } } for (int i = 0; i < 640*240; i += 4) { LOAD_32LE(test, (framebufferBottomHalfBase + (i)) & memoryMask, MemoryBlockC0); for (int j = 0; j < 4; j++) { - pixels.emplace_back(getByteIdx(test, j)); + pixels.emplace_back(getByteIdx(test, 3-j)); } } - gpioController->flip_gpio(); - - // printf("Palette:\n"); - // int newline = 0; - // for (uint16_t pal : palette) { - // newline++; - // printf("%04x ", pal); - // if (newline % 32 == 0) { - // printf("\n"); - // } - // } - // printf("\n"); - - // printf("Pixels:\n"); - // newline = 0; - // for (uint8_t pix : pixels) { - // newline++; - // printf("%02x ", pix); - // if (newline % 64 == 0) { - // printf("\n"); - // } - // } - // printf("\n"); - - // printf("Pixel count %d\n", pixels.size()); - - // printf("PBS: %x\n", (palette[0] >> 12) & 0x3); - - // uint8_t* framebufferTopHalf = &MemoryBlockC0[512]; - // uint8_t* framebufferBottomHalf = &MemoryBlockC0[512 + (640*240)]; - - //printf("Display Size %dx%d\n", lcdController->getWidth(), lcdController->getHeight()); - for (int i = 0; i < 480; i++) { uint16_t* line = reinterpret_cast(lines[i]); memset(line, 0, 2*640); for (int j = 0; j < 640; j++) { - line[j] = palette[pixels[(480*i)+j] & 0x0FFF]; - //uint8_t pixel = pixels[(480*i)+j]; - // if (pixel != 0) { - // printf("Pixel data is %02x\n", pixel); - // } - //line[j] = pixel; - //printf("Pixel %08x\n", line[j]); + line[j] = palette[pixels[(640*i)+j]]; } } lcdController->finish_one_frame(); - - // int wordsPerRow = lcdController->getWidth() / 4; - // for (int i = 0; i < lcdController->getHeight(); i++) { - // line1 = reinterpret_cast(lines[i]); - // line2 = reinterpret_cast(lines[240+i]); - - // for (int j = 0; j < wordsPerRow; j++) { - // LOAD_32LE(pixels1, (framebufferTopHalfBase + 4 * (j + (i*wordsPerRow))) & 0xFFFFFF, MemoryBlockC0); - // LOAD_32LE(pixels2, (framebufferBottomHalfBase + 4 * (j + (i*wordsPerRow))) & 0xFFFFFF, MemoryBlockC0); - // for (int k = 0; k < 4; k++) { - // line1[(4*j)+k] = palette[getByteIdx(pixels1, 3-k)] & 0xFFF; - // line2[(4*j)+k] = palette[getByteIdx(pixels2, 3-k)] & 0xFFF; - // } - // } - // } - //for (int i = 0; i < 256; i++) { -// printf("%02x%02x \n", MemoryBlockC0[paletteBase+i], MemoryBlockC0[paletteBase+i+1]); -// }//printf("Palette: %d\n", palette->PBS); - - // if (!initRgbValues) { - // initRgbValues = true; - // for (int i = 0; i < 16; i++) { - // int r = (0x99 * i) / 15; - // int g = (0xAA * i) / 15; - // int b = (0x88 * i) / 15; - // rgbValues[15 - i] = r | (g << 8) | (b << 16) | 0xFF000000; - // } - // } - - // if ((lcdAddress >> 24) == 0xC0) { - // const uint8_t *lcdBuf = &MemoryBlockC0[lcdAddress - 0xC0000000]; - // int width = 640, height = 480; - - // // fetch palette - // int bpp = 1 << (lcdBuf[1] >> 4); - // int ppb = 8 / bpp; - // uint16_t palette[16]; - // for (int i = 0; i < 16; i++) - // palette[i] = lcdBuf[i*2] | ((lcdBuf[i*2+1] << 8) & 0xF00); - - // // build our image out - // int lineWidth = (width * bpp) / 8; - // for (int y = 0; y < height; y++) { - // int lineOffs = 0x20 + (lineWidth * y); - // for (int x = 0; x < width; x++) { - // uint8_t byte = lcdBuf[lineOffs + (x / ppb)]; - // int shift = (x & (ppb - 1)) * bpp; - // int mask = (1 << bpp) - 1; - // int palIdx = (byte >> shift) & mask; - // int palValue = palette[palIdx]; - - // if (is32BitOutput) { - // auto line = (uint32_t *)lines[y]; - // line[x] = rgbValues[palValue]; - // } else { - // palValue |= (palValue << 4); - // lines[y][x] = palValue ^ 0xFF; - // } - // } - // } - // } } -- 2.45.2