luajitos

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

vesa.h (6704B)


      1 #ifndef VESA_H
      2 #define VESA_H
      3 
      4 #include <stdint.h>
      5 #include <lua.h>
      6 
      7 /* VESA VBE 2.0+ structures and constants */
      8 
      9 /* VBE Function Numbers (for INT 0x10) */
     10 #define VBE_FUNCTION_CONTROLLER_INFO    0x4F00
     11 #define VBE_FUNCTION_MODE_INFO          0x4F01
     12 #define VBE_FUNCTION_SET_MODE           0x4F02
     13 #define VBE_FUNCTION_GET_MODE           0x4F03
     14 #define VBE_FUNCTION_SAVE_RESTORE       0x4F04
     15 
     16 /* VBE Mode Attributes */
     17 #define VBE_MODE_SUPPORTED              (1 << 0)
     18 #define VBE_MODE_TTY                    (1 << 2)
     19 #define VBE_MODE_COLOR                  (1 << 3)
     20 #define VBE_MODE_GRAPHICS               (1 << 4)
     21 #define VBE_MODE_NOT_VGA_COMPATIBLE     (1 << 5)
     22 #define VBE_MODE_NO_VGA_WINDOW          (1 << 6)
     23 #define VBE_MODE_LINEAR_FRAMEBUFFER     (1 << 7)
     24 
     25 /* VBE Mode Flags */
     26 #define VBE_USE_LINEAR_FRAMEBUFFER      (1 << 14)
     27 #define VBE_DONT_CLEAR_DISPLAY          (1 << 15)
     28 
     29 /* VBE Memory Models */
     30 #define VBE_MEMORY_MODEL_TEXT           0x00
     31 #define VBE_MEMORY_MODEL_CGA            0x01
     32 #define VBE_MEMORY_MODEL_HERCULES       0x02
     33 #define VBE_MEMORY_MODEL_PLANAR         0x03
     34 #define VBE_MEMORY_MODEL_PACKED_PIXEL   0x04
     35 #define VBE_MEMORY_MODEL_NON_CHAIN4     0x05
     36 #define VBE_MEMORY_MODEL_DIRECT_COLOR   0x06
     37 #define VBE_MEMORY_MODEL_YUV            0x07
     38 
     39 /* VBE Controller Information Block */
     40 typedef struct {
     41     char signature[4];           // "VESA" or "VBE2"
     42     uint16_t version;            // VBE version (0x0300 for VBE 3.0)
     43     uint32_t oem_string_ptr;     // Pointer to OEM string
     44     uint32_t capabilities;       // Capabilities flags
     45     uint32_t video_mode_ptr;     // Pointer to video mode list
     46     uint16_t total_memory;       // Total memory in 64KB blocks
     47     uint16_t oem_software_rev;   // OEM software revision
     48     uint32_t oem_vendor_name_ptr;
     49     uint32_t oem_product_name_ptr;
     50     uint32_t oem_product_rev_ptr;
     51     uint8_t reserved[222];       // Reserved for future use
     52     uint8_t oem_data[256];       // OEM-specific data
     53 } __attribute__((packed)) vbe_controller_info_t;
     54 
     55 /* VBE Mode Information Block */
     56 typedef struct {
     57     // Mandatory information
     58     uint16_t attributes;         // Mode attributes
     59     uint8_t window_a;            // Window A attributes
     60     uint8_t window_b;            // Window B attributes
     61     uint16_t granularity;        // Window granularity in KB
     62     uint16_t window_size;        // Window size in KB
     63     uint16_t segment_a;          // Window A segment
     64     uint16_t segment_b;          // Window B segment
     65     uint32_t win_func_ptr;       // Real mode pointer to window function
     66     uint16_t pitch;              // Bytes per scan line
     67 
     68     // VBE 1.2+ information
     69     uint16_t width;              // Width in pixels
     70     uint16_t height;             // Height in pixels
     71     uint8_t w_char;              // Character cell width
     72     uint8_t y_char;              // Character cell height
     73     uint8_t planes;              // Number of memory planes
     74     uint8_t bpp;                 // Bits per pixel
     75     uint8_t banks;               // Number of banks
     76     uint8_t memory_model;        // Memory model type
     77     uint8_t bank_size;           // Bank size in KB
     78     uint8_t image_pages;         // Number of image pages
     79     uint8_t reserved0;           // Reserved (always 1)
     80 
     81     // Direct color fields (required for direct/6 and YUV/7 memory models)
     82     uint8_t red_mask_size;       // Size of direct color red mask
     83     uint8_t red_field_position;  // Bit position of red mask LSB
     84     uint8_t green_mask_size;     // Size of direct color green mask
     85     uint8_t green_field_position;// Bit position of green mask LSB
     86     uint8_t blue_mask_size;      // Size of direct color blue mask
     87     uint8_t blue_field_position; // Bit position of blue mask LSB
     88     uint8_t reserved_mask_size;  // Size of direct color reserved mask
     89     uint8_t reserved_field_position; // Bit position of reserved mask LSB
     90     uint8_t direct_color_attributes; // Direct color mode attributes
     91 
     92     // VBE 2.0+ information
     93     uint32_t framebuffer;        // Physical address of linear framebuffer
     94     uint32_t off_screen_mem_off; // Pointer to start of off-screen memory
     95     uint16_t off_screen_mem_size;// Amount of off-screen memory in 1KB units
     96 
     97     uint8_t reserved1[206];      // Reserved
     98 } __attribute__((packed)) vbe_mode_info_t;
     99 
    100 /* VESA mode information */
    101 typedef struct {
    102     uint16_t mode_number;
    103     uint16_t width;
    104     uint16_t height;
    105     uint8_t bpp;
    106     uint32_t framebuffer;
    107     uint16_t pitch;
    108     uint8_t memory_model;
    109     uint8_t red_mask_size;
    110     uint8_t red_field_position;
    111     uint8_t green_mask_size;
    112     uint8_t green_field_position;
    113     uint8_t blue_mask_size;
    114     uint8_t blue_field_position;
    115 } vesa_mode_t;
    116 
    117 /* Current VESA state */
    118 typedef struct {
    119     int initialized;
    120     int active;
    121     vesa_mode_t current_mode;
    122     uint8_t* framebuffer;
    123 } vesa_state_t;
    124 
    125 /* Global VESA state */
    126 extern vesa_state_t vesa_state;
    127 
    128 /* VESA initialization and mode setting */
    129 int vesa_init(void);
    130 int vesa_detect_modes(void);
    131 int vesa_set_mode(uint16_t width, uint16_t height, uint8_t bpp);
    132 int vesa_get_current_mode(void);
    133 void vesa_list_modes(void);
    134 
    135 /* Lua bindings */
    136 int lua_vesa_init(lua_State* L);
    137 int lua_vesa_set_mode(lua_State* L);
    138 int lua_vesa_get_mode_info(lua_State* L);
    139 int lua_vesa_list_modes(lua_State* L);
    140 int lua_vesa_create_window_buffer(lua_State* L);
    141 int lua_vesa_free_window_buffer(lua_State* L);
    142 int lua_vesa_blit_window_buffer(lua_State* L);
    143 int lua_vesa_blit_window_buffer_region(lua_State* L);
    144 int lua_vesa_set_render_target(lua_State* L);
    145 int lua_vesa_inspect_buffer(lua_State* L);
    146 
    147 /* VESA drawing functions (RGB framebuffer) */
    148 int lua_vesa_set_pixel(lua_State* L);
    149 int lua_vesa_draw_rect(lua_State* L);
    150 int lua_vesa_clear_screen(lua_State* L);
    151 int lua_vesa_draw_text(lua_State* L);
    152 int lua_vesa_move_region(lua_State* L);
    153 int lua_vesa_set_double_buffer_mode(lua_State* L);
    154 int lua_vesa_process_buffered_draw_ops(lua_State* L);
    155 
    156 /* Helper drawing functions for VESA */
    157 void vesa_draw_pixel(int x, int y, uint32_t color);
    158 void vesa_draw_rect_fill(int x, int y, int width, int height, uint32_t color);
    159 void vesa_draw_rect_outline(int x, int y, int width, int height, uint32_t color, int thickness);
    160 void vesa_draw_line(int x0, int y0, int x1, int y1, uint32_t color, int thickness);
    161 void vesa_draw_circle_fill(int cx, int cy, int radius, uint32_t color);
    162 void vesa_draw_circle_outline(int cx, int cy, int radius, uint32_t color, int thickness);
    163 void vesa_draw_triangle_fill(int x0, int y0, int x1, int y1, int x2, int y2, uint32_t color);
    164 
    165 /* Color conversion helpers */
    166 uint32_t vesa_rgb_to_color(uint8_t r, uint8_t g, uint8_t b);
    167 void vesa_color_to_rgb(uint32_t color, uint8_t* r, uint8_t* g, uint8_t* b);
    168 
    169 #endif /* VESA_H */