~ubuntu-branches/ubuntu/raring/vice/raring

« back to all changes in this revision

Viewing changes to src/arch/os2/video.c

  • Committer: Bazaar Package Importer
  • Author(s): Zed Pobre
  • Date: 2005-02-01 11:30:26 UTC
  • mto: (9.1.1 lenny) (1.1.6 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20050201113026-6gy97mcqlg2ykg4z
Tags: upstream-1.16
ImportĀ upstreamĀ versionĀ 1.16

Show diffs side-by-side

added added

removed removed

Lines of Context:
69
69
#include "dragndrop.h"
70
70
#include "cmdline.h"
71
71
#include "resources.h"
 
72
#include "viewport.h"
72
73
 
73
74
#include "machine.h"         // machine_canvas_screenshot
74
75
#include "screenshot.h"      // screenshot_t
122
123
    FCF_AUTOICON | FCF_MINBUTTON | FCF_CLOSEBUTTON;
123
124
 
124
125
/* ------------------------------------------------------------------------ */
125
 
/* Video-related resources.  */
 
126
/* Video-related resources.                                                 */
126
127
 
127
128
int stretch;            // Strech factor for window (1,2,3,...)
128
129
static int border;      // PM Border Type
780
781
 
781
782
    int i;
782
783
 
783
 
    video_render_initconfig(c->videoconfig);
784
 
 
785
784
    // video_render_setrawrgb: index, r, g, b
786
785
    for (i=0; i<0x100; i++)
787
786
        video_render_setrawrgb(i,
792
791
    video_render_initraw();
793
792
}
794
793
 
 
794
video_canvas_t *initcanvas;
 
795
 
795
796
MRESULT WmCreate(HWND hwnd)
796
797
{
797
798
    ULONG rc;
798
799
 
799
800
    /*video_canvas_t *canvas_new = (video_canvas_t *)calloc(1, sizeof(video_canvas_t));*/
800
 
    video_canvas_t *canvas_new = video_canvas_init();
 
801
    video_canvas_t *canvas_new = initcanvas; //video_canvas_init();
801
802
 
802
803
    archdep_create_mutex_sem(&canvas_new->hmtx, "Video", FALSE);
803
804
 
1053
1054
    const UINT  linesz = dsx*c->draw_buffer->draw_buffer_width;
1054
1055
    const UINT  bufh   = dsy*c->draw_buffer->draw_buffer_height;
1055
1056
 
 
1057
    /*********FIXME?**********/
 
1058
    if (c->ulBuffer==0)
 
1059
        return;
 
1060
    /*************************/
 
1061
 
1056
1062
    //
1057
1063
    // xs, xy is double sized
1058
1064
    // w,  h  is double sized
1151
1157
                                    &numlines);
1152
1158
    if (rc!=DIVE_SUCCESS)
1153
1159
    {
1154
 
        log_error(vidlog, "Call to DiveBeginImageBufferAccess failed, rc = 0x%x", rc);
 
1160
        log_error(vidlog, "Call to DiveBeginImageBufferAccess(%d, %d) failed, rc = 0x%x", c->hDiveInst, c->ulBuffer, rc);
1155
1161
        return;
1156
1162
    }
1157
1163
    video_canvas_render(c,
1158
 
                        targetbuffer,      // c->bitmaptrg,        // bitmap target (screen/dive)
1159
 
                        w, h,              // f->width, f->height, // bitmap width, height (2copy)
1160
 
                        xs/dsx, ys/dsy,    // 0, 0,                // top, left source
1161
 
                        xi, yi,            // 0, 0,                // top, left target
1162
 
                        scanlinesize,      // fccColorEncoding,    // c->width,            // line size target
 
1164
                        targetbuffer,   // c->bitmaptrg,        // bitmap target (screen/dive)
 
1165
                        w, h,           // f->width, f->height, // bitmap width, height (2copy)
 
1166
                        xs/dsx, ys/dsy, // 0, 0,                // top, left source
 
1167
                        xi, yi,         // 0, 0,                // top, left target
 
1168
                        scanlinesize,   // fccColorEncoding,    // c->width,            // line size target
1163
1169
                        c->bDepth);
1164
1170
 
 
1171
    //
 
1172
    // and blit the image to the screen
 
1173
    //
 
1174
    rc = DiveBlitImage(c->hDiveInst, c->ulBuffer, DIVE_BUFFER_SCREEN);
 
1175
    if (rc!=DIVE_SUCCESS)
 
1176
    {
 
1177
        log_error(vidlog, "Call to DiveBlitImage failed, rc = 0x%x", rc);
 
1178
        return;
 
1179
    }
 
1180
 
 
1181
    //
 
1182
    // It seems, that this must be _after_ DiveBlitImage!
 
1183
    //
1165
1184
    rc = DiveEndImageBufferAccess(c->hDiveInst, c->ulBuffer);
1166
1185
    if (rc!=DIVE_SUCCESS)
1167
1186
    {
1168
1187
        log_error(vidlog, "Call to DiveEndImageBufferAccess failed, rc = 0x%x", rc);
1169
1188
        return;
1170
1189
    }
1171
 
 
1172
 
    //
1173
 
    // and blit the image to the screen
1174
 
    //
1175
 
    rc = DiveBlitImage(c->hDiveInst, c->ulBuffer, DIVE_BUFFER_SCREEN);
1176
 
    if (rc!=DIVE_SUCCESS)
1177
 
    {
1178
 
        log_error(vidlog, "Call to DiveBlitImage failed, rc = 0x%x", rc);
1179
 
        return;
1180
 
    }
1181
1190
    /*
1182
1191
     {
1183
1192
     BYTE mask[500];
1621
1630
    draw_buffer_t         *draw_buffer;
1622
1631
    viewport_t            *viewport;
1623
1632
    geometry_t            *geometry;
1624
 
    const palette_t       *palette;
 
1633
    palette_t             *palette;
1625
1634
};
1626
1635
 
1627
1636
typedef struct canvas_init_s canvas_init_t;
1634
1643
    HWND   hwndFrame;
1635
1644
    HWND   hwndClient;
1636
1645
 
1637
 
    video_canvas_t *c;
1638
 
 
1639
 
    canvas_init_t *ini = (canvas_init_t*)arg;
 
1646
    video_canvas_t *c = (video_canvas_t*)arg;
1640
1647
 
1641
1648
    // archdep_setup_signals(0); // signals are not shared between threads!
1642
1649
 
1645
1652
 
1646
1653
    //
1647
1654
    // 16 Byte Memory (Used eg for the Anchor Blocks)
1648
 
    //  CS_MOVENOTIFY, CS_SIZEREDRAW skipped
 
1655
    //  CS_MOVENOTI8FY, CS_SIZEREDRAW skipped
1649
1656
    //  CS_SYNCPAINT:       send WM_PAINT messages immediately
1650
1657
    //   don't send WM_PAINT befor canvas is resized
1651
1658
    //  CS_BYTEALIGNWINDOW: 0x2000
1655
1662
    //
1656
1663
    // create window on desktop, FIXME: WS_ANIMATE looks sometimes strange
1657
1664
    //
 
1665
    initcanvas = c;
1658
1666
    hwndFrame = WinCreateStdWindow(HWND_DESKTOP, WS_ANIMATE|WS_VISIBLE,
1659
1667
                                   &flFrameFlags, szClientClass,
1660
 
                                   ini->title, 0L, 0, IDM_VICE2,
 
1668
                                   c->title, 0L, 0, IDM_VICE2,
1661
1669
                                   &hwndClient);
1662
 
 
1663
1670
    if (!hwndFrame)
1664
1671
    {
1665
1672
        ERRORID id = WinGetLastError(hab);
1667
1674
    }
1668
1675
 
1669
1676
    c = GetCanvas(hwndClient);
1670
 
 
1671
1677
    if (!c)
1672
1678
    {
1673
 
        ini->canvas = (void*)-1;
 
1679
        initcanvas->initialized = 0;
1674
1680
        return;
1675
1681
    }
1676
1682
 
1677
 
    c->hwndFrame   = hwndFrame;
1678
 
    c->hwndClient  = hwndClient;
1679
 
    c->title       = ini->title;
1680
 
    c->width       = ini->width;
1681
 
    c->height      = ini->height;
1682
 
    c->stretch     = ini->stretch;
1683
 
    c->videoconfig = ini->videoconfig;
1684
 
    c->draw_buffer = ini->draw_buffer;
1685
 
    c->viewport    = ini->viewport;
1686
 
    c->geometry    = ini->geometry;
1687
 
    c->palette     = ini->palette;
 
1683
    c->hwndFrame  = hwndFrame;
 
1684
    c->hwndClient = hwndClient;
1688
1685
 
1689
1686
    VideoBufferAlloc(c);
1690
1687
 
1739
1736
    if (rc=DosSetPriority(PRTYS_THREAD, PRTYC_REGULAR, +1, 0))
1740
1737
        log_error(vidlog, "DosSetPriority (rc=%li)", rc);
1741
1738
 
1742
 
    log_message(vidlog, "'%s' completely initialized.", ini->title);
 
1739
    log_message(vidlog, "'%s' completely initialized.", c->title);
1743
1740
 
1744
1741
    //
1745
1742
    // Now wake up the emulation thread by setting ini->canvas
1746
1743
    //
1747
 
    ini->canvas = c;
 
1744
    c->initialized = 1;
1748
1745
 
1749
1746
    //
1750
1747
    // MAINLOOP
1821
1818
video_canvas_t *video_canvas_create(video_canvas_t *canvas, UINT *width,
1822
1819
                                    UINT *height, int mapped)
1823
1820
{
1824
 
    canvas_init_t canvini;
1825
 
 
1826
1821
    log_message(vidlog, "Creation of '%s' (%ix%i) requested%s.",
1827
1822
                canvas->viewport->title, *width, *height,
1828
1823
                vsid_mode ? " (vsid mode)" : "");
1829
1824
 
1830
1825
    *strrchr(canvas->viewport->title, ' ') = 0; // FIXME?
1831
1826
 
1832
 
    canvini.title       =  util_concat(szTitleBarText, " - ",
 
1827
    canvas->title       =  util_concat(szTitleBarText, " - ",
1833
1828
                                       canvas->viewport->title + 6, NULL);
1834
 
    canvini.width       = *width;
1835
 
    canvini.height      = *height;
1836
 
    canvini.stretch     =  stretch;
1837
 
    canvini.canvas      =  NULL;
1838
 
    canvini.videoconfig = canvas->videoconfig;
1839
 
    canvini.draw_buffer = canvas->draw_buffer;
1840
 
    canvini.viewport    = canvas->viewport;
1841
 
    canvini.geometry    = canvas->geometry;
1842
 
    canvini.palette     = canvas->palette;
 
1829
    canvas->width       = *width;
 
1830
    canvas->height      = *height;
 
1831
    canvas->stretch     = stretch;
 
1832
    canvas->initialized = 2;
1843
1833
 
1844
1834
    if (canvas->videoconfig->doublesizex)
1845
 
        canvini.width *= 2;
 
1835
        canvas->width *= 2;
1846
1836
 
1847
1837
    if (canvas->videoconfig->doublesizey)
1848
 
        canvini.height *= 2;
 
1838
        canvas->height *= 2;
1849
1839
 
1850
 
    _beginthread(CanvasMainLoop, NULL, 0x4000, &canvini);
 
1840
    _beginthread(CanvasMainLoop, NULL, 0x4000, canvas);
1851
1841
 
1852
1842
    //
1853
1843
    // Wait until the canvas as either created successfully or
1854
1844
    // the canvas creation failed
1855
1845
    //
1856
 
    while (!canvini.canvas)
 
1846
    while (canvas->initialized==2)
1857
1847
        DosSleep(1);
1858
1848
 
1859
1849
    //
1860
1850
    // If initialization of canvas failed
1861
1851
    // canvas_ini.canvas is set to -1
1862
1852
    //
1863
 
    if (canvini.canvas == (void*)-1)
 
1853
    if (canvas == 0)
1864
1854
        return NULL;
1865
1855
 
1866
1856
    log_message(vidlog, "Canvas '%s' (%ix%i) created: hwnd=0x%x.",
1867
1857
                canvas->viewport->title, *width, *height,
1868
 
                canvini.canvas->hwndClient);
1869
 
 
1870
 
    video_canvas_set_palette(canvini.canvas, canvas->palette);
1871
 
 
1872
 
    canvini.canvas->initialized = 1;
1873
 
 
1874
 
    return canvini.canvas;
 
1858
                canvas->hwndClient);
 
1859
 
 
1860
    video_canvas_set_palette(canvas, canvas->palette);
 
1861
 
 
1862
    return canvas;
1875
1863
}
1876
1864
 
1877
1865
void video_canvas_destroy(video_canvas_t *c)
1932
1920
    //
1933
1921
    lib_free(c->title);
1934
1922
    video_canvas_shutdown(c);
1935
 
    lib_free(c);
1936
1923
 
1937
1924
    //    DosReleaseMutexSem(hmtx);
1938
1925
 
2113
2100
                log_error(vidlog, "VideoConvertPalette - DiveSetupBlitter failed, rc=0x%x", rc);
2114
2101
            else
2115
2102
            {
2116
 
                int i;
2117
 
                DWORD color;
2118
2103
                int bytes = c->bDepth/8;
2119
2104
 
2120
2105
                rc = DiveBlitImage(inst, ulSrc, ulTrg);
2122
2107
                    log_error(vidlog, "VideoConvertPalette - DiveBlitImage failed, rc=0x%x", rc);
2123
2108
                else
2124
2109
                {
 
2110
                    int i;
2125
2111
                    for (i=0; i<num; i++)
2126
2112
                    {
2127
2113
                        int b;
 
2114
                        DWORD color = 0;
2128
2115
 
2129
 
                        color = 0;
2130
2116
                        for (b=0; b<bytes; b++)
2131
2117
                            color |= (ULONG)target[i*bytes+b] << (b*8);
2132
2118
 
2157
2143
{
2158
2144
    int i;
2159
2145
 
2160
 
    if (c->bDepth==8)
 
2146
    if (c->bDepth!=8)
 
2147
    {
 
2148
        VideoConvertPalette(c, p->num_entries, p->entries);
 
2149
        WmPaint(c->hwndClient);
 
2150
    }
 
2151
    else
2161
2152
    {
2162
2153
        ULONG rc;
2163
2154
 
2186
2177
            log_message(vidlog, "%d palette entries realized.", p->num_entries);
2187
2178
 
2188
2179
        lib_free(palette);
2189
 
    }
2190
 
 
2191
 
#if 0
2192
 
    for (i=0; i<p->num_entries; i++)
2193
 
        pixel_return[i] = i;
2194
 
#endif
2195
 
 
2196
 
    if (c->bDepth==8)
 
2180
 
2197
2181
        VideoConvertPalette8(c, p->num_entries);
2198
 
    else
2199
 
        VideoConvertPalette(c, p->num_entries, p->entries);
2200
 
 
2201
 
    if (c->bDepth!=8)
2202
 
        WmPaint(c->hwndClient);
 
2182
    }
2203
2183
 
2204
2184
    return 0;
2205
2185
}