Revision 165
renamed graph stuff
proj/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 |
} |
proj/graphics.h | ||
---|---|---|
42 | 42 |
|
43 | 43 |
int (vbe_get_controller_information)(vg_vbe_contr_info_t *info_p); |
44 | 44 |
|
45 |
phys_bytes (get_phys_addr) (void); |
|
46 |
unsigned (get_vram_size) (void); |
|
47 |
uint16_t (get_XRes) (void); |
|
48 |
uint16_t (get_YRes) (void); |
|
49 |
uint16_t (get_bits_pixel) (void); |
|
50 |
uint16_t (get_bytes_pixel) (void); |
|
51 |
uint16_t (get_RedMaskSize) (void); |
|
52 |
uint16_t (get_GreenMaskSize)(void); |
|
53 |
uint16_t (get_BlueMaskSize) (void); |
|
45 |
phys_bytes (graph_get_phys_addr) (void);
|
|
46 |
unsigned (graph_get_vram_size) (void);
|
|
47 |
uint16_t (graph_get_XRes) (void);
|
|
48 |
uint16_t (graph_get_YRes) (void);
|
|
49 |
uint16_t (graph_get_bits_pixel) (void);
|
|
50 |
uint16_t (graph_get_bytes_pixel) (void);
|
|
51 |
uint16_t (graph_get_RedMaskSize) (void);
|
|
52 |
uint16_t (graph_get_GreenMaskSize)(void);
|
|
53 |
uint16_t (graph_get_BlueMaskSize) (void);
|
|
54 | 54 |
|
55 |
int (map_vram)(void); |
|
55 |
int (graph_map_vram)(void);
|
|
56 | 56 |
|
57 |
int (free_memory_map)(void); |
|
57 |
int (graph_free_memory_map)(void);
|
|
58 | 58 |
|
59 |
int (set_pixel) (uint16_t x, uint16_t y, uint32_t color); |
|
60 |
int (set_pixel_alpha)(uint16_t x, uint16_t y, uint32_t color, uint8_t alpha); |
|
59 |
int (graph_set_pixel) (uint16_t x, uint16_t y, uint32_t color);
|
|
60 |
int (graph_set_pixel_alpha)(uint16_t x, uint16_t y, uint32_t color, uint8_t alpha);
|
|
61 | 61 |
|
62 | 62 |
/** |
63 | 63 |
* @brief |
64 | 64 |
* @param mode |
65 | 65 |
* @return |
66 | 66 |
*/ |
67 |
int (set_graphics_mode)(uint16_t mode);
|
|
67 |
int (graph_set_mode)(uint16_t mode);
|
|
68 | 68 |
|
69 |
int (draw_hline)(uint16_t x, uint16_t y, uint16_t len, uint32_t color); |
|
69 |
int (graph_draw_hline)(uint16_t x, uint16_t y, uint16_t len, uint32_t color);
|
|
70 | 70 |
|
71 |
int (draw_rectangle)(uint16_t x, uint16_t y,uint16_t width, uint16_t height, uint32_t color); |
|
71 |
int (graph_draw_rectangle)(uint16_t x, uint16_t y,uint16_t width, uint16_t height, uint32_t color);
|
|
72 | 72 |
|
73 |
int (paint_screen)(uint32_t color); |
|
73 |
int (graph_paint_screen)(uint32_t color);
|
|
74 | 74 |
|
75 |
int (clear_screen)();
|
|
75 |
int (graph_clear_screen)(void);
|
|
76 | 76 |
|
77 |
int (graph_draw)(void); |
|
78 |
|
|
77 | 79 |
#endif /* end of include guard: GRAPHICS_H_INCLUDED */ |
proj/proj.c | ||
---|---|---|
51 | 51 |
return 1; |
52 | 52 |
} |
53 | 53 |
|
54 |
map_vram(); // if function fails it aborts program |
|
54 |
graph_map_vram(); // if function fails it aborts program
|
|
55 | 55 |
|
56 |
if (set_graphics_mode(GRAPH_MODE)) {
|
|
56 |
if (graph_set_mode(GRAPH_MODE)) {
|
|
57 | 57 |
printf("%s: failed to set graphic mode %x.\n", __func__, GRAPH_MODE); |
58 | 58 |
if (cleanup()) |
59 | 59 |
printf("%s: failed to cleanup.\n", __func__); |
... | ... | |
61 | 61 |
}; |
62 | 62 |
|
63 | 63 |
#ifdef DIOGO |
64 |
paint_screen(0x777777); |
|
64 |
graph_paint_screen(0x777777);
|
|
65 | 65 |
sprite_t *shooter1 = get_shooter(); sprite_set_pos(shooter1, 100, 100); |
66 | 66 |
for(double angle = 0; angle < 6.29; angle += 0.01){ |
67 | 67 |
sprite_set_angle(shooter1, angle); |
proj/proj_func.c | ||
---|---|---|
12 | 12 |
|
13 | 13 |
if ((r = vg_exit())) |
14 | 14 |
printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
15 |
if ((r = free_memory_map())) |
|
15 |
if ((r = graph_free_memory_map()))
|
|
16 | 16 |
printf("%s: lm_free failed\n", __func__); |
17 | 17 |
|
18 | 18 |
return r; |
proj/sprite.c | ||
---|---|---|
60 | 60 |
void (sprite_draw)(const sprite_t *p){ |
61 | 61 |
const int16_t diag = sqrt(p->w*p->w + p->h*p->h)+2; |
62 | 62 |
int16_t u, v; |
63 |
for(int16_t y = max(0,p->y-diag); y < min(p->y+diag,get_YRes()); ++y){ |
|
64 |
for(int16_t x = max(0,p->x-diag); x < min(p->x+diag,get_XRes()); ++x){ |
|
63 |
for(int16_t y = max(0,p->y-diag); y < min(p->y+diag,graph_get_YRes()); ++y){
|
|
64 |
for(int16_t x = max(0,p->x-diag); x < min(p->x+diag,graph_get_XRes()); ++x){
|
|
65 | 65 |
sprite_src2pic(p, x, y, &u, &v); |
66 | 66 |
if(0 <= u && u < p->w && 0 <= v && v < p->h){ |
67 | 67 |
uint8_t *m = p->map + (v*p->w + u)*4; |
68 | 68 |
uint32_t color = SET_RGB(*(m+2), *(m+1), *(m)); |
69 |
set_pixel_alpha(p->x + x, p->y + y, color, *(m+3)); |
|
69 |
graph_set_pixel_alpha(p->x + x, p->y + y, color, *(m+3));
|
|
70 | 70 |
} |
71 | 71 |
} |
72 | 72 |
} |
Also available in: Unified diff