Change: Framebuffer puts/printf graphics mode OK
This commit is contained in:
@@ -37,13 +37,13 @@ char* ascii_title =
|
|||||||
|
|
||||||
unsigned int g_multiboot_info_address;
|
unsigned int g_multiboot_info_address;
|
||||||
|
|
||||||
uint32_t white = 0xFFFFFFFF;
|
|
||||||
uint32_t black = 0x00000000;
|
|
||||||
uint32_t red = 0x00FF0000;
|
|
||||||
|
|
||||||
uint32_t* framebuffer;
|
uint32_t* framebuffer;
|
||||||
int scanline;
|
int scanline;
|
||||||
|
|
||||||
|
// in characters, not pixels
|
||||||
|
uint32_t VGA_WIDTH;
|
||||||
|
uint32_t VGA_HEIGHT;
|
||||||
|
|
||||||
void kmain(multiboot2_info *mb_info)
|
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 pitch = fb_info->framebuffer_pitch;
|
||||||
uint32_t bpp = fb_info->framebuffer_bpp;
|
uint32_t bpp = fb_info->framebuffer_bpp;
|
||||||
|
|
||||||
scanline = width * (bpp/8);
|
//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;
|
/* TEST print charset
|
||||||
for (int c=0; c<512; c++)
|
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 (i%(width/9)==0) y_offset++;
|
||||||
if (c%100 == 0) y_offset += 30;
|
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 y = 0; y < 10; y++) {
|
||||||
for (uint32_t x = 0; x < 10; x++) {
|
for (uint32_t x = 0; x < 10; x++) {
|
||||||
putpixel(framebuffer, (int)pitch, (int)bpp, x, y, red);
|
putpixel(framebuffer, (int)pitch, (int)bpp, x, y, red);
|
||||||
//framebuffer[y * (pitch / 4) + x] = 0xFF0000; // Rouge
|
//framebuffer[y * (pitch / 4) + x] = 0xFF0000; // Rouge
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
log("Drew to framebuffer.\r\n", 3);
|
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);
|
while (1);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,31 +3,33 @@
|
|||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include "stdint.h"
|
#include "stdint.h"
|
||||||
#include "../kernel/system.h"
|
#include "../kernel/system.h"
|
||||||
|
#include "../drivers/framebuffer.h"
|
||||||
|
|
||||||
char* fb = (char *) 0x000B8000;
|
extern uint32_t* framebuffer;
|
||||||
const unsigned VGA_WIDTH = 80;
|
extern uint32_t VGA_WIDTH;
|
||||||
const unsigned VGA_HEIGHT = 25;
|
extern uint32_t VGA_HEIGHT;
|
||||||
const unsigned int COLOR = 0x7;
|
|
||||||
unsigned int VGA_X = 0, VGA_Y = 0;
|
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)
|
void move_cursor(int x, int y)
|
||||||
{
|
{
|
||||||
unsigned short pos = y*VGA_WIDTH+x;
|
VGA_X = x;
|
||||||
|
VGA_Y = y;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
draw_char(c, x, y, fg, bg);
|
||||||
}
|
|
||||||
|
|
||||||
void putcolor(int x, int y, unsigned int color)
|
|
||||||
{
|
|
||||||
fb[2*(y*VGA_WIDTH+x)+1] = color;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear(void)
|
void clear(void)
|
||||||
@@ -36,23 +38,10 @@ void clear(void)
|
|||||||
{
|
{
|
||||||
for (unsigned int x=0; x<VGA_WIDTH; x++)
|
for (unsigned int x=0; x<VGA_WIDTH; x++)
|
||||||
{
|
{
|
||||||
putchar(x, y, '\0');
|
putchar(' ', x, y, black, black);
|
||||||
putcolor(x, y, COLOR);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
VGA_X = 0;
|
move_cursor(0, 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];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void scroll(int lines)
|
void scroll(int lines)
|
||||||
@@ -63,8 +52,7 @@ void scroll(int lines)
|
|||||||
{
|
{
|
||||||
for (unsigned int x = 0; x < VGA_WIDTH; x++)
|
for (unsigned int x = 0; x < VGA_WIDTH; x++)
|
||||||
{
|
{
|
||||||
putchar(x, y, getchar(x, y+lines));
|
//putchar(getchar(x, y+lines), x, y, white, black);
|
||||||
putcolor(x, y, getcolor(x, y+lines));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,8 +60,7 @@ void scroll(int lines)
|
|||||||
{
|
{
|
||||||
for (unsigned int x = 0; x < VGA_WIDTH; x++)
|
for (unsigned int x = 0; x < VGA_WIDTH; x++)
|
||||||
{
|
{
|
||||||
putchar(x, y, ' ');
|
//putchar(' ', x, y, black, black);
|
||||||
putcolor(x, y, COLOR);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,10 +97,10 @@ void putc(char c)
|
|||||||
VGA_Y--;
|
VGA_Y--;
|
||||||
VGA_X = VGA_WIDTH-1;
|
VGA_X = VGA_WIDTH-1;
|
||||||
}
|
}
|
||||||
putchar(VGA_X, VGA_Y, ' ');
|
putchar(' ', VGA_X, VGA_Y, white, black);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
putchar(VGA_X, VGA_Y, c);
|
putchar(c, VGA_X, VGA_Y, white, black);
|
||||||
VGA_X++;
|
VGA_X++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -143,8 +130,8 @@ void colorputc(char c, unsigned int color)
|
|||||||
VGA_X += 4;
|
VGA_X += 4;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
putchar(VGA_X, VGA_Y, c);
|
putchar(c, VGA_X, VGA_Y, white, black);
|
||||||
putcolor(VGA_X, VGA_Y, color);
|
//putcolor(VGA_X, VGA_Y, color);
|
||||||
VGA_X++;
|
VGA_X++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
#define FB_LOW_BYTE_CMD 15
|
#define FB_LOW_BYTE_CMD 15
|
||||||
|
|
||||||
void move_cursor(int x, int y);
|
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 puts(const char* str);
|
||||||
void colorputs(const char* str, unsigned int color);
|
void colorputs(const char* str, unsigned int color);
|
||||||
void clear(void);
|
void clear(void);
|
||||||
|
|||||||
Reference in New Issue
Block a user