-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvp_sdl.c
More file actions
142 lines (120 loc) · 2.88 KB
/
vp_sdl.c
File metadata and controls
142 lines (120 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
* Copyright (C) yajin 2008 <yajinzhou@gmail.com >
*
* This file is part of the virtualmips distribution.
* See LICENSE file for terms of the license.
*
*/
#ifdef SIM_LCD
#include "vp_sdl.h"
#include <signal.h>
SDL_Surface *screen;
SDL_Event ev;
static void sdl_update (DisplayState * ds, int x, int y, int w, int h)
{
SDL_UpdateRect (screen, x, y, w, h);
}
static void sdl_resize (DisplayState * ds, int w, int h)
{
int flags;
// printf("resizing to %d %d\n", w, h);
flags = SDL_HWSURFACE | SDL_ASYNCBLIT | SDL_HWACCEL;
again:
screen = SDL_SetVideoMode (w, h, ds->depth, flags);
if (!screen) {
fprintf (stderr, "Could not open SDL display\n");
exit (1);
}
if (!screen->pixels && (flags & SDL_HWSURFACE)
&& (flags & SDL_FULLSCREEN)) {
flags &= ~SDL_HWSURFACE;
goto again;
}
if (!screen->pixels) {
fprintf (stderr, "Could not open SDL display\n");
exit (1);
}
ds->data = screen->pixels;
ds->linesize = screen->pitch;
//ds->depth = screen->format->BitsPerPixel;
if (ds->depth == 32 && screen->format->Rshift == 0) {
ds->bgr = 1;
} else {
ds->bgr = 0;
}
}
SDL_Event *sdl_getmouse_down ()
{
if (SDL_PollEvent (&ev)) {
if (ev.type == SDL_MOUSEBUTTONDOWN) {
return &ev;
}
}
return NULL;
}
SDL_Event *sdl_getmouse_up ()
{
if (SDL_PollEvent (&ev)) {
if (ev.type == SDL_MOUSEBUTTONUP) {
return &ev;
}
}
return NULL;
}
static void sdl_refresh (DisplayState * ds)
{
}
static void sdl_update_caption (void)
{
char buf[1024];
strcpy (buf, "VirtualMIPS");
SDL_WM_SetCaption (buf, "");
}
/*
loading VirtualMIPS logo.
A bit ugly logo.
Sorry CNN, I have not learned how to ps pictures. Please forgive me.
*/
static void sdl_display_logo (void)
{
SDL_Surface *image;
SDL_Rect dest;
image = SDL_LoadBMP ("logo.bmp");
if (image == NULL) {
fprintf (stderr, "can not load logo logo.bmp: %s\n", SDL_GetError ());
return;
}
dest.x = 0;
dest.y = 0;
dest.w = image->w;
dest.h = image->h;
SDL_BlitSurface (image, NULL, screen, &dest);
SDL_UpdateRects (screen, 1, &dest);
}
static void sdl_cleanup (void)
{
printf ("SDL Clean \n");
SDL_Quit ();
}
void sdl_display_init (DisplayState * ds, int full_screen)
{
int flags;
flags = SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE;
if (SDL_Init (flags)) {
fprintf (stderr, "Could not initialize SDL - exiting\n");
exit (1);
}
#ifndef _WIN32
signal (SIGINT, SIG_DFL);
signal (SIGQUIT, SIG_DFL);
#endif
ds->dpy_update = sdl_update;
ds->dpy_resize = sdl_resize;
ds->dpy_refresh = sdl_refresh;
sdl_resize (ds, ds->width, ds->height);
sdl_update_caption ();
sdl_display_logo ();
SDL_EnableUNICODE (1);
atexit (sdl_cleanup);
}
#endif