45 lines
1.1 KiB
C
45 lines
1.1 KiB
C
|
/* vim: tabstop=4 shiftwidth=4 noexpandtab
|
||
|
*
|
||
|
* Graphics library
|
||
|
*/
|
||
|
|
||
|
#include <syscall.h>
|
||
|
#include <stdint.h>
|
||
|
#include "graphics.h"
|
||
|
|
||
|
DEFN_SYSCALL0(getgraphicsaddress, 11);
|
||
|
DEFN_SYSCALL1(kbd_mode, 12, int);
|
||
|
DEFN_SYSCALL0(kbd_get, 13);
|
||
|
DEFN_SYSCALL1(setgraphicsoffset, 16, int);
|
||
|
|
||
|
DEFN_SYSCALL0(getgraphicswidth, 18);
|
||
|
DEFN_SYSCALL0(getgraphicsheight, 19);
|
||
|
DEFN_SYSCALL0(getgraphicsdepth, 20);
|
||
|
|
||
|
uint16_t graphics_width = 0;
|
||
|
uint16_t graphics_height = 0;
|
||
|
uint16_t graphics_depth = 0;
|
||
|
|
||
|
/* Pointer to graphics memory */
|
||
|
uint8_t * gfx_mem = 0;
|
||
|
|
||
|
void init_graphics() {
|
||
|
graphics_width = syscall_getgraphicswidth();
|
||
|
graphics_height = syscall_getgraphicsheight();
|
||
|
graphics_depth = syscall_getgraphicsdepth();
|
||
|
gfx_mem = (void *)syscall_getgraphicsaddress();
|
||
|
}
|
||
|
|
||
|
uint32_t rgb(uint8_t r, uint8_t g, uint8_t b) {
|
||
|
return 0xFF000000 + (r * 0x10000) + (g * 0x100) + (b * 0x1);
|
||
|
}
|
||
|
|
||
|
uint32_t alpha_blend(uint32_t bottom, uint32_t top, uint32_t mask) {
|
||
|
float a = _RED(mask) / 256.0;
|
||
|
uint8_t red = _RED(bottom) * (1.0 - a) + _RED(top) * a;
|
||
|
uint8_t gre = _GRE(bottom) * (1.0 - a) + _GRE(top) * a;
|
||
|
uint8_t blu = _BLU(bottom) * (1.0 - a) + _BLU(top) * a;
|
||
|
return rgb(red,gre,blu);
|
||
|
}
|
||
|
|