]> git.sesse.net Git - pistorm/commitdiff
Fix all the colors, fix some other stuff.
authorbeeanyew <beeanyew@gmail.com>
Wed, 6 Jan 2021 03:56:33 +0000 (04:56 +0100)
committerbeeanyew <beeanyew@gmail.com>
Wed, 6 Jan 2021 03:56:33 +0000 (04:56 +0100)
Workbench still doesn't work.

m68kcpu.h
platforms/amiga/rtg/rtg-output.c
platforms/amiga/rtg/rtg.c
platforms/amiga/rtg/rtg.h
platforms/amiga/rtg/rtg_driver_amiga/pigfx.c
platforms/amiga/rtg/rtg_driver_amiga/pigfx020.card
platforms/amiga/rtg/rtg_driver_amiga/pigfx030.card

index 4262cd90d508412dba513b07aa348f922d90fabe..eb1622460de1c1e363dda7f11af90588a486bb25 100644 (file)
--- 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;
                }
        }
index 23217cb47f563468942a2f2a541630da11d4008d..2b9a8a53da36dca6d9ff34567b4fe7a22ed52e7d 100644 (file)
@@ -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() {
index 040af6ff5ddc4803d3be9b2e7faf0b3987208ada..4ce6dfe32d0f5396d65c48ce17a15eed717a02cd 100644 (file)
@@ -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;
index 0265e1a7291b3d58ef243fde88e7a971123a1932..a27ab2512b0ae29ac28a59652b87a71f7346c223 100644 (file)
@@ -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();
 
index 66557755d9644cb1ecbf98cee0c9dc8b2da093c4..68e4578e56441331e7ecbf0e750c8f96bbad99fd 100644 (file)
@@ -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);
   }
 }
index 00109b8d7eb74eccf7ff30fed0deb1c4178b9311..ee1d1c57472e957b74b6e49398e646197e664c05 100644 (file)
Binary files a/platforms/amiga/rtg/rtg_driver_amiga/pigfx020.card and b/platforms/amiga/rtg/rtg_driver_amiga/pigfx020.card differ
index 00109b8d7eb74eccf7ff30fed0deb1c4178b9311..ee1d1c57472e957b74b6e49398e646197e664c05 100644 (file)
Binary files a/platforms/amiga/rtg/rtg_driver_amiga/pigfx030.card and b/platforms/amiga/rtg/rtg_driver_amiga/pigfx030.card differ