7 #include "../../include/console.h"
8 #include "../../lib/sys/vesa/vesa.h"
9 #include "../../lib/sys/vesa/video.h"
11 int vesacon_load_background(const char *filename);
13 static int vesa_getmodes(lua_State *L)
16 uint16_t mode, *mode_ptr;
17 struct vesa_general_info *gi;
18 struct vesa_mode_info *mi;
21 /* Allocate space in the bounce buffer for these structures */
22 gi = &((struct vesa_info *)__com32.cs_bounce)->gi;
23 mi = &((struct vesa_info *)__com32.cs_bounce)->mi;
25 memset(&rm, 0, sizeof rm);
26 memset(gi, 0, sizeof *gi);
28 gi->signature = VBE2_MAGIC; /* Get VBE2 extended data */
29 rm.eax.w[0] = 0x4F00; /* Get SVGA general information */
30 rm.edi.w[0] = OFFS(gi);
32 __intcall(0x10, &rm, &rm);
34 if ( rm.eax.w[0] != 0x004F )
35 return -1; /* Function call failed */
36 if ( gi->signature != VESA_MAGIC )
37 return -2; /* No magic */
38 if ( gi->version < 0x0102 )
39 return -3; /* VESA 1.2+ required */
41 lua_newtable(L); /* list of modes */
43 /* Copy general info */
44 memcpy(&__vesa_info.gi, gi, sizeof *gi);
46 /* Search for a 640x480 mode with a suitable color and memory model... */
48 mode_ptr = GET_PTR(gi->video_mode_ptr);
50 while ((mode = *mode_ptr++) != 0xFFFF) {
51 mode &= 0x1FF; /* The rest are attributes of sorts */
53 printf("Found mode: 0x%04x (%dx%dx%d)\n", mode, mi->h_res, mi->v_res, mi->bpp);
55 memset(mi, 0, sizeof *mi);
56 rm.eax.w[0] = 0x4F01; /* Get SVGA mode information */
58 rm.edi.w[0] = OFFS(mi);
60 __intcall(0x10, &rm, &rm);
62 /* Must be a supported mode */
63 if ( rm.eax.w[0] != 0x004f )
66 lua_pushnumber(L, nmode++);
67 lua_newtable(L); /* mode info */
69 lua_pushstring(L, "mode");
70 lua_pushnumber(L, mode);
73 lua_pushstring(L, "hres");
74 lua_pushnumber(L, mi->h_res);
77 lua_pushstring(L, "vres");
78 lua_pushnumber(L, mi->v_res);
81 lua_pushstring(L, "bpp");
82 lua_pushnumber(L, mi->bpp);
85 lua_settable(L, -3); /* add to mode list */
93 static int vesa_setmode(lua_State *L)
95 /* Preventing GCC to complain about unused L*/
97 openconsole(&dev_rawcon_r, &dev_vesaserial_w);
103 static int vesa_load_background(lua_State *L)
105 const char *filename = luaL_checkstring(L, 1);
107 vesacon_load_background(filename);
112 static const luaL_reg vesalib[] = {
113 {"getmodes", vesa_getmodes},
114 {"setmode", vesa_setmode},
115 {"load_background", vesa_load_background},
119 /* This defines a function that opens up your library. */
121 LUALIB_API int luaopen_vesa (lua_State *L) {
122 luaL_openlib(L, LUA_VESALIBNAME, vesalib, 0);