2 #include <ui/display.h>
10 #define SDL_PRIV(d) ((struct sdl_display*)(d)->priv)
12 #define REFRESH_INTERVAL_MSEC 50
22 static Uint32 sdl_redraw_callback(Uint32 interval, void *param) {
23 struct display *display = (struct display*)param;
25 display->draw(display);
31 sdl_init(struct display *display,
32 unsigned width, unsigned height, unsigned scale)
34 if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER)) {
35 printf("Failed to initialize SDL: %s\n", SDL_GetError());
41 struct sdl_display *priv = SDL_PRIV(display);
44 priv->height = height;
47 priv->display = SDL_SetVideoMode(width * scale, height * scale, 32, 0);
49 printf("Failed to set SDL video mode: %s\n", SDL_GetError());
53 priv->refresh = SDL_AddTimer(REFRESH_INTERVAL_MSEC,
54 &sdl_redraw_callback, display);
56 printf("Failed to add refresh timer: %s\n", SDL_GetError());
62 sdl_draw(struct display *display)
64 struct sdl_display *priv = SDL_PRIV(display);
66 struct image *img = display->fbuf;
73 if(img->type == PXTYPE_RGB444) {
74 unsigned stride = img->size.w * 2;
77 for(y = 0; y < img->size.h; y++) {
78 for(x = 0; x < img->size.w; x++) {
79 px_t color = image_get_pixel(img, x, y);
81 r.x = x * priv->scale;
82 r.y = y * priv->scale;
84 SDL_FillRect(priv->display, &r, color);
88 puts("Unsupported framebuffer type for SDL emulator.");
92 SDL_UpdateRect(priv->display, 0, 0, 0, 0);
96 static struct sdl_display display_sdl_priv;
98 uint8_t sdl_fbuf[96*64*2];
100 struct image display_sdl_fbuf = {
101 .type = PXTYPE_RGB444,
106 struct display display_sdl = {
107 .name = "Main Display",
108 .fbuf = &display_sdl_fbuf,
109 .priv = &display_sdl_priv,
113 uint16_t fnord_buf[] = {
149 struct image fnord = {
150 .type = PXTYPE_RGB444,
155 uint8_t fubar_img[] = {
156 0x01, 0x02, 0x03, 0x04,
157 0x05, 0x06, 0x07, 0x08,
158 0x09, 0x0a, 0x0b, 0x0c,
159 0x0d, 0x0e, 0x0f, 0x0f
163 struct image fubar = {
164 .type = PXTYPE_MONO_V8,
175 while((r = SDL_WaitEvent(&e))) {
177 if(e.type == SDL_KEYDOWN) {
178 if(e.key.keysym.sym == SDLK_ESCAPE) {
179 puts("Bloody quitter!");
182 if(e.key.keysym.sym == SDLK_SPACE) {
187 image_blit(&display_sdl_fbuf, dp,
198 image_blit(&display_sdl_fbuf, dp,
202 pxrect_t r = {{12,0},{40,20}};
203 image_fill_rect(&display_sdl_fbuf,
212 image_draw_string(&display_sdl_fbuf, dp,
217 image_draw_string(&display_sdl_fbuf, dp,
222 sdl_draw(&display_sdl);
230 printf("Key %d %d\n", e.key.keysym.sym, e.key.state);
236 printf("Failed to wait for SDL event: %s\n", SDL_GetError());
245 sdl_init(&display_sdl, 96, 64, 4);