Change: Framebuffer puts/printf graphics mode OK

This commit is contained in:
xamidev
2024-08-20 13:01:13 +02:00
parent 98d3d346c2
commit 52a92a5358
3 changed files with 48 additions and 60 deletions

View File

@@ -37,13 +37,13 @@ char* ascii_title =
unsigned int g_multiboot_info_address;
uint32_t white = 0xFFFFFFFF;
uint32_t black = 0x00000000;
uint32_t red = 0x00FF0000;
uint32_t* framebuffer;
int scanline;
// in characters, not pixels
uint32_t VGA_WIDTH;
uint32_t VGA_HEIGHT;
void kmain(multiboot2_info *mb_info)
{
@@ -78,34 +78,35 @@ serial_printf(3, "Framebuffer BPP: %u\r\n", fb_info->framebuffer_bpp);
uint32_t pitch = fb_info->framebuffer_pitch;
uint32_t bpp = fb_info->framebuffer_bpp;
//8x16 font padded with 1 for each char = 9px/char
VGA_WIDTH = width/9;
VGA_HEIGHT = height/9;
scanline = width * (bpp/8);
draw_char('S', 2, 2, white, black);
draw_char('A', 3, 2, white, black);
draw_char('L', 4, 2, white, black);
draw_char('U', 5, 2, white, black);
draw_char('T', 6, 2, white, black);
int y_offset = 0;
for (int c=0; c<512; c++)
/* TEST print charset
int y_offset = 2;
for (int i=0; i<512; i++)
{
//draw_char(framebuffer, (int)pitch, (int)bpp, 20+(c-65)*16, 110+y_offset, c, white, black);
if (c%100 == 0) y_offset += 30;
if (i%(width/9)==0) y_offset++;
draw_char(0+i, 0+i, y_offset, white, black);
}
*/
/* TEST print red square
for (uint32_t y = 0; y < 10; y++) {
for (uint32_t x = 0; x < 10; x++) {
putpixel(framebuffer, (int)pitch, (int)bpp, x, y, red);
//framebuffer[y * (pitch / 4) + x] = 0xFF0000; // Rouge
}
}
*/
log("Drew to framebuffer.\r\n", 3);
}
puts("This should NOT work.");
puts("This should work by now! Enter Graphics Mode.");
printf("\nMy name is %s, and I'm %d. 0x%x", "Alan", 34, 0xdeadbeef);
while (1);

View File

@@ -3,31 +3,33 @@
#include "string.h"
#include "stdint.h"
#include "../kernel/system.h"
#include "../drivers/framebuffer.h"
char* fb = (char *) 0x000B8000;
const unsigned VGA_WIDTH = 80;
const unsigned VGA_HEIGHT = 25;
const unsigned int COLOR = 0x7;
extern uint32_t* framebuffer;
extern uint32_t VGA_WIDTH;
extern uint32_t VGA_HEIGHT;
unsigned int VGA_X = 0, VGA_Y = 0;
enum Colors
{
// AARRGGBB?
white = 0xFFFFFFFF,
black = 0x00000000,
red = 0x00FF0000,
green = 0x0000FF00,
blue = 0x000000FF,
};
void move_cursor(int x, int y)
{
unsigned short pos = y*VGA_WIDTH+x;
outb(FB_CMD_PORT, FB_HIGH_BYTE_CMD);
outb(FB_DATA_PORT, ((pos >> 8) & 0x00FF));
outb(FB_CMD_PORT, FB_LOW_BYTE_CMD);
outb(FB_DATA_PORT, pos & 0x00FF);
VGA_X = x;
VGA_Y = y;
}
void putchar(int x, int y, char c)
// stdio wrapper for draw_char in graphics mode
void putchar(unsigned short int c, int x, int y, uint32_t fg, uint32_t bg)
{
fb[2*(y*VGA_WIDTH+x)] = c;
}
void putcolor(int x, int y, unsigned int color)
{
fb[2*(y*VGA_WIDTH+x)+1] = color;
draw_char(c, x, y, fg, bg);
}
void clear(void)
@@ -36,23 +38,10 @@ void clear(void)
{
for (unsigned int x=0; x<VGA_WIDTH; x++)
{
putchar(x, y, '\0');
putcolor(x, y, COLOR);
putchar(' ', x, y, black, black);
}
}
VGA_X = 0;
VGA_Y = 0;
move_cursor(VGA_X, VGA_Y);
}
char getchar(int x, int y)
{
return fb[2*(y*VGA_WIDTH+x)];
}
unsigned int getcolor(int x, int y)
{
return fb[2*(y*VGA_WIDTH+x)+1];
move_cursor(0, 0);
}
void scroll(int lines)
@@ -63,8 +52,7 @@ void scroll(int lines)
{
for (unsigned int x = 0; x < VGA_WIDTH; x++)
{
putchar(x, y, getchar(x, y+lines));
putcolor(x, y, getcolor(x, y+lines));
//putchar(getchar(x, y+lines), x, y, white, black);
}
}
@@ -72,8 +60,7 @@ void scroll(int lines)
{
for (unsigned int x = 0; x < VGA_WIDTH; x++)
{
putchar(x, y, ' ');
putcolor(x, y, COLOR);
//putchar(' ', x, y, black, black);
}
}
@@ -110,10 +97,10 @@ void putc(char c)
VGA_Y--;
VGA_X = VGA_WIDTH-1;
}
putchar(VGA_X, VGA_Y, ' ');
putchar(' ', VGA_X, VGA_Y, white, black);
break;
default:
putchar(VGA_X, VGA_Y, c);
putchar(c, VGA_X, VGA_Y, white, black);
VGA_X++;
break;
}
@@ -143,8 +130,8 @@ void colorputc(char c, unsigned int color)
VGA_X += 4;
break;
default:
putchar(VGA_X, VGA_Y, c);
putcolor(VGA_X, VGA_Y, color);
putchar(c, VGA_X, VGA_Y, white, black);
//putcolor(VGA_X, VGA_Y, color);
VGA_X++;
break;
}

View File

@@ -12,7 +12,7 @@
#define FB_LOW_BYTE_CMD 15
void move_cursor(int x, int y);
void putchar(int x, int y, char c);
void putchar(unsigned short int c, int x, int y, uint32_t fg, uint32_t bg);
void puts(const char* str);
void colorputs(const char* str, unsigned int color);
void clear(void);