b60f2812 |
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 | |
69af03a2 |
39 | static int fbw, fbh, fb24bpp; |
40 | static int flip_cnt, flips_per_sec; |
41 | |
a327967e |
42 | #ifndef __arm__ |
43 | #define bgr555_to_rgb565 memcpy |
1972732a |
44 | #define bgr888_to_rgb888 memcpy |
a327967e |
45 | #endif |
b60f2812 |
46 | |
47 | static void blit(void) |
48 | { |
a327967e |
49 | extern void bgr555_to_rgb565(void *dst, void *src, int bytes); |
1972732a |
50 | extern void bgr888_to_rgb888(void *dst, void *src, int bytes); |
d352cde2 |
51 | int x = PSXDisplay.DisplayPosition.x & ~3; // XXX: align needed by bgr*_to_... |
b60f2812 |
52 | int y = PSXDisplay.DisplayPosition.y; |
53 | int w = PreviousPSXDisplay.Range.x1; |
54 | int h = PreviousPSXDisplay.DisplayMode.y; |
1972732a |
55 | int pitch = PreviousPSXDisplay.DisplayMode.x; |
56 | unsigned short *srcs = psxVuw + y * 1024 + x; |
b60f2812 |
57 | unsigned char *dest = pl_fbdev_buf; |
58 | |
a327967e |
59 | if (w <= 0) |
60 | return; |
61 | |
b60f2812 |
62 | // TODO: clear border if centering |
63 | |
1972732a |
64 | pitch *= PSXDisplay.RGB24 ? 3 : 2; |
65 | |
b60f2812 |
66 | // account for centering |
67 | h -= PreviousPSXDisplay.Range.y0; |
68 | dest += PreviousPSXDisplay.Range.y0 / 2 * pitch; |
69 | dest += PreviousPSXDisplay.Range.x0 * 2; // XXX |
70 | |
1972732a |
71 | if (PSXDisplay.RGB24) |
72 | { |
73 | for (; h-- > 0; dest += pitch, srcs += 1024) |
74 | { |
75 | bgr888_to_rgb888(dest, srcs, w * 3); |
76 | } |
77 | } |
78 | else |
b60f2812 |
79 | { |
b60f2812 |
80 | for (; h-- > 0; dest += pitch, srcs += 1024) |
81 | { |
a327967e |
82 | bgr555_to_rgb565(dest, srcs, w * 2); |
b60f2812 |
83 | } |
69af03a2 |
84 | pl_text_out16(2, fbh - 10, "%2d %2.1f", flips_per_sec, fps_cur); |
b60f2812 |
85 | } |
86 | } |
87 | |
14dffdb7 |
88 | #include "pcnt.h" |
89 | |
b60f2812 |
90 | void DoBufferSwap(void) |
91 | { |
14dffdb7 |
92 | static int fps_counter; |
b60f2812 |
93 | if (PSXDisplay.DisplayMode.x == 0 || PSXDisplay.DisplayMode.y == 0) |
94 | return; |
95 | |
d352cde2 |
96 | /* careful if rearranging this code, we try to set mode and flip |
97 | * to get the hardware apply both changes at the same time */ |
b60f2812 |
98 | if (PSXDisplay.DisplayMode.x != fbw || PSXDisplay.DisplayMode.y != fbh |
99 | || PSXDisplay.RGB24 != fb24bpp) { |
100 | fbw = PSXDisplay.DisplayMode.x; |
101 | fbh = PSXDisplay.DisplayMode.y; |
102 | fb24bpp = PSXDisplay.RGB24; |
103 | pl_fbdev_set_mode(fbw, fbh, fb24bpp ? 24 : 16); |
104 | } |
105 | |
b60f2812 |
106 | blit(); |
107 | pl_fbdev_flip(); |
14dffdb7 |
108 | |
109 | pcnt_end(PCNT_ALL); |
110 | |
69af03a2 |
111 | { |
112 | static int oldsec; |
113 | struct timeval tv; |
114 | flip_cnt++; |
115 | gettimeofday(&tv, 0); |
116 | if (tv.tv_sec != oldsec) { |
117 | flips_per_sec = flip_cnt; |
118 | flip_cnt = 0; |
119 | oldsec = tv.tv_sec; |
120 | } |
121 | } |
14dffdb7 |
122 | if (++fps_counter == 60/6) { |
14dffdb7 |
123 | pcnt_print(fps_cur); |
124 | fps_counter = 0; |
125 | } |
126 | |
127 | pcnt_start(PCNT_ALL); |
b60f2812 |
128 | } |
129 | |
130 | void DoClearScreenBuffer(void) // CLEAR DX BUFFER |
131 | { |
132 | } |
133 | |
134 | void DoClearFrontBuffer(void) // CLEAR DX BUFFER |
135 | { |
136 | } |
137 | |
138 | static int initialize(void) |
139 | { |
140 | iDesktopCol=32; |
141 | |
142 | bUsingTWin=FALSE; |
143 | bIsFirstFrame = FALSE; // done |
144 | |
145 | if(iShowFPS) |
146 | { |
147 | iShowFPS=0; |
148 | ulKeybits|=KEY_SHOWFPS; |
149 | szDispBuf[0]=0; |
150 | BuildDispMenu(0); |
151 | } |
152 | |
153 | return 0; |
154 | } |
155 | |
156 | unsigned long ulInitDisplay(void) |
157 | { |
158 | iShowFPS=1; |
159 | initialize(); |
160 | |
161 | if (pl_fbdev_init() != 0) |
162 | return 0; |
163 | |
164 | return 1; /* ok */ |
165 | } |
166 | |
167 | void CloseDisplay(void) |
168 | { |
169 | CloseMenu(); |
170 | pl_fbdev_finish(); |
14dffdb7 |
171 | //WriteConfig(); |
b60f2812 |
172 | } |
173 | |
174 | void CreatePic(unsigned char * pMem) |
175 | { |
176 | } |
177 | |
178 | void DestroyPic(void) |
179 | { |
180 | } |
181 | |
182 | void HandleKey(int keycode) |
183 | { |
184 | } |