Implement graphics subsystem with VGA mode 0x13 and drawing primitives (AI)

This commit is contained in:
AI
2026-02-24 08:01:20 +00:00
parent 57b2751a81
commit fc5fe9af63
8 changed files with 781 additions and 9 deletions

View File

@@ -31,6 +31,7 @@ typedef int int32_t;
#define SYS_SEND 15
#define SYS_RECV 16
#define SYS_SOCKSTATE 17
#define SYS_GFX 18
static inline int32_t syscall0(int num) {
int32_t ret;
@@ -194,6 +195,92 @@ static inline int32_t sockstate(int32_t sockfd) {
return syscall1(SYS_SOCKSTATE, (uint32_t)sockfd);
}
/* ================================================================
* Graphics system calls
* ================================================================ */
/** Graphics sub-commands. */
#define GFX_CMD_ENTER 0
#define GFX_CMD_LEAVE 1
#define GFX_CMD_PIXEL 2
#define GFX_CMD_CLEAR 3
#define GFX_CMD_FILL_RECT 4
#define GFX_CMD_LINE 5
#define GFX_CMD_CIRCLE 6
#define GFX_CMD_GET_INFO 7
/** Graphics mode dimensions. */
#define GFX_WIDTH 320
#define GFX_HEIGHT 200
/** Palette color constants. */
#define GFX_BLACK 0
#define GFX_BLUE 1
#define GFX_GREEN 2
#define GFX_CYAN 3
#define GFX_RED 4
#define GFX_MAGENTA 5
#define GFX_BROWN 6
#define GFX_LIGHT_GREY 7
#define GFX_DARK_GREY 8
#define GFX_LIGHT_BLUE 9
#define GFX_LIGHT_GREEN 10
#define GFX_LIGHT_CYAN 11
#define GFX_LIGHT_RED 12
#define GFX_LIGHT_MAGENTA 13
#define GFX_YELLOW 14
#define GFX_WHITE 15
/** Command structs for complex drawing operations. */
typedef struct { uint32_t x, y, w, h, color; } gfx_rect_t;
typedef struct { uint32_t x1, y1, x2, y2, color; } gfx_line_t;
typedef struct { uint32_t cx, cy, r, color; } gfx_circle_t;
/** Convert RGB (0-255) to palette index using 6x6x6 color cube. */
static inline uint32_t gfx_rgb(uint32_t r, uint32_t g, uint32_t b) {
return 16 + (r / 51) * 36 + (g / 51) * 6 + (b / 51);
}
/** Enter graphics mode (320x200x256). */
static inline int32_t gfx_enter(void) {
return syscall1(SYS_GFX, GFX_CMD_ENTER);
}
/** Leave graphics mode, return to text. */
static inline int32_t gfx_leave(void) {
return syscall1(SYS_GFX, GFX_CMD_LEAVE);
}
/** Set a pixel. */
static inline int32_t gfx_pixel(uint32_t x, uint32_t y, uint32_t color) {
return syscall3(SYS_GFX, GFX_CMD_PIXEL, (x | (y << 16)), color);
}
/** Clear screen with a color. */
static inline int32_t gfx_clear(uint32_t color) {
return syscall2(SYS_GFX, GFX_CMD_CLEAR, color);
}
/** Fill a rectangle. */
static inline int32_t gfx_fill_rect(const gfx_rect_t *r) {
return syscall2(SYS_GFX, GFX_CMD_FILL_RECT, (uint32_t)r);
}
/** Draw a line. */
static inline int32_t gfx_line(const gfx_line_t *l) {
return syscall2(SYS_GFX, GFX_CMD_LINE, (uint32_t)l);
}
/** Draw a filled circle. */
static inline int32_t gfx_circle(const gfx_circle_t *c) {
return syscall2(SYS_GFX, GFX_CMD_CIRCLE, (uint32_t)c);
}
/** Get graphics info: returns (width | height<<16). */
static inline int32_t gfx_get_info(void) {
return syscall1(SYS_GFX, GFX_CMD_GET_INFO);
}
/* Basic string operations for user-space */
static inline uint32_t strlen(const char *s) {
uint32_t len = 0;