Annotation of uae/src/picasso96.c, revision 1.1.1.13

1.1       root        1: /*
                      2:  * UAE - The U*nix Amiga Emulator
                      3:  *
                      4:  * Picasso96 Support Module
                      5:  *
                      6:  * Copyright 1997 Brian King <[email protected], [email protected]>
                      7:  *
                      8:  * Theory of operation:
                      9:  * On the Amiga side, a Picasso card consists mainly of a memory area that
                     10:  * contains the frame buffer.  On the UAE side, we allocate a block of memory
                     11:  * that will hold the frame buffer.  This block is in normal memory, it is
                     12:  * never directly on the graphics card.  All graphics operations, which are
                     13:  * mainly reads and writes into this block and a few basic operations like
                     14:  * filling a rectangle, operate on this block of memory.
                     15:  * Since the memory is not on the graphics card, some work must be done to
                     16:  * synchronize the display with the data in the Picasso frame buffer.  There
                     17:  * are various ways to do this.  One possibility is to allocate a second
                     18:  * buffer of the same size, and perform all write operations twice.  Since
                     19:  * we never read from the second buffer, it can actually be placed in video
                     20:  * memory.  The X11 driver could be made to use the Picasso frame buffer as
                     21:  * the data buffer of an XImage, which could then be XPutImage()d from time
                     22:  * to time.  Another possibility is to translate all Picasso accesses into
                     23:  * Xlib (or GDI, or whatever your graphics system is) calls.  This possibility
                     24:  * is a bit tricky, since there is a risk of generating very many single pixel
                     25:  * accesses which may be rather slow.
                     26:  *
                     27:  * TODO:
                     28:  * - add panning capability
1.1.1.3   root       29:  * - we want to add a manual switch to override SetSwitch for hardware banging
                     30:  *   programs started from a Picasso workbench.
1.1       root       31:  */
                     32: 
                     33: #include "sysconfig.h"
                     34: #include "sysdeps.h"
                     35: 
                     36: #include "config.h"
                     37: #include "options.h"
1.1.1.11  root       38: #include "threaddep/thread.h"
1.1       root       39: #include "uae.h"
                     40: #include "memory.h"
                     41: #include "custom.h"
                     42: #include "newcpu.h"
                     43: #include "xwin.h"
                     44: #include "picasso96.h"
                     45: 
                     46: #ifdef PICASSO96
                     47: 
1.1.1.13! root       48: /* #define P96TRACING_ENABLED */
1.1.1.4   root       49: #ifdef P96TRACING_ENABLED
                     50: #define P96TRACE(x)    do { write_log x; } while(0)
                     51: #else
                     52: #define P96TRACE(x)
                     53: #endif
                     54: 
1.1       root       55: static uae_u32 gfxmem_lget (uaecptr) REGPARAM;
                     56: static uae_u32 gfxmem_wget (uaecptr) REGPARAM;
                     57: static uae_u32 gfxmem_bget (uaecptr) REGPARAM;
                     58: static void gfxmem_lput (uaecptr, uae_u32) REGPARAM;
                     59: static void gfxmem_wput (uaecptr, uae_u32) REGPARAM;
                     60: static void gfxmem_bput (uaecptr, uae_u32) REGPARAM;
                     61: static int gfxmem_check (uaecptr addr, uae_u32 size) REGPARAM;
                     62: static uae_u8 *gfxmem_xlate (uaecptr addr) REGPARAM;
                     63: 
                     64: static void write_gfx_long (uaecptr addr, uae_u32 value);
                     65: static void write_gfx_word (uaecptr addr, uae_u16 value);
                     66: static void write_gfx_byte (uaecptr addr, uae_u8 value);
                     67: 
1.1.1.4   root       68: static uae_u8 all_ones_bitmap, all_zeros_bitmap;
1.1       root       69: 
                     70: struct picasso96_state_struct picasso96_state;
                     71: struct picasso_vidbuf_description picasso_vidinfo;
                     72: 
                     73: /* These are the maximum resolutions... They are filled in by GetSupportedResolutions() */
                     74: /* have to fill this in, otherwise problems occur
                     75:  * @@@ ??? what problems?
                     76:  */
                     77: struct ScreenResolution planar = { 320, 240 };
                     78: struct ScreenResolution chunky = { 640, 480 };
                     79: struct ScreenResolution hicolour = { 640, 480 };
                     80: struct ScreenResolution truecolour = { 640, 480 };
1.1.1.4   root       81: struct ScreenResolution alphacolour = { 640, 480 };
1.1       root       82: 
                     83: uae_u16 picasso96_pixel_format = RGBFF_CHUNKY;
                     84: 
                     85: struct PicassoResolution DisplayModes[MAX_PICASSO_MODES];
                     86: 
                     87: static int mode_count = 0;
                     88: 
1.1.1.12  root       89: static int set_gc_called = 0;
                     90: static int set_panning_called = 0;
                     91: /* Address of the screen in the Amiga frame buffer at the time of the last
                     92:    SetPanning call.  */
                     93: static uaecptr oldscr;
                     94: 
1.1       root       95: static uae_u32 p2ctab[256][2];
                     96: 
                     97: /*
                     98:  * Debugging dumps
                     99:  */
                    100: 
                    101: static void DumpModeInfoStructure (uaecptr amigamodeinfoptr)
                    102: {
1.1.1.2   root      103:     write_log ("ModeInfo Structure Dump:\n");
                    104:     write_log ("  Node.ln_Succ  = 0x%x\n", get_long (amigamodeinfoptr));
                    105:     write_log ("  Node.ln_Pred  = 0x%x\n", get_long (amigamodeinfoptr + 4));
                    106:     write_log ("  Node.ln_Type  = 0x%x\n", get_byte (amigamodeinfoptr + 8));
                    107:     write_log ("  Node.ln_Pri   = %d\n", get_byte (amigamodeinfoptr + 9));
                    108:     /*write_log ("  Node.ln_Name  = %s\n", uaememptr->Node.ln_Name); */
                    109:     write_log ("  OpenCount     = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_OpenCount));
                    110:     write_log ("  Active        = %d\n", get_byte (amigamodeinfoptr + PSSO_ModeInfo_Active));
                    111:     write_log ("  Width         = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_Width));
                    112:     write_log ("  Height        = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_Height));
                    113:     write_log ("  Depth         = %d\n", get_byte (amigamodeinfoptr + PSSO_ModeInfo_Depth));
                    114:     write_log ("  Flags         = %d\n", get_byte (amigamodeinfoptr + PSSO_ModeInfo_Flags));
                    115:     write_log ("  HorTotal      = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_HorTotal));
                    116:     write_log ("  HorBlankSize  = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_HorBlankSize));
                    117:     write_log ("  HorSyncStart  = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_HorSyncStart));
                    118:     write_log ("  HorSyncSize   = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_HorSyncSize));
                    119:     write_log ("  HorSyncSkew   = %d\n", get_byte (amigamodeinfoptr + PSSO_ModeInfo_HorSyncSkew));
                    120:     write_log ("  HorEnableSkew = %d\n", get_byte (amigamodeinfoptr + PSSO_ModeInfo_HorEnableSkew));
                    121:     write_log ("  VerTotal      = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_VerTotal));
                    122:     write_log ("  VerBlankSize  = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_VerBlankSize));
                    123:     write_log ("  VerSyncStart  = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_VerSyncStart));
                    124:     write_log ("  VerSyncSize   = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_VerSyncSize));
                    125:     write_log ("  Clock         = %d\n", get_byte (amigamodeinfoptr + PSSO_ModeInfo_first_union));
                    126:     write_log ("  ClockDivide   = %d\n", get_byte (amigamodeinfoptr + PSSO_ModeInfo_second_union));
                    127:     write_log ("  PixelClock    = %d\n", get_long (amigamodeinfoptr + PSSO_ModeInfo_PixelClock));
1.1       root      128: }
                    129: 
                    130: static void DumpLibResolutionStructure (uaecptr amigalibresptr)
                    131: {
                    132:     int i;
                    133:     uaecptr amigamodeinfoptr;
1.1.1.8   root      134:     struct LibResolution *uaememptr = (struct LibResolution *) get_mem_bank (amigalibresptr).xlateaddr (amigalibresptr);
                    135: 
1.1       root      136:     return;
                    137: 
1.1.1.2   root      138:     write_log ("LibResolution Structure Dump:\n");
1.1       root      139: 
                    140:     if (get_long (amigalibresptr + PSSO_LibResolution_DisplayID) == 0xFFFFFFFF) {
1.1.1.2   root      141:        write_log ("  Finished With LibResolutions...\n");
1.1       root      142:     } else {
1.1.1.2   root      143:        write_log ("  Name      = %s\n", uaememptr->P96ID);
                    144:        write_log ("  DisplayID = 0x%x\n", get_long (amigalibresptr + PSSO_LibResolution_DisplayID));
                    145:        write_log ("  Width     = %d\n", get_word (amigalibresptr + PSSO_LibResolution_Width));
                    146:        write_log ("  Height    = %d\n", get_word (amigalibresptr + PSSO_LibResolution_Height));
                    147:        write_log ("  Flags     = %d\n", get_word (amigalibresptr + PSSO_LibResolution_Flags));
1.1       root      148:        for (i = 0; i < MAXMODES; i++) {
1.1.1.8   root      149:            amigamodeinfoptr = get_long (amigalibresptr + PSSO_LibResolution_Modes + i * 4);
1.1.1.2   root      150:            write_log ("  ModeInfo[%d] = 0x%x\n", i, amigamodeinfoptr);
1.1       root      151:            if (amigamodeinfoptr)
1.1.1.2   root      152:                DumpModeInfoStructure (amigamodeinfoptr);
1.1       root      153:        }
1.1.1.2   root      154:        write_log ("  BoardInfo = 0x%x\n", get_long (amigalibresptr + PSSO_LibResolution_BoardInfo));
1.1       root      155:     }
                    156: }
                    157: 
1.1.1.4   root      158: static char binary_byte[9];
1.1       root      159: 
                    160: static char *BuildBinaryString (uae_u8 value)
                    161: {
                    162:     int i;
                    163:     for (i = 0; i < 8; i++) {
                    164:        binary_byte[i] = (value & (1 << (7 - i))) ? '#' : '.';
                    165:     }
1.1.1.4   root      166:     binary_byte[8] = '\0';
1.1       root      167:     return binary_byte;
                    168: }
                    169: 
                    170: static void DumpPattern (struct Pattern *patt)
                    171: {
                    172:     uae_u8 *mem;
                    173:     int row, col;
                    174:     for (row = 0; row < (1 << patt->Size); row++) {
                    175:        mem = patt->Memory + row * 2;
                    176:        for (col = 0; col < 2; col++) {
1.1.1.2   root      177:            write_log ("%s", BuildBinaryString (*mem++));
1.1       root      178:        }
1.1.1.2   root      179:        write_log ("\n");
1.1       root      180:     }
                    181: }
                    182: 
                    183: static void DumpTemplate (struct Template *tmp, uae_u16 w, uae_u16 h)
                    184: {
                    185:     uae_u8 *mem = tmp->Memory;
                    186:     int row, col, width;
                    187:     width = (w + 7) >> 3;
1.1.1.2   root      188:     write_log ("xoffset = %d, bpr = %d\n", tmp->XOffset, tmp->BytesPerRow);
1.1       root      189:     for (row = 0; row < h; row++) {
                    190:        mem = tmp->Memory + row * tmp->BytesPerRow;
                    191:        for (col = 0; col < width; col++) {
1.1.1.2   root      192:            write_log ("%s", BuildBinaryString (*mem++));
1.1       root      193:        }
1.1.1.2   root      194:        write_log ("\n");
1.1       root      195:     }
                    196: }
                    197: 
1.1.1.11  root      198: int picasso_nr_resolutions (void)
                    199: {
                    200:     return mode_count;
                    201: }
                    202: 
1.1       root      203: static void ShowSupportedResolutions (void)
                    204: {
                    205:     int i;
1.1.1.8   root      206: 
1.1       root      207:     return;
                    208: 
                    209:     for (i = 0; i < mode_count; i++)
1.1.1.2   root      210:        write_log ("%s\n", DisplayModes[i].name);
                    211: }
                    212: 
                    213: static uae_u8 GetBytesPerPixel (uae_u32 RGBfmt)
                    214: {
                    215:     switch (RGBfmt) {
1.1.1.8   root      216:     case RGBFB_CLUT:
1.1.1.2   root      217:        return 1;
                    218: 
1.1.1.8   root      219:     case RGBFB_A8R8G8B8:
                    220:     case RGBFB_A8B8G8R8:
                    221:     case RGBFB_R8G8B8A8:
                    222:     case RGBFB_B8G8R8A8:
1.1.1.2   root      223:        return 4;
                    224: 
1.1.1.8   root      225:     case RGBFB_B8G8R8:
                    226:     case RGBFB_R8G8B8:
1.1.1.2   root      227:        return 3;
                    228: 
1.1.1.8   root      229:     case RGBFB_R5G5B5:
                    230:     case RGBFB_R5G6B5:
                    231:     case RGBFB_R5G6B5PC:
                    232:     case RGBFB_R5G5B5PC:
                    233:     case RGBFB_B5G6R5PC:
                    234:     case RGBFB_B5G5R5PC:
1.1.1.2   root      235:        return 2;
1.1.1.8   root      236:     default:
1.1.1.2   root      237:        write_log ("ERROR - GetBytesPerPixel() was unsuccessful with 0x%x?!\n", RGBfmt);
                    238:        return 0;
                    239:     }
1.1       root      240: }
                    241: 
                    242: /*
                    243:  * Amiga <-> native structure conversion functions
                    244:  */
                    245: 
                    246: static int CopyRenderInfoStructureA2U (uaecptr amigamemptr, struct RenderInfo *ri)
                    247: {
                    248:     uaecptr memp = get_long (amigamemptr + PSSO_RenderInfo_Memory);
                    249: 
1.1.1.4   root      250:     if (valid_address (memp, PSSO_RenderInfo_sizeof)) {
1.1       root      251:        ri->Memory = get_real_address (memp);
                    252:        ri->BytesPerRow = get_word (amigamemptr + PSSO_RenderInfo_BytesPerRow);
                    253:        ri->RGBFormat = get_long (amigamemptr + PSSO_RenderInfo_RGBFormat);
                    254:        return 1;
                    255:     }
1.1.1.2   root      256:     write_log ("ERROR - Invalid RenderInfo memory area...\n");
1.1       root      257:     return 0;
                    258: }
                    259: 
                    260: static int CopyPatternStructureA2U (uaecptr amigamemptr, struct Pattern *pattern)
                    261: {
                    262:     uaecptr memp = get_long (amigamemptr + PSSO_Pattern_Memory);
1.1.1.4   root      263:     if (valid_address (memp, PSSO_Pattern_sizeof)) {
1.1       root      264:        pattern->Memory = get_real_address (memp);
                    265:        pattern->XOffset = get_word (amigamemptr + PSSO_Pattern_XOffset);
                    266:        pattern->YOffset = get_word (amigamemptr + PSSO_Pattern_YOffset);
                    267:        pattern->FgPen = get_long (amigamemptr + PSSO_Pattern_FgPen);
                    268:        pattern->BgPen = get_long (amigamemptr + PSSO_Pattern_BgPen);
                    269:        pattern->Size = get_byte (amigamemptr + PSSO_Pattern_Size);
                    270:        pattern->DrawMode = get_byte (amigamemptr + PSSO_Pattern_DrawMode);
                    271:        return 1;
                    272:     }
1.1.1.2   root      273:     write_log ("ERROR - Invalid Pattern memory area...\n");
1.1       root      274:     return 0;
                    275: }
                    276: 
                    277: static void CopyColorIndexMappingA2U (uaecptr amigamemptr, struct ColorIndexMapping *cim)
                    278: {
                    279:     int i;
                    280:     cim->ColorMask = get_long (amigamemptr);
                    281:     for (i = 0; i < 256; i++, amigamemptr += 4)
                    282:        cim->Colors[i] = get_long (amigamemptr + 4);
                    283: }
                    284: 
                    285: static int CopyBitMapStructureA2U (uaecptr amigamemptr, struct BitMap *bm)
                    286: {
                    287:     int i;
                    288: 
                    289:     bm->BytesPerRow = get_word (amigamemptr + PSSO_BitMap_BytesPerRow);
                    290:     bm->Rows = get_word (amigamemptr + PSSO_BitMap_Rows);
                    291:     bm->Flags = get_byte (amigamemptr + PSSO_BitMap_Flags);
                    292:     bm->Depth = get_byte (amigamemptr + PSSO_BitMap_Depth);
                    293: 
                    294:     for (i = 0; i < bm->Depth; i++) {
1.1.1.8   root      295:        uaecptr plane = get_long (amigamemptr + PSSO_BitMap_Planes + i * 4);
1.1       root      296:        switch (plane) {
1.1.1.8   root      297:        case 0:
1.1       root      298:            bm->Planes[i] = &all_zeros_bitmap;
                    299:            break;
1.1.1.8   root      300:        case 0xFFFFFFFF:
1.1       root      301:            bm->Planes[i] = &all_ones_bitmap;
                    302:            break;
1.1.1.8   root      303:        default:
1.1       root      304:            if (valid_address (plane, bm->BytesPerRow * bm->Rows))
                    305:                bm->Planes[i] = get_real_address (plane);
                    306:            else
                    307:                return 0;
                    308:            break;
                    309:        }
                    310:     }
                    311:     return 1;
                    312: }
                    313: 
                    314: static int CopyTemplateStructureA2U (uaecptr amigamemptr, struct Template *tmpl)
                    315: {
                    316:     uaecptr memp = get_long (amigamemptr + PSSO_Template_Memory);
                    317: 
1.1.1.8   root      318:     if (valid_address (memp, 1 /* FIXME */ )) {
1.1       root      319:        tmpl->Memory = get_real_address (memp);
                    320:        tmpl->BytesPerRow = get_word (amigamemptr + PSSO_Template_BytesPerRow);
                    321:        tmpl->XOffset = get_byte (amigamemptr + PSSO_Template_XOffset);
                    322:        tmpl->DrawMode = get_byte (amigamemptr + PSSO_Template_DrawMode);
                    323:        tmpl->FgPen = get_long (amigamemptr + PSSO_Template_FgPen);
                    324:        tmpl->BgPen = get_long (amigamemptr + PSSO_Template_BgPen);
                    325:        return 1;
                    326:     }
1.1.1.2   root      327:     write_log ("ERROR - Invalid Template memory area...\n");
1.1       root      328:     return 0;
                    329: }
                    330: 
                    331: static void CopyLibResolutionStructureU2A (struct LibResolution *libres, uaecptr amigamemptr)
                    332: {
                    333:     char *uaememptr = 0;
                    334:     int i;
                    335: 
1.1.1.8   root      336:     uaememptr = gfxmem_xlate (amigamemptr);    /* I know that amigamemptr is inside my gfxmem chunk, so I can just do the xlate() */
                    337:     memset (uaememptr, 0, PSSO_LibResolution_sizeof);  /* zero out our LibResolution structure */
1.1.1.3   root      338:     strcpy (uaememptr + PSSO_LibResolution_P96ID, libres->P96ID);
1.1.1.2   root      339:     put_long (amigamemptr + PSSO_LibResolution_DisplayID, libres->DisplayID);
                    340:     put_word (amigamemptr + PSSO_LibResolution_Width, libres->Width);
                    341:     put_word (amigamemptr + PSSO_LibResolution_Height, libres->Height);
                    342:     put_word (amigamemptr + PSSO_LibResolution_Flags, libres->Flags);
1.1       root      343:     for (i = 0; i < MAXMODES; i++)
1.1.1.8   root      344:        put_long (amigamemptr + PSSO_LibResolution_Modes + i * 4, libres->Modes[i]);
1.1       root      345: #if 0
1.1.1.2   root      346:     put_long (amigamemptr, libres->Node.ln_Succ);
                    347:     put_long (amigamemptr + 4, libres->Node.ln_Pred);
                    348:     put_byte (amigamemptr + 8, libres->Node.ln_Type);
                    349:     put_byte (amigamemptr + 9, libres->Node.ln_Pri);
1.1       root      350: #endif
1.1.1.2   root      351:     put_long (amigamemptr + 10, amigamemptr + PSSO_LibResolution_P96ID);
                    352:     put_long (amigamemptr + PSSO_LibResolution_BoardInfo, libres->BoardInfo);
1.1       root      353: }
                    354: 
                    355: /* list is Amiga address of list, in correct endian format for UAE
                    356:  * node is Amiga address of node, in correct endian format for UAE */
                    357: static void AmigaListAddTail (uaecptr list, uaecptr node)
                    358: {
                    359:     uaecptr amigamemptr = 0;
                    360: 
                    361:     if (get_long (list + 8) == list) {
                    362:        /* Empty list - set it up */
1.1.1.8   root      363:        put_long (list, node);  /* point the lh_Head to our new node */
                    364:        put_long (list + 4, 0); /* set the lh_Tail to NULL */
                    365:        put_long (list + 8, node);      /* point the lh_TailPred to our new node */
1.1       root      366: 
                    367:        /* Adjust the new node - don't rely on it being zeroed out */
1.1.1.8   root      368:        put_long (node, 0);     /* ln_Succ */
                    369:        put_long (node + 4, 0); /* ln_Pred */
1.1       root      370:     } else {
1.1.1.8   root      371:        amigamemptr = get_long (list + 8);      /* get the lh_TailPred contents */
1.1       root      372: 
1.1.1.8   root      373:        put_long (list + 8, node);      /* point the lh_TailPred to our new node */
1.1       root      374: 
                    375:        /* Adjust the previous lh_TailPred node */
1.1.1.8   root      376:        put_long (amigamemptr, node);   /* point the ln_Succ to our new node */
1.1       root      377: 
                    378:        /* Adjust the new node - don't rely on it being zeroed out */
1.1.1.8   root      379:        put_long (node, 0);     /* ln_Succ */
                    380:        put_long (node + 4, amigamemptr);       /* ln_Pred */
1.1       root      381:     }
                    382: }
                    383: 
                    384: /*
                    385:  * Functions to perform an action on the real screen
                    386:  */
                    387: 
                    388: /*
                    389:  * Fill a rectangle on the screen.  src points to the start of a line of the
                    390:  * filled rectangle in the frame buffer; it can be used as a memcpy source if
                    391:  * there is no OS specific function to fill the rectangle.
                    392:  */
                    393: 
1.1.1.12  root      394: static void do_fillrect (uae_u8 * src, int x, int y, int width, int height,
                    395:                         uae_u32 pen, int Bpp, RGBFTYPE rgbtype)
1.1       root      396: {
                    397:     uae_u8 *dst;
1.1.1.12  root      398: 
                    399:     /* Clipping.  */
                    400:     x -= picasso96_state.XOffset;
                    401:     y -= picasso96_state.YOffset;
                    402:     if (x < 0) {
                    403:        width += x;
                    404:        x = 0;
                    405:     }
                    406:     if (y < 0) {
                    407:        height += y;
                    408:        y = 0;
                    409:     }
                    410:     if (x + width > picasso96_state.Width)
                    411:        width = picasso96_state.Width - x;
                    412:     if (y + height > picasso96_state.Height)
                    413:        height = picasso96_state.Height - y;
                    414: 
1.1.1.13! root      415:     if (width <= 0 || height <= 0)
        !           416:        return;
        !           417: 
1.1       root      418:     /* Try OS specific fillrect function here; and return if successful.  */
                    419: 
                    420:     DX_Invalidate (y, y + height - 1);
1.1.1.8   root      421:     if (!picasso_vidinfo.extra_mem)
1.1       root      422:        return;
                    423: 
                    424:     width *= picasso96_state.BytesPerPixel;
1.1.1.2   root      425:     dst = gfx_lock_picasso ();
1.1       root      426:     if (!dst)
1.1.1.2   root      427:        goto out;
1.1       root      428: 
1.1.1.8   root      429:     dst += y * picasso_vidinfo.rowbytes + x * picasso_vidinfo.pixbytes;
1.1.1.2   root      430:     if (picasso_vidinfo.rgbformat == picasso96_state.RGBFormat) {
1.1.1.12  root      431:        if (Bpp == 1) {
                    432:            while (height-- > 0) {
                    433:                memset (dst, pen, width);
                    434:                dst += picasso_vidinfo.rowbytes;
                    435:            }
                    436:        } else {
                    437:            while (height-- > 0) {
                    438:                memcpy (dst, src, width);
                    439:                dst += picasso_vidinfo.rowbytes;
                    440:            }
1.1.1.2   root      441:        }
                    442:     } else {
                    443:        int psiz = GetBytesPerPixel (picasso_vidinfo.rgbformat);
                    444:        if (picasso96_state.RGBFormat != RGBFB_CHUNKY)
                    445:            abort ();
                    446: 
                    447:        while (height-- > 0) {
                    448:            int i;
                    449:            switch (psiz) {
1.1.1.8   root      450:            case 2:
1.1.1.2   root      451:                for (i = 0; i < width; i++)
1.1.1.8   root      452:                    *((uae_u16 *) dst + i) = picasso_vidinfo.clut[src[i]];
1.1.1.2   root      453:                break;
1.1.1.8   root      454:            case 4:
1.1.1.2   root      455:                for (i = 0; i < width; i++)
1.1.1.8   root      456:                    *((uae_u32 *) dst + i) = picasso_vidinfo.clut[src[i]];
1.1.1.2   root      457:                break;
1.1.1.8   root      458:            default:
                    459:                abort ();
1.1.1.2   root      460:            }
                    461:            dst += picasso_vidinfo.rowbytes;
                    462:        }
1.1       root      463:     }
1.1.1.8   root      464:   out:
1.1.1.2   root      465:     gfx_unlock_picasso ();
1.1       root      466: }
                    467: 
                    468: /*
                    469:  * This routine modifies the real screen buffer after a blit has been
                    470:  * performed in the save area. If can_do_blit is nonzero, the blit can
                    471:  * be performed within the real screen buffer; otherwise, this routine
                    472:  * must do it by hand using the data in the save area, pointed to by
                    473:  * srcp.
                    474:  */
                    475: 
1.1.1.12  root      476: static void do_blit (struct RenderInfo *ri, int Bpp, int srcx, int srcy,
                    477:                     int dstx, int dsty, int width, int height,
                    478:                     BLIT_OPCODE opcode, int can_do_blit)
                    479: {
                    480:     int xoff = picasso96_state.XOffset;
                    481:     int yoff = picasso96_state.YOffset;
                    482:     uae_u8 *srcp, *dstp;
                    483: 
                    484:     /* Clipping.  */
                    485:     dstx -= xoff;
                    486:     dsty -= yoff;
                    487:     if (srcy < yoff || srcx < xoff
                    488:        || srcx - xoff + width > picasso96_state.Width
                    489:        || srcy - yoff + height > picasso96_state.Height)
                    490:     {
                    491:        can_do_blit = 0;
                    492:     }
                    493:     if (dstx < 0) {
                    494:        srcx -= dstx;
                    495:        width += dstx;
                    496:        dstx = 0;
                    497:     }
                    498:     if (dsty < 0) {
                    499:        srcy -= dsty;
                    500:        height += dsty;
                    501:        dsty = 0;
                    502:     }
                    503:     if (dstx + width > picasso96_state.Width)
                    504:        width = picasso96_state.Width - dstx;
                    505:     if (dsty + height > picasso96_state.Height)
                    506:        height = picasso96_state.Height - dsty;
1.1.1.13! root      507:     if (width <= 0 || height <= 0)
        !           508:        return;
1.1.1.12  root      509: 
1.1       root      510:     /* If this RenderInfo points at something else than the currently visible
                    511:      * screen, we must ignore the blit.  */
                    512:     if (can_do_blit) {
                    513:        /*
                    514:         * Call OS blitting function that can do it in video memory.
                    515:         * Should return if it was successful
                    516:         */
                    517:     }
                    518: 
1.1.1.12  root      519:     /* If no OS blit available, we do a copy from the P96 framebuffer in Amiga
                    520:        memory to the host's frame buffer.  */
1.1       root      521:     DX_Invalidate (dsty, dsty + height - 1);
1.1.1.8   root      522:     if (!picasso_vidinfo.extra_mem)
1.1       root      523:        return;
                    524: 
1.1.1.2   root      525:     dstp = gfx_lock_picasso ();
1.1       root      526:     if (dstp == 0)
1.1.1.2   root      527:        goto out;
                    528:     dstp += dsty * picasso_vidinfo.rowbytes + dstx * picasso_vidinfo.pixbytes;
1.1.1.13! root      529:     P96TRACE(("do_blit with srcp 0x%x, dstp 0x%x, dst_rowbytes %d, srcx %d, srcy %d, dstx %d, dsty %d, w %d, h %d, dst_pixbytes %d\n",
        !           530:         srcp, dstp, picasso_vidinfo.rowbytes, srcx, srcy, dstx, dsty, width, height, picasso_vidinfo.pixbytes));
        !           531:     P96TRACE(("gfxmem is at 0x%x\n",gfxmemory));
1.1.1.12  root      532: 
                    533:     srcp = ri->Memory + srcx * Bpp + srcy * ri->BytesPerRow;
1.1.1.2   root      534:     if (picasso_vidinfo.rgbformat == picasso96_state.RGBFormat) {
1.1.1.12  root      535:        width *= Bpp;
1.1.1.2   root      536:        while (height-- > 0) {
                    537:            memcpy (dstp, srcp, width);
1.1.1.12  root      538:            srcp += ri->BytesPerRow;
1.1.1.2   root      539:            dstp += picasso_vidinfo.rowbytes;
                    540:        }
                    541:     } else {
                    542:        int psiz = GetBytesPerPixel (picasso_vidinfo.rgbformat);
                    543:        if (picasso96_state.RGBFormat != RGBFB_CHUNKY)
                    544:            abort ();
                    545: 
                    546:        while (height-- > 0) {
                    547:            int i;
                    548:            switch (psiz) {
1.1.1.8   root      549:            case 2:
1.1.1.2   root      550:                for (i = 0; i < width; i++)
1.1.1.8   root      551:                    *((uae_u16 *) dstp + i) = picasso_vidinfo.clut[srcp[i]];
1.1.1.2   root      552:                break;
1.1.1.8   root      553:            case 4:
1.1.1.2   root      554:                for (i = 0; i < width; i++)
1.1.1.8   root      555:                    *((uae_u32 *) dstp + i) = picasso_vidinfo.clut[srcp[i]];
1.1.1.2   root      556:                break;
1.1.1.8   root      557:            default:
                    558:                abort ();
1.1.1.2   root      559:            }
1.1.1.12  root      560:            srcp += ri->BytesPerRow;
1.1.1.2   root      561:            dstp += picasso_vidinfo.rowbytes;
                    562:        }
1.1       root      563:     }
1.1.1.8   root      564:   out:
1.1.1.2   root      565:     gfx_unlock_picasso ();
1.1       root      566: }
                    567: 
                    568: /*
1.1.1.12  root      569:  * Invert a rectangle on the screen.
1.1       root      570:  */
                    571: 
1.1.1.12  root      572: static void do_invertrect (struct RenderInfo *ri, int Bpp, int x, int y, int width, int height)
1.1       root      573: {
1.1.1.12  root      574: #if 0
                    575:     /* Clipping.  */
                    576:     x -= picasso96_state.XOffset;
                    577:     y -= picasso96_state.YOffset;
                    578:     if (x < 0) {
                    579:        width += x;
                    580:        x = 0;
                    581:     }
                    582:     if (y < 0) {
                    583:        height += y;
                    584:        y = 0;
                    585:     }
                    586:     if (x + width > picasso96_state.Width)
                    587:        width = picasso96_state.Width - x;
                    588:     if (y + height > picasso96_state.Height)
                    589:        height = picasso96_state.Height - y;
1.1.1.13! root      590: 
        !           591:     if (width <= 0 || height <= 0)
        !           592:        return;
        !           593: 
1.1.1.12  root      594: #endif
1.1.1.2   root      595:     /* TODO: Try OS specific invertrect function here; and return if successful.  */
1.1       root      596: 
1.1.1.12  root      597:     do_blit (ri, Bpp, x, y, x, y, width, height, BLIT_SRC, 0);
1.1       root      598: }
                    599: 
                    600: static uaecptr wgfx_linestart;
                    601: static uaecptr wgfx_lineend;
                    602: static uaecptr wgfx_min, wgfx_max;
1.1.1.12  root      603: static long wgfx_y;
1.1       root      604: 
                    605: static void wgfx_do_flushline (void)
                    606: {
1.1.1.12  root      607:     int src_y = wgfx_y;
                    608:     long x0, x1, width;
1.1       root      609:     uae_u8 *src, *dstp;
1.1.1.12  root      610:     int Bpp = GetBytesPerPixel (picasso_vidinfo.rgbformat);
                    611:     int fb_bpp = picasso96_state.BytesPerPixel;
                    612: 
                    613:     wgfx_y -= picasso96_state.YOffset;
                    614:     if (wgfx_y < 0 || wgfx_y >= picasso96_state.Height)
                    615:        goto out;
1.1       root      616: 
                    617:     DX_Invalidate (wgfx_y, wgfx_y);
1.1.1.8   root      618:     if (!picasso_vidinfo.extra_mem)
1.1       root      619:        goto out;
                    620: 
1.1.1.12  root      621:     x0 = wgfx_min - wgfx_linestart;
                    622:     width = wgfx_max - wgfx_min;
                    623:     x0 -= picasso96_state.XOffset * fb_bpp;
                    624:     if (x0 < 0) {
                    625:        width += x0;
                    626:        wgfx_min += x0;
                    627:        x0 = 0;
                    628:     }
                    629:     if (x0 + width > picasso96_state.Width * fb_bpp)
                    630:        width = picasso96_state.Width * fb_bpp - x0;
                    631: 
1.1.1.2   root      632:     dstp = gfx_lock_picasso ();
1.1       root      633:     if (dstp == 0)
                    634:        goto out;
1.1.1.12  root      635: 
1.1.1.13! root      636:     P96TRACE(("flushing %d\n", wgfx_y));
1.1.1.2   root      637:     src = gfxmemory + wgfx_min;
1.1       root      638: 
1.1.1.2   root      639:     if (picasso_vidinfo.rgbformat == picasso96_state.RGBFormat) {
1.1.1.12  root      640:        dstp += wgfx_y * picasso_vidinfo.rowbytes + x0;
                    641:        memcpy (dstp, src, width);
1.1.1.2   root      642:     } else {
                    643:        int i;
                    644: 
                    645:        if (picasso96_state.RGBFormat != RGBFB_CHUNKY)
                    646:            abort ();
                    647: 
1.1.1.12  root      648:        dstp += wgfx_y * picasso_vidinfo.rowbytes + x0 * Bpp;
                    649:        switch (Bpp) {
1.1.1.8   root      650:        case 2:
1.1.1.2   root      651:            for (i = 0; i < width; i++)
1.1.1.8   root      652:                *((uae_u16 *) dstp + i) = picasso_vidinfo.clut[src[i]];
1.1.1.2   root      653:            break;
1.1.1.8   root      654:        case 4:
1.1.1.2   root      655:            for (i = 0; i < width; i++)
1.1.1.8   root      656:                *((uae_u32 *) dstp + i) = picasso_vidinfo.clut[src[i]];
1.1.1.2   root      657:            break;
1.1.1.8   root      658:        default:
                    659:            abort ();
1.1.1.2   root      660:        }
                    661:     }
1.1       root      662: 
1.1.1.8   root      663:   out:
1.1.1.2   root      664:     gfx_unlock_picasso ();
1.1       root      665:     wgfx_linestart = 0xFFFFFFFF;
                    666: }
                    667: 
1.1.1.7   root      668: STATIC_INLINE void wgfx_flushline (void)
1.1       root      669: {
1.1.1.8   root      670:     if (wgfx_linestart == 0xFFFFFFFF || !picasso_on)
1.1       root      671:        return;
                    672:     wgfx_do_flushline ();
                    673: }
                    674: 
                    675: static int renderinfo_is_current_screen (struct RenderInfo *ri)
                    676: {
1.1.1.8   root      677:     if (!picasso_on)
1.1       root      678:        return 0;
1.1.1.3   root      679:     if (ri->Memory != gfxmemory + (picasso96_state.Address - gfxmem_start))
1.1       root      680:        return 0;
1.1.1.3   root      681: 
1.1       root      682:     return 1;
                    683: }
                    684: 
                    685: /* Clear our screen, since we've got a new Picasso screen-mode, and refresh with the proper contents
1.1.1.2   root      686:  * This is called on several occasions:
                    687:  * 1. Amiga-->Picasso transition, via SetSwitch()
                    688:  * 2. Picasso-->Picasso transition, via SetPanning().
                    689:  * 3. whenever the graphics code notifies us that the screen contents have been lost.
                    690:  */
                    691: void picasso_refresh (void)
1.1       root      692: {
                    693:     struct RenderInfo ri;
                    694: 
1.1.1.8   root      695:     if (!picasso_on)
1.1       root      696:        return;
                    697: 
                    698:     /* Make sure that the first time we show a Picasso video mode, we don't blit any crap.
                    699:      * We can do this by checking if we have an Address yet.  */
                    700:     if (picasso96_state.Address) {
1.1.1.12  root      701:        unsigned int width, height;
1.1       root      702:        /* blit the stuff from our static frame-buffer to the gfx-card */
1.1.1.12  root      703:        ri.Memory = gfxmemory + (picasso96_state.Address - gfxmem_start);
1.1       root      704:        ri.BytesPerRow = picasso96_state.BytesPerRow;
                    705:        ri.RGBFormat = picasso96_state.RGBFormat;
1.1.1.12  root      706: 
                    707:         if (set_panning_called) {
                    708:            width = picasso96_state.VirtualWidth;
                    709:            height = picasso96_state.VirtualHeight;
                    710:        } else {
                    711:            width = picasso96_state.Width;
                    712:            height = picasso96_state.Height;
                    713:        }
                    714: 
                    715:        do_blit (&ri, picasso96_state.BytesPerPixel, 0, 0, 0, 0, width, height, BLIT_SRC, 0);
1.1       root      716:     } else
1.1.1.2   root      717:        write_log ("ERROR - picasso_refresh() can't refresh!\n");
1.1       root      718: }
                    719: 
                    720: /*
                    721:  * BOOL FindCard(struct BoardInfo *bi);       and
                    722:  *
                    723:  * FindCard is called in the first stage of the board initialisation and
                    724:  * configuration and is used to look if there is a free and unconfigured
                    725:  * board of the type the driver is capable of managing. If it finds one,
                    726:  * it immediately reserves it for use by Picasso96, usually by clearing
                    727:  * the CDB_CONFIGME bit in the flags field of the ConfigDev struct of
                    728:  * this expansion card. But this is only a common example, a driver can
                    729:  * do whatever it wants to mark this card as used by the driver. This
                    730:  * mechanism is intended to ensure that a board is only configured and
                    731:  * used by one driver. FindBoard also usually fills some fields of the
                    732:  * BoardInfo struct supplied by the caller, the rtg.library, for example
                    733:  * the MemoryBase, MemorySize and RegisterBase fields.
                    734:  */
                    735: uae_u32 picasso_FindCard (void)
                    736: {
1.1.1.2   root      737:     uaecptr AmigaBoardInfo = m68k_areg (regs, 0);
1.1       root      738:     /* NOTES: See BoardInfo struct definition in Picasso96 dev info */
                    739: 
1.1.1.2   root      740:     if (allocated_gfxmem && !picasso96_state.CardFound) {
1.1       root      741:        /* Fill in MemoryBase, MemorySize */
1.1.1.2   root      742:        put_long (AmigaBoardInfo + PSSO_BoardInfo_MemoryBase, gfxmem_start);
1.1       root      743:        /* size of memory, minus a 32K chunk: 16K for pattern bitmaps, 16K for resolution list */
1.1.1.2   root      744:        put_long (AmigaBoardInfo + PSSO_BoardInfo_MemorySize, allocated_gfxmem - 32768);
1.1       root      745: 
1.1.1.8   root      746:        picasso96_state.CardFound = 1;  /* mark our "card" as being found */
1.1       root      747:        return -1;
                    748:     } else
                    749:        return 0;
                    750: }
                    751: 
                    752: static void FillBoardInfo (uaecptr amigamemptr, struct LibResolution *res, struct PicassoResolution *dm)
                    753: {
                    754:     char *uaememptr;
                    755:     switch (dm->depth) {
1.1.1.8   root      756:     case 1:
1.1       root      757:        res->Modes[CHUNKY] = amigamemptr;
                    758:        break;
1.1.1.8   root      759:     case 2:
1.1       root      760:        res->Modes[HICOLOR] = amigamemptr;
                    761:        break;
1.1.1.8   root      762:     case 3:
1.1       root      763:        res->Modes[TRUECOLOR] = amigamemptr;
                    764:        break;
1.1.1.8   root      765:     default:
1.1       root      766:        res->Modes[TRUEALPHA] = amigamemptr;
                    767:        break;
                    768:     }
1.1.1.8   root      769:     uaememptr = gfxmem_xlate (amigamemptr);    /* I know that amigamemptr is inside my gfxmem chunk, so I can just do the xlate() */
                    770:     memset (uaememptr, 0, PSSO_ModeInfo_sizeof);       /* zero out our ModeInfo struct */
1.1       root      771: 
1.1.1.2   root      772:     put_word (amigamemptr + PSSO_ModeInfo_Width, dm->res.width);
                    773:     put_word (amigamemptr + PSSO_ModeInfo_Height, dm->res.height);
                    774:     put_byte (amigamemptr + PSSO_ModeInfo_Depth, dm->depth * 8);
                    775:     put_byte (amigamemptr + PSSO_ModeInfo_Flags, 0);
                    776:     put_word (amigamemptr + PSSO_ModeInfo_HorTotal, dm->res.width);
                    777:     put_word (amigamemptr + PSSO_ModeInfo_HorBlankSize, 0);
                    778:     put_word (amigamemptr + PSSO_ModeInfo_HorSyncStart, 0);
                    779:     put_word (amigamemptr + PSSO_ModeInfo_HorSyncSize, 0);
                    780:     put_byte (amigamemptr + PSSO_ModeInfo_HorSyncSkew, 0);
                    781:     put_byte (amigamemptr + PSSO_ModeInfo_HorEnableSkew, 0);
                    782: 
                    783:     put_word (amigamemptr + PSSO_ModeInfo_VerTotal, dm->res.height);
                    784:     put_word (amigamemptr + PSSO_ModeInfo_VerBlankSize, 0);
                    785:     put_word (amigamemptr + PSSO_ModeInfo_VerSyncStart, 0);
                    786:     put_word (amigamemptr + PSSO_ModeInfo_VerSyncSize, 0);
1.1       root      787: 
1.1.1.2   root      788:     put_byte (amigamemptr + PSSO_ModeInfo_first_union, 98);
                    789:     put_byte (amigamemptr + PSSO_ModeInfo_second_union, 14);
1.1       root      790: 
1.1.1.2   root      791:     put_long (amigamemptr + PSSO_ModeInfo_PixelClock, dm->res.width * dm->res.height * dm->refresh);
1.1       root      792: }
                    793: 
1.1.1.4   root      794: static uae_u32 AssignModeID (int i, int count)
                    795: {
                    796:     if (DisplayModes[i].res.width == 320 && DisplayModes[i].res.height == 200)
                    797:        return 0x50001000;
                    798:     else if (DisplayModes[i].res.width == 320 && DisplayModes[i].res.height == 240)
                    799:        return 0x50011000;
                    800:     else if (DisplayModes[i].res.width == 640 && DisplayModes[i].res.height == 400)
                    801:        return 0x50021000;
                    802:     else if (DisplayModes[i].res.width == 640 && DisplayModes[i].res.height == 480)
                    803:        return 0x50031000;
                    804:     else if (DisplayModes[i].res.width == 800 && DisplayModes[i].res.height == 600)
                    805:        return 0x50041000;
                    806:     else if (DisplayModes[i].res.width == 1024 && DisplayModes[i].res.height == 768)
                    807:        return 0x50051000;
                    808:     else if (DisplayModes[i].res.width == 1152 && DisplayModes[i].res.height == 864)
                    809:        return 0x50061000;
                    810:     else if (DisplayModes[i].res.width == 1280 && DisplayModes[i].res.height == 1024)
                    811:        return 0x50071000;
                    812:     else if (DisplayModes[i].res.width == 1600 && DisplayModes[i].res.height == 1280)
                    813:        return 0x50081000;
                    814: 
                    815:     return 0x50091000 + count * 0x10000;
                    816: }
                    817: 
1.1       root      818: /****************************************
                    819: * InitCard()
                    820: *
                    821: * a2: BoardInfo structure ptr - Amiga-based address in Intel endian-format
                    822: *
                    823: * Job - fill in the following structure members:
                    824: * gbi_RGBFormats: the pixel formats that the host-OS of UAE supports
                    825: *     If UAE is running in a window, it should ONLY report the pixel format of the host-OS desktop
                    826: *     If UAE is running full-screen, it should report ALL pixel formats that the host-OS can handle in full-screen
                    827: *     NOTE: If full-screen, and the user toggles to windowed-mode, all hell will break loose visually.  Must inform
                    828: *           user that they're doing something stupid (unless their desktop and full-screen colour modes match).
                    829: * gbi_SoftSpriteFlags: should be the same as above for now, until actual cursor support is added
                    830: * gbi_BitsPerCannon: could be 6 or 8 or ???, depending on the host-OS gfx-card
                    831: * gbi_MaxHorResolution: fill this in for all modes (even if you don't support them)
                    832: * gbi_MaxVerResolution: fill this in for all modes (even if you don't support them)
                    833: */
                    834: uae_u32 picasso_InitCard (void)
                    835: {
                    836:     struct LibResolution res;
                    837:     int i;
                    838:     int ModeInfoStructureCount = 1, LibResolutionStructureCount = 0;
                    839:     uaecptr amigamemptr = 0;
1.1.1.2   root      840:     uaecptr AmigaBoardInfo = m68k_areg (regs, 2);
1.1.1.8   root      841:     put_word (AmigaBoardInfo + PSSO_BoardInfo_BitsPerCannon, DX_BitsPerCannon ());
1.1.1.2   root      842:     put_word (AmigaBoardInfo + PSSO_BoardInfo_RGBFormats, picasso96_pixel_format);
                    843:     put_word (AmigaBoardInfo + PSSO_BoardInfo_SoftSpriteFlags, picasso96_pixel_format);
1.1.1.12  root      844:     put_long (AmigaBoardInfo + PSSO_BoardInfo_BoardType, BT_uaegfx);
1.1.1.2   root      845:     put_word (AmigaBoardInfo + PSSO_BoardInfo_MaxHorResolution + 0, planar.width);
                    846:     put_word (AmigaBoardInfo + PSSO_BoardInfo_MaxHorResolution + 2, chunky.width);
                    847:     put_word (AmigaBoardInfo + PSSO_BoardInfo_MaxHorResolution + 4, hicolour.width);
                    848:     put_word (AmigaBoardInfo + PSSO_BoardInfo_MaxHorResolution + 6, truecolour.width);
                    849:     put_word (AmigaBoardInfo + PSSO_BoardInfo_MaxHorResolution + 8, alphacolour.width);
                    850:     put_word (AmigaBoardInfo + PSSO_BoardInfo_MaxVerResolution + 0, planar.height);
                    851:     put_word (AmigaBoardInfo + PSSO_BoardInfo_MaxVerResolution + 2, chunky.height);
                    852:     put_word (AmigaBoardInfo + PSSO_BoardInfo_MaxVerResolution + 4, hicolour.height);
                    853:     put_word (AmigaBoardInfo + PSSO_BoardInfo_MaxVerResolution + 6, truecolour.height);
                    854:     put_word (AmigaBoardInfo + PSSO_BoardInfo_MaxVerResolution + 8, alphacolour.height);
1.1       root      855: 
                    856:     for (i = 0; i < mode_count;) {
                    857:        int j = i;
                    858:        /* Add a LibResolution structure to the ResolutionsList MinList in our BoardInfo */
1.1.1.4   root      859:        res.DisplayID = AssignModeID (i, LibResolutionStructureCount);
1.1       root      860:        res.BoardInfo = AmigaBoardInfo;
                    861:        res.Width = DisplayModes[i].res.width;
                    862:        res.Height = DisplayModes[i].res.height;
                    863:        res.Flags = P96F_PUBLIC;
                    864:        res.P96ID[0] = 'P';
                    865:        res.P96ID[1] = '9';
                    866:        res.P96ID[2] = '6';
                    867:        res.P96ID[3] = '-';
                    868:        res.P96ID[4] = '0';
                    869:        res.P96ID[5] = ':';
                    870:        strcpy (res.Name, "uaegfx:");
1.1.1.3   root      871:        strncat (res.Name, DisplayModes[i].name, strchr (DisplayModes[i].name, ',') - DisplayModes[i].name);
1.1       root      872:        res.Modes[PLANAR] = 0;
                    873:        res.Modes[CHUNKY] = 0;
                    874:        res.Modes[HICOLOR] = 0;
                    875:        res.Modes[TRUECOLOR] = 0;
                    876:        res.Modes[TRUEALPHA] = 0;
                    877: 
                    878:        do {
                    879:            /* Handle this display mode's depth */
1.1.1.12  root      880:            /* Only add the modes when there is enough P96 RTG memory to hold the bitmap */
                    881:            long required = DisplayModes[i].res.width * DisplayModes[i].res.height * DisplayModes[i].depth;
                    882:            if (allocated_gfxmem - 32768 > required) {
                    883:                amigamemptr = gfxmem_start + allocated_gfxmem - (PSSO_ModeInfo_sizeof * ModeInfoStructureCount++);
                    884:                FillBoardInfo (amigamemptr, &res, &DisplayModes[i]);
                    885:            }
1.1       root      886:            i++;
                    887:        } while (i < mode_count
                    888:                 && DisplayModes[i].res.width == DisplayModes[j].res.width
                    889:                 && DisplayModes[i].res.height == DisplayModes[j].res.height);
                    890: 
1.1.1.2   root      891:        amigamemptr = gfxmem_start + allocated_gfxmem - 16384 + (PSSO_LibResolution_sizeof * LibResolutionStructureCount++);
1.1       root      892:        CopyLibResolutionStructureU2A (&res, amigamemptr);
1.1.1.8   root      893:        DumpLibResolutionStructure (amigamemptr);
1.1       root      894:        AmigaListAddTail (AmigaBoardInfo + PSSO_BoardInfo_ResolutionsList, amigamemptr);
                    895:     }
                    896: 
                    897:     return 0;
                    898: }
                    899: 
                    900: extern int x_size, y_size;
                    901: 
                    902: /*
                    903:  * SetSwitch:
                    904:  * a0: struct BoardInfo
                    905:  * d0.w:       BOOL state
                    906:  * this function should set a board switch to let the Amiga signal pass
                    907:  * through when supplied with a 0 in d0 and to show the board signal if
                    908:  * a 1 is passed in d0. You should remember the current state of the
                    909:  * switch to avoid unneeded switching. If your board has no switch, then
                    910:  * simply supply a function that does nothing except a RTS.
                    911:  *
                    912:  * NOTE: Return the opposite of the switch-state. BDK
                    913: */
                    914: uae_u32 picasso_SetSwitch (void)
                    915: {
1.1.1.2   root      916:     uae_u16 flag = m68k_dreg (regs, 0) & 0xFFFF;
1.1       root      917: 
                    918:     /* Do not switch immediately.  Tell the custom chip emulation about the
                    919:      * desired state, and wait for custom.c to call picasso_enablescreen
                    920:      * whenever it is ready to change the screen state.  */
                    921:     picasso_requested_on = !!flag;
1.1.1.11  root      922: #if 0
1.1.1.8   root      923:     write_log ("SetSwitch() - trying to show %s screen\n", flag ? "picasso96" : "amiga");
1.1.1.11  root      924: #endif
1.1       root      925:     /* Put old switch-state in D0 */
                    926:     return !flag;
                    927: }
                    928: 
                    929: void picasso_enablescreen (int on)
                    930: {
                    931:     wgfx_linestart = 0xFFFFFFFF;
                    932:     picasso_refresh ();
1.1.1.11  root      933: #if 0
1.1.1.8   root      934:     write_log ("SetSwitch() - showing %s screen\n", on ? "picasso96" : "amiga");
1.1.1.11  root      935: #endif
                    936: }
                    937: 
                    938: static int first_color_changed = 256;
                    939: static int last_color_changed = -1;
                    940: 
                    941: void picasso_handle_vsync (void)
                    942: {
                    943:     if (first_color_changed < last_color_changed) {
1.1.1.12  root      944:        DX_SetPalette (first_color_changed, last_color_changed - first_color_changed);
1.1.1.11  root      945:        /* If we're emulating a CLUT mode, we need to redraw the entire screen.  */
                    946:        if (picasso_vidinfo.rgbformat != picasso96_state.RGBFormat)
                    947:            picasso_refresh ();
                    948:     }
                    949: 
                    950:     first_color_changed = 256;
                    951:     last_color_changed = -1;
1.1       root      952: }
                    953: 
1.1.1.12  root      954: void picasso_clip_mouse (int *px, int *py)
                    955: {
                    956:     int xoff = picasso96_state.XOffset;
                    957:     int yoff = picasso96_state.YOffset;
                    958:     if (*px < -xoff)
                    959:        *px = -xoff;
                    960:     if (*px + xoff > picasso_vidinfo.width)
                    961:        *px = picasso_vidinfo.width - xoff;
                    962:     if (*py < -yoff)
                    963:        *py = -yoff;
                    964:     if (*py + yoff > picasso_vidinfo.height)
                    965:        *py = picasso_vidinfo.height - yoff;
                    966: }
                    967: 
1.1       root      968: /*
                    969:  * SetColorArray:
                    970:  * a0: struct BoardInfo
                    971:  * d0.w: startindex
                    972:  * d1.w: count
                    973:  * when this function is called, your driver has to fetch "count" color
                    974:  * values starting at "startindex" from the CLUT field of the BoardInfo
                    975:  * structure and write them to the hardware. The color values are always
                    976:  * between 0 and 255 for each component regardless of the number of bits
                    977:  * per cannon your board has. So you might have to shift the colors
                    978:  * before writing them to the hardware.
                    979:  */
                    980: uae_u32 picasso_SetColorArray (void)
                    981: {
                    982:     /* Fill in some static UAE related structure about this new CLUT setting
                    983:      * We need this for CLUT-based displays, and for mapping CLUT to hi/true colour */
1.1.1.2   root      984:     uae_u16 start = m68k_dreg (regs, 0);
                    985:     uae_u16 count = m68k_dreg (regs, 1);
1.1       root      986:     int i;
1.1.1.2   root      987:     uaecptr boardinfo = m68k_areg (regs, 0);
1.1       root      988:     uaecptr clut = boardinfo + PSSO_BoardInfo_CLUT + start * 3;
1.1.1.2   root      989:     int changed = 0;
1.1       root      990: 
                    991:     for (i = start; i < start + count; i++) {
1.1.1.2   root      992:        int r = get_byte (clut);
                    993:        int g = get_byte (clut + 1);
                    994:        int b = get_byte (clut + 2);
                    995: 
1.1.1.8   root      996:        changed |= (picasso96_state.CLUT[i].Red != r || picasso96_state.CLUT[i].Green != g || picasso96_state.CLUT[i].Blue != b);
                    997: 
                    998:        picasso96_state.CLUT[i].Red = r;
1.1.1.2   root      999:        picasso96_state.CLUT[i].Green = g;
                   1000:        picasso96_state.CLUT[i].Blue = b;
1.1       root     1001:        clut += 3;
                   1002:     }
1.1.1.2   root     1003:     if (changed) {
1.1.1.11  root     1004:        if (start < first_color_changed)
                   1005:            first_color_changed = start;
                   1006:        if (start + count > last_color_changed)
                   1007:            last_color_changed = start + count;
1.1       root     1008:     }
1.1.1.2   root     1009:     /*write_log ("SetColorArray(%d,%d)\n", start, count); */
1.1.1.4   root     1010:     return 1;
1.1       root     1011: }
                   1012: 
                   1013: /*
                   1014:  * SetDAC:
                   1015:  * a0: struct BoardInfo
                   1016:  * d7: RGBFTYPE RGBFormat
                   1017:  * This function is called whenever the RGB format of the display changes,
                   1018:  * e.g. from chunky to TrueColor. Usually, all you have to do is to set
                   1019:  * the RAMDAC of your board accordingly.
                   1020:  */
                   1021: uae_u32 picasso_SetDAC (void)
                   1022: {
                   1023:     /* Fill in some static UAE related structure about this new DAC setting
                   1024:      * Lets us keep track of what pixel format the Amiga is thinking about in our frame-buffer */
                   1025: 
1.1.1.2   root     1026:     write_log ("SetDAC()\n");
1.1.1.4   root     1027:     return 1;
1.1       root     1028: }
                   1029: 
1.1.1.6   root     1030: static void init_picasso_screen (void)
                   1031: {
1.1.1.12  root     1032:     int width = picasso96_state.Width;
                   1033:     int height = picasso96_state.Height;
                   1034:     int vwidth = picasso96_state.VirtualWidth;
                   1035:     int vheight = picasso96_state.VirtualHeight;
                   1036:     int xoff = 0;
                   1037:     int yoff = 0;
                   1038: 
1.1.1.8   root     1039:     if (!set_gc_called)
1.1.1.6   root     1040:        return;
                   1041: 
1.1.1.12  root     1042:     if (set_panning_called) {
                   1043:        picasso96_state.Extent = picasso96_state.Address + (picasso96_state.BytesPerRow * vheight);
                   1044:        xoff = picasso96_state.XOffset;
                   1045:        yoff = picasso96_state.YOffset;
                   1046:     }
1.1.1.6   root     1047: 
1.1.1.12  root     1048:     gfx_set_picasso_modeinfo (width, height, picasso96_state.GC_Depth, picasso96_state.RGBFormat);
1.1.1.6   root     1049:     DX_SetPalette (0, 256);
                   1050: 
                   1051:     wgfx_linestart = 0xFFFFFFFF;
                   1052:     picasso_refresh ();
                   1053: }
                   1054: 
1.1       root     1055: /*
                   1056:  * SetGC:
                   1057:  * a0: struct BoardInfo
                   1058:  * a1: struct ModeInfo
                   1059:  * d0: BOOL Border
                   1060:  * This function is called whenever another ModeInfo has to be set. This
                   1061:  * function simply sets up the CRTC and TS registers to generate the
                   1062:  * timing used for that screen mode. You should not set the DAC, clocks
                   1063:  * or linear start adress. They will be set when appropriate by their
                   1064:  * own functions.
                   1065:  */
                   1066: uae_u32 picasso_SetGC (void)
                   1067: {
                   1068:     /* Fill in some static UAE related structure about this new ModeInfo setting */
1.1.1.2   root     1069:     uaecptr modeinfo = m68k_areg (regs, 1);
1.1       root     1070: 
                   1071:     picasso96_state.Width = get_word (modeinfo + PSSO_ModeInfo_Width);
1.1.1.8   root     1072:     picasso96_state.VirtualWidth = picasso96_state.Width;      /* in case SetPanning doesn't get called */
1.1       root     1073: 
                   1074:     picasso96_state.Height = get_word (modeinfo + PSSO_ModeInfo_Height);
                   1075:     picasso96_state.VirtualHeight = picasso96_state.Height;
                   1076: 
                   1077:     picasso96_state.GC_Depth = get_byte (modeinfo + PSSO_ModeInfo_Depth);
                   1078:     picasso96_state.GC_Flags = get_byte (modeinfo + PSSO_ModeInfo_Flags);
                   1079: 
1.1.1.13! root     1080:     P96TRACE (("SetGC(%d,%d,%d)\n", picasso96_state.Width, picasso96_state.Height, picasso96_state.GC_Depth));
1.1       root     1081: 
1.1.1.8   root     1082:     set_gc_called = 1;         /* @@@ when do we need to reset this? */
1.1.1.6   root     1083:     init_picasso_screen ();
1.1.1.4   root     1084:     return 1;
1.1       root     1085: }
                   1086: 
                   1087: /*
                   1088:  * SetPanning:
                   1089:  * a0: struct BoardInfo
                   1090:  * a1: UBYTE *Memory
                   1091:  * d0: uae_u16 Width
                   1092:  * d1: WORD XOffset
                   1093:  * d2: WORD YOffset
                   1094:  * d7: RGBFTYPE RGBFormat
                   1095:  * This function sets the view origin of a display which might also be
                   1096:  * overscanned. In register a1 you get the start address of the screen
                   1097:  * bitmap on the Amiga side. You will have to subtract the starting
                   1098:  * address of the board memory from that value to get the memory start
                   1099:  * offset within the board. Then you get the offset in pixels of the
                   1100:  * left upper edge of the visible part of an overscanned display. From
                   1101:  * these values you will have to calculate the LinearStartingAddress
                   1102:  * fields of the CRTC registers.
                   1103: 
                   1104:  * NOTE: SetPanning() can be used to know when a Picasso96 screen is
                   1105:  * being opened.  Better to do the appropriate clearing of the
                   1106:  * background here than in SetSwitch() derived functions,
                   1107:  * because SetSwitch() is not called for subsequent Picasso screens.
                   1108:  */
                   1109: uae_u32 picasso_SetPanning (void)
                   1110: {
1.1.1.2   root     1111:     uae_u16 Width = m68k_dreg (regs, 0);
                   1112:     uaecptr start_of_screen = m68k_areg (regs, 1);
1.1.1.12  root     1113:     uaecptr bi = m68k_areg (regs, 0);
                   1114:     uaecptr bmeptr = get_long (bi + PSSO_BoardInfo_BitMapExtra);        /* Get our BoardInfo ptr's BitMapExtra ptr */
                   1115:     int oldxoff = picasso96_state.XOffset;
                   1116:     int oldyoff = picasso96_state.YOffset;
                   1117: #if 0
                   1118:     /* @@@ This is in WinUAE, but it breaks things.  */
                   1119:     if (oldscr == 0) {
                   1120:        oldscr = start_of_screen;
                   1121:     }
                   1122:     if ((oldscr != start_of_screen)) {
                   1123:        set_gc_called = 0;
                   1124:        oldscr = start_of_screen;
                   1125:     }
                   1126: #endif
1.1       root     1127: 
1.1.1.8   root     1128:     picasso96_state.Address = start_of_screen; /* Amiga-side address */
                   1129:     picasso96_state.XOffset = (uae_s16) m68k_dreg (regs, 1);
                   1130:     picasso96_state.YOffset = (uae_s16) m68k_dreg (regs, 2);
1.1.1.12  root     1131:     picasso96_state.VirtualWidth = get_word (bmeptr + PSSO_BitMapExtra_Width);
                   1132:     picasso96_state.VirtualHeight = get_word (bmeptr + PSSO_BitMapExtra_Height);
1.1.1.2   root     1133:     picasso96_state.RGBFormat = m68k_dreg (regs, 7);
                   1134:     picasso96_state.BytesPerPixel = GetBytesPerPixel (picasso96_state.RGBFormat);
1.1       root     1135:     picasso96_state.BytesPerRow = Width * picasso96_state.BytesPerPixel;
                   1136: 
1.1.1.6   root     1137:     set_panning_called = 1;
1.1.1.13! root     1138:     P96TRACE (("SetPanning(%d, %d, %d) Start 0x%x, BPR %d\n",
        !          1139:               Width, picasso96_state.XOffset, picasso96_state.YOffset, start_of_screen, picasso96_state.BytesPerRow));
1.1       root     1140: 
1.1.1.6   root     1141:     init_picasso_screen ();
1.1       root     1142: 
1.1.1.12  root     1143:     lastmx += oldxoff - picasso96_state.XOffset;
                   1144:     lastmy += oldyoff - picasso96_state.YOffset;
                   1145:     
1.1.1.4   root     1146:     return 1;
1.1       root     1147: }
                   1148: 
1.1.1.8   root     1149: static void do_xor8 (uae_u8 * ptr, long len, uae_u32 val)
1.1       root     1150: {
                   1151:     int i;
                   1152: #if 0 && defined ALIGN_POINTER_TO32
1.1.1.8   root     1153:     int align_adjust = ALIGN_POINTER_TO32 (ptr);
1.1       root     1154:     int len2;
                   1155: 
                   1156:     len -= align_adjust;
                   1157:     while (align_adjust) {
                   1158:        *ptr ^= val;
                   1159:        ptr++;
                   1160:        align_adjust--;
                   1161:     }
                   1162:     len2 = len >> 2;
                   1163:     len -= len2 << 2;
                   1164:     for (i = 0; i < len2; i++, ptr += 4) {
1.1.1.8   root     1165:        *(uae_u32 *) ptr ^= val;
1.1       root     1166:     }
                   1167:     while (len) {
                   1168:        *ptr ^= val;
                   1169:        ptr++;
                   1170:        len--;
                   1171:     }
                   1172:     return;
                   1173: #endif
                   1174:     for (i = 0; i < len; i++, ptr++) {
                   1175:        do_put_mem_byte (ptr, do_get_mem_byte (ptr) ^ val);
                   1176:     }
                   1177: }
                   1178: 
                   1179: /*
                   1180:  * InvertRect:
                   1181:  * 
                   1182:  * Inputs:
                   1183:  * a0:struct BoardInfo *bi
                   1184:  * a1:struct RenderInfo *ri
                   1185:  * d0.w:X
                   1186:  * d1.w:Y
                   1187:  * d2.w:Width
                   1188:  * d3.w:Height
                   1189:  * d4.l:Mask
                   1190:  * d7.l:RGBFormat
                   1191:  * 
                   1192:  * This function is used to invert a rectangular area on the board. It is called by BltBitMap,
                   1193:  * BltPattern and BltTemplate.
                   1194:  */
                   1195: uae_u32 picasso_InvertRect (void)
                   1196: {
1.1.1.2   root     1197:     uaecptr renderinfo = m68k_areg (regs, 1);
1.1.1.8   root     1198:     unsigned long X = (uae_u16) m68k_dreg (regs, 0);
                   1199:     unsigned long Y = (uae_u16) m68k_dreg (regs, 1);
                   1200:     unsigned long Width = (uae_u16) m68k_dreg (regs, 2);
                   1201:     unsigned long Height = (uae_u16) m68k_dreg (regs, 3);
1.1.1.2   root     1202:     uae_u32 mask = m68k_dreg (regs, 4);
                   1203:     int Bpp = GetBytesPerPixel (m68k_dreg (regs, 7));
1.1       root     1204:     uae_u32 xorval;
1.1.1.5   root     1205:     unsigned int lines;
1.1       root     1206:     struct RenderInfo ri;
1.1.1.12  root     1207:     uae_u8 *uae_mem;
1.1.1.5   root     1208:     unsigned long width_in_bytes;
1.1       root     1209: 
                   1210:     wgfx_flushline ();
                   1211: 
1.1.1.8   root     1212:     if (!CopyRenderInfoStructureA2U (renderinfo, &ri))
1.1       root     1213:        return 0;
                   1214: 
1.1.1.13! root     1215:     P96TRACE (("InvertRect: X %d Y %d Width %d Height %d\n", X, Y, Width, Height));
1.1.1.8   root     1216:     /*write_log ("InvertRect %d %lx\n", Bpp, (long)mask); */
1.1       root     1217: 
                   1218:     /* ??? Brian? mask used to be 32 bit, but it appears that only 8 bit
                   1219:      * values are passed to this function.  This code here seems to work
                   1220:      * much better... */
1.1.1.12  root     1221:     if (mask != 0xFF && Bpp > 1) {
1.1.1.2   root     1222:        write_log ("InvertRect: not obeying mask 0x%x properly with Bpp %d.\n", mask, Bpp);
1.1       root     1223:        mask = 0xFF;
                   1224:     }
                   1225:     if ((mask & ~0xFF) != 0) {
1.1.1.2   root     1226:        write_log ("InvertRect: mask has high bits set!\n");
1.1       root     1227:     }
                   1228:     xorval = 0x01010101 * (mask & 0xFF);
                   1229:     width_in_bytes = Bpp * Width;
1.1.1.12  root     1230:     uae_mem = ri.Memory + Y * ri.BytesPerRow + X * Bpp;
1.1       root     1231: 
1.1.1.2   root     1232:     for (lines = 0; lines < Height; lines++, uae_mem += ri.BytesPerRow)
1.1       root     1233:        do_xor8 (uae_mem, width_in_bytes, xorval);
1.1.1.2   root     1234: 
1.1       root     1235:     if (renderinfo_is_current_screen (&ri)) {
                   1236:        if (mask == 0xFF)
1.1.1.12  root     1237:            do_invertrect (&ri, Bpp, X, Y, Width, Height);
1.1       root     1238:        else
1.1.1.12  root     1239:            do_blit (&ri, Bpp, X, Y, X, Y, Width, Height, BLIT_SRC, 0);
1.1       root     1240:     }
                   1241: 
1.1.1.8   root     1242:     return 1;                  /* 1 if supported, 0 otherwise */
1.1       root     1243: }
                   1244: 
1.1.1.12  root     1245: /* Fill a rectangle in the Amiga-memory frame buffer.  */
                   1246: 
                   1247: STATIC_INLINE void do_fillrect_frame_buffer (struct RenderInfo *ri, int X, int Y,
                   1248:                                             int Width, int Height, uae_u32 Pen, int Bpp,
                   1249:                                             RGBFTYPE RGBFormat)
                   1250: {
                   1251:     uae_u8 *start, *oldstart, *dst;
                   1252:     long lines, cols;
                   1253: 
                   1254:     /* Do our virtual frame-buffer memory.  First, we do a single line fill by hand */
                   1255:     oldstart = start = ri->Memory + Y * ri->BytesPerRow + X * Bpp;
                   1256:     switch (Bpp) {
                   1257:     case 1:
                   1258:        memset (start, Pen, Width);
                   1259:        break;
                   1260:     case 2:
                   1261:        for (cols = 0; cols < Width; cols++) {
                   1262:            do_put_mem_word ((uae_u16 *) start, Pen);
                   1263:            start += 2;
                   1264:        }
                   1265:        break;
                   1266:     case 3:
                   1267:        for (cols = 0; cols < Width; cols++) {
                   1268:            do_put_mem_byte (start, Pen & 0x000000FF);
                   1269:            start++;
                   1270:            *(uae_u16 *) (start) = (Pen & 0x00FFFF00) >> 8;
                   1271:            start += 2;
                   1272:        }
                   1273:        break;
                   1274:     case 4:
                   1275:        for (cols = 0; cols < Width; cols++) {
                   1276:            /**start = Pen; */
                   1277:            do_put_mem_long ((uae_u32 *) start, Pen);
                   1278:            start += 4;
                   1279:        }
                   1280:        break;
                   1281:     }
                   1282: 
                   1283:     dst = oldstart + ri->BytesPerRow;
                   1284:     /* next, we do the remaining line fills via memcpy() for > 1 BPP, otherwise some more memset() calls */
                   1285:     if (Bpp > 1) {
                   1286:        for (lines = 0; lines < (Height - 1); lines++, dst += ri->BytesPerRow)
                   1287:            memcpy (dst, oldstart, Width * Bpp);
                   1288:     } else {
                   1289:        for (lines = 0; lines < (Height - 1); lines++, dst += ri->BytesPerRow)
                   1290:            memset (dst, Pen, Width);
                   1291:     }
                   1292: }
                   1293: 
                   1294: 
1.1       root     1295: /***********************************************************
                   1296: FillRect:
                   1297: ***********************************************************
                   1298: * a0:  struct BoardInfo *
                   1299: * a1:  struct RenderInfo *
                   1300: * d0:  WORD X
                   1301: * d1:  WORD Y
                   1302: * d2:  WORD Width
                   1303: * d3:  WORD Height
                   1304: * d4:  uae_u32 Pen
                   1305: * d5:  UBYTE Mask
                   1306: * d7:  uae_u32 RGBFormat
                   1307: ***********************************************************/
                   1308: uae_u32 picasso_FillRect (void)
                   1309: {
1.1.1.2   root     1310:     uaecptr renderinfo = m68k_areg (regs, 1);
1.1.1.8   root     1311:     unsigned long X = (uae_u16) m68k_dreg (regs, 0);
                   1312:     unsigned long Y = (uae_u16) m68k_dreg (regs, 1);
                   1313:     unsigned long Width = (uae_u16) m68k_dreg (regs, 2);
                   1314:     unsigned long Height = (uae_u16) m68k_dreg (regs, 3);
1.1.1.2   root     1315:     uae_u32 Pen = m68k_dreg (regs, 4);
1.1.1.8   root     1316:     uae_u8 Mask = (uae_u8) m68k_dreg (regs, 5);
1.1.1.2   root     1317:     uae_u32 RGBFormat = m68k_dreg (regs, 7);
1.1       root     1318: 
                   1319:     int Bpp;
                   1320:     struct RenderInfo ri;
                   1321: 
                   1322:     wgfx_flushline ();
                   1323: 
1.1.1.8   root     1324:     if (!CopyRenderInfoStructureA2U (renderinfo, &ri) || Y == 0xFFFF)
1.1       root     1325:        return 0;
                   1326: 
1.1.1.13! root     1327:     P96TRACE(("FillRect(%d, %d, %d, %d) Pen 0x%x BPP %d BPR %d Mask 0x%x\n",
        !          1328:              X, Y, Width, Height, Pen, Bpp, ri.BytesPerRow, Mask));
        !          1329: 
1.1       root     1330:     if (ri.RGBFormat != RGBFormat)
1.1.1.2   root     1331:        write_log ("Weird Stuff!\n");
1.1       root     1332: 
1.1.1.2   root     1333:     Bpp = GetBytesPerPixel (RGBFormat);
1.1       root     1334: 
1.1.1.12  root     1335:     /* write_log ("FillRect(%d, %d, %d, %d) Pen 0x%x BPP %d BPR %d Mask 0x%x\n",
1.1.1.8   root     1336:        X, Y, Width, Height, Pen, Bpp, ri.BytesPerRow, Mask); */
1.1       root     1337: 
                   1338:     if (Mask == 0xFF) {
1.1.1.12  root     1339:        do_fillrect_frame_buffer (&ri, X, Y, Width, Height, Pen, Bpp, RGBFormat);
1.1       root     1340: 
1.1.1.2   root     1341:        if (renderinfo_is_current_screen (&ri))
1.1.1.12  root     1342:            do_fillrect (ri.Memory + Y * ri.BytesPerRow + X * Bpp, X, Y,
                   1343:                         Width, Height, Pen, Bpp, RGBFormat);
1.1.1.2   root     1344: 
1.1       root     1345:        return 1;
                   1346:     }
                   1347: 
                   1348:     /* We get here only if Mask != 0xFF */
                   1349:     if (Bpp != 1) {
                   1350:        write_log ("Picasso: mask != 0xFF in truecolor mode!\n");
                   1351:        return 0;
                   1352:     }
                   1353:     Pen &= Mask;
                   1354:     Mask = ~Mask;
                   1355: 
1.1.1.5   root     1356:     {
1.1.1.12  root     1357:        uae_u8 *start = ri.Memory + Y * ri.BytesPerRow + X * Bpp;
1.1.1.5   root     1358:        uae_u8 *end = start + Height * ri.BytesPerRow;
                   1359:        for (; start != end; start += ri.BytesPerRow) {
                   1360:            uae_u8 *p = start;
                   1361:            unsigned long cols;
                   1362:            for (cols = 0; cols < Width; cols++) {
                   1363:                uae_u32 tmpval = do_get_mem_byte (p + cols) & Mask;
                   1364:                do_put_mem_byte (p + cols, Pen | tmpval);
                   1365:            }
1.1       root     1366:        }
                   1367:     }
1.1.1.12  root     1368: 
1.1       root     1369:     if (renderinfo_is_current_screen (&ri))
1.1.1.12  root     1370:        do_blit (&ri, Bpp, X, Y, X, Y, Width, Height, BLIT_SRC, 0);
1.1       root     1371: 
                   1372:     return 1;
                   1373: }
                   1374: 
                   1375: /*
                   1376:  * BlitRect() is a generic (any chunky pixel format) rectangle copier
                   1377:  * NOTE: If dstri is NULL, then we're only dealing with one RenderInfo area, and called from picasso_BlitRect()
                   1378:  */
                   1379: static void BlitRect (struct RenderInfo *ri, struct RenderInfo *dstri,
1.1.1.5   root     1380:                      unsigned long srcx, unsigned long srcy, unsigned long dstx, unsigned long dsty,
1.1.1.12  root     1381:                      unsigned long width, unsigned long height, uae_u8 mask, BLIT_OPCODE opcode)
1.1       root     1382: {
                   1383:     uae_u8 *src, *dst, *tmp, *tmp2, *tmp3;
1.1.1.5   root     1384:     unsigned long lines;
1.1.1.8   root     1385:     uae_u8 Bpp = GetBytesPerPixel (ri->RGBFormat);
1.1       root     1386:     uae_u8 *blitsrc;
                   1387:     unsigned long total_width = width * Bpp;
                   1388:     unsigned long linewidth = (total_width + 15) & ~15;
                   1389:     int cant_blit = 1;
                   1390: 
                   1391:     /*
                   1392:      * If we have no destination RenderInfo, then we're dealing with a single-buffer action, called
                   1393:      * from picasso_BlitRect().  The code up to the DX_xxxxx() functions deals with the frame-buffer,
                   1394:      * while the DX_ functions actually deal with the visible screen.
                   1395:      *
                   1396:      * If we have a destination RenderInfo, then we've been called from picasso_BlitRectNoMaskComplete()
                   1397:      * and we need to put the results on the screen from the frame-buffer.
                   1398:      */
                   1399:     if (dstri == NULL) {
                   1400:        dstri = ri;
                   1401:        cant_blit = 0;
                   1402:     }
                   1403: 
                   1404:     /* Do our virtual frame-buffer memory first */
1.1.1.8   root     1405:     src = ri->Memory + srcx * Bpp + srcy * ri->BytesPerRow;
                   1406:     dst = dstri->Memory + dstx * Bpp + dsty * dstri->BytesPerRow;
1.1       root     1407:     blitsrc = dst;
                   1408:     if (mask != 0xFF && Bpp > 1)
1.1.1.2   root     1409:        write_log ("ERROR - not obeying BlitRect() mask 0x%x properly with Bpp %d.\n", mask, Bpp);
1.1       root     1410: 
                   1411:     if (mask == 0xFF || Bpp > 1) {
                   1412:        /* handle normal case efficiently */
                   1413:        if (ri->Memory == dstri->Memory && dsty == srcy) {
1.1.1.5   root     1414:            unsigned long i;
1.1       root     1415:            for (i = 0; i < height; i++, src += ri->BytesPerRow, dst += dstri->BytesPerRow)
                   1416:                memmove (dst, src, total_width);
                   1417:        } else if (dsty < srcy) {
1.1.1.5   root     1418:            unsigned long i;
1.1       root     1419:            for (i = 0; i < height; i++, src += ri->BytesPerRow, dst += dstri->BytesPerRow)
                   1420:                memcpy (dst, src, total_width);
                   1421:        } else {
1.1.1.5   root     1422:            unsigned long i;
1.1.1.8   root     1423:            src += (height - 1) * ri->BytesPerRow;
                   1424:            dst += (height - 1) * dstri->BytesPerRow;
1.1       root     1425:            for (i = 0; i < height; i++, src -= ri->BytesPerRow, dst -= dstri->BytesPerRow)
                   1426:                memcpy (dst, src, total_width);
                   1427:        }
1.1.1.12  root     1428:        if (cant_blit)
                   1429:            srcx = dstx, srcy = dsty;
1.1       root     1430:        if (renderinfo_is_current_screen (dstri))
1.1.1.12  root     1431:            do_blit (dstri, Bpp, srcx, srcy, dstx, dsty, width, height, opcode, !cant_blit);
1.1       root     1432:        return;
                   1433:     }
                   1434: 
1.1.1.8   root     1435:     tmp3 = tmp2 = tmp = xmalloc (linewidth * height);  /* allocate enough memory for the src-rect */
1.1       root     1436:     if (!tmp)
                   1437:        return;
                   1438: 
                   1439:     /* copy the src-rect into our temporary buffer space */
                   1440:     for (lines = 0; lines < height; lines++, src += ri->BytesPerRow, tmp2 += linewidth) {
                   1441:        memcpy (tmp2, src, total_width);
                   1442:     }
                   1443: 
                   1444:     /* copy the temporary buffer to the destination */
                   1445:     for (lines = 0; lines < height; lines++, dst += dstri->BytesPerRow, tmp += linewidth) {
1.1.1.5   root     1446:        unsigned long cols;
1.1       root     1447:        for (cols = 0; cols < width; cols++) {
                   1448:            dst[cols] &= ~mask;
                   1449:            dst[cols] |= tmp[cols] & mask;
                   1450:        }
                   1451:     }
                   1452:     if (renderinfo_is_current_screen (dstri))
1.1.1.12  root     1453:        do_blit (dstri, Bpp, dstx, dsty, dstx, dsty, width, height, opcode, 0);
                   1454: 
1.1       root     1455:     /* free the temp-buf */
                   1456:     free (tmp3);
                   1457: 
                   1458: }
                   1459: 
                   1460: /***********************************************************
                   1461: BlitRect:
                   1462: ***********************************************************
                   1463: * a0:  struct BoardInfo
                   1464: * a1:  struct RenderInfo
                   1465: * d0:  WORD SrcX
                   1466: * d1:  WORD SrcY
                   1467: * d2:  WORD DstX
                   1468: * d3:  WORD DstY
                   1469: * d4:   WORD Width
                   1470: * d5:   WORD Height
                   1471: * d6:  UBYTE Mask
                   1472: * d7:  uae_u32 RGBFormat
                   1473: ***********************************************************/
                   1474: uae_u32 picasso_BlitRect (void)
                   1475: {
1.1.1.2   root     1476:     uaecptr renderinfo = m68k_areg (regs, 1);
1.1.1.8   root     1477:     unsigned long srcx = (uae_u16) m68k_dreg (regs, 0);
                   1478:     unsigned long srcy = (uae_u16) m68k_dreg (regs, 1);
                   1479:     unsigned long dstx = (uae_u16) m68k_dreg (regs, 2);
                   1480:     unsigned long dsty = (uae_u16) m68k_dreg (regs, 3);
                   1481:     unsigned long width = (uae_u16) m68k_dreg (regs, 4);
                   1482:     unsigned long height = (uae_u16) m68k_dreg (regs, 5);
                   1483:     uae_u8 Mask = (uae_u8) m68k_dreg (regs, 6);
1.1       root     1484: 
                   1485:     struct RenderInfo ri;
                   1486: 
                   1487:     wgfx_flushline ();
                   1488: 
1.1.1.8   root     1489:     if (!CopyRenderInfoStructureA2U (renderinfo, &ri))
1.1       root     1490:        return 0;
                   1491: 
1.1.1.13! root     1492:     P96TRACE(("BlitRect(%d, %d, %d, %d, %d, %d, 0x%x)\n", srcx, srcy, dstx, dsty, width, height, Mask));
1.1.1.12  root     1493:     BlitRect (&ri, NULL, srcx, srcy, dstx, dsty, width, height, Mask, BLIT_SRC);
1.1.1.2   root     1494:     /*write_log ("BlitRect(%d, %d, %d, %d, %d, %d, 0x%x)\n", srcx, srcy, dstx, dsty, width, height, Mask); */
1.1       root     1495: 
                   1496:     return 1;
                   1497: }
                   1498: 
                   1499: /***********************************************************
                   1500: BlitRectNoMaskComplete:
                   1501: ***********************************************************
                   1502: * a0:  struct BoardInfo
                   1503: * a1:  struct RenderInfo (src)
                   1504: * a2:   struct RenderInfo (dst)
                   1505: * d0:  WORD SrcX
                   1506: * d1:  WORD SrcY
                   1507: * d2:  WORD DstX
                   1508: * d3:  WORD DstY
                   1509: * d4:   WORD Width
                   1510: * d5:   WORD Height
                   1511: * d6:  UBYTE OpCode
                   1512: * d7:  uae_u32 RGBFormat
                   1513: * NOTE: MUST return 0 in D0 if we're not handling this operation
                   1514: *       because the RGBFormat or opcode aren't supported.
                   1515: *       OTHERWISE return 1
                   1516: ***********************************************************/
                   1517: uae_u32 picasso_BlitRectNoMaskComplete (void)
                   1518: {
1.1.1.2   root     1519:     uaecptr srcri = m68k_areg (regs, 1);
                   1520:     uaecptr dstri = m68k_areg (regs, 2);
1.1.1.8   root     1521:     unsigned long srcx = (uae_u16) m68k_dreg (regs, 0);
                   1522:     unsigned long srcy = (uae_u16) m68k_dreg (regs, 1);
                   1523:     unsigned long dstx = (uae_u16) m68k_dreg (regs, 2);
                   1524:     unsigned long dsty = (uae_u16) m68k_dreg (regs, 3);
                   1525:     unsigned long width = (uae_u16) m68k_dreg (regs, 4);
                   1526:     unsigned long height = (uae_u16) m68k_dreg (regs, 5);
1.1.1.2   root     1527:     uae_u8 OpCode = m68k_dreg (regs, 6);
                   1528:     uae_u32 RGBFmt = m68k_dreg (regs, 7);
1.1       root     1529:     struct RenderInfo src_ri, dst_ri;
                   1530: 
                   1531:     wgfx_flushline ();
                   1532: 
1.1.1.8   root     1533:     if (!CopyRenderInfoStructureA2U (srcri, &src_ri)
                   1534:        || !CopyRenderInfoStructureA2U (dstri, &dst_ri))
1.1       root     1535:        return 0;
                   1536: 
1.1.1.13! root     1537:     P96TRACE(("BlitRectNoMaskComplete() op 0x%2x, xy(%4d,%4d) --> xy(%4d,%4d), wh(%4d,%4d)\n",
        !          1538:        OpCode, srcx, srcy, dstx, dsty, width, height));
1.1       root     1539: 
                   1540:     switch (OpCode) {
1.1.1.8   root     1541:     case 0x0C:
1.1.1.12  root     1542:        BlitRect (&src_ri, &dst_ri, srcx, srcy, dstx, dsty, width, height, 0xFF, OpCode);
1.1       root     1543:        return 1;
                   1544: 
1.1.1.8   root     1545:     default:
1.1       root     1546:        /* FOR NOW! */
                   1547:        return 0;
                   1548:     }
                   1549: }
                   1550: 
                   1551: /* This utility function is used both by BlitTemplate() and BlitPattern() */
1.1.1.8   root     1552: STATIC_INLINE void PixelWrite1 (uae_u8 * mem, int bits, uae_u32 fgpen, uae_u32 mask)
1.1       root     1553: {
                   1554:     if (mask != 0xFF)
                   1555:        fgpen = (fgpen & mask) | (do_get_mem_byte (mem + bits) & ~mask);
                   1556:     do_put_mem_byte (mem + bits, fgpen);
                   1557: }
                   1558: 
1.1.1.8   root     1559: STATIC_INLINE void PixelWrite2 (uae_u8 * mem, int bits, uae_u32 fgpen)
1.1       root     1560: {
1.1.1.8   root     1561:     do_put_mem_word (((uae_u16 *) mem) + bits, fgpen);
1.1       root     1562: }
                   1563: 
1.1.1.8   root     1564: STATIC_INLINE void PixelWrite3 (uae_u8 * mem, int bits, uae_u32 fgpen)
1.1       root     1565: {
1.1.1.8   root     1566:     do_put_mem_byte (mem + bits * 3, fgpen & 0x000000FF);
                   1567:     *(uae_u16 *) (mem + bits * 3 + 1) = (fgpen & 0x00FFFF00) >> 8;
1.1       root     1568: }
                   1569: 
1.1.1.8   root     1570: STATIC_INLINE void PixelWrite4 (uae_u8 * mem, int bits, uae_u32 fgpen)
1.1       root     1571: {
1.1.1.8   root     1572:     do_put_mem_long (((uae_u32 *) mem) + bits, fgpen);
1.1       root     1573: }
                   1574: 
1.1.1.8   root     1575: STATIC_INLINE void PixelWrite (uae_u8 * mem, int bits, uae_u32 fgpen, uae_u8 Bpp, uae_u32 mask)
1.1       root     1576: {
                   1577:     switch (Bpp) {
                   1578:     case 1:
                   1579:        if (mask != 0xFF)
                   1580:            fgpen = (fgpen & mask) | (do_get_mem_byte (mem + bits) & ~mask);
                   1581:        do_put_mem_byte (mem + bits, fgpen);
                   1582:        break;
                   1583:     case 2:
1.1.1.8   root     1584:        do_put_mem_word (((uae_u16 *) mem) + bits, fgpen);
1.1       root     1585:        break;
                   1586:     case 3:
1.1.1.8   root     1587:        do_put_mem_byte (mem + bits * 3, fgpen & 0x000000FF);
                   1588:        *(uae_u16 *) (mem + bits * 3 + 1) = (fgpen & 0x00FFFF00) >> 8;
1.1       root     1589:        break;
                   1590:     case 4:
1.1.1.8   root     1591:        do_put_mem_long (((uae_u32 *) mem) + bits, fgpen);
1.1       root     1592:        break;
                   1593:     }
                   1594: }
                   1595: 
                   1596: /*
                   1597:  * BlitPattern:
                   1598:  * 
                   1599:  * Synopsis:BlitPattern(bi, ri, pattern, X, Y, Width, Height, Mask, RGBFormat);
                   1600:  * Inputs:
                   1601:  * a0:struct BoardInfo *bi
                   1602:  * a1:struct RenderInfo *ri
                   1603:  * a2:struct Pattern *pattern
                   1604:  * d0.w:X
                   1605:  * d1.w:Y
                   1606:  * d2.w:Width
                   1607:  * d3.w:Height
                   1608:  * d4.w:Mask
                   1609:  * d7.l:RGBFormat
                   1610:  * 
                   1611:  * This function is used to paint a pattern on the board memory using the blitter. It is called by
                   1612:  * BltPattern, if a AreaPtrn is used with positive AreaPtSz. The pattern consists of a b/w image
                   1613:  * using a single plane of image data which will be expanded repeatedly to the destination RGBFormat
                   1614:  * using ForeGround and BackGround pens as well as draw modes. The width of the pattern data is
                   1615:  * always 16 pixels (one word) and the height is calculated as 2^Size. The data must be shifted up
                   1616:  * and to the left by XOffset and YOffset pixels at the beginning.
                   1617:  */
                   1618: uae_u32 picasso_BlitPattern (void)
                   1619: {
1.1.1.2   root     1620:     uaecptr rinf = m68k_areg (regs, 1);
                   1621:     uaecptr pinf = m68k_areg (regs, 2);
1.1.1.8   root     1622:     unsigned long X = (uae_u16) m68k_dreg (regs, 0);
                   1623:     unsigned long Y = (uae_u16) m68k_dreg (regs, 1);
                   1624:     unsigned long W = (uae_u16) m68k_dreg (regs, 2);
                   1625:     unsigned long H = (uae_u16) m68k_dreg (regs, 3);
                   1626:     uae_u8 Mask = (uae_u8) m68k_dreg (regs, 4);
1.1.1.2   root     1627:     uae_u32 RGBFmt = m68k_dreg (regs, 7);
1.1       root     1628: 
1.1.1.3   root     1629:     uae_u8 Bpp = GetBytesPerPixel (RGBFmt);
1.1       root     1630:     int inversion = 0;
                   1631:     struct RenderInfo ri;
                   1632:     struct Pattern pattern;
1.1.1.5   root     1633:     unsigned long rows;
1.1.1.2   root     1634:     uae_u32 fgpen;
1.1.1.12  root     1635:     uae_u8 *uae_mem;
1.1       root     1636:     int xshift;
1.1.1.2   root     1637:     unsigned long ysize_mask;
1.1       root     1638: 
                   1639:     wgfx_flushline ();
                   1640: 
1.1.1.12  root     1641:     if (! CopyRenderInfoStructureA2U (rinf, &ri)
1.1.1.8   root     1642:        || !CopyPatternStructureA2U (pinf, &pattern))
1.1       root     1643:        return 0;
                   1644: 
1.1.1.8   root     1645:     Bpp = GetBytesPerPixel (ri.RGBFormat);
                   1646:     uae_mem = ri.Memory + Y * ri.BytesPerRow + X * Bpp;        /* offset with address */
1.1       root     1647: 
                   1648:     if (pattern.DrawMode & INVERS)
                   1649:        inversion = 1;
                   1650: 
                   1651:     pattern.DrawMode &= 0x03;
                   1652:     if (Mask != 0xFF) {
                   1653:        if (Bpp > 1)
1.1.1.2   root     1654:            write_log ("ERROR - not obeying BlitPattern() mask 0x%x properly with Bpp %d.\n", Mask, Bpp);
1.1       root     1655:        else if (pattern.DrawMode == COMP) {
1.1.1.2   root     1656:            write_log ("ERROR - Unsupported Mask value 0x%x with COMP Draw in BlitPattern(), using fallback method.\n", Mask);
1.1       root     1657:            return 0;
                   1658:        }
                   1659:     }
                   1660: 
1.1.1.13! root     1661:     P96TRACE (("BlitPattern() xy(%d,%d), wh(%d,%d) draw 0x%x, off(%d,%d), ph %d\n",
        !          1662:               X, Y, W, H, pattern.DrawMode, pattern.XOffset, pattern.YOffset, 1 << pattern.Size));
1.1       root     1663: #ifdef _DEBUG
1.1.1.8   root     1664:     DumpPattern (&pattern);
1.1       root     1665: #endif
                   1666:     ysize_mask = (1 << pattern.Size) - 1;
                   1667:     xshift = pattern.XOffset & 15;
                   1668: 
                   1669:     for (rows = 0; rows < H; rows++, uae_mem += ri.BytesPerRow) {
1.1.1.5   root     1670:        unsigned long prow = (rows + pattern.YOffset) & ysize_mask;
1.1.1.8   root     1671:        unsigned int d = do_get_mem_word (((uae_u16 *) pattern.Memory) + prow);
1.1       root     1672:        uae_u8 *uae_mem2 = uae_mem;
1.1.1.5   root     1673:        unsigned long cols;
1.1       root     1674: 
                   1675:        if (xshift != 0)
                   1676:            d = (d << xshift) | (d >> (16 - xshift));
                   1677: 
                   1678:        for (cols = 0; cols < W; cols += 16, uae_mem2 += Bpp << 4) {
                   1679:            long bits;
                   1680:            long max = W - cols;
                   1681:            unsigned int data = d;
                   1682: 
                   1683:            if (max > 16)
                   1684:                max = 16;
1.1.1.8   root     1685: 
1.1       root     1686:            for (bits = 0; bits < max; bits++) {
                   1687:                int bit_set = data & 0x8000;
                   1688:                data <<= 1;
                   1689:                switch (pattern.DrawMode) {
1.1.1.8   root     1690:                case JAM1:
1.1       root     1691:                    if (inversion)
                   1692:                        bit_set = !bit_set;
                   1693:                    if (bit_set)
1.1.1.2   root     1694:                        PixelWrite (uae_mem2, bits, pattern.FgPen, Bpp, Mask);
1.1       root     1695:                    break;
1.1.1.8   root     1696:                case JAM2:
1.1       root     1697:                    if (inversion)
                   1698:                        bit_set = !bit_set;
                   1699:                    if (bit_set)
1.1.1.2   root     1700:                        PixelWrite (uae_mem2, bits, pattern.FgPen, Bpp, Mask);
1.1       root     1701:                    else
1.1.1.2   root     1702:                        PixelWrite (uae_mem2, bits, pattern.BgPen, Bpp, Mask);
1.1       root     1703:                    break;
1.1.1.8   root     1704:                case COMP:
1.1       root     1705:                    if (bit_set) {
                   1706:                        fgpen = pattern.FgPen;
                   1707: 
                   1708:                        switch (Bpp) {
1.1.1.8   root     1709:                        case 1:
1.1       root     1710:                            {
                   1711:                                uae_u8 *addr = uae_mem2 + bits;
                   1712:                                do_put_mem_byte (addr, do_get_mem_byte (addr) ^ fgpen);
                   1713:                            }
                   1714:                            break;
1.1.1.8   root     1715:                        case 2:
1.1       root     1716:                            {
1.1.1.8   root     1717:                                uae_u16 *addr = ((uae_u16 *) uae_mem2) + bits;
1.1       root     1718:                                do_put_mem_word (addr, do_get_mem_word (addr) ^ fgpen);
                   1719:                            }
                   1720:                            break;
1.1.1.8   root     1721:                        case 3:
1.1       root     1722:                            {
1.1.1.8   root     1723:                                uae_u32 *addr = (uae_u32 *) (uae_mem2 + bits * 3);
1.1       root     1724:                                do_put_mem_long (addr, do_get_mem_long (addr) ^ (fgpen & 0x00FFFFFF));
                   1725:                            }
                   1726:                            break;
1.1.1.8   root     1727:                        case 4:
1.1       root     1728:                            {
1.1.1.8   root     1729:                                uae_u32 *addr = ((uae_u32 *) uae_mem2) + bits;
1.1       root     1730:                                do_put_mem_long (addr, do_get_mem_long (addr) ^ fgpen);
                   1731:                            }
                   1732:                            break;
                   1733:                        }
                   1734:                    }
                   1735:                    break;
                   1736:                }
                   1737:            }
                   1738:        }
                   1739:     }
                   1740: 
                   1741:     if (renderinfo_is_current_screen (&ri))
1.1.1.12  root     1742:        do_blit (&ri, Bpp, X, Y, X, Y, W, H, BLIT_SRC, 0);
1.1       root     1743: 
                   1744:     return 1;
                   1745: }
                   1746: 
                   1747: /*************************************************
                   1748: BlitTemplate:
                   1749: **************************************************
                   1750: * Synopsis: BlitTemplate(bi, ri, template, X, Y, Width, Height, Mask, RGBFormat);
                   1751: * a0: struct BoardInfo *bi
                   1752: * a1: struct RenderInfo *ri
                   1753: * a2: struct Template *template
                   1754: * d0.w: X
                   1755: * d1.w: Y
                   1756: * d2.w: Width
                   1757: * d3.w: Height
                   1758: * d4.w: Mask
                   1759: * d7.l: RGBFormat
                   1760: *
                   1761: * This function is used to paint a template on the board memory using the blitter.
                   1762: * It is called by BltPattern and BltTemplate. The template consists of a b/w image
                   1763: * using a single plane of image data which will be expanded to the destination RGBFormat
                   1764: * using ForeGround and BackGround pens as well as draw modes.
                   1765: ***********************************************************************************/
                   1766: uae_u32 picasso_BlitTemplate (void)
                   1767: {
                   1768:     uae_u8 inversion = 0;
1.1.1.2   root     1769:     uaecptr rinf = m68k_areg (regs, 1);
                   1770:     uaecptr tmpl = m68k_areg (regs, 2);
1.1.1.8   root     1771:     unsigned long X = (uae_u16) m68k_dreg (regs, 0);
                   1772:     unsigned long Y = (uae_u16) m68k_dreg (regs, 1);
                   1773:     unsigned long W = (uae_u16) m68k_dreg (regs, 2);
                   1774:     unsigned long H = (uae_u16) m68k_dreg (regs, 3);
                   1775:     uae_u16 Mask = (uae_u16) m68k_dreg (regs, 4);
1.1       root     1776:     struct Template tmp;
                   1777:     struct RenderInfo ri;
1.1.1.5   root     1778:     unsigned long rows;
1.1       root     1779:     int bitoffset;
1.1.1.2   root     1780:     uae_u32 fgpen;
1.1.1.12  root     1781:     uae_u8 *uae_mem, Bpp;
1.1       root     1782:     uae_u8 *tmpl_base;
                   1783: 
                   1784:     wgfx_flushline ();
                   1785: 
1.1.1.8   root     1786:     if (!CopyRenderInfoStructureA2U (rinf, &ri)
                   1787:        || !CopyTemplateStructureA2U (tmpl, &tmp))
1.1       root     1788:        return 0;
                   1789: 
1.1.1.8   root     1790:     Bpp = GetBytesPerPixel (ri.RGBFormat);
                   1791:     uae_mem = ri.Memory + Y * ri.BytesPerRow + X * Bpp;        /* offset into address */
1.1       root     1792: 
                   1793:     if (tmp.DrawMode & INVERS)
                   1794:        inversion = 1;
                   1795: 
                   1796:     tmp.DrawMode &= 0x03;
                   1797:     if (Mask != 0xFF) {
                   1798:        if (Bpp > 1)
1.1.1.2   root     1799:            write_log ("ERROR - not obeying BlitTemplate() mask 0x%x properly with Bpp %d.\n", Mask, Bpp);
1.1       root     1800:        else if (tmp.DrawMode == COMP) {
1.1.1.2   root     1801:            write_log ("ERROR - Unsupported Mask value 0x%x with COMP Draw in BlitTemplate(), using fallback method.\n", Mask);
1.1       root     1802:            return 0;
                   1803:        }
                   1804:     }
                   1805: 
1.1.1.13! root     1806:     P96TRACE (("BlitTemplate() xy(%d,%d), wh(%d,%d) draw 0x%x fg 0x%x bg 0x%x \n",
        !          1807:               X, Y, W, H, tmp.DrawMode, tmp.FgPen, tmp.BgPen));
1.1       root     1808: 
                   1809:     bitoffset = tmp.XOffset % 8;
                   1810: 
                   1811: #ifdef _DEBUG
1.1.1.8   root     1812:     DumpTemplate (&tmp, W, H);
1.1       root     1813: #endif
                   1814: 
1.1.1.8   root     1815:     tmpl_base = tmp.Memory + tmp.XOffset / 8;
1.1       root     1816: 
                   1817:     for (rows = 0; rows < H; rows++, uae_mem += ri.BytesPerRow, tmpl_base += tmp.BytesPerRow) {
1.1.1.5   root     1818:        unsigned long cols;
1.1       root     1819:        uae_u8 *tmpl_mem = tmpl_base;
                   1820:        uae_u8 *uae_mem2 = uae_mem;
                   1821:        unsigned int data = *tmpl_mem;
                   1822: 
                   1823:        for (cols = 0; cols < W; cols += 8, uae_mem2 += Bpp << 3) {
                   1824:            unsigned int byte;
                   1825:            long bits;
                   1826:            long max = W - cols;
                   1827: 
                   1828:            if (max > 8)
                   1829:                max = 8;
                   1830: 
                   1831:            data <<= 8;
                   1832:            data |= *++tmpl_mem;
                   1833: 
                   1834:            byte = data >> (8 - bitoffset);
                   1835: 
                   1836:            for (bits = 0; bits < max; bits++) {
                   1837:                int bit_set = (byte & 0x80);
                   1838:                byte <<= 1;
                   1839:                switch (tmp.DrawMode) {
1.1.1.8   root     1840:                case JAM1:
1.1       root     1841:                    if (inversion)
                   1842:                        bit_set = !bit_set;
                   1843:                    if (bit_set) {
                   1844:                        fgpen = tmp.FgPen;
1.1.1.8   root     1845:                        PixelWrite (uae_mem2, bits, fgpen, Bpp, Mask);
1.1       root     1846:                    }
                   1847:                    break;
1.1.1.8   root     1848:                case JAM2:
1.1       root     1849:                    if (inversion)
                   1850:                        bit_set = !bit_set;
                   1851:                    fgpen = tmp.BgPen;
                   1852:                    if (bit_set)
                   1853:                        fgpen = tmp.FgPen;
                   1854: 
1.1.1.8   root     1855:                    PixelWrite (uae_mem2, bits, fgpen, Bpp, Mask);
1.1       root     1856:                    break;
1.1.1.8   root     1857:                case COMP:
1.1       root     1858:                    if (bit_set) {
                   1859:                        fgpen = tmp.FgPen;
                   1860: 
                   1861:                        switch (Bpp) {
1.1.1.8   root     1862:                        case 1:
1.1       root     1863:                            {
                   1864:                                uae_u8 *addr = uae_mem2 + bits;
                   1865:                                do_put_mem_byte (addr, do_get_mem_byte (addr) ^ fgpen);
                   1866:                            }
                   1867:                            break;
1.1.1.8   root     1868:                        case 2:
1.1       root     1869:                            {
1.1.1.8   root     1870:                                uae_u16 *addr = ((uae_u16 *) uae_mem2) + bits;
1.1       root     1871:                                do_put_mem_word (addr, do_get_mem_word (addr) ^ fgpen);
                   1872:                            }
                   1873:                            break;
1.1.1.8   root     1874:                        case 3:
1.1       root     1875:                            {
1.1.1.8   root     1876:                                uae_u32 *addr = (uae_u32 *) (uae_mem2 + bits * 3);
1.1       root     1877:                                do_put_mem_long (addr, do_get_mem_long (addr) ^ (fgpen & 0x00FFFFFF));
                   1878:                            }
                   1879:                            break;
1.1.1.8   root     1880:                        case 4:
1.1       root     1881:                            {
1.1.1.8   root     1882:                                uae_u32 *addr = ((uae_u32 *) uae_mem2) + bits;
1.1       root     1883:                                do_put_mem_long (addr, do_get_mem_long (addr) ^ fgpen);
                   1884:                            }
                   1885:                            break;
                   1886:                        }
                   1887:                    }
                   1888:                    break;
                   1889:                }
                   1890:            }
                   1891:        }
                   1892:     }
                   1893: 
                   1894:     if (renderinfo_is_current_screen (&ri))
1.1.1.12  root     1895:        do_blit (&ri, Bpp, X, Y, X, Y, W, H, BLIT_SRC, 0);
1.1       root     1896: 
                   1897:     return 1;
                   1898: }
                   1899: 
                   1900: /*
                   1901:  * CalculateBytesPerRow:
                   1902:  * a0:         struct BoardInfo
                   1903:  * d0:         uae_u16 Width
                   1904:  * d7: RGBFTYPE RGBFormat
                   1905:  * This function calculates the amount of bytes needed for a line of
                   1906:  * "Width" pixels in the given RGBFormat.
                   1907:  */
                   1908: uae_u32 picasso_CalculateBytesPerRow (void)
                   1909: {
1.1.1.2   root     1910:     uae_u16 width = m68k_dreg (regs, 0);
                   1911:     uae_u32 type = m68k_dreg (regs, 7);
1.1       root     1912: 
1.1.1.8   root     1913:     width = GetBytesPerPixel (type) * width;
1.1.1.13! root     1914:     P96TRACE  (("CalculateBytesPerRow() = %d\n", width)); 
1.1       root     1915: 
                   1916:     return width;
                   1917: }
                   1918: 
                   1919: /*
                   1920:  * SetDisplay:
                   1921:  * a0: struct BoardInfo
                   1922:  * d0: BOOL state
                   1923:  * This function enables and disables the video display.
                   1924:  * 
                   1925:  * NOTE: return the opposite of the state
                   1926:  */
                   1927: uae_u32 picasso_SetDisplay (void)
                   1928: {
1.1.1.2   root     1929:     uae_u32 state = m68k_dreg (regs, 0);
1.1.1.13! root     1930:     P96TRACE (("SetDisplay(%d)\n", state));
1.1       root     1931:     return !state;
                   1932: }
                   1933: 
                   1934: /*
                   1935:  * WaitVerticalSync:
                   1936:  * a0: struct BoardInfo
                   1937:  * This function waits for the next horizontal retrace.
                   1938:  */
                   1939: uae_u32 picasso_WaitVerticalSync (void)
                   1940: {
1.1.1.8   root     1941:     /*write_log ("WaitVerticalSync()\n"); */
1.1       root     1942:     return 1;
                   1943: }
                   1944: 
                   1945: /* NOTE: Watch for those planeptrs of 0x00000000 and 0xFFFFFFFF for all zero / all one bitmaps !!!! */
1.1.1.8   root     1946: static void PlanarToChunky (struct RenderInfo *ri, struct BitMap *bm,
                   1947:                            unsigned long srcx, unsigned long srcy,
                   1948:                            unsigned long dstx, unsigned long dsty, unsigned long width, unsigned long height, uae_u8 mask)
1.1       root     1949: {
1.1.1.2   root     1950:     int j;
1.1       root     1951: 
1.1.1.8   root     1952:     uae_u8 *PLANAR[8], *image = ri->Memory + dstx * GetBytesPerPixel (ri->RGBFormat) + dsty * ri->BytesPerRow;
1.1       root     1953:     int Depth = bm->Depth;
1.1.1.5   root     1954:     unsigned long rows, bitoffset = srcx & 7;
1.1       root     1955:     long eol_offset;
                   1956: 
                   1957:     /* if (mask != 0xFF) 
1.1.1.8   root     1958:        write_log ("P2C - pixel-width = %d, bit-offset = %d\n", width, bitoffset); */
1.1.1.5   root     1959: 
1.1       root     1960:     /* Set up our bm->Planes[] pointers to the right horizontal offset */
                   1961:     for (j = 0; j < Depth; j++) {
                   1962:        uae_u8 *p = bm->Planes[j];
                   1963:        if (p != &all_zeros_bitmap && p != &all_ones_bitmap)
1.1.1.8   root     1964:            p += srcx / 8 + srcy * bm->BytesPerRow;
1.1       root     1965:        PLANAR[j] = p;
                   1966:        if ((mask & (1 << j)) == 0)
                   1967:            PLANAR[j] = &all_zeros_bitmap;
                   1968:     }
1.1.1.8   root     1969:     eol_offset = (long) bm->BytesPerRow - (long) ((width + 7) >> 3);
1.1       root     1970:     for (rows = 0; rows < height; rows++, image += ri->BytesPerRow) {
1.1.1.5   root     1971:        unsigned long cols;
1.1       root     1972: 
                   1973:        for (cols = 0; cols < width; cols += 8) {
                   1974:            int k;
                   1975:            uae_u32 a = 0, b = 0;
                   1976:            unsigned int msk = 0xFF;
                   1977:            long tmp = cols + 8 - width;
                   1978:            if (tmp > 0) {
                   1979:                msk <<= tmp;
1.1.1.8   root     1980:                b = do_get_mem_long ((uae_u32 *) (image + cols + 4));
1.1       root     1981:                if (tmp < 4)
                   1982:                    b &= 0xFFFFFFFF >> (32 - tmp * 8);
                   1983:                else if (tmp > 4) {
1.1.1.8   root     1984:                    a = do_get_mem_long ((uae_u32 *) (image + cols));
1.1       root     1985:                    a &= 0xFFFFFFFF >> (64 - tmp * 8);
                   1986:                }
                   1987:            }
                   1988:            for (k = 0; k < Depth; k++) {
                   1989:                unsigned int data;
                   1990:                if (PLANAR[k] == &all_zeros_bitmap)
                   1991:                    data = 0;
                   1992:                else if (PLANAR[k] == &all_ones_bitmap)
                   1993:                    data = 0xFF;
                   1994:                else {
1.1.1.8   root     1995:                    data = (uae_u8) (do_get_mem_word ((uae_u16 *) PLANAR[k]) >> (8 - bitoffset));
1.1       root     1996:                    PLANAR[k]++;
                   1997:                }
                   1998:                data &= msk;
                   1999:                a |= p2ctab[data][0] << k;
                   2000:                b |= p2ctab[data][1] << k;
                   2001:            }
1.1.1.8   root     2002:            do_put_mem_long ((uae_u32 *) (image + cols), a);
                   2003:            do_put_mem_long ((uae_u32 *) (image + cols + 4), b);
1.1       root     2004:        }
                   2005:        for (j = 0; j < Depth; j++) {
                   2006:            if (PLANAR[j] != &all_zeros_bitmap && PLANAR[j] != &all_ones_bitmap) {
                   2007:                PLANAR[j] += eol_offset;
                   2008:            }
                   2009:        }
                   2010:     }
                   2011: }
                   2012: 
                   2013: /*
                   2014:  * BlitPlanar2Chunky:
                   2015:  * a0: struct BoardInfo *bi
                   2016:  * a1: struct BitMap *bm - source containing planar information and assorted details
                   2017:  * a2: struct RenderInfo *ri - dest area and its details
                   2018:  * d0.w: SrcX
                   2019:  * d1.w: SrcY
                   2020:  * d2.w: DstX
                   2021:  * d3.w: DstY
                   2022:  * d4.w: SizeX
                   2023:  * d5.w: SizeY
                   2024:  * d6.b: MinTerm - uh oh!
                   2025:  * d7.b: Mask - uh oh!
                   2026:  *
                   2027:  * This function is currently used to blit from planar bitmaps within system memory to chunky bitmaps
                   2028:  * on the board. Watch out for plane pointers that are 0x00000000 (represents a plane with all bits "0")
                   2029:  * or 0xffffffff (represents a plane with all bits "1").
                   2030:  */
                   2031: uae_u32 picasso_BlitPlanar2Chunky (void)
                   2032: {
1.1.1.2   root     2033:     uaecptr bm = m68k_areg (regs, 1);
                   2034:     uaecptr ri = m68k_areg (regs, 2);
1.1.1.8   root     2035:     unsigned long srcx = (uae_u16) m68k_dreg (regs, 0);
                   2036:     unsigned long srcy = (uae_u16) m68k_dreg (regs, 1);
                   2037:     unsigned long dstx = (uae_u16) m68k_dreg (regs, 2);
                   2038:     unsigned long dsty = (uae_u16) m68k_dreg (regs, 3);
                   2039:     unsigned long width = (uae_u16) m68k_dreg (regs, 4);
                   2040:     unsigned long height = (uae_u16) m68k_dreg (regs, 5);
1.1.1.2   root     2041:     uae_u8 minterm = m68k_dreg (regs, 6) & 0xFF;
                   2042:     uae_u8 mask = m68k_dreg (regs, 7) & 0xFF;
1.1       root     2043:     struct RenderInfo local_ri;
                   2044:     struct BitMap local_bm;
                   2045: 
                   2046:     wgfx_flushline ();
                   2047: 
                   2048:     if (minterm != 0x0C) {
1.1.1.8   root     2049:        write_log ("ERROR - BlitPlanar2Chunky() has minterm 0x%x, which I don't handle. Using fall-back routine.\n", minterm);
1.1       root     2050:        return 0;
                   2051:     }
1.1.1.8   root     2052:     if (!CopyRenderInfoStructureA2U (ri, &local_ri)
                   2053:        || !CopyBitMapStructureA2U (bm, &local_bm))
1.1       root     2054:        return 0;
                   2055: 
1.1.1.13! root     2056:     P96TRACE (("BlitPlanar2Chunky(%d, %d, %d, %d, %d, %d) Minterm 0x%x, Mask 0x%x, Depth %d\n",
        !          2057:               srcx, srcy, dstx, dsty, width, height, minterm, mask, local_bm.Depth));
        !          2058:     P96TRACE (("P2C - BitMap has %d BPR, %d rows\n", local_bm.BytesPerRow, local_bm.Rows));
1.1.1.2   root     2059:     PlanarToChunky (&local_ri, &local_bm, srcx, srcy, dstx, dsty, width, height, mask);
1.1       root     2060:     if (renderinfo_is_current_screen (&local_ri))
1.1.1.12  root     2061:        do_blit (&local_ri, GetBytesPerPixel (local_ri.RGBFormat), dstx, dsty, dstx, dsty, width, height, BLIT_SRC, 0);
1.1       root     2062: 
1.1.1.4   root     2063:     return 1;
1.1       root     2064: }
                   2065: 
1.1.1.8   root     2066: static void PlanarToDirect (struct RenderInfo *ri, struct BitMap *bm,
                   2067:                            unsigned long srcx, unsigned long srcy,
                   2068:                            unsigned long dstx, unsigned long dsty,
                   2069:                            unsigned long width, unsigned long height, uae_u8 mask, struct ColorIndexMapping *cim)
1.1       root     2070: {
                   2071:     int j;
1.1.1.8   root     2072:     int bpp = GetBytesPerPixel (ri->RGBFormat);
1.1       root     2073:     uae_u8 *PLANAR[8];
                   2074:     uae_u8 *image = ri->Memory + dstx * bpp + dsty * ri->BytesPerRow;
                   2075:     int Depth = bm->Depth;
1.1.1.5   root     2076:     unsigned long rows;
1.1       root     2077:     long eol_offset;
                   2078: 
                   2079:     /* Set up our bm->Planes[] pointers to the right horizontal offset */
                   2080:     for (j = 0; j < Depth; j++) {
                   2081:        uae_u8 *p = bm->Planes[j];
                   2082:        if (p != &all_zeros_bitmap && p != &all_ones_bitmap)
1.1.1.8   root     2083:            p += srcx / 8 + srcy * bm->BytesPerRow;
1.1       root     2084:        PLANAR[j] = p;
                   2085:        if ((mask & (1 << j)) == 0)
                   2086:            PLANAR[j] = &all_zeros_bitmap;
                   2087:     }
                   2088: 
1.1.1.8   root     2089:     eol_offset = (long) bm->BytesPerRow - (long) ((width + (srcx & 7)) >> 3);
1.1       root     2090:     for (rows = 0; rows < height; rows++, image += ri->BytesPerRow) {
1.1.1.5   root     2091:        unsigned long cols;
1.1       root     2092:        uae_u8 *image2 = image;
                   2093:        unsigned int bitoffs = 7 - (srcx & 7);
                   2094:        int i;
                   2095: 
1.1.1.8   root     2096:        for (cols = 0; cols < width; cols++) {
1.1       root     2097:            int v = 0, k;
                   2098:            for (k = 0; k < Depth; k++) {
                   2099:                if (PLANAR[k] == &all_ones_bitmap)
                   2100:                    v |= 1 << k;
                   2101:                else if (PLANAR[k] != &all_zeros_bitmap) {
                   2102:                    v |= ((*PLANAR[k] >> bitoffs) & 1) << k;
                   2103:                }
                   2104:            }
                   2105: 
                   2106:            switch (bpp) {
1.1.1.8   root     2107:            case 2:
                   2108:                do_put_mem_word ((uae_u16 *) image2, cim->Colors[v]);
1.1       root     2109:                image2 += 2;
                   2110:                break;
1.1.1.8   root     2111:            case 3:
1.1       root     2112:                do_put_mem_byte (image2++, cim->Colors[v] & 0x000000FF);
1.1.1.8   root     2113:                do_put_mem_word ((uae_u16 *) image2, (cim->Colors[v] & 0x00FFFF00) >> 8);
1.1       root     2114:                image2 += 2;
                   2115:                break;
1.1.1.8   root     2116:            case 4:
                   2117:                do_put_mem_long ((uae_u32 *) image2, cim->Colors[v]);
1.1       root     2118:                image2 += 4;
                   2119:                break;
                   2120:            }
                   2121:            bitoffs--;
                   2122:            bitoffs &= 7;
                   2123:            if (bitoffs == 7) {
                   2124:                int k;
                   2125:                for (k = 0; k < Depth; k++) {
                   2126:                    if (PLANAR[k] != &all_zeros_bitmap && PLANAR[k] != &all_ones_bitmap) {
                   2127:                        PLANAR[k]++;
                   2128:                    }
                   2129:                }
                   2130:            }
                   2131:        }
                   2132: 
                   2133:        for (i = 0; i < Depth; i++) {
                   2134:            if (PLANAR[i] != &all_zeros_bitmap && PLANAR[i] != &all_ones_bitmap) {
                   2135:                PLANAR[i] += eol_offset;
                   2136:            }
                   2137:        }
                   2138:     }
                   2139: }
                   2140: 
                   2141: /*
                   2142:  * BlitPlanar2Direct: 
                   2143:  * 
                   2144:  * Synopsis:
                   2145:  * BlitPlanar2Direct(bi, bm, ri, cim, SrcX, SrcY, DstX, DstY, SizeX, SizeY, MinTerm, Mask);
                   2146:  * Inputs:
                   2147:  * a0:struct BoardInfo *bi
                   2148:  * a1:struct BitMap *bm
                   2149:  * a2:struct RenderInfo *ri
                   2150:  * a3:struct ColorIndexMapping *cmi
                   2151:  * d0.w:SrcX
                   2152:  * d1.w:SrcY
                   2153:  * d2.w:DstX
                   2154:  * d3.w:DstY
                   2155:  * d4.w:SizeX
                   2156:  * d5.w:SizeY
                   2157:  * d6.b:MinTerm
                   2158:  * d7.b:Mask
                   2159:  * 
                   2160:  * This function is currently used to blit from planar bitmaps within system memory to direct color
                   2161:  * bitmaps (15, 16, 24 or 32 bit) on the board. Watch out for plane pointers that are 0x00000000 (represents
                   2162:  * a plane with all bits "0") or 0xffffffff (represents a plane with all bits "1"). The ColorIndexMapping is
                   2163:  * used to map the color index of each pixel formed by the bits in the bitmap's planes to a direct color value
                   2164:  * which is written to the destination RenderInfo. The color mask and all colors within the mapping are words,
                   2165:  * triple bytes or longwords respectively similar to the color values used in FillRect(), BlitPattern() or
                   2166:  * BlitTemplate(). 
                   2167:  */
                   2168: uae_u32 picasso_BlitPlanar2Direct (void)
                   2169: {
1.1.1.2   root     2170:     uaecptr bm = m68k_areg (regs, 1);
                   2171:     uaecptr ri = m68k_areg (regs, 2);
                   2172:     uaecptr cim = m68k_areg (regs, 3);
1.1.1.8   root     2173:     unsigned long srcx = (uae_u16) m68k_dreg (regs, 0);
                   2174:     unsigned long srcy = (uae_u16) m68k_dreg (regs, 1);
                   2175:     unsigned long dstx = (uae_u16) m68k_dreg (regs, 2);
                   2176:     unsigned long dsty = (uae_u16) m68k_dreg (regs, 3);
                   2177:     unsigned long width = (uae_u16) m68k_dreg (regs, 4);
                   2178:     unsigned long height = (uae_u16) m68k_dreg (regs, 5);
1.1.1.2   root     2179:     uae_u8 minterm = m68k_dreg (regs, 6);
                   2180:     uae_u8 Mask = m68k_dreg (regs, 7);
1.1       root     2181:     struct RenderInfo local_ri;
                   2182:     struct BitMap local_bm;
                   2183:     struct ColorIndexMapping local_cim;
                   2184: 
                   2185:     wgfx_flushline ();
                   2186: 
                   2187:     if (minterm != 0x0C) {
1.1.1.8   root     2188:        write_log ("ERROR - BlitPlanar2Direct() has op-code 0x%x, which I don't handle. Using fall-back routine.\n", minterm);
1.1       root     2189:        return 0;
                   2190:     }
                   2191:     if (Mask != 0xFF) {
1.1.1.2   root     2192:        write_log ("ERROR - Unsupported Mask value 0x%x in BlitPlanar2Direct(), using fallback method.\n", Mask);
1.1       root     2193:        return 0;
                   2194:     }
1.1.1.8   root     2195:     if (!CopyRenderInfoStructureA2U (ri, &local_ri)
                   2196:        || !CopyBitMapStructureA2U (bm, &local_bm))
1.1       root     2197:        return 0;
                   2198: 
                   2199:     CopyColorIndexMappingA2U (cim, &local_cim);
1.1.1.13! root     2200:     P96TRACE (("BlitPlanar2Direct(%d, %d, %d, %d, %d, %d) Minterm 0x%x, Mask 0x%x, Depth %d\n",
        !          2201:        srcx, srcy, dstx, dsty, width, height, minterm, Mask, local_bm.Depth));
1.1.1.2   root     2202:     PlanarToDirect (&local_ri, &local_bm, srcx, srcy, dstx, dsty, width, height, Mask, &local_cim);
1.1       root     2203:     if (renderinfo_is_current_screen (&local_ri))
1.1.1.12  root     2204:        do_blit (&local_ri, GetBytesPerPixel (local_ri.RGBFormat), dstx, dsty, dstx, dsty, width, height, BLIT_SRC, 0);
1.1       root     2205:     return 1;
                   2206: }
                   2207: 
                   2208: /* @@@ - Work to be done here!
                   2209:  *
                   2210:  * The address is the offset into our Picasso96 frame-buffer (pointed to by gfxmem_start)
                   2211:  * where the value was put.
                   2212:  *
                   2213:  * Porting work: on some machines you may not need these functions, ie. if the memory for the
                   2214:  * Picasso96 frame-buffer is directly viewable or directly blittable.  On Win32 with DirectX,
                   2215:  * this is not the case.  So I provide some write-through functions (as per Mathias' orders!)
                   2216:  */
                   2217: static void write_gfx_long (uaecptr addr, uae_u32 value)
                   2218: {
                   2219:     uaecptr oldaddr = addr;
                   2220:     int x, xbytes, y;
                   2221:     uae_u8 *dst;
                   2222: 
                   2223:     if (!picasso_on)
                   2224:        return;
                   2225: 
                   2226:     /*
                   2227:      * Several writes to successive memory locations are a common access pattern.
                   2228:      * Try to optimize it.
                   2229:      */
                   2230:     if (addr >= wgfx_linestart && addr + 4 <= wgfx_lineend) {
                   2231:        if (addr < wgfx_min)
                   2232:            wgfx_min = addr;
                   2233:        if (addr + 4 > wgfx_max)
                   2234:            wgfx_max = addr + 4;
                   2235:        return;
                   2236:     } else
                   2237:        wgfx_flushline ();
                   2238: 
                   2239:     addr += gfxmem_start;
                   2240:     /* Check to see if this needs to be written through to the display, or was it an "offscreen" area? */
                   2241:     if (addr < picasso96_state.Address || addr + 4 > picasso96_state.Extent)
                   2242:        return;
                   2243: 
                   2244:     addr -= picasso96_state.Address;
                   2245:     y = addr / picasso96_state.BytesPerRow;
                   2246: 
1.1.1.12  root     2247:     if (y >= picasso96_state.VirtualHeight)
1.1       root     2248:        return;
                   2249:     wgfx_linestart = picasso96_state.Address - gfxmem_start + y * picasso96_state.BytesPerRow;
                   2250:     wgfx_lineend = wgfx_linestart + picasso96_state.BytesPerRow;
                   2251:     wgfx_y = y;
                   2252:     wgfx_min = oldaddr;
                   2253:     wgfx_max = oldaddr + 4;
                   2254: }
                   2255: 
                   2256: static void write_gfx_word (uaecptr addr, uae_u16 value)
                   2257: {
                   2258:     uaecptr oldaddr = addr;
                   2259:     int x, xbytes, y;
                   2260:     uae_u8 *dst;
                   2261: 
                   2262:     if (!picasso_on)
                   2263:        return;
                   2264: 
                   2265:     /*
                   2266:      * Several writes to successive memory locations are a common access pattern.
                   2267:      * Try to optimize it.
                   2268:      */
                   2269:     if (addr >= wgfx_linestart && addr + 2 <= wgfx_lineend) {
                   2270:        if (addr < wgfx_min)
                   2271:            wgfx_min = addr;
                   2272:        if (addr + 2 > wgfx_max)
                   2273:            wgfx_max = addr + 2;
                   2274:        return;
                   2275:     } else
                   2276:        wgfx_flushline ();
                   2277: 
                   2278:     addr += gfxmem_start;
                   2279:     /* Check to see if this needs to be written through to the display, or was it an "offscreen" area? */
                   2280:     if (addr < picasso96_state.Address || addr + 2 > picasso96_state.Extent)
                   2281:        return;
                   2282: 
                   2283:     addr -= picasso96_state.Address;
                   2284:     y = addr / picasso96_state.BytesPerRow;
                   2285: 
1.1.1.12  root     2286:     if (y >= picasso96_state.VirtualHeight)
1.1       root     2287:        return;
                   2288:     wgfx_linestart = picasso96_state.Address - gfxmem_start + y * picasso96_state.BytesPerRow;
                   2289:     wgfx_lineend = wgfx_linestart + picasso96_state.BytesPerRow;
                   2290:     wgfx_y = y;
                   2291:     wgfx_min = oldaddr;
                   2292:     wgfx_max = oldaddr + 2;
                   2293: }
                   2294: 
                   2295: static void write_gfx_byte (uaecptr addr, uae_u8 value)
                   2296: {
                   2297:     uaecptr oldaddr = addr;
                   2298:     int x, xbytes, y;
                   2299:     uae_u8 *dst;
                   2300: 
                   2301:     if (!picasso_on)
                   2302:        return;
                   2303: 
                   2304:     /*
                   2305:      * Several writes to successive memory locations are a common access pattern.
                   2306:      * Try to optimize it.
                   2307:      */
                   2308:     if (addr >= wgfx_linestart && addr + 4 <= wgfx_lineend) {
                   2309:        if (addr < wgfx_min)
                   2310:            wgfx_min = addr;
                   2311:        if (addr + 1 > wgfx_max)
                   2312:            wgfx_max = addr + 1;
                   2313:        return;
                   2314:     } else
                   2315:        wgfx_flushline ();
                   2316: 
                   2317:     addr += gfxmem_start;
                   2318:     /* Check to see if this needs to be written through to the display, or was it an "offscreen" area? */
                   2319:     if (addr < picasso96_state.Address || addr + 1 > picasso96_state.Extent)
                   2320:        return;
                   2321: 
                   2322:     addr -= picasso96_state.Address;
                   2323:     y = addr / picasso96_state.BytesPerRow;
                   2324: 
1.1.1.12  root     2325:     if (y >= picasso96_state.VirtualHeight)
1.1       root     2326:        return;
                   2327:     wgfx_linestart = picasso96_state.Address - gfxmem_start + y * picasso96_state.BytesPerRow;
                   2328:     wgfx_lineend = wgfx_linestart + picasso96_state.BytesPerRow;
                   2329:     wgfx_y = y;
                   2330:     wgfx_min = oldaddr;
                   2331:     wgfx_max = oldaddr + 1;
                   2332: }
                   2333: 
                   2334: static uae_u32 REGPARAM2 gfxmem_lget (uaecptr addr)
                   2335: {
                   2336:     uae_u32 *m;
                   2337:     addr -= gfxmem_start & gfxmem_mask;
                   2338:     addr &= gfxmem_mask;
1.1.1.8   root     2339:     m = (uae_u32 *) (gfxmemory + addr);
                   2340:     return do_get_mem_long (m);
1.1       root     2341: }
                   2342: 
                   2343: static uae_u32 REGPARAM2 gfxmem_wget (uaecptr addr)
                   2344: {
                   2345:     uae_u16 *m;
                   2346:     addr -= gfxmem_start & gfxmem_mask;
                   2347:     addr &= gfxmem_mask;
1.1.1.8   root     2348:     m = (uae_u16 *) (gfxmemory + addr);
                   2349:     return do_get_mem_word (m);
1.1       root     2350: }
                   2351: 
                   2352: static uae_u32 REGPARAM2 gfxmem_bget (uaecptr addr)
                   2353: {
                   2354:     addr -= gfxmem_start & gfxmem_mask;
                   2355:     addr &= gfxmem_mask;
                   2356:     return gfxmemory[addr];
                   2357: }
                   2358: 
                   2359: static void REGPARAM2 gfxmem_lput (uaecptr addr, uae_u32 l)
                   2360: {
                   2361:     uae_u32 *m;
                   2362:     addr -= gfxmem_start & gfxmem_mask;
                   2363:     addr &= gfxmem_mask;
1.1.1.8   root     2364:     m = (uae_u32 *) (gfxmemory + addr);
                   2365:     do_put_mem_long (m, l);
1.1       root     2366: 
                   2367:     /* write the long-word to our displayable memory */
1.1.1.8   root     2368:     write_gfx_long (addr, l);
1.1       root     2369: }
                   2370: 
                   2371: static void REGPARAM2 gfxmem_wput (uaecptr addr, uae_u32 w)
                   2372: {
                   2373:     uae_u16 *m;
                   2374:     addr -= gfxmem_start & gfxmem_mask;
                   2375:     addr &= gfxmem_mask;
1.1.1.8   root     2376:     m = (uae_u16 *) (gfxmemory + addr);
                   2377:     do_put_mem_word (m, (uae_u16) w);
1.1       root     2378: 
                   2379:     /* write the word to our displayable memory */
1.1.1.8   root     2380:     write_gfx_word (addr, (uae_u16) w);
1.1       root     2381: }
                   2382: 
                   2383: static void REGPARAM2 gfxmem_bput (uaecptr addr, uae_u32 b)
                   2384: {
                   2385:     addr -= gfxmem_start & gfxmem_mask;
                   2386:     addr &= gfxmem_mask;
                   2387:     gfxmemory[addr] = b;
                   2388: 
                   2389:     /* write the byte to our displayable memory */
1.1.1.8   root     2390:     write_gfx_byte (addr, (uae_u8) b);
1.1       root     2391: }
                   2392: 
                   2393: static int REGPARAM2 gfxmem_check (uaecptr addr, uae_u32 size)
                   2394: {
                   2395:     addr -= gfxmem_start & gfxmem_mask;
                   2396:     addr &= gfxmem_mask;
1.1.1.2   root     2397:     return (addr + size) < allocated_gfxmem;
1.1       root     2398: }
                   2399: 
                   2400: static uae_u8 REGPARAM2 *gfxmem_xlate (uaecptr addr)
                   2401: {
                   2402:     addr -= gfxmem_start & gfxmem_mask;
                   2403:     addr &= gfxmem_mask;
                   2404:     return gfxmemory + addr;
                   2405: }
                   2406: 
                   2407: addrbank gfxmem_bank = {
                   2408:     gfxmem_lget, gfxmem_wget, gfxmem_bget,
                   2409:     gfxmem_lput, gfxmem_wput, gfxmem_bput,
1.1.1.10  root     2410:     gfxmem_xlate, gfxmem_check, NULL
1.1       root     2411: };
                   2412: 
1.1.1.11  root     2413: int picasso_display_mode_index (uae_u32 x, uae_u32 y, uae_u32 d)
                   2414: {
                   2415:     int i;
                   2416:     for (i = 0; i < mode_count; i++) {
                   2417:         if (DisplayModes[i].res.width == x
                   2418:            && DisplayModes[i].res.height == y
                   2419:            && DisplayModes[i].depth == d)
                   2420:             break;
                   2421:     }
                   2422:     if (i == mode_count)
                   2423:         i = -1;
                   2424:     return i;
                   2425: }
                   2426: 
1.1       root     2427: static int resolution_compare (const void *a, const void *b)
                   2428: {
1.1.1.8   root     2429:     struct PicassoResolution *ma = (struct PicassoResolution *) a;
                   2430:     struct PicassoResolution *mb = (struct PicassoResolution *) b;
1.1       root     2431:     if (ma->res.width > mb->res.width)
                   2432:        return -1;
                   2433:     if (ma->res.width < mb->res.width)
                   2434:        return 1;
                   2435:     if (ma->res.height > mb->res.height)
                   2436:        return -1;
                   2437:     if (ma->res.height < mb->res.height)
                   2438:        return 1;
                   2439:     return ma->depth - mb->depth;
                   2440: }
1.1.1.8   root     2441: 
1.1       root     2442: /* Call this function first, near the beginning of code flow
                   2443:  * NOTE: Don't stuff it in InitGraphics() which seems reasonable...
                   2444:  * Instead, put it in customreset() for safe-keeping.  */
                   2445: void InitPicasso96 (void)
                   2446: {
                   2447:     static int first_time = 1;
                   2448: 
1.1.1.8   root     2449:     memset (&picasso96_state, 0, sizeof (struct picasso96_state_struct));
1.1.1.2   root     2450: 
1.1       root     2451:     if (first_time) {
                   2452:        int i;
                   2453: 
                   2454:        for (i = 0; i < 256; i++) {
                   2455:            p2ctab[i][0] = (((i & 128) ? 0x01000000 : 0)
                   2456:                            | ((i & 64) ? 0x010000 : 0)
                   2457:                            | ((i & 32) ? 0x0100 : 0)
                   2458:                            | ((i & 16) ? 0x01 : 0));
                   2459:            p2ctab[i][1] = (((i & 8) ? 0x01000000 : 0)
                   2460:                            | ((i & 4) ? 0x010000 : 0)
                   2461:                            | ((i & 2) ? 0x0100 : 0)
                   2462:                            | ((i & 1) ? 0x01 : 0));
                   2463:        }
                   2464:        mode_count = DX_FillResolutions (&picasso96_pixel_format);
1.1.1.8   root     2465:        qsort (DisplayModes, mode_count, sizeof (struct PicassoResolution), resolution_compare);
1.1       root     2466: 
                   2467:        for (i = 0; i < mode_count; i++) {
1.1.1.8   root     2468:            sprintf (DisplayModes[i].name, "%dx%d, %d-bit, %d Hz",
                   2469:                     DisplayModes[i].res.width, DisplayModes[i].res.height, DisplayModes[i].depth * 8, DisplayModes[i].refresh);
1.1       root     2470:            switch (DisplayModes[i].depth) {
1.1.1.8   root     2471:            case 1:
1.1       root     2472:                if (DisplayModes[i].res.width > chunky.width)
                   2473:                    chunky.width = DisplayModes[i].res.width;
                   2474:                if (DisplayModes[i].res.height > chunky.height)
                   2475:                    chunky.height = DisplayModes[i].res.height;
                   2476:                break;
1.1.1.8   root     2477:            case 2:
1.1       root     2478:                if (DisplayModes[i].res.width > hicolour.width)
                   2479:                    hicolour.width = DisplayModes[i].res.width;
                   2480:                if (DisplayModes[i].res.height > hicolour.height)
                   2481:                    hicolour.height = DisplayModes[i].res.height;
                   2482:                break;
1.1.1.8   root     2483:            case 3:
1.1       root     2484:                if (DisplayModes[i].res.width > truecolour.width)
                   2485:                    truecolour.width = DisplayModes[i].res.width;
                   2486:                if (DisplayModes[i].res.height > truecolour.height)
                   2487:                    truecolour.height = DisplayModes[i].res.height;
                   2488:                break;
1.1.1.8   root     2489:            case 4:
1.1       root     2490:                if (DisplayModes[i].res.width > alphacolour.width)
                   2491:                    alphacolour.width = DisplayModes[i].res.width;
                   2492:                if (DisplayModes[i].res.height > alphacolour.height)
                   2493:                    alphacolour.height = DisplayModes[i].res.height;
                   2494:                break;
                   2495:            }
                   2496:        }
1.1.1.2   root     2497:        ShowSupportedResolutions ();
1.1       root     2498: 
                   2499:        first_time = 0;
                   2500:     }
                   2501: }
                   2502: 
                   2503: #endif

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.