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

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

unix.superglobalmegacorp.com

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