pull in more code from PicoDrive
[pcsx_rearmed.git] / plugins / dfxvideo / draw_fb.c
1 /*
2  * (C) notaz, 2010
3  *
4  * This work is licensed under the terms of the GNU GPLv2 or later.
5  * See the COPYING file in the top-level directory.
6  */
7
8 #define _IN_DRAW
9
10 #include "externals.h"
11 #include "gpu.h"
12 #include "draw.h"
13 #include "prim.h"
14 #include "menu.h"
15 #include "interp.h"
16 #include "swap.h"
17
18 #include "plugin_lib.h"
19
20 // misc globals
21 int            iResX;
22 int            iResY;
23 long           lLowerpart;
24 BOOL           bIsFirstFrame = TRUE;
25 BOOL           bCheckMask = FALSE;
26 unsigned short sSetMask = 0;
27 unsigned long  lSetMask = 0;
28 int            iDesktopCol = 16;
29 int            iShowFPS = 0;
30 int            iWinSize; 
31 int            iMaintainAspect = 0;
32 int            iUseNoStretchBlt = 0;
33 int            iFastFwd = 0;
34 int            iFVDisplay = 0;
35 PSXPoint_t     ptCursorPoint[8];
36 unsigned short usCursorActive = 0;
37 char *         pCaptionText;
38
39 #ifndef __arm__
40 #define bgr555_to_rgb565 memcpy
41 #define bgr888_to_rgb888 memcpy
42 #endif
43
44 static void blit(void)
45 {
46  extern void bgr555_to_rgb565(void *dst, void *src, int bytes);
47  extern void bgr888_to_rgb888(void *dst, void *src, int bytes);
48  int x = PSXDisplay.DisplayPosition.x;
49  int y = PSXDisplay.DisplayPosition.y;
50  int w = PreviousPSXDisplay.Range.x1;
51  int h = PreviousPSXDisplay.DisplayMode.y;
52  int pitch = PreviousPSXDisplay.DisplayMode.x;
53  unsigned short *srcs = psxVuw + y * 1024 + x;
54  unsigned char *dest = pl_fbdev_buf;
55
56  if (w <= 0)
57    return;
58
59  // TODO: clear border if centering
60
61  pitch *= PSXDisplay.RGB24 ? 3 : 2;
62
63  // account for centering
64  h -= PreviousPSXDisplay.Range.y0;
65  dest += PreviousPSXDisplay.Range.y0 / 2 * pitch;
66  dest += PreviousPSXDisplay.Range.x0 * 2; // XXX
67
68  if (PSXDisplay.RGB24)
69  {
70    for (; h-- > 0; dest += pitch, srcs += 1024)
71    {
72      bgr888_to_rgb888(dest, srcs, w * 3);
73    }
74  }
75  else
76  {
77    for (; h-- > 0; dest += pitch, srcs += 1024)
78    {
79      bgr555_to_rgb565(dest, srcs, w * 2);
80    }
81  }
82 }
83
84 static int fbw, fbh, fb24bpp;
85
86 #include "pcnt.h"
87
88 void DoBufferSwap(void)
89 {
90  static int fps_counter;
91  if (PSXDisplay.DisplayMode.x == 0 || PSXDisplay.DisplayMode.y == 0)
92   return;
93
94  if (PSXDisplay.DisplayMode.x != fbw || PSXDisplay.DisplayMode.y != fbh
95      || PSXDisplay.RGB24 != fb24bpp) {
96   fbw = PSXDisplay.DisplayMode.x;
97   fbh = PSXDisplay.DisplayMode.y;
98   fb24bpp = PSXDisplay.RGB24;
99   pl_fbdev_set_mode(fbw, fbh, fb24bpp ? 24 : 16);
100  }
101
102  blit();
103  pl_fbdev_flip();
104
105  pcnt_end(PCNT_ALL);
106
107  if (++fps_counter == 60/6) {
108   //printf("%2.1f\n", fps_cur);
109   pcnt_print(fps_cur);
110   fps_counter = 0;
111  }
112
113  pcnt_start(PCNT_ALL);
114 }
115
116 void DoClearScreenBuffer(void)                         // CLEAR DX BUFFER
117 {
118 }
119
120 void DoClearFrontBuffer(void)                          // CLEAR DX BUFFER
121 {
122 }
123
124 static int initialize(void)
125 {
126  iDesktopCol=32;
127
128  bUsingTWin=FALSE;
129  bIsFirstFrame = FALSE;                                // done
130
131  if(iShowFPS)
132   {
133    iShowFPS=0;
134    ulKeybits|=KEY_SHOWFPS;
135    szDispBuf[0]=0;
136    BuildDispMenu(0);
137   }
138
139  return 0;
140 }
141
142 unsigned long ulInitDisplay(void)
143 {
144  iShowFPS=1;
145  initialize();
146
147  if (pl_fbdev_init() != 0)
148   return 0;
149
150  return 1; /* ok */
151 }
152
153 void CloseDisplay(void)
154 {
155  CloseMenu();
156  pl_fbdev_finish();
157  //WriteConfig();
158 }
159
160 void CreatePic(unsigned char * pMem)
161 {
162 }
163
164 void DestroyPic(void)
165 {
166 }
167
168 void HandleKey(int keycode)
169 {
170 }