Since window is singleton anyway, get rid of window* parameters
[lsnes.git] / framebuffer.cpp
blobec2d9a3b279465a6dc9fcc6c7b0ca58f422c8b7b
1 #include "framebuffer.hpp"
2 #include "lua.hpp"
3 #include "window.hpp"
4 #include "render.hpp"
6 lcscreen framebuffer;
7 lcscreen screen_nosignal;
8 lcscreen screen_corrupt;
9 extern uint32_t fontdata[];
11 namespace
13 struct render_list_entry
15 uint32_t codepoint;
16 uint32_t x;
17 uint32_t y;
18 uint32_t scale;
21 struct render_list_entry rl_nosignal[] = {
22 {'N', 4, 168, 7},
23 {'O', 60, 168, 7},
24 {'S', 172, 168, 7},
25 {'I', 228, 168, 7},
26 {'G', 284, 168, 7},
27 {'N', 340, 168, 7},
28 {'A', 396, 168, 7},
29 {'L', 452, 168, 7},
30 {0, 0, 0, 0}
33 struct render_list_entry rl_corrupt[] = {
34 {'S', 88, 56, 7},
35 {'Y', 144, 56, 7},
36 {'S', 200, 56, 7},
37 {'T', 256, 56, 7},
38 {'E', 312, 56, 7},
39 {'M', 368, 56, 7},
40 {'S', 116, 168, 7},
41 {'T', 172, 168, 7},
42 {'A', 224, 168, 7},
43 {'T', 280, 168, 7},
44 {'E', 336, 168, 7},
45 {'C', 60, 280, 7},
46 {'O', 116, 280, 7},
47 {'R', 172, 280, 7},
48 {'R', 228, 280, 7},
49 {'U', 284, 280, 7},
50 {'P', 340, 280, 7},
51 {'T', 396, 280, 7},
52 {0, 0, 0, 0}
55 void draw_special_screen(uint16_t* target, struct render_list_entry* rlist)
57 while(rlist->scale) {
58 int32_t x;
59 int32_t y;
60 auto g = find_glyph(rlist->codepoint, 0, 0, 0, x, y);
61 for(uint32_t j = 0; j < 16; j++) {
62 for(uint32_t i = 0; i < 8; i++) {
63 uint32_t slice = g.second + j / 4;
64 uint32_t bit = 31 - ((j % 4) * 8 + i);
65 uint32_t value = (fontdata[slice] >> bit) & 1;
66 if(value) {
67 uint32_t basex = rlist->x + rlist->scale * i;
68 uint32_t basey = rlist->y + rlist->scale * j;
69 for(uint32_t j2 = 0; j2 < rlist->scale; j2++)
70 for(uint32_t i2 = 0; i2 < rlist->scale; i2++)
71 target[(basey + j2) * 512 + (basex + i2)] = 0x7FFF;
75 rlist++;
79 void draw_nosignal(uint16_t* target)
81 for(unsigned i = 0; i < 512 * 448; i++)
82 target[i] = 0x1F;
83 draw_special_screen(target, rl_nosignal);
86 void draw_corrupt(uint16_t* target)
88 for(unsigned i = 0; i < 512 * 448; i++)
89 target[i] = 0x1F;
90 draw_special_screen(target, rl_corrupt);
94 screen main_screen;
97 void init_special_screens() throw(std::bad_alloc)
99 uint16_t buf[512*448];
100 draw_nosignal(buf);
101 screen_nosignal = lcscreen(buf, 512, 448);
102 draw_corrupt(buf);
103 screen_corrupt = lcscreen(buf, 512, 448);
106 void redraw_framebuffer()
108 uint32_t hscl = 1, vscl = 1;
109 if(framebuffer.width < 512)
110 hscl = 2;
111 if(framebuffer.height < 400)
112 vscl = 2;
113 render_queue rq;
114 struct lua_render_context lrc;
115 lrc.left_gap = 0;
116 lrc.right_gap = 0;
117 lrc.bottom_gap = 0;
118 lrc.top_gap = 0;
119 lrc.queue = &rq;
120 lrc.width = framebuffer.width * hscl;
121 lrc.height = framebuffer.height * vscl;
122 lrc.rshift = main_screen.active_rshift;
123 lrc.gshift = main_screen.active_gshift;
124 lrc.bshift = main_screen.active_bshift;
125 lua_callback_do_paint(&lrc);
126 main_screen.reallocate(framebuffer.width * hscl + lrc.left_gap + lrc.right_gap, framebuffer.height * vscl +
127 lrc.top_gap + lrc.bottom_gap, lrc.left_gap, lrc.top_gap);
128 main_screen.copy_from(framebuffer, hscl, vscl);
129 //We would want divide by 2, but we'll do it ourselves in order to do mouse.
130 window::set_window_compensation(lrc.left_gap, lrc.top_gap, 1, 1);
131 rq.run(main_screen);
132 window::notify_screen_update();