Browse Source

moved stuf

master
Mathieu Serandour 1 year ago
parent
commit
9a68f97872
  1. 22
      kernel/video/terminal.c
  2. 34
      kernel/video/terminal.h
  3. 67
      kernel/video/video.c
  4. 2
      kernel/video/video.h

22
kernel/video/terminal.c

@ -27,6 +27,13 @@ static terminal_handler_t terminal_handler = NULL;
static bool need_refresh = false;
void default_terminal_handler(const char* s, size_t l) {
(void) (s + l);
// empty handler by default,
// make sure not to execute the address 0 :)
}
static Image* charmap = NULL;
@ -50,21 +57,21 @@ void setup_terminal(void) {
assert(charmap == NULL);
charmap = loadBMP_24b_1b(&_binary_charmap_bmp);
assert(0);
assert(charmap != NULL);
assert(charmap->bpp == 1);
assert(charmap->pitch == 1);
assert(charmap->w == CHARMAP_W);
assert(charmap->h == CHARMAP_H);
assert(charmap->w == TERMINAL_CHARMAP_W);
assert(charmap->h == TERMINAL_CHARMAP_H);
const Image* screenImage = getScreenImage();
// dynamicly create the terminal
// with right size
ncols = screenImage->w / FONTWIDTH;
term_nlines = (screenImage->h / LINE_HEIGHT) - 3;
nlines = N_PAGES * term_nlines;
ncols = screenImage->w / TERMINAL_FONTWIDTH;
term_nlines = (screenImage->h / TERMINAL_LINE_HEIGHT) - 3;
nlines = TERMINAL_N_PAGES * term_nlines;
@ -217,7 +224,7 @@ static void print_char(const struct Char* restrict c, int line, int col) {
blitchar(charmap, c->c, c->fg_color, c->bg_color,
col * FONTWIDTH, line * LINE_HEIGHT);
col * TERMINAL_FONTWIDTH, line * TERMINAL_LINE_HEIGHT);
//imageDraw(charmap, NULL, NULL);
@ -260,6 +267,7 @@ terminal_handler_t get_terminal_handler(void) {
}
void set_terminal_handler(terminal_handler_t h) {
terminal_handler = h;
}

34
kernel/video/terminal.h

@ -5,36 +5,40 @@
#include "../debug/assert.h"
#define CHARMAP_W 6
#define CHARMAP_H 2048
#define TERMINAL_CHARMAP_W 6
#define TERMINAL_CHARMAP_H 2048
// must be divisible by 4 !!!
static_assert(CHARMAP_H % 4 == 0);
static_assert(TERMINAL_CHARMAP_H % 4 == 0);
#define FONTWIDTH CHARMAP_W
#define FONTHEIGHT (CHARMAP_H / 256)
#define INTERLINE 0
#define LINE_HEIGHT (FONTHEIGHT + INTERLINE)
#define TERMINAL_FONTWIDTH TERMINAL_CHARMAP_W
#define TERMINAL_FONTHEIGHT (TERMINAL_CHARMAP_H / 256)
#define TERMINAL_INTERLINE 0
#define TERMINAL_LINE_HEIGHT (TERMINAL_FONTHEIGHT + TERMINAL_INTERLINE)
#define N_PAGES 4
#define TERMINAL_N_PAGES 4
struct stivale2_struct_tag_framebuffer;
typedef void (*terminal_handler_t)(const char *string, size_t length);
/**
* return NULL if no terminal output is installed
**/
// the default terminal handler
terminal_handler_t get_terminal_handler(void);
void set_terminal_bgcolor(uint32_t c);
void set_terminal_fgcolor(uint32_t c);
void setup_terminal(void);
void terminal_clear(void);
// no use another terminal handler
// change the default terminal handler,
// which is an empty function
void set_terminal_handler(terminal_handler_t h);
/**
* the arguments of the following functions are expected
* to be on the little endian RGB format
*/
void set_terminal_bgcolor(uint32_t c);
void set_terminal_fgcolor(uint32_t c);
void terminal_set_colors(uint32_t foreground, uint32_t background);

67
kernel/video/video.c

@ -1,12 +1,14 @@
#include <stdbool.h>
// for initialization
#include <stivale2.h>
#include "../klib/string.h"
#include "../klib/sprintf.h"
#include "video.h"
#include "terminal.h"
#include "../common.h"
#include "../memory/kalloc.h"
#include "../common.h"
#include "../debug/assert.h"
#include "../debug/dump.h"
#include "video.h"
#include "terminal.h"
#define MAX(X,Y) X > Y ? X : Y
@ -19,13 +21,21 @@ inline void lower_blit(const Image* src, const Image* dst,
uint16_t dstx, uint16_t dsty,
uint16_t width, uint16_t height);
void initVideo(const Image* s) {
assert(s != NULL);
assert(s->bpp == 32);
void initVideo(const struct stivale2_struct_tag_framebuffer* fbtag) {
assert(fbtag != NULL);
memcpy(&screen,s, sizeof(Image));
}
screen = (Image){
.w = fbtag->framebuffer_width,
.h = fbtag->framebuffer_height,
.pitch= fbtag->framebuffer_pitch,
.bpp = fbtag->framebuffer_bpp,
.pix = (void*)fbtag->framebuffer_addr
};
assert(screen.bpp == 32);
}
void imageLower_blit(const Image* img,
uint16_t srcx, uint16_t srcy,
@ -410,6 +420,7 @@ for(ptr = col; ; ptr += 2px) {
*ptr = map+4*in'
}
*/
__attribute__((optimize("unroll-loops")))
void blitchar(const struct Image* charset,
char c, uint32_t fg_color, uint32_t bg_color,
@ -422,11 +433,11 @@ void blitchar(const struct Image* charset,
((uint64_t) fg_color << 32) | fg_color,
};
uint16_t srcy = c * FONTHEIGHT;
uint16_t srcy = c * TERMINAL_FONTHEIGHT;
uint64_t* dst_ptr = (uint64_t *)(screen.pix + screen.pitch * dsty + 4 * dstx);
uint16_t dst_skip = screen.pitch - FONTWIDTH * 4;
uint16_t dst_skip = screen.pitch - TERMINAL_FONTWIDTH * 4;
// 4 2-byte lines = 8*8 = 64 (1 access every 4 lines)
@ -436,17 +447,14 @@ void blitchar(const struct Image* charset,
// loop over 4-line chunks
// for(size_t n_lines = FONTHEIGHT / 4; n_lines > 0; --n_lines) {
uint64_t lines = *lines_ptr;
// 64 bit = 8 lines
#pragma GCC unroll 8
for(size_t n_line = 8; n_line > 0; n_line--) {
// lines are 8bit aligned
#pragma GCC unroll 3
for(size_t n_col2 = FONTWIDTH / 2 ; n_col2 > 0 ; n_col2--) {
for(size_t n_col2 = TERMINAL_FONTWIDTH / 2 ; n_col2 > 0 ; n_col2--) {
uint16_t index = lines & 0b11;
*(dst_ptr++) = colormap[index];
@ -454,13 +462,14 @@ void blitchar(const struct Image* charset,
}
dst_ptr += dst_skip / 8;
lines >>= 8 - FONTWIDTH;
lines >>= 8 - TERMINAL_FONTWIDTH;
}
}
__attribute__((optimize("unroll-loops")))
void blitcharX2(const struct Image* charset,
char c, uint32_t fg_color, uint32_t bg_color,
@ -473,22 +482,20 @@ void blitcharX2(const struct Image* charset,
((uint64_t) fg_color << 32) | fg_color,
};
uint16_t srcy = c * FONTHEIGHT;
uint16_t srcy = c * TERMINAL_FONTHEIGHT;
uint64_t* dst_ptr = (uint64_t *)(screen.pix + screen.pitch * dsty + 4 * dstx);
uint16_t dst_skip = 2 * screen.pitch - 2 * FONTWIDTH * 4;
uint16_t dst_skip = 2 * screen.pitch - 2 * TERMINAL_FONTWIDTH * 4;
/// second line to modify
uint64_t* dst_ptr2 = dst_ptr + screen.pitch / 8;
uint64_t* lines_ptr = (uint64_t*)charset->pix + srcy / sizeof(uint64_t);
uint64_t lines = *lines_ptr;
#pragma GCC unroll 8
for(size_t n_line = 8; n_line > 0; n_line--) {
#pragma GCC unroll 3
for(size_t n_col2 = FONTWIDTH / 2 ; n_col2 > 0 ; n_col2--) {
for(size_t n_col2 = TERMINAL_FONTWIDTH / 2 ; n_col2 > 0 ; n_col2--) {
uint16_t index = lines & 0b11;
register uint64_t pixs_val = colormap[index];
@ -506,15 +513,15 @@ void blitcharX2(const struct Image* charset,
dst_ptr2 += dst_skip / 8;
lines >>= 8 - FONTWIDTH;
lines >>= 8 - TERMINAL_FONTWIDTH;
}
}
// else this func wont work
static_assert(FONTWIDTH == 6);
static_assert(FONTWIDTH % 2 == 0);
static_assert(FONTHEIGHT == 8);
static_assert(TERMINAL_FONTWIDTH == 6);
static_assert(TERMINAL_FONTWIDTH % 2 == 0);
static_assert(TERMINAL_FONTHEIGHT == 8);
@ -527,20 +534,12 @@ Image* loadBMP_24b_1b(const void* rawFile) {
if(check_BMP_header(header))
return NULL;
//assert(header->bpp == 24); 5 ->
uint32_t w = header->w;
uint32_t h = header->h;
const uint8_t* srcpix = (const uint8_t *)header + header->body_offset;
kprintf("%x ; %u\n", header, header->body_offset);
dump(srcpix, 4 * 6 * 20, 4 * 5, DUMP_HEX8);
//asm volatile("hlt");
Image* ret = alloc_image(w,h, 1);
assert(ret->pitch == 1);

2
kernel/video/video.h

@ -25,7 +25,7 @@ typedef struct
const Image *getScreenImage(void);
void initVideo(const Image *srceen);
void initVideo(const struct stivale2_struct_tag_framebuffer* fbtag);
void imageDraw(const Image *img, const Pos *srcpos, const Rect *dstrect);
void imageLower_blit(

Loading…
Cancel
Save