4 * This work is licensed under the terms of the GNU GPLv2 or later.
5 * See the COPYING file in the top-level directory.
13 #include <sys/types.h>
18 #include "plugin_lib.h"
19 #include "linux/fbdev.h"
20 #include "common/fonts.h"
21 #include "common/input.h"
25 #include "../libpcsxcore/new_dynarec/new_dynarec.h"
29 static int pl_fbdev_w, pl_fbdev_h, pl_fbdev_bpp;
30 static int flip_cnt, flips_per_sec, tick_per_sec;
31 extern float fps_cur; // XXX
33 static int get_cpu_ticks(void)
35 static unsigned long last_utime;
37 unsigned long utime, ret;
41 fd = open("/proc/self/stat", O_RDONLY);
42 lseek(fd, 0, SEEK_SET);
44 read(fd, buf, sizeof(buf));
45 buf[sizeof(buf) - 1] = 0;
47 sscanf(buf, "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %lu", &utime);
48 ret = utime - last_utime;
53 static void print_fps(void)
55 if (pl_fbdev_bpp == 16)
56 pl_text_out16(2, pl_fbdev_h - 10, "%2d %4.1f", flips_per_sec, fps_cur);
59 static void print_cpu_usage(void)
61 if (pl_fbdev_bpp == 16)
62 pl_text_out16(pl_fbdev_w - 28, pl_fbdev_h - 10, "%3d", tick_per_sec);
65 void *pl_fbdev_set_mode(int w, int h, int bpp)
69 if (w == pl_fbdev_w && h == pl_fbdev_h && bpp == pl_fbdev_bpp)
76 vout_fbdev_clear(layer_fb);
77 ret = vout_fbdev_resize(layer_fb, w, h, bpp, 0, 0, 0, 0, 3);
79 fprintf(stderr, "failed to set mode\n");
83 menu_notify_mode_change(w, h, bpp);
88 void *pl_fbdev_flip(void)
92 if (pl_fbdev_buf != NULL) {
93 if (g_opts & OPT_SHOWFPS)
95 if (g_opts & OPT_SHOWCPU)
100 pl_fbdev_buf = vout_fbdev_flip(layer_fb);
104 int pl_fbdev_open(void)
106 pl_fbdev_buf = vout_fbdev_flip(layer_fb);
107 omap_enable_layer(1);
111 void pl_fbdev_close(void)
113 omap_enable_layer(0);
116 static void update_input(void)
118 int actions[IN_BINDTYPE_COUNT] = { 0, };
121 if (actions[IN_BINDTYPE_EMU] & PEV_MENU)
123 keystate = actions[IN_BINDTYPE_PLAYER12];
126 extern void x11_update_keys(void);
131 /* called on every vsync */
132 void pl_frame_limit(void)
134 extern void CheckFrameRate(void);
138 /* doing input here because the pad is polled
139 * thousands of times per frame for some reason */
143 gettimeofday(&tv, 0);
145 if (tv.tv_sec != oldsec) {
146 flips_per_sec = flip_cnt;
149 if (g_opts & OPT_SHOWCPU)
150 tick_per_sec = get_cpu_ticks();
153 static int ya_vsync_count;
154 if (++ya_vsync_count == PCNT_FRAMES) {
162 pcnt_start(PCNT_ALL);
165 static void pl_text_out16_(int x, int y, const char *text)
167 int i, l, len = strlen(text), w = pl_fbdev_w;
168 unsigned short *screen = (unsigned short *)pl_fbdev_buf + x + y * w;
169 unsigned short val = 0xffff;
171 for (i = 0; i < len; i++, screen += 8)
173 for (l = 0; l < 8; l++)
175 unsigned char fd = fontdata8x8[text[i] * 8 + l];
176 unsigned short *s = screen + l * w;
177 if (fd&0x80) s[0] = val;
178 if (fd&0x40) s[1] = val;
179 if (fd&0x20) s[2] = val;
180 if (fd&0x10) s[3] = val;
181 if (fd&0x08) s[4] = val;
182 if (fd&0x04) s[5] = val;
183 if (fd&0x02) s[6] = val;
184 if (fd&0x01) s[7] = val;
189 void pl_text_out16(int x, int y, const char *texto, ...)
194 va_start(args, texto);
195 vsnprintf(buffer, sizeof(buffer), texto, args);
198 pl_text_out16_(x, y, buffer);
201 static void pl_get_layer_pos(int *x, int *y, int *w, int *h)
209 extern int UseFrameSkip; // hmh
211 const struct rearmed_cbs pl_rearmed_cbs = {