Skip to content

Commit

Permalink
drivers,fb: make scrolling optional (default)
Browse files Browse the repository at this point in the history
Framebuffer scrolling can be enabled/disabled either on boot time
via 'fb_scroll' cmdline parameter or on runtime using set_fb_scroll();

Signed-off-by: Pawel Wieczorkiewicz <[email protected]>
  • Loading branch information
wipawel committed Aug 23, 2023
1 parent 1da50f4 commit c351a82
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
3 changes: 3 additions & 0 deletions common/cmdline.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ string_cmd("com3", opt_com3);
static char opt_com4[20];
string_cmd("com4", opt_com4);

bool opt_fb_scroll = true;
bool_cmd("fb_scroll", opt_fb_scroll);

const char *kernel_cmdline;

void __text_init cmdline_parse(const char *cmdline) {
Expand Down
22 changes: 19 additions & 3 deletions drivers/fb/fb.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ extern uint64_t fonts[];
#define TEXT_AREA_FIRST_ROW (((LOGO_HEIGHT + FONT_SIZE) / FONT_SIZE) * FONT_SIZE)

static bool has_fb = false;
static bool scroll = false;

static uint32_t width;
static uint32_t height;
Expand Down Expand Up @@ -134,6 +135,7 @@ bool setup_framebuffer(void) {
memset(video_memory, 0, buffer_size);

register_console_callback(fb_console_write, video_memory);
scroll = opt_fb_scroll;
return true;
}

Expand Down Expand Up @@ -169,11 +171,19 @@ void draw_logo(void) {
draw_line(0, LOGO_HEIGHT + 2, width, LOGO_HEIGHT + 2, FB_WHITE);
}

void scroll_up_line(void) {
void set_fb_scroll(bool state) {
scroll = state;
}

static inline void scroll_up_line(void) {
memmove(first_line_addr, first_line_addr + line_width,
last_line_addr - first_line_addr);
}

static inline void clear_screen(void) {
memset(first_line_addr, 0, last_line_addr - first_line_addr);
}

void fb_write(void *fb_addr, const char *buf, size_t len, uint32_t color) {
static uint32_t row = TEXT_AREA_FIRST_ROW, col = 0;

Expand All @@ -186,8 +196,14 @@ void fb_write(void *fb_addr, const char *buf, size_t len, uint32_t color) {
}

if ((row + FONT_SIZE) >= height) {
scroll_up_line();
row -= FONT_SIZE;
if (scroll) {
scroll_up_line();
row -= FONT_SIZE;
}
else {
clear_screen();
row = TEXT_AREA_FIRST_ROW;
}
col = 0;
}

Expand Down
1 change: 1 addition & 0 deletions include/cmdline.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ extern bool opt_hpet;
extern bool opt_fpu;
extern bool opt_qemu_console;
extern bool opt_poweroff;
extern bool opt_fb_scroll;

extern const char *kernel_cmdline;

Expand Down
1 change: 1 addition & 0 deletions include/drivers/fb.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ extern void draw_line(uint32_t x1, uint32_t y1, uint32_t x2, uint32_t y2, uint32
extern void draw_logo(void);
extern void fb_write(void *fb_addr, const char *buf, size_t len, uint32_t color);
extern bool setup_framebuffer(void);
extern void set_fb_scroll(bool state);

#endif /* KTF_DRV_FB_H */

0 comments on commit c351a82

Please sign in to comment.