luajitos

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

graphics.h (1966B)


      1 #ifndef GRAPHICS_H
      2 #define GRAPHICS_H
      3 
      4 #include <stdint.h>
      5 #include <lua.h>
      6 
      7 /* VGA Graphics Constants */
      8 #define VGA_WIDTH 320
      9 #define VGA_HEIGHT 200
     10 
     11 /* VGA register ports */
     12 #define VGA_MISC_WRITE    0x3C2
     13 #define VGA_SEQ_INDEX     0x3C4
     14 #define VGA_SEQ_DATA      0x3C5
     15 #define VGA_CRTC_INDEX    0x3D4
     16 #define VGA_CRTC_DATA     0x3D5
     17 #define VGA_GC_INDEX      0x3CE
     18 #define VGA_GC_DATA       0x3CF
     19 #define VGA_AC_INDEX      0x3C0
     20 #define VGA_AC_WRITE      0x3C0
     21 #define VGA_AC_READ       0x3C1
     22 #define VGA_INSTAT_READ   0x3DA
     23 
     24 /* Draw operation type constants (must match graphicslib.lua) */
     25 #define OP_PIXEL         0
     26 #define OP_RECT          1
     27 #define OP_RECT_FILL     2
     28 #define OP_CIRCLE        3
     29 #define OP_CIRCLE_FILL   4
     30 #define OP_TRIANGLE      5
     31 #define OP_TRIANGLE_FILL 6
     32 #define OP_POLYGON       7
     33 #define OP_POLYGON_FILL  8
     34 #define OP_LINE          9
     35 
     36 /* VGA memory pointer */
     37 extern uint8_t* vga_memory;
     38 
     39 /* Port I/O functions */
     40 static inline void outb(uint16_t port, uint8_t val) {
     41     __asm__ volatile ("outb %0, %1" : : "a"(val), "Nd"(port));
     42 }
     43 
     44 static inline uint8_t inb(uint16_t port) {
     45     uint8_t ret;
     46     __asm__ volatile ("inb %1, %0" : "=a"(ret) : "Nd"(port));
     47     return ret;
     48 }
     49 
     50 /* VGA mode functions */
     51 int lua_enter_graphics_mode(lua_State* L);
     52 int lua_exit_graphics_mode(lua_State* L);
     53 
     54 /* Basic drawing functions */
     55 int lua_set_pixel(lua_State* L);
     56 int lua_draw_rect(lua_State* L);
     57 int lua_clear_screen(lua_State* L);
     58 
     59 /* Buffered drawing */
     60 int lua_process_buffered_draw_ops(lua_State* L);
     61 
     62 /* Helper drawing functions */
     63 void draw_rect_outline(int x, int y, int width, int height, int color, int thickness);
     64 void draw_circle_fill(int cx, int cy, int radius, int color);
     65 void draw_circle_outline(int cx, int cy, int radius, int color, int thickness);
     66 void draw_triangle_fill(int x0, int y0, int x1, int y1, int x2, int y2, int color);
     67 void draw_line(int x0, int y0, int x1, int y1, int color, int thickness);
     68 
     69 #endif /* GRAPHICS_H */