Revision 134
corrected dragging and flickering. now one or + pixels do not match
lab5/graphics.c | ||
---|---|---|
172 | 172 |
return !lm_free(&mem_map); |
173 | 173 |
} |
174 | 174 |
|
175 |
int (set_pixel)(uint16_t x, uint16_t y, uint32_t color) { |
|
176 |
if (x >= vbe_mem_info.XResolution || y >= vbe_mem_info.YResolution) { |
|
177 |
printf("%s: invalid pixel.\n", __func__); |
|
178 |
return OUT_OF_RANGE; |
|
179 |
} |
|
180 |
unsigned int pos = (x + y * vbe_mem_info.XResolution) * get_bytes_pixel(); |
|
181 |
memcpy((void*)((unsigned int)video_mem + pos), &color, get_bytes_pixel()); |
|
182 |
return SUCCESS; |
|
183 |
} |
|
184 |
|
|
185 | 175 |
int (set_graphics_mode)(uint16_t mode) { |
186 | 176 |
struct reg86 reg_86; |
187 | 177 |
|
... | ... | |
202 | 192 |
return SUCCESS; |
203 | 193 |
} |
204 | 194 |
|
195 |
|
|
196 |
int (set_pixel)(uint16_t x, uint16_t y, uint32_t color) { |
|
197 |
if (x >= vbe_mem_info.XResolution || y >= vbe_mem_info.YResolution) { |
|
198 |
printf("%s: invalid pixel.\n", __func__); |
|
199 |
return OUT_OF_RANGE; |
|
200 |
} |
|
201 |
unsigned int pos = (x + y * vbe_mem_info.XResolution) * get_bytes_pixel(); |
|
202 |
memcpy((void*)((unsigned int)video_mem + pos), &color, get_bytes_pixel()); |
|
203 |
return SUCCESS; |
|
204 |
} |
|
205 |
|
|
205 | 206 |
int (draw_hline)(uint16_t x, uint16_t y, uint16_t len, uint32_t color){ |
206 | 207 |
int r; |
207 | 208 |
for (uint16_t i = 0; i < len; i++) |
... | ... | |
221 | 222 |
int (vg_draw_rectangle)(uint16_t x, uint16_t y,uint16_t width, uint16_t height, uint32_t color){ |
222 | 223 |
return draw_rectangle(x,y,width,height, color); |
223 | 224 |
} |
225 |
|
|
226 |
int paint_screen(uint32_t color){ |
|
227 |
return draw_rectangle(0,0,get_XRes(),get_YRes(),color); |
|
228 |
} |
|
229 |
|
|
230 |
int clear_screen(){ |
|
231 |
return paint_screen(0); |
|
232 |
} |
lab5/graphics.h | ||
---|---|---|
74 | 74 |
|
75 | 75 |
int (draw_rectangle)(uint16_t x, uint16_t y,uint16_t width, uint16_t height, uint32_t color); |
76 | 76 |
|
77 |
int (paint_screen)(uint32_t color); |
|
78 |
|
|
79 |
int (clear_screen)(); |
|
80 |
|
|
77 | 81 |
#endif /* end of include guard: GRAPHICS_H_INCLUDED */ |
lab5/lab5.c | ||
---|---|---|
12 | 12 |
#include "kbc.h" |
13 | 13 |
#include "kbc_macros.h" |
14 | 14 |
#include "timer.h" |
15 |
#include "utils.h" |
|
15 | 16 |
|
16 | 17 |
// Any header files included below this line should have been created by you |
17 | 18 |
|
... | ... | |
411 | 412 |
case HARDWARE: /* hardware interrupt notification */ |
412 | 413 |
if (msg.m_notify.interrupts & timer_irq) { /* subscribed interrupt */ |
413 | 414 |
timer_int_handler(); |
415 |
if(no_interrupts == dt){ |
|
416 |
no_interrupts = 0; |
|
417 |
i = (i+1)%Nt; |
|
418 |
if(i == 0 && (dx || dy)){ |
|
419 |
if(dx) draw_rectangle(min(x,x+dframe),y , abs(dframe) , sprite_get_h(sp), 0); |
|
420 |
if(dy) draw_rectangle(x ,min(y,y+dframe),sprite_get_w(sp), abs(dframe) , 0); |
|
421 |
if(dx) x += dframe; |
|
422 |
if(dy) y += dframe; |
|
423 |
if(dx && (x-xi)*(x-xf) >= 0){ |
|
424 |
x = xf; |
|
425 |
dx = 0; |
|
426 |
} |
|
427 |
if(dy && (y-yi)*(y-yf) >= 0){ |
|
428 |
y = yf; |
|
429 |
dy = 0; |
|
430 |
} |
|
431 |
sprite_set_pos(sp,x,y); |
|
432 |
sprite_draw(sp); |
|
433 |
} |
|
434 |
} |
|
414 | 435 |
} |
415 | 436 |
if (msg.m_notify.interrupts & kbc_irq) { /* subscribed interrupt */ |
416 | 437 |
kbc_ih(); |
... | ... | |
424 | 445 |
/* no standart message expected: do nothing */ |
425 | 446 |
} |
426 | 447 |
if(good == 0) continue; |
427 |
if(no_interrupts == dt){ |
|
428 |
no_interrupts = 0; |
|
429 |
i = (i+1)%Nt; |
|
430 |
if(i == 0){ |
|
431 |
if(dx) x += dframe; |
|
432 |
if(dy) y += dframe; |
|
433 |
if((dx < 0 && x <= xf)|| |
|
434 |
(dx > 0 && x >= xf)){ |
|
435 |
x = xf; |
|
436 |
good = 0; |
|
437 |
} |
|
438 |
if((dy < 0 && y <= yf)|| |
|
439 |
(dy > 0 && y >= yf)){ |
|
440 |
y = yf; |
|
441 |
good = 0; |
|
442 |
} |
|
443 |
sprite_set_pos(sp,x,y); |
|
444 |
sprite_draw(sp); |
|
445 |
} |
|
446 |
} |
|
447 | 448 |
} |
448 | 449 |
|
449 | 450 |
if (unsubscribe_interrupt(&kbc_id)) { |
lab5/sprite.c | ||
---|---|---|
38 | 38 |
sprite_set_y(p, y); |
39 | 39 |
} |
40 | 40 |
|
41 |
int sprite_get_w(const sprite_t *p){ return p->w; } |
|
42 |
int sprite_get_h(const sprite_t *p){ return p->h; } |
|
43 |
|
|
41 | 44 |
void sprite_draw(const sprite_t *p){ |
42 | 45 |
for (int i = 0; i < p->w; i++) { |
43 | 46 |
for (int j = 0; j < p->h; j++) { |
lab5/sprite.h | ||
---|---|---|
11 | 11 |
void sprite_set_y(sprite_t *p, int y); |
12 | 12 |
void sprite_set_pos(sprite_t *p, int x, int y); |
13 | 13 |
|
14 |
int sprite_get_h(const sprite_t *p); |
|
15 |
int sprite_get_w(const sprite_t *p); |
|
16 |
|
|
14 | 17 |
void sprite_draw(const sprite_t *p); |
15 | 18 |
|
16 | 19 |
#endif //SPRITE_H_INCLUDED |
lab5/utils.c | ||
---|---|---|
35 | 35 |
int16_t abs16(int16_t x) { |
36 | 36 |
return (x >= 0) ? (int16_t)(x) : (int16_t)(-x); |
37 | 37 |
} |
38 |
|
|
39 |
uint16_t min(uint16_t a, uint16_t b){ |
|
40 |
return (b < a ? b : a); |
|
41 |
} |
lab5/utils.h | ||
---|---|---|
29 | 29 |
*/ |
30 | 30 |
int (util_sys_inb)(int port, uint8_t *value); |
31 | 31 |
|
32 |
uint16_t min(uint16_t a, uint16_t b); |
|
33 |
|
|
32 | 34 |
#endif //UTILS_H_INCLUDED |
Also available in: Unified diff