3 #include "kvm/framebuffer.h"
12 static u8 keymap
[255] = {
25 [22] = 0x66, /* <backspace> */
38 [36] = 0x5a, /* <enter> */
50 [50] = 0x12, /* <left shift> */
64 [62] = 0x59, /* <right shift> */
65 [65] = 0x29, /* <space> */
68 static u8
to_code(u8 scancode
)
70 return keymap
[scancode
];
73 static void *sdl__thread(void *p
)
75 Uint32 rmask
, gmask
, bmask
, amask
;
76 struct framebuffer
*fb
= p
;
77 SDL_Surface
*guest_screen
;
82 if (SDL_Init(SDL_INIT_VIDEO
) != 0)
83 die("Unable to initialize SDL");
90 guest_screen
= SDL_CreateRGBSurfaceFrom(fb
->mem
, fb
->width
, fb
->height
, fb
->depth
, fb
->width
* fb
->depth
/ 8, rmask
, gmask
, bmask
, amask
);
92 die("Unable to create SDL RBG surface");
94 flags
= SDL_HWSURFACE
| SDL_ASYNCBLIT
| SDL_HWACCEL
| SDL_DOUBLEBUF
;
96 screen
= SDL_SetVideoMode(fb
->width
, fb
->height
, fb
->depth
, flags
);
98 die("Unable to set SDL video mode");
101 SDL_BlitSurface(guest_screen
, NULL
, screen
, NULL
);
104 while (SDL_PollEvent(&ev
)) {
107 u8 code
= to_code(ev
.key
.keysym
.scancode
);
111 pr_warning("key '%d' not found in keymap", ev
.key
.keysym
.scancode
);
115 u8 code
= to_code(ev
.key
.keysym
.scancode
);
127 SDL_Delay(1000 / FRAME_RATE
);
133 static int sdl__start(struct framebuffer
*fb
)
137 if (pthread_create(&thread
, NULL
, sdl__thread
, fb
) != 0)
143 static struct fb_target_operations sdl_ops
= {
147 void sdl__init(struct framebuffer
*fb
)
149 fb__attach(fb
, &sdl_ops
);