SayoriOS 0.3.3

screen.h
1 #pragma once
2
3 #include <common.h>
4 #include "lib/string.h"
5
6 extern uint8_t* framebuffer_addr;
7 extern uint32_t framebuffer_bpp;
8 extern uint32_t framebuffer_pitch;
9 extern uint8_t* back_framebuffer_addr;
10 extern uint32_t framebuffer_size;
11
12 #define VESA_WIDTH (getScreenWidth())
13 #define VESA_HEIGHT (getScreenHeight())
14
15
16 #define PACK_INTO_RGB(struct_px) ((struct_px.r & 0xff) << 16) |\
17 ((struct_px.g & 0xff) << 8) |\
18 (struct_px.b & 0xff)
19
20 typedef struct rgba_struct {
21 uint8_t r;
22 uint8_t g;
23 uint8_t b;
24 uint8_t a;
25 } rgba_color;
26
27 typedef struct rgb_struct {
28 uint8_t r;
29 uint8_t g;
30 uint8_t b;
31 } rgb_color;
32
33
34 enum colors {
35 VESA_BLACK = 0x000000,
36 VESA_BLUE = 0x0000AA,
37 VESA_GREEN = 0x00AA00,
38 VESA_CYAN = 0x00AAAA,
39 VESA_RED = 0xAA0000,
40 VESA_MAGENTA = 0xAA00AA,
41 VESA_YELLOW = 0xAA5500,
42 VESA_LIGHT_GREY = 0xAAAAAA,
43 VESA_DARK_GREY = 0x555555,
44 VESA_LIGHT_BLUE = 0x5555FF,
45 VESA_LIGHT_GREEN = 0x55FF55,
46 VESA_LIGHT_CYAN = 0x55FFFF,
47 VESA_LIGHT_RED = 0xFF5555,
48 VESA_LIGHT_MAGENTA = 0xFF55FF,
49 VESA_LIGHT_YELLOW = 0xffff55,
50 VESA_WHITE = 0xFFFFFF,
51 };
52
53 typedef struct svga_mode_info {
54 uint16_t attributes;
55 uint8_t windowA, windowB;
56 uint16_t granularity;
57 uint16_t windowSize;
58 uint16_t segmentA, segmentB;
59 uint32_t winFuncPtr;
60 uint16_t pitch;
61
62 uint16_t screen_width, screen_height;
63 uint8_t wChar, yChar, planes, bpp, banks;
64 uint8_t memoryModel, bankSize, imagePages;
65 uint8_t reserved0;
66
67 // Color masks
68 uint8_t readMask, redPosition;
69 uint8_t greenMask, greenPosition;
70 uint8_t blueMask, bluePosition;
71 uint8_t reservedMask, reservedPosition;
72 uint8_t directColorAttributes;
73
74 uint32_t physbase;
75 uint32_t offScreenMemOff;
76 uint16_t offScreenMemSize;
77 uint8_t reserved1[206];
78 } __attribute__ ((packed)) svga_mode_info_t;
79
80 #define punch() memcpy(framebuffer_addr, back_framebuffer_addr, framebuffer_size)
81 // #define punch() sse_memcpy(framebuffer_addr, back_framebuffer_addr, framebuffer_size)
82 //#define punch() rect_copy(0, 0, VESA_WIDTH, VESA_HEIGHT)
83
84 uint32_t getDisplayPitch();
85 uint32_t getScreenWidth();
86 uint32_t getScreenHeight();
87 size_t getDisplayAddr();
88 uint32_t getDisplayBpp();
89 size_t getFrameBufferAddr();
90 size_t getPixel(int32_t x, int32_t y);
91
92
100 inline static __attribute__((always_inline)) void set_pixel(uint32_t x, uint32_t y, uint32_t color) {
101 #ifndef RELEASE
102 if (x >= VESA_WIDTH ||
103 y >= VESA_HEIGHT) {
104 return;
105 }
106 #endif
107 uint8_t* pixels = back_framebuffer_addr + (x * (framebuffer_bpp >> 3)) + y * framebuffer_pitch;
108
109 pixels[0] = color & 255;
110 pixels[1] = (color >> 8) & 255;
111 pixels[2] = (color >> 16) & 255;
112 }
113
119 inline static __attribute__((always_inline)) uint32_t getDisplaySize(){
120 return framebuffer_size;
121 }
122
123 void setPixelAlpha(uint32_t x, uint32_t y, rgba_color color);
124 void rect_copy(int x, int y, int width, int height);
125 void graphics_update(uint32_t new_width, uint32_t new_height, uint32_t new_pitch);
126
common.h
Основные определения ядра
__attribute__
struct registers __attribute__((packed))
Структура данных пакета от мыши
Definition: psf.h:19
rgb_struct
Definition: screen.h:27
rgba_struct
Definition: screen.h:20
svga_mode_info
Definition: screen.h:53