From: beeanyew Date: Wed, 6 Jan 2021 03:56:33 +0000 (+0100) Subject: Fix all the colors, fix some other stuff. X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=4ee88c22666d018ab300ec31c908903637f31681;p=pistorm Fix all the colors, fix some other stuff. Workbench still doesn't work. --- diff --git a/m68kcpu.h b/m68kcpu.h index 4262cd9..eb16224 100644 --- a/m68kcpu.h +++ b/m68kcpu.h @@ -1147,7 +1147,7 @@ static inline uint m68ki_read_8_fc(uint address, uint fc) for (int i = 0; i < read_ranges; i++) { if(address >= read_addr[i] && address < read_upper[i]) { - return read_data[i][address]; + return read_data[i][address - read_addr[i]]; } } @@ -1204,7 +1204,7 @@ static inline void m68ki_write_8_fc(uint address, uint fc, uint value) for (int i = 0; i < write_ranges; i++) { if(address >= write_addr[i] && address < write_upper[i]) { - write_data[i][address] = (unsigned char)value; + write_data[i][address - write_addr[i]] = (unsigned char)value; return; } } diff --git a/platforms/amiga/rtg/rtg-output.c b/platforms/amiga/rtg/rtg-output.c index 23217cb..2b9a8a5 100644 --- a/platforms/amiga/rtg/rtg-output.c +++ b/platforms/amiga/rtg/rtg-output.c @@ -39,9 +39,9 @@ static uint32_t palette[256]; void rtg_update_screen() {} uint32_t rtg_to_sdl2[RTGFMT_NUM] = { - SDL_PIXELFORMAT_BGRA8888, + SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGB565, - SDL_PIXELFORMAT_BGRA8888, + SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGB555, }; @@ -122,16 +122,26 @@ reinit_sdl:; printf("Created %dx%d texture.\n", width, height); } - if (format == RTGFMT_8BIT) { - indexed_buf = calloc(1, width * height * 4); - pitch = width * 4; + switch (format) { + case RTGFMT_8BIT: + indexed_buf = calloc(1, width * height * 4); + pitch = width * 4; + break; + case RTGFMT_RBG565: + indexed_buf = calloc(1, width * height * 2); + break; + default: + break; } while (1) { if (renderer && win && img) { SDL_RenderClear(renderer); if (*data->running) { - SDL_UpdateTexture(img, NULL, (format != RTGFMT_8BIT) ? &data->memory[*data->addr] : (uint8_t *)indexed_buf, pitch); + if (format == RTGFMT_RGB32) + SDL_UpdateTexture(img, NULL, &data->memory[*data->addr], pitch); + else + SDL_UpdateTexture(img, NULL, (uint8_t *)indexed_buf, pitch); SDL_RenderCopy(renderer, img, NULL, NULL); } SDL_RenderPresent(renderer); @@ -141,12 +151,21 @@ reinit_sdl:; reinit = 1; goto shutdown_sdl; } - if (format == RTGFMT_8BIT) { - for (int y = 0; y < height; y++) { - for (int x = 0; x < width; x++) { - indexed_buf[x + (y * width)] = palette[data->memory[*data->addr + x + (y * width)]]; + switch (format) { + case RTGFMT_8BIT: + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { + indexed_buf[x + (y * width)] = palette[data->memory[*data->addr + x + (y * width)]]; + } + } + break; + case RTGFMT_RBG565: + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { + ((uint16_t *)indexed_buf)[x + (y * width)] = be16toh(((uint16_t *)data->memory)[*data->addr + x + (y * width)]); + } } - } + break; } } else @@ -174,11 +193,8 @@ shutdown_sdl:; return args; } -void rtg_set_clut_entry(uint8_t index, uint8_t r, uint8_t g, uint8_t b) { - //int r = (int)((float)rtg_u8[1] / 255.0f * 31.0f); - //int g = (int)((float)rtg_u8[2] / 255.0f * 63.0f); - //int b = (int)((float)rtg_u8[3] / 255.0f * 31.0f); - palette[index] = (r << 24) | (g << 16) | (b << 8) | 0xFF; +void rtg_set_clut_entry(uint8_t index, uint32_t xrgb) { + palette[index] = xrgb; } void rtg_init_display() { diff --git a/platforms/amiga/rtg/rtg.c b/platforms/amiga/rtg/rtg.c index 040af6f..4ce6dfe 100644 --- a/platforms/amiga/rtg/rtg.c +++ b/platforms/amiga/rtg/rtg.c @@ -102,9 +102,7 @@ void rtg_write(uint32_t address, uint32_t value, uint8_t mode) { *(( uint16_t *) (&rtg_mem[address - PIGFX_REG_SIZE])) = htobe16(value); break; case OP_TYPE_LONGWORD: - *(( uint16_t *) (&rtg_mem[address - PIGFX_REG_SIZE] + 2)) = htobe16(value & 0xFFFF); - *(( uint16_t *) (&rtg_mem[address - PIGFX_REG_SIZE])) = htobe16((value >> 16)); - //*(( uint32_t *) (&rtg_mem[address - PIGFX_REG_SIZE])) = htobe32(value); + *(( uint32_t *) (&rtg_mem[address - PIGFX_REG_SIZE])) = htobe32(value); break; default: return; @@ -116,10 +114,17 @@ void rtg_write(uint32_t address, uint32_t value, uint8_t mode) { case OP_TYPE_BYTE: switch (address) { case RTG_U81: + rtg_u8[0] = value; + break; case RTG_U82: + rtg_u8[1] = value; + break; case RTG_U83: + rtg_u8[2] = value; + break; case RTG_U84: - rtg_u8[address - RTG_U81] = value; + rtg_u8[3] = value; + break; } break; case OP_TYPE_WORD: @@ -204,8 +209,9 @@ static void handle_rtg_command(uint32_t cmd) { break; case RTGCMD_SETCLUT: { //printf("Command: SetCLUT.\n"); - printf("Set palette entry %d to %d, %d, %d\n", rtg_u8[0], rtg_u8[1], rtg_u8[2], rtg_u8[3]); - rtg_set_clut_entry(rtg_u8[0], rtg_u8[1], rtg_u8[2], rtg_u8[3]); + //printf("Set palette entry %d to %d, %d, %d\n", rtg_u8[0], rtg_u8[1], rtg_u8[2], rtg_u8[3]); + //printf("Set palette entry %d to 32-bit palette color: %.8X\n", rtg_u8[0], rtg_rgb[0]); + rtg_set_clut_entry(rtg_u8[0], rtg_rgb[0]); break; } case RTGCMD_SETDISPLAY: @@ -237,19 +243,25 @@ void rtg_fillrect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t color uint8_t *dptr = &rtg_mem[framebuffer_addr + (x << format) + (y * rtg_pitch)]; switch(format) { case RTGFMT_8BIT: { + //printf("Incoming 8-bit color: %.8X\n", color); for (int xs = 0; xs < w; xs++) { dptr[xs] = color & 0xFF; } break; } case RTGFMT_RBG565: { + //printf("Incoming raw 16-bit color: %.8X\n", htobe32(color)); + color = htobe16((color & 0xFFFF)); + //printf("Incoming 16-bit color: %.8X\n", color); uint16_t *ptr = (uint16_t *)dptr; for (int xs = 0; xs < w; xs++) { - ptr[xs] = (color & 0xFFFF); + ptr[xs] = color; } break; } case RTGFMT_RGB32: { + color = htobe32(color); + //printf("Incoming 32-bit color: %.8X\n", color); uint32_t *ptr = (uint32_t *)dptr; for (int xs = 0; xs < w; xs++) { ptr[xs] = color; diff --git a/platforms/amiga/rtg/rtg.h b/platforms/amiga/rtg/rtg.h index 0265e1a..a27ab25 100644 --- a/platforms/amiga/rtg/rtg.h +++ b/platforms/amiga/rtg/rtg.h @@ -44,7 +44,7 @@ enum rtg_formats { void rtg_write(uint32_t address, uint32_t value, uint8_t mode); unsigned int rtg_read(uint32_t address, uint8_t mode); -void rtg_set_clut_entry(uint8_t index, uint8_t r, uint8_t g, uint8_t b); +void rtg_set_clut_entry(uint8_t index, uint32_t xrgb); void rtg_init_display(); void rtg_shutdown_display(); diff --git a/platforms/amiga/rtg/rtg_driver_amiga/pigfx.c b/platforms/amiga/rtg/rtg_driver_amiga/pigfx.c index 6655775..68e4578 100644 --- a/platforms/amiga/rtg/rtg_driver_amiga/pigfx.c +++ b/platforms/amiga/rtg/rtg_driver_amiga/pigfx.c @@ -417,11 +417,16 @@ void SetColorArray (__REGA0(struct BoardInfo *b), __REGD0(UWORD start), __REGD1( // Sets the color components of X color components for 8-bit paletted display modes. if (!b->CLUT) return; - for(int i = start; i < num; i++) { + + int j = start + num; + + for(int i = start; i < j; i++) { + //WRITEBYTE(RTG_U82, (unsigned char)b->CLUT[i].Red); + //WRITEBYTE(RTG_U83, (unsigned char)b->CLUT[i].Green); + //WRITEBYTE(RTG_U84, (unsigned char)b->CLUT[i].Blue); + unsigned int xrgb = 0 | (b->CLUT[i].Red << 16) | (b->CLUT[i].Green << 8) | (b->CLUT[i].Blue); WRITEBYTE(RTG_U81, (unsigned char)i); - WRITEBYTE(RTG_U82, (unsigned char)b->CLUT[i].Red); - WRITEBYTE(RTG_U83, (unsigned char)b->CLUT[i].Green); - WRITEBYTE(RTG_U84, (unsigned char)b->CLUT[i].Blue); + WRITELONG(RTG_RGB1, xrgb); WRITESHORT(RTG_COMMAND, RTGCMD_SETCLUT); } } diff --git a/platforms/amiga/rtg/rtg_driver_amiga/pigfx020.card b/platforms/amiga/rtg/rtg_driver_amiga/pigfx020.card index 00109b8..ee1d1c5 100644 Binary files a/platforms/amiga/rtg/rtg_driver_amiga/pigfx020.card and b/platforms/amiga/rtg/rtg_driver_amiga/pigfx020.card differ diff --git a/platforms/amiga/rtg/rtg_driver_amiga/pigfx030.card b/platforms/amiga/rtg/rtg_driver_amiga/pigfx030.card index 00109b8..ee1d1c5 100644 Binary files a/platforms/amiga/rtg/rtg_driver_amiga/pigfx030.card and b/platforms/amiga/rtg/rtg_driver_amiga/pigfx030.card differ