Revision 165
renamed graph stuff
graphics.c | ||
---|---|---|
38 | 38 |
// BIOS CALL |
39 | 39 |
if (sys_int86(®_86) || reg_86.ah != AH_SUCCESS) { |
40 | 40 |
printf("%s: sys_int86 failed\n", __func__); |
41 |
if (free_memory_map()) { |
|
41 |
if (graph_free_memory_map()) {
|
|
42 | 42 |
printf("%s: lm_free failed\n", __func__); |
43 | 43 |
} |
44 | 44 |
return BIOS_CALL_ERROR; |
... | ... | |
123 | 123 |
return SUCCESS; |
124 | 124 |
} |
125 | 125 |
|
126 |
phys_bytes get_phys_addr(void) { |
|
127 |
return vbe_mem_info.PhysBasePtr; |
|
128 |
} |
|
126 |
phys_bytes (graph_get_phys_addr) (void){ return vbe_mem_info.PhysBasePtr; } |
|
127 |
unsigned (graph_get_vram_size) (void){ return vbe_mem_info.XResolution * vbe_mem_info.YResolution * ((vbe_mem_info.BitsPerPixel + 7) >> 3); } |
|
128 |
uint16_t (graph_get_XRes) (void){ return vbe_mem_info.XResolution; } |
|
129 |
uint16_t (graph_get_YRes) (void){ return vbe_mem_info.YResolution; } |
|
130 |
uint16_t (graph_get_bits_pixel) (void){ return vbe_mem_info.BitsPerPixel; } |
|
131 |
uint16_t (graph_get_bytes_pixel) (void){ return (vbe_mem_info.BitsPerPixel + 7) >> 3; } |
|
132 |
uint16_t (graph_get_RedMaskSize) (void){ return vbe_mem_info.RedMaskSize ; } |
|
133 |
uint16_t (graph_get_GreenMaskSize)(void){ return vbe_mem_info.GreenMaskSize; } |
|
134 |
uint16_t (graph_get_BlueMaskSize) (void){ return vbe_mem_info.BlueMaskSize ; } |
|
129 | 135 |
|
130 |
unsigned int get_vram_size(void) { |
|
131 |
return vbe_mem_info.XResolution * vbe_mem_info.YResolution * ((vbe_mem_info.BitsPerPixel + 7) >> 3); |
|
132 |
} |
|
133 |
|
|
134 |
uint16_t get_XRes(void) { |
|
135 |
return vbe_mem_info.XResolution; |
|
136 |
} |
|
137 |
|
|
138 |
uint16_t get_YRes(void) { |
|
139 |
return vbe_mem_info.YResolution; |
|
140 |
} |
|
141 |
|
|
142 |
uint16_t get_bits_pixel(void) { |
|
143 |
return vbe_mem_info.BitsPerPixel; |
|
144 |
} |
|
145 |
|
|
146 |
uint16_t get_bytes_pixel(void) { |
|
147 |
return (vbe_mem_info.BitsPerPixel + 7) >> 3; |
|
148 |
} |
|
149 |
|
|
150 |
uint16_t get_RedMaskSize (void){ return vbe_mem_info.RedMaskSize ; } |
|
151 |
uint16_t get_GreenMaskSize(void){ return vbe_mem_info.GreenMaskSize; } |
|
152 |
uint16_t get_BlueMaskSize (void){ return vbe_mem_info.BlueMaskSize ; } |
|
153 |
|
|
154 |
int (map_vram)(void) { |
|
136 |
int (graph_map_vram)(void) { |
|
155 | 137 |
int r; |
156 |
unsigned int vram_base = get_phys_addr(); |
|
157 |
unsigned int vram_size = get_vram_size(); |
|
138 |
unsigned int vram_base = graph_get_phys_addr();
|
|
139 |
unsigned int vram_size = graph_get_vram_size();
|
|
158 | 140 |
if ((r = get_permission(vram_base, vram_size))) { |
159 |
if (free_memory_map()) { |
|
141 |
if (graph_free_memory_map()) {
|
|
160 | 142 |
printf("%s: lm_free failed\n", __func__); |
161 | 143 |
} |
162 | 144 |
panic("%s: sys_privctl (ADD MEM) failed: %d\n", __func__, r); |
... | ... | |
165 | 147 |
video_mem = vm_map_phys(SELF, (void *)vram_base, vram_size); |
166 | 148 |
|
167 | 149 |
if (video_mem == MAP_FAILED) { |
168 |
if (free_memory_map()) { |
|
150 |
if (graph_free_memory_map()) {
|
|
169 | 151 |
printf("%s: lm_free failed\n", __func__); |
170 | 152 |
} |
171 | 153 |
panic("%s: couldn't map video memory.", __func__); |
... | ... | |
174 | 156 |
return SUCCESS; |
175 | 157 |
} |
176 | 158 |
|
177 |
int (free_memory_map)(void) { |
|
159 |
int (graph_free_memory_map)(void) {
|
|
178 | 160 |
return !lm_free(&mem_map); |
179 | 161 |
} |
180 | 162 |
|
181 |
int (set_graphics_mode)(uint16_t mode) {
|
|
163 |
int (graph_set_mode)(uint16_t mode) {
|
|
182 | 164 |
struct reg86 reg_86; |
183 | 165 |
|
184 | 166 |
memset(®_86, 0, sizeof(struct reg86)); // reset struct |
... | ... | |
198 | 180 |
return SUCCESS; |
199 | 181 |
} |
200 | 182 |
|
201 |
int (set_pixel)(uint16_t x, uint16_t y, uint32_t color) { |
|
183 |
int (graph_set_pixel)(uint16_t x, uint16_t y, uint32_t color) {
|
|
202 | 184 |
if (x >= vbe_mem_info.XResolution || y >= vbe_mem_info.YResolution) { |
203 | 185 |
printf("%s: invalid pixel.\n", __func__); |
204 | 186 |
return OUT_OF_RANGE; |
205 | 187 |
} |
206 |
unsigned int pos = (x + y * vbe_mem_info.XResolution) * get_bytes_pixel(); |
|
207 |
memcpy((void*)((unsigned int)video_mem + pos), &color, get_bytes_pixel()); |
|
188 |
unsigned int pos = (x + y * vbe_mem_info.XResolution) * graph_get_bytes_pixel();
|
|
189 |
memcpy((void*)((unsigned int)video_mem + pos), &color, graph_get_bytes_pixel());
|
|
208 | 190 |
return SUCCESS; |
209 | 191 |
} |
210 |
int (set_pixel_alpha)(uint16_t x, uint16_t y, uint32_t color, uint8_t alpha){ |
|
211 |
unsigned int pos = (x + y * vbe_mem_info.XResolution) * get_bytes_pixel(); |
|
192 |
int (graph_set_pixel_alpha)(uint16_t x, uint16_t y, uint32_t color, uint8_t alpha){
|
|
193 |
unsigned int pos = (x + y * vbe_mem_info.XResolution) * graph_get_bytes_pixel();
|
|
212 | 194 |
uint32_t color_; |
213 |
memcpy(&color_, (void*)((unsigned int)video_mem + pos), get_bytes_pixel()); |
|
195 |
memcpy(&color_, (void*)((unsigned int)video_mem + pos), graph_get_bytes_pixel());
|
|
214 | 196 |
float a = 1.0-(alpha&0xFF)/(float)0xFF; |
215 | 197 |
uint8_t r = GET_RED(color)*a + GET_RED(color_)*(1.0-a); |
216 | 198 |
uint8_t g = GET_GRE(color)*a + GET_GRE(color_)*(1.0-a); |
217 | 199 |
uint8_t b = GET_BLU(color)*a + GET_BLU(color_)*(1.0-a); |
218 |
return set_pixel(x,y,SET_RGB(r,g,b)); |
|
200 |
return graph_set_pixel(x,y,SET_RGB(r,g,b));
|
|
219 | 201 |
//return set_pixel(x,y,color); |
220 | 202 |
} |
221 | 203 |
|
222 |
int (draw_hline)(uint16_t x, uint16_t y, uint16_t len, uint32_t color){ |
|
204 |
int (graph_draw_hline)(uint16_t x, uint16_t y, uint16_t len, uint32_t color){
|
|
223 | 205 |
int r; |
224 | 206 |
for (uint16_t i = 0; i < len; i++) |
225 |
if ((r = set_pixel(x + i, y, color))) return r; |
|
207 |
if ((r = graph_set_pixel(x + i, y, color))) return r;
|
|
226 | 208 |
return SUCCESS; |
227 | 209 |
} |
228 | 210 |
int (vg_draw_hline)(uint16_t x, uint16_t y, uint16_t len, uint32_t color){ |
229 |
return draw_hline(x,y,len,color); |
|
211 |
return graph_draw_hline(x,y,len,color);
|
|
230 | 212 |
} |
231 | 213 |
|
232 |
int (draw_rectangle)(uint16_t x, uint16_t y,uint16_t width, uint16_t height, uint32_t color) { |
|
214 |
int (graph_draw_rectangle)(uint16_t x, uint16_t y,uint16_t width, uint16_t height, uint32_t color) {
|
|
233 | 215 |
int r; |
234 | 216 |
for (uint16_t i = 0; i < height; i++) |
235 |
if ((r = draw_hline(x, y + i, width, color))) return r; |
|
217 |
if ((r = graph_draw_hline(x, y + i, width, color))) return r;
|
|
236 | 218 |
return SUCCESS; |
237 | 219 |
} |
238 | 220 |
int (vg_draw_rectangle)(uint16_t x, uint16_t y,uint16_t width, uint16_t height, uint32_t color){ |
239 |
return draw_rectangle(x,y,width,height, color); |
|
221 |
return graph_draw_rectangle(x,y,width,height, color);
|
|
240 | 222 |
} |
241 | 223 |
|
242 |
int paint_screen(uint32_t color){
|
|
243 |
return draw_rectangle(0,0,get_XRes(),get_YRes(),color);
|
|
224 |
int (graph_paint_screen)(uint32_t color){
|
|
225 |
return graph_draw_rectangle(0,0,graph_get_XRes(),graph_get_YRes(),color);
|
|
244 | 226 |
} |
245 | 227 |
|
246 |
int clear_screen(){
|
|
247 |
return paint_screen(BLACK); |
|
228 |
int (graph_clear_screen)(void){
|
|
229 |
return graph_paint_screen(BLACK);
|
|
248 | 230 |
} |
231 |
|
|
232 |
int (graph_draw)(void){ |
|
233 |
return 0; |
|
234 |
} |
Also available in: Unified diff