mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-24 00:00:44 +01:00
Kandinsky now uses KDSetPixel for framebuffer access
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
#include <kandinsky/line.h>
|
||||
#include <kandinsky/referential.h>
|
||||
#include <kandinsky/pixel.h>
|
||||
|
||||
void KDDrawLine(KDPoint p1, KDPoint p2) {
|
||||
void KDDrawLine(KDPoint p1, KDPoint p2) { //, KDColor c) {
|
||||
for (KDCoordinate x = p1.x; x<p2.x; x++) {
|
||||
// COLOR(KDPOINT(x, p1.y)) = 0xFF;
|
||||
KDSetPixel(KDPOINT(x, p1.y), 0xFF /* c */);
|
||||
}
|
||||
}
|
||||
|
||||
42
kandinsky/src/pixel.c
Normal file
42
kandinsky/src/pixel.c
Normal file
@@ -0,0 +1,42 @@
|
||||
#include <kandinsky/pixel.h>
|
||||
#include <kandinsky/config.h>
|
||||
#include <assert.h>
|
||||
|
||||
static KDPoint sOrigin = {.x = 0, .y = 0};
|
||||
|
||||
#define BIT_MASK(high, low) ((((uint32_t)1<<((high)-(low)+1))-1)<<(low))
|
||||
#define BIT_VALUE(value, high, low) (((value)<<(low))&BIT_MASK(high, low))
|
||||
|
||||
static inline void set_color(KDColor * address, int8_t high_bit, int8_t low_bit, KDColor value) {
|
||||
assert(high_bit-low_bit+1 <= 8*sizeof(KDColor)); // Interval too large
|
||||
assert(low_bit >= 0); // Interval starts too early
|
||||
assert(low_bit < 8*sizeof(KDColor)); // Interval ends too late
|
||||
KDColor mask = ((((KDColor)1<<(high_bit-low_bit+1))-1)<<low_bit);
|
||||
assert(address >= KD_FRAMEBUFFER_ADDRESS);
|
||||
assert(address < (KD_FRAMEBUFFER_ADDRESS+(KD_FRAMEBUFFER_WIDTH*KD_FRAMEBUFFER_HEIGHT*KD_BITS_PER_PIXEL)/8));
|
||||
*address = (*address & ~mask) | (value & mask);
|
||||
}
|
||||
|
||||
void KDSetOrigin(KDPoint origin) {
|
||||
sOrigin = origin;
|
||||
}
|
||||
|
||||
KDPoint KDGetOrigin() {
|
||||
return sOrigin;
|
||||
}
|
||||
|
||||
void KDSetPixel(KDPoint p, KDColor c) {
|
||||
assert(p.x >= 0);
|
||||
assert(p.x < KD_FRAMEBUFFER_WIDTH);
|
||||
assert(p.y >= 0);
|
||||
assert(p.y < KD_FRAMEBUFFER_HEIGHT);
|
||||
int pixels_offset = p.y*(KD_FRAMEBUFFER_WIDTH) + p.x;
|
||||
int bits_offset = (KD_BITS_PER_PIXEL)*pixels_offset;
|
||||
const uint8_t color_bitsize = 8*sizeof(KDColor);
|
||||
// Notice: the "const" here is rather important. Indeed, it hints the compiler
|
||||
// for the following "modulo", which helps us avoid idivmod.
|
||||
int color_offset = bits_offset/color_bitsize;
|
||||
int8_t low_bit = bits_offset % color_bitsize;
|
||||
int8_t high_bit = low_bit + KD_BITS_PER_PIXEL - 1;
|
||||
set_color((KDColor *)(KD_FRAMEBUFFER_ADDRESS+color_offset), high_bit, low_bit, c);
|
||||
}
|
||||
@@ -1,9 +1,15 @@
|
||||
#include <kandinsky/rect.h>
|
||||
#include <kandinsky/referential.h>
|
||||
#include <kandinsky/pixel.h>
|
||||
#include <string.h>
|
||||
|
||||
void KDFillRect(KDRect rect, KDColor color) {
|
||||
for (KDCoordinate y = rect.y ; y < (rect.y + rect.height); y++) {
|
||||
memset(KDPixelAddress((KDPoint){.x=rect.x, .y=y}), color, rect.width);
|
||||
//for (KDCoordinate y = rect.y ; y < (rect.y + rect.height); y++) {
|
||||
//memset(KDPixelAddress((KDPoint){.x=rect.x, .y=y}), color, rect.width);
|
||||
//}
|
||||
KDPoint p;
|
||||
for (p.x = rect.x; p.x<(rect.x+rect.width-1); p.x++) {
|
||||
for (p.y = rect.y; p.y<(rect.y+rect.height-1); p.y++) {
|
||||
KDSetPixel(p, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
#include <kandinsky/referential.h>
|
||||
#include <kandinsky/config.h>
|
||||
|
||||
static KDPoint sOrigin = {.x = 0, .y = 0};
|
||||
|
||||
void KDSetOrigin(KDPoint origin) {
|
||||
sOrigin = origin;
|
||||
}
|
||||
|
||||
KDPoint KDGetOrigin() {
|
||||
return sOrigin;
|
||||
}
|
||||
|
||||
KDColor * KDPixelAddress(KDPoint p) {
|
||||
KDPoint origin = KDGetOrigin();
|
||||
return (KDColor *)(KD_FRAMEBUFFER_ADDRESS
|
||||
+ KD_FRAMEBUFFER_WIDTH*(p.y + origin.y)
|
||||
+ (p.x + origin.x));
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#include <kandinsky/text.h>
|
||||
#include <kandinsky/referential.h>
|
||||
#include <kandinsky/pixel.h>
|
||||
#include <string.h>
|
||||
#include "font.h"
|
||||
|
||||
void KDDrawChar(char character, KDPoint p) {
|
||||
for (int j=0; j<BITMAP_FONT_CHARACTER_HEIGHT;j++) {
|
||||
for (int i=0; i<BITMAP_FONT_CHARACTER_WIDTH;i++) {
|
||||
COLOR(KDPOINT(p.x+i, p.y+j)) = 0xFF-bitmapFont[character-BITMAP_FONT_FIRST_CHARACTER][j][i];
|
||||
KDSetPixel(KDPOINT(p.x+i, p.y+j), 0xFF-bitmapFont[character-BITMAP_FONT_FIRST_CHARACTER][j][i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user