home *** CD-ROM | disk | FTP | other *** search
/ ftp.whtech.com / ftp.whtech.com.7z / ftp.whtech.com / emulators / v9t9 / linux / sources / V9t9 / source / Modules / video_gtk.c < prev    next >
Encoding:
C/C++ Source or Header  |  2006-10-19  |  14.8 KB  |  778 lines

  1.  
  2. /*
  3.  *    Video module for GTK+
  4.  *    
  5.  *    This writes to the GtkDrawingArea inside the v9t9_window
  6.  */
  7. #include <conf.h>
  8.  
  9. #if defined(UNDER_UNIX)
  10. #include <gdk/gdkx.h>
  11. #elif defined(UNDER_WIN32)
  12. #include "winv9t9.h"
  13. #define WIN32_LEAN_AND_MEAN
  14. #include <gdk/win32/gdkwin32.h>
  15. #endif
  16.  
  17. #include <gtk/gtk.h>
  18.  
  19. #include "gtkinterface.h"
  20. #include "gtkcallbacks.h"
  21. #include "gtkloop.h"
  22.  
  23. #include "v9t9_common.h"
  24. #include "video.h"
  25. #include "vdp.h"
  26. #include "memory.h"
  27. #include "9900.h"
  28. #include "v9t9.h"
  29.  
  30. #define _L LOG_VIDEO
  31.  
  32. static GdkColor v9t9_gdk_palette[17];
  33.  
  34. //    GC for each color we'll display...
  35. static GdkGC    *v9t9_gdk_colors[17];
  36.  
  37. //    true if colors 0 and 17 can be changed without redrawing
  38. static gboolean    v9t9_gdk_paletted;
  39.  
  40. //    mapping from TI color (0=bg, 17=fg, others the same)
  41. //    to v9t9_gdk_color[] entry
  42. static gint        cmap[17];
  43.  
  44. static void
  45. video_setpaletteentry(int index, int c)
  46. {
  47.     logger(_L | L_1, "Setting index %d to color %d\n", index, c);
  48.  
  49.     if (v9t9_gdk_paletted) {
  50.         /* !!! */
  51.     } else {
  52.         cmap[index] = c == 0 ? vdpbg : c == 16 ? vdpfg : c;
  53.     }
  54. }
  55.  
  56. static void
  57. video_updatepalette(void)
  58. {
  59.     int         x;
  60.  
  61.     for (x = 1; x < 16; x++)
  62.         video_setpaletteentry(x, x);
  63.     video_setpaletteentry(0, vdpbg);
  64.     video_setpaletteentry(16, vdpfg);
  65. }
  66.  
  67. static vmResult system_gtkvideo_detect(void);
  68. static vmResult system_gtkvideo_init(void);
  69. static vmResult system_gtkvideo_enable(void);
  70. static vmResult system_gtkvideo_disable(void);
  71. static vmResult system_gtkvideo_restart(void);
  72. static vmResult system_gtkvideo_restop(void);
  73. static vmResult system_gtkvideo_term(void);
  74.  
  75.  
  76. static      vmResult
  77. gtkvideo_detect(void)
  78. {
  79.     return system_gtkvideo_detect();
  80. }
  81.  
  82. static      vmResult
  83. gtkvideo_init(void)
  84. {
  85.     int i;
  86.  
  87.     for (i = 1; i < 16; i++)
  88.     {
  89.         v9t9_gdk_palette[i].red = RGB_8_TO_16(vdp_palette[i][0]);
  90.         v9t9_gdk_palette[i].green = RGB_8_TO_16(vdp_palette[i][1]);
  91.         v9t9_gdk_palette[i].blue = RGB_8_TO_16(vdp_palette[i][2]);
  92.     }
  93.  
  94.     features |= FE_SHOWVIDEO;
  95.     my_assert(v9t9_drawing_area);
  96.     return system_gtkvideo_init();
  97. }
  98.  
  99. static      vmResult
  100. gtkvideo_enable(void)
  101. {
  102.     if (VALID_WINDOW(v9t9_window)) {
  103.         gtk_widget_show(v9t9_window);
  104.         return system_gtkvideo_enable();
  105.     } else
  106.         return vmInternalError;
  107. }
  108.  
  109. static      vmResult
  110. gtkvideo_disable(void)
  111. {
  112.     vmResult result;
  113.     if (VALID_WINDOW(v9t9_window)) {
  114.         if ((result = system_gtkvideo_disable()) != vmOk)
  115.             return result;
  116.         gtk_widget_hide(v9t9_window);
  117.         return vmOk;
  118.     } else
  119.         return vmInternalError;
  120. }
  121.  
  122. static      vmResult
  123. gtkvideo_restart(void)
  124. {
  125.     // allocate our colors
  126.     GdkColormap *map;
  127.     int i;
  128.  
  129.     if (!VALID_WINDOW(v9t9_window)) {
  130.         return vmInternalError;
  131.     }
  132.  
  133.     map = gdk_window_get_colormap(v9t9_drawing_area->window);
  134.  
  135.     // we must get the middle colors
  136.     for (i = 1; i <= 15; i++) {
  137.         if (!gdk_colormap_alloc_color(map, 
  138.                                       v9t9_gdk_palette + i, 
  139.                                       false    /* writeable */,   
  140.                                       true    /* best_match */))
  141.         {
  142.             logger(_L|LOG_USER|LOG_ERROR, "Could not allocate 15 colors\n");
  143.             return vmInternalError;
  144.         }
  145.     }
  146.  
  147.     // this appears to work, but shouldn't
  148. #if 0
  149.     // try to get bg and fg palettized
  150.     gdk_colormap_alloc_colors(map,
  151.                               v9t9_gdk_palette,
  152.                               1,
  153.                               true /* writeable */,
  154.                               true /* best_match */,
  155.                               &success);
  156.  
  157.     if (success) {
  158.         gdk_colormap_alloc_colors(map,
  159.                                   v9t9_gdk_palette+16,
  160.                                   1,
  161.                                   true /* writeable */,
  162.                                   true /* best_match */,
  163.                                   &success);
  164.         if (success) {
  165.             v9t9_gdk_paletted = true;
  166.             logger(_L|LOG_USER, "Got writeable colors for bg/fg\n");
  167.         } else {
  168.             v9t9_gdk_paletted = false;
  169.             gdk_colormap_free_colors(map, v9t9_gdk_palette, 1);
  170.         }
  171.     } else 
  172. #endif
  173.     {
  174.         v9t9_gdk_paletted = false;
  175.         logger(_L, "No writeable colors available\n");
  176.     }
  177.  
  178.     for (i = 0; i < 17; i++) {
  179.         logger(_L|L_1, "Color %d is %08X\n", i, v9t9_gdk_palette[i].pixel);
  180.     }
  181.  
  182.     //    Set up the colors in GCs that stay allocated
  183.     for (i = 0; i < 17; i++) {
  184.         v9t9_gdk_colors[i] = gdk_gc_new(v9t9_drawing_area->window);
  185.         gdk_gc_set_foreground(v9t9_gdk_colors[i], v9t9_gdk_palette + i);
  186.     }
  187.  
  188.     return system_gtkvideo_restart();
  189. }
  190.  
  191. static      vmResult
  192. gtkvideo_restop(void)
  193. {
  194.     GdkColormap *map;
  195.     int i;
  196.     vmResult result;
  197.  
  198.     if (!VALID_WINDOW(v9t9_window)) {
  199.         return vmInternalError;
  200.     }
  201.  
  202.     result = system_gtkvideo_restop();
  203.     if (result != vmOk)
  204.         return result;
  205.  
  206.     // free our colors
  207.     for (i = 0; i < 17; i++) {
  208.         gdk_gc_unref(v9t9_gdk_colors[i]);
  209.         v9t9_gdk_colors[i] = 0L;
  210.     }
  211.  
  212.     map = gdk_window_get_colormap(v9t9_drawing_area->window);
  213.     if (v9t9_gdk_paletted) {
  214.         gdk_colormap_free_colors(map, v9t9_gdk_palette, 1);
  215.         gdk_colormap_free_colors(map, v9t9_gdk_palette+16, 1);
  216.     }
  217.     gdk_colormap_free_colors(map, v9t9_gdk_palette+1, 15);
  218.         
  219.     return vmOk;
  220. }
  221.  
  222. static      vmResult
  223. gtkvideo_term(void)
  224. {
  225.     if (!VALID_WINDOW(v9t9_window)) {
  226.         return vmInternalError;
  227.     }
  228.  
  229.     system_gtkvideo_term();
  230.     gtk_widget_unref(v9t9_window);
  231.     v9t9_drawing_area = 0L;
  232.     v9t9_window = 0L;
  233.     return vmOk;
  234. }
  235.  
  236. /**************/
  237. #if 0
  238. #pragma mark -
  239. #pragma mark [ X Windows ]
  240. #endif
  241.  
  242. #if defined(UNDER_UNIX)
  243.  
  244. static      vmResult
  245. system_gtkvideo_detect(void)
  246. {
  247.     return vmOk;
  248. }
  249.  
  250. static      vmResult
  251. system_gtkvideo_init(void)
  252. {
  253.     return vmOk;
  254. }
  255.  
  256. static      vmResult
  257. system_gtkvideo_enable(void)
  258. {
  259.     return vmOk;
  260. }
  261.  
  262. static      vmResult
  263. system_gtkvideo_disable(void)
  264. {
  265.     return vmOk;
  266. }
  267.  
  268. static      vmResult
  269. system_gtkvideo_restart(void)
  270. {
  271.     return vmOk;
  272. }
  273.  
  274. static      vmResult
  275. system_gtkvideo_restop(void)
  276. {
  277.     return vmOk;
  278. }
  279.  
  280. static      vmResult
  281. system_gtkvideo_term(void)
  282. {
  283.     return vmOk;
  284. }
  285.  
  286. /*
  287.  *    Use X11 stuff directly, since it's really fast
  288.  */
  289. static  void
  290. gtk_update_area(struct updateblock *ptr, int num)
  291. {
  292.     int            width = 8;
  293.     u8         *blk;
  294.     XRectangle    points[17][64], *pptr[17];
  295.     int            rects = 0, pixels = 0;
  296.     int            xoffs = (256 - GTK_x_size) / 2;
  297.     int         i;
  298.     int         j;
  299.  
  300.     Display *display;
  301.     Window window;
  302.  
  303.     int total = num, solid = 0;
  304.  
  305.     /*
  306.      * configure/expose callback should have been sent so we can
  307.      * figure out where it is 
  308.      */
  309.  
  310.     display = GDK_WINDOW_XDISPLAY(v9t9_drawing_area->window);
  311.     window = GDK_WINDOW_XWINDOW(v9t9_drawing_area->window);
  312.     my_assert(v9t9_drawing_area);
  313.  
  314.     if (!num)
  315.         return;
  316.  
  317.     while (num--) {
  318.         u8            c = 0;
  319.         int            d;
  320.  
  321.         ptr->r *= GTK_y_mult;
  322.         ptr->c = (ptr->c + xoffs) * GTK_x_mult;
  323.  
  324.         if (video_block_is_solid(ptr, !v9t9_gdk_paletted, &c) &&
  325.             v9t9_gdk_colors[cmap[c]]) {
  326.             XFillRectangle(display, window,
  327.                            GDK_GC_XGC(v9t9_gdk_colors[cmap[c]]), 
  328.                            ptr->c, 
  329.                            ptr->r,
  330.                            GTK_x_mult * width, 
  331.                            GTK_y_mult * 8);
  332.             solid++;
  333.         }
  334.         else
  335.         {
  336.             /* Reset lists for each color (remember text mode has color==16) */
  337.             for (c = 0; c < 17; c++)
  338.                 pptr[c] = points[c];
  339.  
  340.             /* Generate a list of rectangles for each color
  341.                in the 8x8 block */
  342.             for (i = 0; i < 8; i++) {
  343.                 j = 0;
  344.                 while (j < width) {
  345.                     /* Find the longest run of pixels of this color */
  346.                     c = ptr->data[j];
  347.                     d = 1;
  348.                     while (j + d < width && ptr->data[j + d] == c)
  349.                         d++;
  350.  
  351.                     pptr[c]->x = ptr->c + j * GTK_x_mult;
  352.                     pptr[c]->y = ptr->r + i * GTK_y_mult;
  353.                     pptr[c]->width = GTK_x_mult * d;
  354.                     pptr[c]->height = GTK_y_mult;
  355.  
  356.                     rects++;
  357.                     pixels += pptr[c]->width * pptr[c]->height;
  358.  
  359.                     pptr[c]++;
  360.                     j += d;
  361.                 }
  362.                 ptr->data += UPDATEBLOCK_ROW_STRIDE;
  363.             }
  364.  
  365.             for (c = 0; c <= 16; c++) {
  366.                 if (pptr[c] > points[c] && v9t9_gdk_colors[cmap[c]]) {
  367.                     XFillRectangles(display, window,
  368.                                     GDK_GC_XGC(v9t9_gdk_colors[cmap[c]]), 
  369.                                     points[c], 
  370.                                     pptr[c] - points[c]);
  371.                 }
  372.             }
  373.  
  374.         }
  375.  
  376.         ptr++;
  377.     }
  378.  
  379. //    XFlush(GDK_WINDOW_XDISPLAY(v9t9_drawing_area->window));
  380.     logger(_L | L_2, "Drew %d rects, %d pixels\n", rects, pixels);
  381.  
  382.     logger(_L|L_2, "%d/%d solid\n", solid, total);
  383. }
  384.  
  385. #endif
  386.  
  387. /**************/
  388.  
  389. #if 0
  390. #pragma mark -
  391. #pragma mark [ Win32 ]
  392. #endif
  393.  
  394. #if defined(UNDER_WIN32)
  395.  
  396. static GdkVisual *gdkvisual;
  397. static GdkImage *gdkimage;
  398.  
  399. static      vmResult
  400. system_gtkvideo_detect(void)
  401. {
  402.         /* get our visual, 8-bit paletted */
  403.         
  404.     gdkvisual = gdk_visual_get_best();
  405.     
  406.     if (!gdkvisual)
  407.     {
  408.         logger(_L|LOG_USER|LOG_ERROR, "Could not get visual\n");
  409.         return vmNotAvailable;
  410.     }
  411.                     
  412.     return vmOk;
  413. }
  414.  
  415. static      vmResult
  416. system_gtkvideo_init(void)
  417. {
  418.  
  419.     return vmOk;
  420. }
  421.  
  422. static      vmResult
  423. system_gtkvideo_enable(void)
  424. {
  425.         /* create a GdkImage for the v9t9 screen */
  426.     
  427.     gdkimage = gdk_image_new(GDK_IMAGE_SHARED_PIXMAP, gdkvisual, 256*4, 256*4);
  428.     if (!gdkimage)
  429.     {
  430.         logger(_L|LOG_USER|LOG_ERROR, "Could not get image\n");
  431.         return vmNotAvailable;
  432.     }
  433.     
  434.     return vmOk;
  435. }
  436.  
  437. static      vmResult
  438. system_gtkvideo_disable(void)
  439. {
  440.     gdk_image_unref(gdkimage);
  441.     
  442.     return vmOk;
  443. }
  444.  
  445. static      vmResult
  446. system_gtkvideo_restart(void)
  447. {
  448.     return vmOk;
  449. }
  450.  
  451. static      vmResult
  452. system_gtkvideo_restop(void)
  453. {
  454.     return vmOk;
  455. }
  456.  
  457. static      vmResult
  458. system_gtkvideo_term(void)
  459. {
  460.     return vmOk;
  461. }
  462.  
  463. #define MSBFirst 1
  464. #define x11_24_order 0
  465. int vwxsz;
  466.  
  467. #define vwxm GTK_x_mult
  468. #define vwym GTK_y_mult
  469. #define cmapping(x) v9t9_gdk_palette[cmap[x]].pixel
  470.  
  471. #include "video_X_draw.h"
  472.  
  473. static  void
  474. gtk_update_area(struct updateblock *ptr, int num)
  475. {
  476.     int    width = 8;
  477.     static int video_updating;
  478.     RECT updaterect, rect;
  479.     u8 *scrn;
  480.     int i,j;
  481.     int offs;
  482.  
  483.     drawpixelsfunc func;
  484.     GdkGC *gc;
  485.     
  486.     if (video_updating)
  487.         return;
  488.  
  489.     video_updating = 1;
  490.  
  491.     if (GTK_x_mult >= 1 && GTK_x_mult <= 4)
  492.         func = drawpixels_NxN[GTK_x_mult-1][gdkimage->bpp-1];
  493.     else
  494.         func = drawpixels_XxY[gdkimage->bpp-1];
  495.     
  496.     gc = gdk_gc_new(v9t9_drawing_area->window);
  497.     
  498.     if (!gdkimage || !gdkimage->mem)
  499.         return;
  500.         
  501.     SetRectEmpty(&updaterect);
  502.     
  503.     offs=(GTK_x_size/2)-128;
  504.     while (num--)
  505.     {
  506.         scrn = (u8*)gdkimage->mem + 
  507.             (ptr->r * GTK_y_mult * gdkimage->bpl) + 
  508.             (ptr->c + offs) * GTK_x_mult * gdkimage->bpp;
  509.  
  510.         for (i = 0; i < 8; i++) {
  511.             for (j = 0; j < GTK_y_mult; j++) {
  512.                 func(scrn, ptr->data, width);
  513.                 scrn += gdkimage->bpl;
  514.             }
  515.             ptr->data += UPDATEBLOCK_ROW_STRIDE;
  516.         }
  517.         
  518.         SetRect(&rect, ptr->c, ptr->r, ptr->c + width, ptr->r + 8);
  519.         UnionRect(&updaterect, &updaterect, &rect);
  520.         ptr++;
  521.     }
  522.  
  523.     gdk_draw_image(v9t9_drawing_area->window,
  524.         gc,
  525.         gdkimage,
  526.         updaterect.left, updaterect.top,
  527.         (updaterect.left + offs) * GTK_x_mult, updaterect.top * GTK_y_mult,
  528.         (updaterect.right - updaterect.left) * GTK_x_mult,
  529.         (updaterect.bottom - updaterect.top) * GTK_y_mult);
  530.     
  531.     gdk_gc_unref(gc);
  532.  
  533.     video_updating = 0;
  534. }
  535.  
  536. #elif 0
  537.  
  538. static  void
  539. gtk_update_area(struct updateblock *ptr, int num)
  540. {
  541.     int width = 8;
  542.     RECT updaterect, physrect, rect;
  543.     u8 *scrn;
  544.     PAINTSTRUCT pstruct;
  545.     HDC hdc;
  546.     int i,j;
  547.     int offs;
  548.  
  549.     GdkGC *gc = gdk_gc_new(v9t9_drawing_area->window);
  550.     
  551.     if (!gdkimage || !gdkimage->mem)
  552.         return;
  553.         
  554.     SetRectEmpty(&updaterect);
  555.     
  556.     offs=(GTK_x_size/2)-128;
  557.     while (num--)
  558.     {
  559. //        scrn = gdkimage->mem + 
  560. //            ((ptr->r * 256) + ptr->c + offs) * gdkimage->bpp;
  561.         for (i=0; i<8; i++)
  562.         {
  563.             for (j=0; j<width; j++)
  564.                 gdk_image_put_pixel(gdkimage, ptr->c+j, ptr->r+i,
  565.                     v9t9_gdk_palette[ptr->data[j]].pixel);
  566. //            memcpy(scrn,ptr->data,8);
  567.             ptr->data+=UPDATEBLOCK_ROW_STRIDE;
  568. //            scrn += 256;
  569.         }
  570.  
  571.         SetRect(&rect, ptr->c, ptr->r, ptr->c + width, ptr->r + 8);
  572.         //window_invalidate(&rect);
  573.         UnionRect(&updaterect, &updaterect, &rect);
  574.         ptr++;
  575.     }
  576.  
  577.     gdk_draw_image(v9t9_drawing_area->window,
  578.         gc,
  579.         gdkimage,
  580.         updaterect.left, updaterect.top,
  581.         updaterect.left + offs * GTK_x_mult, updaterect.top,
  582.         updaterect.right - updaterect.left,
  583.         updaterect.bottom - updaterect.top);
  584.     
  585.     gdk_gc_unref(gc);
  586. }
  587. #elif 0
  588.  
  589. static  void
  590. gtk_update_area(struct updateblock *ptr, int num)
  591. {
  592.     int            width = 8;
  593.     u8         *blk;
  594.     RECT        points[17][64], *pptr[17], *iter;
  595.     int            rects = 0, pixels = 0;
  596.     int            xoffs = (256 - GTK_x_size) / 2;
  597.  
  598.     HDC hdc = GetDC((HWND)GDK_WINDOW_XWINDOW((GdkWindowPrivate *)(v9t9_drawing_area->window)));
  599.     
  600.     while (num--) {
  601.         int         i;
  602.         int         j;
  603.         u8            c;
  604.         int            d;
  605.  
  606.         ptr->r *= GTK_y_mult;
  607.         ptr->c = (ptr->c + xoffs) * GTK_x_mult;
  608.  
  609.         /* Reset lists for each color (remember text mode has color==16) */
  610.         for (c = 0; c < 17; c++)
  611.             pptr[c] = points[c];
  612.  
  613.         /* Generate a list of rectangles for each color
  614.            in the 8x8 block */
  615.         for (i = 0; i < 8; i++) {
  616.             j = 0;
  617.             while (j < width) {
  618.                 /* Find the longest run of pixels of this color */
  619.                 c = ptr->data[j];
  620.                 d = 1;
  621.                 while (j + d < width && ptr->data[j + d] == c)
  622.                     d++;
  623.  
  624.                 pptr[c]->left = ptr->c + j * GTK_x_mult;
  625.                 pptr[c]->top = ptr->r + i * GTK_y_mult;
  626.                 pptr[c]->right = GTK_x_mult * d;
  627.                 pptr[c]->bottom = GTK_y_mult;
  628.  
  629.                 rects++;
  630.                 pixels += pptr[c]->right * pptr[c]->bottom;
  631.  
  632.                 pptr[c]++;
  633.                 j += d;
  634.             }
  635.             ptr->data += UPDATEBLOCK_ROW_STRIDE;
  636.         }
  637.  
  638.         for (c = 0; c <= 16; c++) {
  639.             if (pptr[c] > points[c] && v9t9_gdk_colors[cmap[c]]) {
  640.                 iter = points[c];
  641.                 while (iter < pptr[c]) {
  642.                     gdk_draw_rectangle(v9t9_drawing_area->window,
  643.                                     v9t9_gdk_colors[cmap[c]],
  644.                                     TRUE /* filled */,
  645.                                     iter->left,
  646.                                     iter->top,
  647.                                     iter->right,
  648.                                     iter->bottom);
  649.                     iter++;
  650.                 }
  651.             }
  652.         }
  653.  
  654.         ptr++;
  655.     }
  656.  
  657.     ReleaseDC((HWND)GDK_WINDOW_XWINDOW((GdkWindowPrivate *)(v9t9_drawing_area->window)), hdc);
  658.  
  659. //    XFlush(GDK_WINDOW_XDISPLAY(v9t9_drawing_area->window));
  660.     logger(_L | L_2, "Drew %d rects, %d pixels\n", rects, pixels);
  661.     
  662. //    g_free(gc);
  663. }
  664. #endif    
  665.  
  666.  
  667. #if 0
  668. #pragma mark -
  669. #endif
  670.  
  671. /*****************/
  672.  
  673. #if defined(UNDER_UNIX)
  674.  
  675.  
  676. #elif defined(UNDER_WIN32)
  677.  
  678. #endif
  679.  
  680. static      vmResult
  681. gtkvideo_updatelist(struct updateblock *ptr, int num)
  682. {
  683.     gtk_update_area(ptr, num);
  684.     return vmOk;
  685. }
  686.  
  687. void GTK_clear_sides(int total, int inside)
  688. {
  689.     if (inside < total && v9t9_gdk_colors[vdpbg])
  690.     {
  691.         int strip = (total - inside) * GTK_x_mult / 2;
  692.  
  693.         // clear sides
  694.         gdk_draw_rectangle(v9t9_drawing_area->window, v9t9_gdk_colors[vdpbg], 1,
  695.                            0, 0, 
  696.                            strip, GTK_y_size * GTK_y_mult);
  697.         gdk_draw_rectangle(v9t9_drawing_area->window, v9t9_gdk_colors[vdpbg], 1,
  698.                            total * GTK_x_mult - strip, 0,
  699.                            strip, GTK_y_size * GTK_y_mult);
  700.     }
  701. }
  702.  
  703. static      vmResult
  704. gtkvideo_resize(u32 newxsize, u32 newysize)
  705. {
  706.     GTK_clear_sides(GTK_x_size, newxsize);
  707.     GTK_x_size = newxsize;
  708.     GTK_y_size = newysize;
  709.     gtk_widget_queue_resize(v9t9_window);
  710.     return vmOk;
  711. }
  712.  
  713. static      vmResult
  714. gtkvideo_setfgbg(u8 fg, u8 bg)
  715. {
  716.     video_setpaletteentry(0, bg);
  717.     video_setpaletteentry(16, fg);
  718.     if (!v9t9_gdk_paletted) {
  719.         GTK_clear_sides(256, GTK_x_size);
  720.         vdpcompleteredraw();
  721.     }
  722.     return vmOk;
  723. }
  724.  
  725. static      vmResult
  726. gtkvideo_setblank(u8 bg)
  727. {
  728.     int         x;
  729.  
  730.     for (x = 0; x <= 16; x++)
  731.         video_setpaletteentry(x, bg);
  732.     if (!v9t9_gdk_paletted) {
  733. //        GTK_clear_sides(256, GTK_x_size);
  734.         vdpcompleteredraw();
  735.     }
  736.     return vmOk;
  737. }
  738.  
  739. static      vmResult
  740. gtkvideo_resetfromblank(void)
  741. {
  742.     video_updatepalette();
  743.     if (!v9t9_gdk_paletted) {
  744. //        GTK_clear_sides(256, GTK_x_size);
  745.         vdpcompleteredraw();
  746.     }
  747.     return vmOk;
  748. }
  749.  
  750. /***********************************************************/
  751.  
  752. static vmVideoModule gtkvideo_videoModule = {
  753.     3,
  754.     gtkvideo_updatelist,
  755.     gtkvideo_resize,
  756.     gtkvideo_setfgbg,
  757.     gtkvideo_setblank,
  758.     gtkvideo_resetfromblank
  759. };
  760.  
  761. vmModule    gtkVideo = {
  762.     3,
  763.     "GTK+ video",
  764.     "vidGTK",
  765.  
  766.     vmTypeVideo,
  767.     vmFlagsExclusive,
  768.  
  769.     gtkvideo_detect,
  770.     gtkvideo_init,
  771.     gtkvideo_term,
  772.     gtkvideo_enable,
  773.     gtkvideo_disable,
  774.     gtkvideo_restart,
  775.     gtkvideo_restop,
  776.     {(vmGenericModule *) & gtkvideo_videoModule}
  777. };
  778.