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
;
22 gi
= lmalloc(sizeof *gi
);
26 mi
= lmalloc(sizeof *mi
);
30 memset(&rm
, 0, sizeof rm
);
31 memset(gi
, 0, sizeof *gi
);
33 gi
->signature
= VBE2_MAGIC
; /* Get VBE2 extended data */
34 rm
.eax
.w
[0] = 0x4F00; /* Get SVGA general information */
35 rm
.edi
.w
[0] = OFFS(gi
);
37 __intcall(0x10, &rm
, &rm
);
39 if ( rm
.eax
.w
[0] != 0x004F )
40 goto out
; /* Function call failed */
41 if ( gi
->signature
!= VESA_MAGIC
) {
42 rv
= -2; /* No magic */
45 if ( gi
->version
< 0x0102 ) {
46 rv
= -3; /* VESA 1.2+ required */
50 lua_newtable(L
); /* list of modes */
52 /* Copy general info */
53 memcpy(&__vesa_info
.gi
, gi
, sizeof *gi
);
55 /* Search for a 640x480 mode with a suitable color and memory model... */
57 mode_ptr
= GET_PTR(gi
->video_mode_ptr
);
59 while ((mode
= *mode_ptr
++) != 0xFFFF) {
60 mode
&= 0x1FF; /* The rest are attributes of sorts */
62 printf("Found mode: 0x%04x (%dx%dx%d)\n", mode
, mi
->h_res
, mi
->v_res
, mi
->bpp
);
64 memset(mi
, 0, sizeof *mi
);
65 rm
.eax
.w
[0] = 0x4F01; /* Get SVGA mode information */
67 rm
.edi
.w
[0] = OFFS(mi
);
69 __intcall(0x10, &rm
, &rm
);
71 /* Must be a supported mode */
72 if ( rm
.eax
.w
[0] != 0x004f )
75 lua_pushnumber(L
, nmode
++);
76 lua_newtable(L
); /* mode info */
78 lua_pushstring(L
, "mode");
79 lua_pushnumber(L
, mode
);
82 lua_pushstring(L
, "hres");
83 lua_pushnumber(L
, mi
->h_res
);
86 lua_pushstring(L
, "vres");
87 lua_pushnumber(L
, mi
->v_res
);
90 lua_pushstring(L
, "bpp");
91 lua_pushnumber(L
, mi
->bpp
);
94 lua_settable(L
, -3); /* add to mode list */
106 static int vesa_setmode(lua_State
*L
)
108 /* Preventing GCC to complain about unused L*/
110 openconsole(&dev_rawcon_r
, &dev_vesaserial_w
);
116 static int vesa_load_background(lua_State
*L
)
118 const char *filename
= luaL_checkstring(L
, 1);
120 vesacon_load_background(filename
);
125 static const luaL_reg vesalib
[] = {
126 {"getmodes", vesa_getmodes
},
127 {"setmode", vesa_setmode
},
128 {"load_background", vesa_load_background
},
132 /* This defines a function that opens up your library. */
134 LUALIB_API
int luaopen_vesa (lua_State
*L
) {
135 luaL_openlib(L
, LUA_VESALIBNAME
, vesalib
, 0);