~ubuntu-branches/debian/squeeze/stella/squeeze

« back to all changes in this revision

Viewing changes to src/wince/FrameBufferWinCE.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mario Iseli
  • Date: 2006-04-08 18:38:25 UTC
  • mfrom: (1.1.2 upstream) (2.1.1 etch)
  • Revision ID: james.westby@ubuntu.com-20060408183825-vu1jk57rk929derx
* New Maintainer (Closes: #361345)
* New upstream release (Closes: #349725)
* Build-Depend now on libslang2-dev (Closes: #325577)
* Complete rebuild of debian/, upgraded to policy-standards
  3.6.2 and compat-level 5.
* Removed stellarc since stella only reads ~/.stellarc and even
  works without a first config.
* New debian/watch file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//============================================================================
 
2
//
 
3
//   SSSS    tt          lll  lll
 
4
//  SS  SS   tt           ll   ll
 
5
//  SS     tttttt  eeee   ll   ll   aaaa
 
6
//   SSSS    tt   ee  ee  ll   ll      aa
 
7
//      SS   tt   eeeeee  ll   ll   aaaaa  --  "An Atari 2600 VCS Emulator"
 
8
//  SS  SS   tt   ee      ll   ll  aa  aa
 
9
//   SSSS     ttt  eeeee llll llll  aaaaa
 
10
//
 
11
// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team
 
12
//
 
13
// See the file "license" for information on usage and redistribution of
 
14
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
 
15
//
 
16
// Windows CE Port by Kostas Nakos
 
17
//============================================================================
 
18
 
 
19
#include <windows.h>
 
20
#include "FrameBufferWinCE.hxx"
 
21
#include "Console.hxx"
 
22
#include "OSystem.hxx"
 
23
#include "Font.hxx"
 
24
 
 
25
#define OPTPIXAVERAGE(pix1,pix2) ( ((((pix1 & optgreenmaskN) + (pix2 & optgreenmaskN)) >> 1) & optgreenmaskN) | ((((pix1 & optgreenmask) + (pix2 & optgreenmask)) >> 1) & optgreenmask) )
 
26
 
 
27
FrameBufferWinCE::FrameBufferWinCE(OSystem *osystem)
 
28
: FrameBuffer(osystem), myDstScreen(NULL), SubsystemInited(false), displacement(0),
 
29
issmartphone(true), islandscape(false), displaymode(0), legacygapi(true), devres(SM_LOW)
 
30
{
 
31
        gxdp.cxWidth = gxdp.cyHeight = gxdp.cbxPitch = gxdp.cbyPitch = gxdp.cBPP = gxdp.ffFormat = 0;
 
32
}
 
33
 
 
34
FrameBufferWinCE::~FrameBufferWinCE()
 
35
{
 
36
}
 
37
 
 
38
void FrameBufferWinCE::GetDeviceProperties(void)
 
39
{
 
40
        if (gxdp.cxWidth) return;
 
41
 
 
42
        // screen access mode
 
43
        gxdp = GXGetDisplayProperties();
 
44
        legacygapi = true;
 
45
        if (((unsigned int) GetSystemMetrics(SM_CXSCREEN) != gxdp.cxWidth) || ((unsigned int) GetSystemMetrics(SM_CYSCREEN) != gxdp.cyHeight))
 
46
        {
 
47
                // 2003SE+ and lying about the resolution. good luck.
 
48
                legacygapi = false;
 
49
 
 
50
                RawFrameBufferInfo rfbi;
 
51
                HDC hdc = GetDC(NULL);
 
52
                ExtEscape(hdc, GETRAWFRAMEBUFFER, 0, NULL, sizeof(RawFrameBufferInfo), (char *) &rfbi);
 
53
                ReleaseDC(NULL, hdc);
 
54
 
 
55
                if (rfbi.wFormat == FORMAT_565)
 
56
                        gxdp.ffFormat = kfDirect565;
 
57
                else if (rfbi.wFormat == FORMAT_555)
 
58
                        gxdp.ffFormat = kfDirect555;
 
59
                else
 
60
                        gxdp.ffFormat = 0;
 
61
                gxdp.cBPP = rfbi.wBPP;
 
62
                gxdp.cbxPitch = rfbi.cxStride;
 
63
                gxdp.cbyPitch = rfbi.cyStride;
 
64
                gxdp.cxWidth  = rfbi.cxPixels;
 
65
                gxdp.cyHeight = rfbi.cyPixels;
 
66
        }
 
67
 
 
68
        // device detection (some redundancy here, but nevermind :)
 
69
        TCHAR platform[100];
 
70
        issmartphone = false;
 
71
        if (gxdp.cxWidth == 176 && gxdp.cyHeight == 220)
 
72
                issmartphone = true;
 
73
        if (SystemParametersInfo(SPI_GETPLATFORMTYPE, 100, platform, 0))
 
74
        {
 
75
                if (wcsstr(platform, _T("mart")))
 
76
                        issmartphone = true;
 
77
        }
 
78
        else
 
79
                issmartphone = true;    // most likely
 
80
 
 
81
        if (gxdp.cxWidth == 176 && gxdp.cyHeight == 220)
 
82
                devres = SM_LOW;
 
83
        /*else if (gxdp.cxWidth == 480 && gxdp.cyHeight == 640)
 
84
                devres = VGA;*/
 
85
        else
 
86
                devres = QVGA;
 
87
}
 
88
 
 
89
void FrameBufferWinCE::setPalette(const uInt32* palette)
 
90
{
 
91
        //setup palette
 
92
        GetDeviceProperties();
 
93
        for (uInt16 i=0; i<256; i++)
 
94
        {
 
95
                uInt8 r = (uInt8) ((palette[i] & 0xFF0000) >> 16);
 
96
                uInt8 g = (uInt8) ((palette[i] & 0x00FF00) >> 8);
 
97
                uInt8 b = (uInt8) (palette[i] & 0x0000FF);
 
98
                if(gxdp.ffFormat & kfDirect565)
 
99
                        pal[i] = (uInt16) ( ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | ((b & 0xF8) >> 3) );
 
100
                else if(gxdp.ffFormat & kfDirect555)
 
101
                        pal[i] = (uInt16) ( ((r & 0xF8) << 7) | ((g & 0xF8) << 3) | ((b & 0xF8) >> 3) );
 
102
                else
 
103
                        return;
 
104
        }
 
105
        SubsystemInited = false;
 
106
}
 
107
 
 
108
bool FrameBufferWinCE::initSubsystem()
 
109
{
 
110
        GetDeviceProperties();
 
111
        for (int i=0; i<kNumColors - 256; i++)
 
112
        {
 
113
                uInt8 r = (ourGUIColors[i][0] & 0xFF);
 
114
                uInt8 g = (ourGUIColors[i][1] & 0xFF);
 
115
                uInt8 b = (ourGUIColors[i][2] & 0xFF);
 
116
                if(gxdp.ffFormat & kfDirect565)
 
117
                        guipal[i] = (uInt16) ( ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | ((b & 0xF8) >> 3) );
 
118
                else if(gxdp.ffFormat & kfDirect555)
 
119
                        guipal[i] = (uInt16) ( ((r & 0xF8) << 7) | ((g & 0xF8) << 3) | ((b & 0xF8) >> 3) );
 
120
                else
 
121
                        return false;
 
122
        }
 
123
        // screen extents
 
124
        if(gxdp.ffFormat & kfDirect565)
 
125
        {
 
126
                optgreenmask = 0x7E0;
 
127
                optgreenmaskN = 0xF81F;
 
128
        }
 
129
        else
 
130
        {
 
131
                optgreenmask = 0x3E0;
 
132
                optgreenmaskN = 0x7C1F;
 
133
        }
 
134
 
 
135
        scrwidth = gxdp.cxWidth;
 
136
        scrheight = gxdp.cyHeight;
 
137
        scrpixelstep = gxdp.cbxPitch;
 
138
        scrlinestep = gxdp.cbyPitch;
 
139
 
 
140
//      if (scrwidth == 176 && scrheight == 220)
 
141
//              issmartphone = true;
 
142
//      else
 
143
//              issmartphone = false;
 
144
 
 
145
        setmode(displaymode);
 
146
        SubsystemInited = false;
 
147
        return true;
 
148
}
 
149
 
 
150
void FrameBufferWinCE::setmode(uInt8 mode)
 
151
{
 
152
        displaymode = mode % 3;
 
153
        switch (displaymode)
 
154
        {
 
155
                // portrait
 
156
                case 0:
 
157
                        pixelstep = gxdp.cbxPitch;
 
158
                        linestep = gxdp.cbyPitch;
 
159
                        islandscape = false;
 
160
                        break;
 
161
 
 
162
                // landscape
 
163
                case 1:
 
164
                        pixelstep = - gxdp.cbyPitch;
 
165
                        linestep = gxdp.cbxPitch;
 
166
                        islandscape = true;
 
167
                        break;
 
168
 
 
169
                // inverted landscape
 
170
                case 2:
 
171
                        pixelstep = gxdp.cbyPitch;
 
172
                        linestep = - gxdp.cbxPitch;
 
173
                        islandscape = true;
 
174
                        break;
 
175
        }
 
176
 
 
177
        pixelsteptimes5 = pixelstep * 5;
 
178
        pixelsteptimes6 = pixelstep * 6;
 
179
        SubsystemInited = false;
 
180
}
 
181
 
 
182
uInt8 FrameBufferWinCE::rotatedisplay(void)
 
183
{
 
184
        displaymode = (displaymode + 1) % 3;
 
185
        setmode(displaymode);
 
186
        wipescreen();
 
187
        return displaymode;
 
188
}
 
189
 
 
190
void FrameBufferWinCE::lateinit(void)
 
191
{
 
192
        int w,h;
 
193
 
 
194
        myWidth = myOSystem->console().mediaSource().width();
 
195
        myHeight = myOSystem->console().mediaSource().height();
 
196
        myWidthdiv4 = myWidth >> 2;
 
197
 
 
198
        if (devres == SM_LOW)
 
199
                if (!islandscape)
 
200
                        w = myWidth;
 
201
                else
 
202
                        w = (int) ((float) myWidth * 11.0f / 8.0f + 0.5f);
 
203
        else //if (devres == QVGA)
 
204
                if (!islandscape)
 
205
                        w = (int) ((float) myWidth * 3.0f / 2.0f + 0.5f);
 
206
                else
 
207
                        w = myWidth * 2;
 
208
        /*else
 
209
        {
 
210
                // VGA
 
211
        }
 
212
        */
 
213
        if (devres == SM_LOW && islandscape)
 
214
                h = (int) ((float) myHeight * 4.0f / 5.0f + 0.5f);
 
215
        else
 
216
                h = myHeight;
 
217
 
 
218
        switch (displaymode)
 
219
        {
 
220
                case 0:
 
221
                        if (scrwidth > w)
 
222
                                displacement = (scrwidth - w) / 2 * gxdp.cbxPitch;
 
223
                        else
 
224
                                displacement = 0;
 
225
                        if (scrheight > h)
 
226
                        {
 
227
                                displacement += (scrheight - h) / 2 * gxdp.cbyPitch;
 
228
                                minydim = h;
 
229
                        }
 
230
                        else
 
231
                                minydim = scrheight;
 
232
                        break;
 
233
 
 
234
                case 1:
 
235
                        displacement = gxdp.cbyPitch*(gxdp.cyHeight-1);
 
236
                        if (scrwidth > h)
 
237
                        {
 
238
                                minydim = h;
 
239
                                displacement += (scrwidth - h) / 2 * gxdp.cbxPitch;
 
240
                        }
 
241
                        else
 
242
                                minydim = scrwidth;
 
243
                        if (scrheight > w)
 
244
                                displacement -= (scrheight - w) / 2 * gxdp.cbyPitch;
 
245
                        break;
 
246
 
 
247
                case 2:
 
248
                        displacement = gxdp.cbxPitch*(gxdp.cxWidth-1);
 
249
                        if (scrwidth > h)
 
250
                        {
 
251
                                minydim = h;
 
252
                                displacement -= (scrwidth - h) / 2 * gxdp.cbxPitch;
 
253
                        }
 
254
                        else
 
255
                                minydim = scrwidth;
 
256
                        if (scrheight > w)
 
257
                                displacement += (scrheight - w) / 2 * gxdp.cbyPitch;
 
258
                        break;
 
259
 
 
260
        }
 
261
 
 
262
        SubsystemInited = true;
 
263
}
 
264
 
 
265
void FrameBufferWinCE::preFrameUpdate()
 
266
{
 
267
        static HDC hdc;
 
268
        static RawFrameBufferInfo rfbi;
 
269
 
 
270
        if (legacygapi)
 
271
                myDstScreen = (uInt8 *) GXBeginDraw();
 
272
        else
 
273
        {
 
274
                hdc = GetDC(NULL);
 
275
                ExtEscape(hdc, GETRAWFRAMEBUFFER, 0, NULL, sizeof(RawFrameBufferInfo), (char *) &rfbi);
 
276
                ReleaseDC(NULL, hdc);
 
277
                myDstScreen = (uInt8 *) rfbi.pFramePointer;
 
278
        }
 
279
}
 
280
 
 
281
void FrameBufferWinCE::drawMediaSource()
 
282
{
 
283
        static uInt8 *sc, *sp, *sc_n, *sp_n;
 
284
        static uInt8 *d, *pl, *p;
 
285
        static uInt16 pix1, pix2, pix3, x, y;
 
286
 
 
287
        if (!SubsystemInited)
 
288
                lateinit();
 
289
        
 
290
        if ( (d = myDstScreen) == NULL )
 
291
                return;
 
292
 
 
293
        d += displacement;
 
294
        pl = d;
 
295
        sc = myOSystem->console().mediaSource().currentFrameBuffer();
 
296
        sp = myOSystem->console().mediaSource().previousFrameBuffer();
 
297
 
 
298
        if (theRedrawTIAIndicator)
 
299
        {
 
300
                p = sp;
 
301
                for (uInt16 y=0; y<myHeight; y++)
 
302
                        for (uInt16 x=0; x<myWidth; x += 4, *p = *p + 1, p += 4);
 
303
                theRedrawTIAIndicator = false;
 
304
        }
 
305
        
 
306
        if (devres == SM_LOW && !islandscape)
 
307
        {
 
308
                // straight
 
309
                for (y=0; y<minydim; y++)
 
310
                {
 
311
                        for (x=0; x<myWidthdiv4; x++)
 
312
                        {
 
313
                                if ( *((uInt32 *) sc) != *((uInt32 *) sp) )
 
314
                                {
 
315
                                        *((uInt16 *)d) = pal[*sc++]; d += pixelstep;
 
316
                                        *((uInt16 *)d) = pal[*sc++]; d += pixelstep;
 
317
                                        *((uInt16 *)d) = pal[*sc++]; d += pixelstep;
 
318
                                        *((uInt16 *)d) = pal[*sc++]; d += pixelstep;
 
319
                                }
 
320
                                else
 
321
                                {
 
322
                                        sc += 4;
 
323
                                        d += (pixelstep << 2);
 
324
                                }
 
325
                                sp += 4;
 
326
                        }
 
327
                        d = pl + linestep;
 
328
                        pl = d;
 
329
                }
 
330
        }
 
331
        else if (devres == SM_LOW && islandscape)
 
332
        {
 
333
                for (y=0; y<minydim; y++)
 
334
                {
 
335
                        // 4/5
 
336
                        if ((y & 3) ^ 3)
 
337
                        {       // normal line
 
338
                                for (x=0; x<myWidthdiv4; x++)
 
339
                                {
 
340
                                        // 11/8
 
341
                                        // **X**
 
342
                                        if ( *((uInt32 *) sc) != *((uInt32 *) sp) )
 
343
                                        {
 
344
                                                *((uInt16 *)d) = pal[*sc++]; d += pixelstep;
 
345
                                                pix1 = pal[*sc++]; pix2 = pal[*sc++];
 
346
                                                *((uInt16 *)d) = pix1; d += pixelstep;
 
347
                                                *((uInt16 *)d) = OPTPIXAVERAGE(pix1,pix2); d += pixelstep;
 
348
                                                *((uInt16 *)d) = pix2; d += pixelstep;
 
349
                                                *((uInt16 *)d) = pal[*sc++]; d += pixelstep;
 
350
                                        }
 
351
                                        else
 
352
                                        {
 
353
                                                sc += 4;
 
354
                                                d += pixelsteptimes5;
 
355
                                        }
 
356
                                        sp += 4;
 
357
                                        if (++x>=myWidthdiv4) break;
 
358
 
 
359
                                        // *X**X*
 
360
                                        if ( *((uInt32 *) sc) != *((uInt32 *) sp) )
 
361
                                        {
 
362
                                                pix1 = pal[*sc++]; pix2 = pal[*sc++];
 
363
                                                *((uInt16 *)d) = pix1; d += pixelstep;
 
364
                                                *((uInt16 *)d) = OPTPIXAVERAGE(pix1,pix2); d += pixelstep;
 
365
                                                *((uInt16 *)d) = pix2; d += pixelstep;
 
366
                                                pix1 = pal[*sc++]; pix2 = pal[*sc++];
 
367
                                                *((uInt16 *)d) = pix1; d += pixelstep;
 
368
                                                *((uInt16 *)d) = OPTPIXAVERAGE(pix1,pix2); d += pixelstep;
 
369
                                                *((uInt16 *)d) = pix2; d += pixelstep;
 
370
                                        }
 
371
                                        else
 
372
                                        {
 
373
                                                sc += 4;
 
374
                                                d += pixelsteptimes6;
 
375
                                        }
 
376
                                        sp += 4;
 
377
                                }
 
378
                        }
 
379
                        else
 
380
                        {       // skipped line
 
381
                                sc_n = sc + myWidth;
 
382
                                sp_n = sp + myWidth;
 
383
                                for (x=0; x<myWidthdiv4; x++)
 
384
                                {
 
385
                                        // 11/8
 
386
                                        // **X**
 
387
                                        if ( (*((uInt32 *) sc) != *((uInt32 *) sp)) || (*((uInt32 *) sc_n) != *((uInt32 *) sp_n)) )
 
388
                                        {
 
389
                                                pix1 = pal[*sc++]; pix2 = pal[*sc_n++];
 
390
                                                *((uInt16 *)d) = OPTPIXAVERAGE(pix1,pix2); d += pixelstep;
 
391
                                                pix1 = pal[*sc++]; pix2 = pal[*sc_n++];
 
392
                                                pix1 = OPTPIXAVERAGE(pix1,pix2);
 
393
                                                *((uInt16 *)d) = pix1; d += pixelstep;
 
394
                                                pix2 = pal[*sc++]; pix3 = pal[*sc_n++];
 
395
                                                pix2 = OPTPIXAVERAGE(pix2,pix3);
 
396
                                                pix3 = OPTPIXAVERAGE(pix1,pix2);
 
397
                                                *((uInt16 *)d) = pix3; d += pixelstep;
 
398
                                                *((uInt16 *)d) = pix2; d += pixelstep;
 
399
                                                pix1 = pal[*sc++]; pix2 = pal[*sc_n++];
 
400
                                                *((uInt16 *)d) = OPTPIXAVERAGE(pix1,pix2); d += pixelstep;
 
401
                                        }
 
402
                                        else
 
403
                                        {
 
404
                                                sc += 4;
 
405
                                                sc_n += 4;
 
406
                                                d += pixelsteptimes5;
 
407
                                        }
 
408
                                        sp += 4;
 
409
                                        sp_n += 4;
 
410
                                        if (++x>=myWidthdiv4) break;
 
411
 
 
412
                                        // *X**X*
 
413
                                        if ( (*((uInt32 *) sc) != *((uInt32 *) sp)) || (*((uInt32 *) sc_n) != *((uInt32 *) sp_n)) )
 
414
                                        {
 
415
                                                pix1 = pal[*sc++]; pix2 = pal[*sc_n++];
 
416
                                                pix1 = OPTPIXAVERAGE(pix1,pix2);
 
417
                                                *((uInt16 *)d) = pix1; d += pixelstep;
 
418
                                                pix2 = pal[*sc++]; pix3 = pal[*sc_n++];
 
419
                                                pix2 = OPTPIXAVERAGE(pix2,pix3);
 
420
                                                pix3 = OPTPIXAVERAGE(pix1,pix2);
 
421
                                                *((uInt16 *)d) = pix3; d += pixelstep;
 
422
                                                *((uInt16 *)d) = pix2; d += pixelstep;
 
423
                                                pix1 = pal[*sc++]; pix2 = pal[*sc_n++];
 
424
                                                pix1 = OPTPIXAVERAGE(pix1,pix2);
 
425
                                                *((uInt16 *)d) = pix1; d += pixelstep;
 
426
                                                pix2 = pal[*sc++]; pix3 = pal[*sc_n++];
 
427
                                                pix2 = OPTPIXAVERAGE(pix2,pix3);
 
428
                                                pix3 = OPTPIXAVERAGE(pix1,pix2);
 
429
                                                *((uInt16 *)d) = pix3; d += pixelstep;
 
430
                                                *((uInt16 *)d) = pix2; d += pixelstep;
 
431
                                        }
 
432
                                        else
 
433
                                        {
 
434
                                                sc += 4;
 
435
                                                sc_n += 4;
 
436
                                                d += pixelsteptimes6;
 
437
                                        }
 
438
                                        sp += 4;
 
439
                                        sp_n += 4;
 
440
                                }
 
441
                                sc += myWidth;
 
442
                                sp += myWidth;
 
443
                        }
 
444
                        d = pl + linestep;
 
445
                        pl = d;
 
446
                }
 
447
        }
 
448
        else if (devres == QVGA && !islandscape)
 
449
        {
 
450
                // 3/2
 
451
                for (y=0; y<minydim; y++)
 
452
                {
 
453
                        for (x=0; x<myWidthdiv4; x++)
 
454
                        {
 
455
                                if ( *((uInt32 *) sc) != *((uInt32 *) sp) )
 
456
                                {
 
457
                                        pix1 = pal[*sc++]; pix2 = pal[*sc++];
 
458
                                        *((uInt16 *)d) = pix1; d += pixelstep;
 
459
                                        *((uInt16 *)d) = OPTPIXAVERAGE(pix1,pix2); d += pixelstep;
 
460
                                        *((uInt16 *)d) = pix2; d += pixelstep;
 
461
                                        pix1 = pal[*sc++]; pix2 = pal[*sc++];
 
462
                                        *((uInt16 *)d) = pix1; d += pixelstep;
 
463
                                        *((uInt16 *)d) = OPTPIXAVERAGE(pix1,pix2); d += pixelstep;
 
464
                                        *((uInt16 *)d) = pix2; d += pixelstep;
 
465
                                }
 
466
                                else
 
467
                                {
 
468
                                        sc += 4;
 
469
                                        d += pixelsteptimes6;
 
470
                                }
 
471
                                sp += 4;
 
472
                        }
 
473
                        d = pl + linestep;
 
474
                        pl = d;
 
475
                }
 
476
        }
 
477
        else if (devres == QVGA && islandscape)
 
478
        {
 
479
                // 2/1
 
480
                for (y=0; y<minydim; y++)
 
481
                {
 
482
                        for (x=0; x<myWidthdiv4; x++)
 
483
                        {
 
484
                                if ( *((uInt32 *) sc) != *((uInt32 *) sp) )
 
485
                                {
 
486
                                        pix1 = pal[*sc++]; pix2 = pal[*sc++];
 
487
                                        *((uInt16 *)d) = pix1; d += pixelstep;
 
488
                                        *((uInt16 *)d) = OPTPIXAVERAGE(pix1,pix2); d += pixelstep;
 
489
                                        pix1 = pal[*sc++];
 
490
                                        *((uInt16 *)d) = pix2; d += pixelstep;
 
491
                                        *((uInt16 *)d) = OPTPIXAVERAGE(pix1,pix2); d += pixelstep;
 
492
                                        pix2 = pal[*sc++];
 
493
                                        *((uInt16 *)d) = pix1; d += pixelstep;
 
494
                                        *((uInt16 *)d) = OPTPIXAVERAGE(pix1,pix2); d += pixelstep;
 
495
                                        *((uInt16 *)d) = pix2; d += pixelstep;
 
496
                                        *((uInt16 *)d) = pix2; d += pixelstep;
 
497
                                }
 
498
                                else
 
499
                                {
 
500
                                        sc += 4;
 
501
                                        d += (pixelstep << 3);
 
502
                                }
 
503
                                sp += 4;
 
504
                        }
 
505
                        d = pl + linestep;
 
506
                        pl = d;
 
507
                }
 
508
        }
 
509
 
 
510
}
 
511
 
 
512
void FrameBufferWinCE::wipescreen(void)
 
513
{
 
514
        if (!SubsystemInited)
 
515
                lateinit();
 
516
 
 
517
        uInt8 *s = myOSystem->console().mediaSource().currentFrameBuffer();
 
518
        memset(s, 0, myWidth*myHeight-1);
 
519
        s = myOSystem->console().mediaSource().previousFrameBuffer();
 
520
        memset(s, 0, myWidth*myHeight-1);
 
521
 
 
522
        preFrameUpdate();
 
523
        //uInt8 *d;
 
524
        //d=myDstScreen;
 
525
        //for (int i=0; i < scrwidth*scrheight; i++, *((uInt16 *)d) = 0, d += scrpixelstep);
 
526
        memset(myDstScreen, 0, scrwidth*scrheight*2);
 
527
        postFrameUpdate();
 
528
}
 
529
 
 
530
void FrameBufferWinCE::postFrameUpdate()
 
531
{
 
532
        if (legacygapi) GXEndDraw();
 
533
}
 
534
 
 
535
void FrameBufferWinCE::drawChar(const GUI::Font* font, uInt8 c, uInt32 x, uInt32 y, OverlayColor color)
 
536
{
 
537
  GUI::Font* myfont = (GUI::Font*)font;
 
538
  const FontDesc& desc = myfont->desc();
 
539
 
 
540
  if (!myDstScreen) return;
 
541
 
 
542
  if(c < desc.firstchar || c >= desc.firstchar + desc.size)
 
543
  {
 
544
    if (c == ' ')
 
545
      return;
 
546
    c = desc.defaultchar;
 
547
  }
 
548
 
 
549
  Int32 w = myfont->getCharWidth(c);
 
550
  const Int32 h = myfont->getFontHeight();
 
551
  c -= desc.firstchar;
 
552
  const uInt16* tmp = desc.bits + (desc.offset ? desc.offset[c] : (c * h));
 
553
 
 
554
  if (x<0 || y<0 || (x>>1)+w>scrwidth || y+h>scrheight) return;
 
555
 
 
556
  uInt8 *d;
 
557
  uInt32 stride;
 
558
  if (devres == SM_LOW)
 
559
  {
 
560
          d = myDstScreen + y * scrlinestep + ((x+1) >> 1) * scrpixelstep;
 
561
          stride = (scrwidth - w) * scrpixelstep;
 
562
  }
 
563
  else
 
564
  {
 
565
          if (displaymode != 2)
 
566
                d = myDstScreen + (scrheight-x-1) * scrlinestep + (y-1) * scrpixelstep;
 
567
          else
 
568
                d = myDstScreen + x * scrlinestep + (scrwidth-y-1) * scrpixelstep;
 
569
  }
 
570
 
 
571
  uInt16 col = guipal[((int) color) - 256];
 
572
 
 
573
  for(int y2 = 0; y2 < h; y2++)
 
574
  {
 
575
    const uInt16 buffer = *tmp++;
 
576
        if (devres == SM_LOW)
 
577
        {
 
578
                uInt16 mask = 0xC000;
 
579
                for(int x2 = 0; x2 < w; x2++, mask >>= 2)
 
580
                {
 
581
                  if (buffer & mask)
 
582
                          *((uInt16 *)d) = col;
 
583
                  d += scrpixelstep;
 
584
                }
 
585
                d += stride;
 
586
        }
 
587
        else
 
588
        {
 
589
                uInt16 mask = 0x8000;
 
590
                uInt8 *tmp = d;
 
591
                for(int x2 = 0; x2 < w; x2++, mask >>= 1)
 
592
                {
 
593
                  if (buffer & mask)
 
594
                          *((uInt16 *)d) = col;
 
595
                  if (displaymode != 2)
 
596
                        d -= scrlinestep;
 
597
                  else
 
598
                        d += scrlinestep;
 
599
                }
 
600
                if (displaymode != 2)
 
601
                        d = tmp + scrpixelstep;
 
602
                else
 
603
                        d = tmp - scrpixelstep;
 
604
        }
 
605
  }
 
606
}
 
607
 
 
608
void FrameBufferWinCE::scanline(uInt32 row, uInt8* data)
 
609
{
 
610
        return;
 
611
}
 
612
 
 
613
void FrameBufferWinCE::setAspectRatio()
 
614
{
 
615
        return;
 
616
}
 
617
 
 
618
bool FrameBufferWinCE::createScreen()
 
619
{
 
620
        return true;
 
621
}
 
622
 
 
623
void FrameBufferWinCE::toggleFilter()
 
624
{
 
625
        return;
 
626
}
 
627
 
 
628
uInt32 FrameBufferWinCE::mapRGB(Uint8 r, Uint8 g, Uint8 b)
 
629
{
 
630
        return 0xFFFFFFFF;
 
631
}
 
632
 
 
633
void FrameBufferWinCE::hLine(uInt32 x, uInt32 y, uInt32 x2, OverlayColor color)
 
634
{
 
635
        if (devres == SM_LOW)
 
636
        {
 
637
                int kx = x >> 1; int ky = y; int kx2 = x2>> 1;
 
638
                if (kx<0) kx=0; if (ky<0) ky=0; if (ky>scrheight-1) return; if (kx2>scrwidth-1) kx2=scrwidth-1;
 
639
                PlothLine(kx, ky, kx2, color);
 
640
        }
 
641
        else
 
642
                if (displaymode != 2)
 
643
                        PlotvLine(y, scrheight-x, scrheight-x2-1, color);
 
644
                else
 
645
                        PlotvLine(scrwidth-y-1, x, x2+1, color);
 
646
}
 
647
 
 
648
void FrameBufferWinCE::PlothLine(uInt32 x, uInt32 y, uInt32 x2, OverlayColor color)
 
649
{
 
650
        if (!myDstScreen) return;
 
651
        if (x>x2) { x2 ^= x; x ^= x2; x2 ^= x;} //lazy swap
 
652
        uInt8 *d = myDstScreen + y * scrlinestep + x * scrpixelstep;
 
653
        uInt16 col = guipal[((int) color) - 256];
 
654
        for (;x < x2; x++, *((uInt16 *)d) = col, d += scrpixelstep);
 
655
}
 
656
 
 
657
void FrameBufferWinCE::vLine(uInt32 x, uInt32 y, uInt32 y2, OverlayColor color)
 
658
{
 
659
        if (devres == SM_LOW)
 
660
        {
 
661
                int kx = x >> 1; int ky = y; int ky2 = y2;
 
662
                if (kx<0) kx=0; if (ky<0) ky=0; if (kx>scrwidth-1) return; if (ky>scrheight-1) ky=scrheight-1; if (ky2>scrheight-1) ky2=scrheight-1;
 
663
                PlotvLine(kx, ky, ky2, color);
 
664
        }
 
665
        else
 
666
                if (displaymode != 2)
 
667
                        PlothLine(y, scrheight-x-1, y2, color);
 
668
                else
 
669
                        PlothLine(scrwidth-y, x, scrwidth-y2, color);
 
670
 
 
671
}
 
672
 
 
673
void FrameBufferWinCE::PlotvLine(uInt32 x, uInt32 y, uInt32 y2, OverlayColor color)
 
674
{
 
675
        if (y>y2) { y2 ^= y; y ^= y2; y2 ^= y;} //lazy swap
 
676
        if (!myDstScreen) return;
 
677
        uInt8 *d = myDstScreen + y * scrlinestep + x * scrpixelstep;
 
678
        uInt16 col = guipal[((int) color) - 256];
 
679
        for (;y < y2; y++, *((uInt16 *)d) = col, d += scrlinestep);
 
680
}
 
681
 
 
682
void FrameBufferWinCE::fillRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h, OverlayColor color)
 
683
{
 
684
        if (devres == SM_LOW)
 
685
        {
 
686
                int kx = x >> 1; int ky = y; int kw = (w >> 1); int kh = h;
 
687
                if (ky>scrheight-1) return; if (kx>scrwidth-1) return;
 
688
                if (kx<0) kx=0; if (ky<0) ky=0;if (kw<0) kw=0; if (kh<0) kh=0;
 
689
                if (kx+kw>scrwidth-1) kw=scrwidth-kx-1; if (ky+kh>scrheight-1) kh=scrheight-ky-1;
 
690
                PlotfillRect(kx, ky, kw, kh, color);
 
691
        }
 
692
        else
 
693
        {
 
694
                if (x>scrheight) return; if (y>scrwidth) return;
 
695
                if (x+w>scrheight) w=scrheight-x; if (y+h>scrwidth) h=scrwidth-y;
 
696
                if (displaymode != 2)
 
697
                        PlotfillRect(y, scrheight-x-w, h-1, w-1, color);
 
698
                else
 
699
                        PlotfillRect(scrwidth-y-h, x, h-1, w-1, color);
 
700
        }
 
701
 
 
702
}
 
703
 
 
704
void FrameBufferWinCE::PlotfillRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h, OverlayColor color)
 
705
{
 
706
        if (!myDstScreen) return;
 
707
        uInt8 *d = myDstScreen + y * scrlinestep + x * scrpixelstep;
 
708
        uInt16 col = guipal[((int) color) - 256];
 
709
        uInt32 stride = (scrwidth - w - 1) * scrpixelstep;
 
710
        for (h++; h != 0; h--, d += stride)
 
711
                for (int w2=w; w2>=0; w2--, *((uInt16 *)d) = col, d += scrpixelstep);
 
712
}
 
713
 
 
714
void FrameBufferWinCE::drawBitmap(uInt32* bitmap, Int32 x, Int32 y, OverlayColor color, Int32 h)
 
715
{
 
716
        return;
 
717
}
 
718
 
 
719
void FrameBufferWinCE::translateCoords(Int32* x, Int32* y)
 
720
{
 
721
        if (!issmartphone)
 
722
        {
 
723
                if ((displaymode == 1) || (displaymode==0 && myOSystem->eventHandler().state() != 1))
 
724
                {
 
725
                        Int32 x2 = *x;
 
726
                        *x = scrheight - *y;
 
727
                        *y = x2;
 
728
                }
 
729
                else if (displaymode == 2)
 
730
                {
 
731
                        Int32 x2 = *x;
 
732
                        *x = *y;
 
733
                        *y = scrwidth - x2;
 
734
                }
 
735
        }
 
736
        return;
 
737
}
 
738
 
 
739
void FrameBufferWinCE::addDirtyRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h)
 
740
{
 
741
        static bool initflag = false;
 
742
 
 
743
        if (myOSystem->eventHandler().state() == 3)
 
744
                initflag = true;
 
745
 
 
746
        if (myOSystem->eventHandler().state()==1 && initflag)
 
747
        {
 
748
                // TODO: optimize here
 
749
                theRedrawTIAIndicator = true;
 
750
        }
 
751
 
 
752
        return;
 
753
}
 
754
 
 
755
uInt32 FrameBufferWinCE::lineDim()
 
756
{
 
757
        return 1;
 
758
}
 
759
 
 
760