Add: graphics mode terminal scrolling
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
#include "../libc/stdint.h"
|
#include "../libc/stdint.h"
|
||||||
#include "framebuffer.h"
|
#include "framebuffer.h"
|
||||||
#include "serial.h"
|
#include "serial.h"
|
||||||
|
#include "../kernel/system.h"
|
||||||
|
|
||||||
//extern uint32_t *g_framebuffer;
|
//extern uint32_t *g_framebuffer;
|
||||||
|
|
||||||
@@ -53,3 +54,40 @@ void draw_char(unsigned short int c, int cx, int cy, uint32_t fg, uint32_t bg)
|
|||||||
offs += scanline;
|
offs += scanline;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void scroll()
|
||||||
|
{
|
||||||
|
serial_printf(3, "Scrolling...\r");
|
||||||
|
uint32_t bg_color = 0x00000000;
|
||||||
|
PSF_font *font = (PSF_font*)&_binary_include_fonts_UniCyr_8x16_psf_start;
|
||||||
|
|
||||||
|
int line_size = font->height * scanline;
|
||||||
|
int framebuffer_size = scanline * font->height * (1080/font->height);
|
||||||
|
|
||||||
|
// Erasing first line
|
||||||
|
for (uint32_t y=0; y<font->height; y++)
|
||||||
|
{
|
||||||
|
for (uint32_t x=0; x<scanline/sizeof(PIXEL); x++)
|
||||||
|
{
|
||||||
|
*((PIXEL*)(framebuffer + y * scanline + x * sizeof(PIXEL))) = bg_color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Moving all lines up by 1 line
|
||||||
|
for (int y=1; y<(framebuffer_size/line_size); y++)
|
||||||
|
{
|
||||||
|
void* src = framebuffer + y*line_size;
|
||||||
|
void* dst = framebuffer + (y-1)*line_size;
|
||||||
|
memmove(dst, src, line_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Erasing last line
|
||||||
|
int last_line_start = (framebuffer_size/line_size-1) * line_size;
|
||||||
|
for (uint32_t y=0; y<font->height; y++)
|
||||||
|
{
|
||||||
|
for (uint32_t x=0; x<scanline/sizeof(PIXEL); x++)
|
||||||
|
{
|
||||||
|
*((PIXEL*)(framebuffer + last_line_start + y * scanline + x * sizeof(PIXEL))) = bg_color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -26,5 +26,6 @@ typedef struct {
|
|||||||
//extern const unsigned char font[512][64];
|
//extern const unsigned char font[512][64];
|
||||||
void putpixel(uint32_t* fb, int pitch, int bpp, int x, int y, uint32_t color);
|
void putpixel(uint32_t* fb, int pitch, int bpp, int x, int y, uint32_t color);
|
||||||
void draw_char(unsigned short int c, int cx, int cy, uint32_t fg, uint32_t bg);
|
void draw_char(unsigned short int c, int cx, int cy, uint32_t fg, uint32_t bg);
|
||||||
|
void scroll();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -77,9 +77,9 @@ serial_printf(3, "Framebuffer BPP: %u\r\n", fb_info->framebuffer_bpp);
|
|||||||
uint32_t pitch = fb_info->framebuffer_pitch;
|
uint32_t pitch = fb_info->framebuffer_pitch;
|
||||||
uint32_t bpp = fb_info->framebuffer_bpp;
|
uint32_t bpp = fb_info->framebuffer_bpp;
|
||||||
|
|
||||||
//8x16 font padded with 1 for each char = 9px/char
|
//8x16 font, not padded
|
||||||
VGA_WIDTH = width/9;
|
VGA_WIDTH = width/8;
|
||||||
VGA_HEIGHT = height/9;
|
VGA_HEIGHT = height/16;
|
||||||
|
|
||||||
scanline = width * (bpp/8);
|
scanline = width * (bpp/8);
|
||||||
|
|
||||||
@@ -114,6 +114,11 @@ serial_printf(3, "Framebuffer BPP: %u\r\n", fb_info->framebuffer_bpp);
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
for (int i=0; i<100; i++)
|
||||||
|
{
|
||||||
|
printf("%d\n", i);
|
||||||
|
}
|
||||||
|
|
||||||
//colorputs("Wow, such colorful output!", green, blue);
|
//colorputs("Wow, such colorful output!", green, blue);
|
||||||
|
|
||||||
colorputs(ascii_title, green, black);
|
colorputs(ascii_title, green, black);
|
||||||
|
|||||||
@@ -8,6 +8,27 @@ void *memset(void *dest, char val, size_t count)
|
|||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *memmove(void* dest, const void* src, size_t n)
|
||||||
|
{
|
||||||
|
unsigned char* d = (unsigned char*)dest;
|
||||||
|
const unsigned char* s = (const unsigned char*)src;
|
||||||
|
|
||||||
|
if (d < s)
|
||||||
|
{
|
||||||
|
for (size_t i=0; i<n; i++)
|
||||||
|
{
|
||||||
|
d[i] = s[i];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (size_t i=n; i>0; i--)
|
||||||
|
{
|
||||||
|
d[i-1] = s[i-1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return dest;
|
||||||
|
}
|
||||||
|
|
||||||
void panic()
|
void panic()
|
||||||
{
|
{
|
||||||
for (;;);
|
for (;;);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
typedef int size_t;
|
typedef int size_t;
|
||||||
|
|
||||||
void *memset(void *dest, char val, size_t count);
|
void *memset(void *dest, char val, size_t count);
|
||||||
|
void *memmove(void* dest, const void* src, size_t n);
|
||||||
|
|
||||||
struct regs
|
struct regs
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "stdint.h"
|
#include "stdint.h"
|
||||||
#include "../kernel/system.h"
|
#include "../kernel/system.h"
|
||||||
#include "../drivers/framebuffer.h"
|
#include "../drivers/framebuffer.h"
|
||||||
|
#include "../drivers/serial.h"
|
||||||
|
|
||||||
extern uint32_t* framebuffer;
|
extern uint32_t* framebuffer;
|
||||||
extern uint32_t VGA_WIDTH;
|
extern uint32_t VGA_WIDTH;
|
||||||
@@ -35,32 +36,6 @@ void clear(void)
|
|||||||
move_cursor(0, 0);
|
move_cursor(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void scroll(int lines)
|
|
||||||
{
|
|
||||||
if (lines <= 0 || (unsigned int)lines >= VGA_HEIGHT) return;
|
|
||||||
|
|
||||||
for (unsigned int y = 0; y < VGA_HEIGHT-lines; y++)
|
|
||||||
{
|
|
||||||
for (unsigned int x = 0; x < VGA_WIDTH; x++)
|
|
||||||
{
|
|
||||||
//putchar(getchar(x, y+lines), x, y, white, black);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (unsigned int y = VGA_HEIGHT-lines; y<VGA_HEIGHT; y++)
|
|
||||||
{
|
|
||||||
for (unsigned int x = 0; x < VGA_WIDTH; x++)
|
|
||||||
{
|
|
||||||
//putchar(' ', x, y, black, black);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
VGA_Y -= lines;
|
|
||||||
if ((int)VGA_Y < 0) {
|
|
||||||
VGA_Y = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void putc(char c)
|
void putc(char c)
|
||||||
{
|
{
|
||||||
switch(c)
|
switch(c)
|
||||||
@@ -101,7 +76,12 @@ void putc(char c)
|
|||||||
VGA_Y++;
|
VGA_Y++;
|
||||||
VGA_X = 0;
|
VGA_X = 0;
|
||||||
}
|
}
|
||||||
if (VGA_Y >= VGA_HEIGHT) scroll(1);
|
if (VGA_Y >= VGA_HEIGHT)
|
||||||
|
{
|
||||||
|
serial_printf(3, "VGA_Y=%d, VGA_HEIGHT=%d: Scrolling...\r", VGA_Y, VGA_HEIGHT);
|
||||||
|
scroll();
|
||||||
|
VGA_Y = VGA_HEIGHT - 1;
|
||||||
|
}
|
||||||
|
|
||||||
move_cursor(VGA_X, VGA_Y);
|
move_cursor(VGA_X, VGA_Y);
|
||||||
}
|
}
|
||||||
@@ -131,7 +111,14 @@ void colorputc(char c, uint32_t fg, uint32_t bg)
|
|||||||
VGA_Y++;
|
VGA_Y++;
|
||||||
VGA_X = 0;
|
VGA_X = 0;
|
||||||
}
|
}
|
||||||
if (VGA_Y >= VGA_HEIGHT) scroll(1);
|
|
||||||
|
if (VGA_Y >= VGA_HEIGHT)
|
||||||
|
{
|
||||||
|
serial_printf(3, "VGA_Y=%d, VGA_HEIGHT=%d: Scrolling...\r", VGA_Y, VGA_HEIGHT);
|
||||||
|
scroll();
|
||||||
|
VGA_Y = VGA_HEIGHT - 1;
|
||||||
|
}
|
||||||
|
|
||||||
move_cursor(VGA_X, VGA_Y);
|
move_cursor(VGA_X, VGA_Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ void colorputs(const char* str, uint32_t fg, uint32_t bg);
|
|||||||
void putcolor(int x, int y, unsigned int color);
|
void putcolor(int x, int y, unsigned int color);
|
||||||
char getchar(int x, int y);
|
char getchar(int x, int y);
|
||||||
unsigned int getcolor(int x, int y);
|
unsigned int getcolor(int x, int y);
|
||||||
void scroll(int lines);
|
|
||||||
void putc(char c);
|
void putc(char c);
|
||||||
void colorputc(char c, uint32_t fg, uint32_t bg);
|
void colorputc(char c, uint32_t fg, uint32_t bg);
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include "../libc/stdio.h"
|
#include "../libc/stdio.h"
|
||||||
#include "../kernel/system.h"
|
#include "../kernel/system.h"
|
||||||
#include "../libc/string.h"
|
#include "../libc/string.h"
|
||||||
|
#include "../drivers/framebuffer.h"
|
||||||
|
|
||||||
// Print a rainbow colorful text for testing
|
// Print a rainbow colorful text for testing
|
||||||
|
|
||||||
@@ -29,7 +30,7 @@ void program_rainbow()
|
|||||||
|
|
||||||
void program_clear()
|
void program_clear()
|
||||||
{
|
{
|
||||||
for (int i=0; i<ROWS; i++) scroll(1);
|
for (int i=0; i<ROWS; i++) scroll();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get uptime in ticks
|
// Get uptime in ticks
|
||||||
|
|||||||
Reference in New Issue
Block a user