Page 1 of 1

Resolution seems to be cut off

Posted: Mon Sep 08, 2014 12:30 am
by goku420
For some reason I can only draw up to a certain point.

Image

I'm using [url=http://www.inp.nsk.su./~bolkhov/files/fonts/univga/]univga[url] for the font. Here is my code:

Code: Select all

; boot.asm
MODE_TYPE   equ  0
WIDTH       equ  640
HEIGHT      equ  480
DEPTH       equ  16

Code: Select all

int x_ = 0, y_ = font.Height;

void putpixel(int x, int y, int color) {
    unsigned char* screen = (unsigned char*) 0xA0000;
    // Hard-coded
    unsigned where = x*2 + y*1280;
    screen[where] = color & 255;              // BLUE
    screen[where + 1] = (color >> 8) & 255;   // GREEN
    screen[where + 2] = (color >> 16) & 255;  // RED
}

unsigned char reverse(unsigned char b) {
   b = (b & 0xF0) >> 4 | (b & 0x0F) << 4;
   b = (b & 0xCC) >> 2 | (b & 0x33) << 2;
   b = (b & 0xAA) >> 1 | (b & 0x55) << 1;
   return b;
}

void drawchar(char c, int x, int y, int fgcolor, int bgcolor)
{
	int cx, cy;
	int mask[8]={1,2,4,8,16,32,64,128};
        // Font layout starts from space (ascii 32)
        // Skip first character
	const unsigned char *glyph = font.Bitmap + ((int)c - 32 + 1) * font.Height;
 
	for(cy = 0; cy < font.Height; cy++){
		for(cx = 0; cx < font.Width; cx++) {
                        // For some reason it draws the glyphs backwards
			putpixel(x + cx, y + cy - 12, reverse(glyph[cy]) & mask[cx] ? fgcolor : bgcolor);
		}
	}
	x_ += font.Width;
	if (x_ >= 640)
	{
		x_ = 0;
		y_ += font.Height;
	}	
}

void drawchar(char c)
{
	drawchar(c, x_, y_, 0xFFFFFF, 0xAAAAAA);
}

void drawstring(int x, int y, const char* input)
{
	char buffer[strlen(input) + 1];
	memcpy(buffer, input, strlen(input)+1);

	char * ptr = buffer;
	while (*ptr)
	{
		if (*ptr == '\n')
		{
			x = 0;
			y += font.Height;
			x_ = x;
			y_ = y;
		} else {
			drawchar(*ptr, x, y, 0xFFFFFF, 0xAAAAAA);
			x += font.Width;
		}
		++ptr;
	}
}

void drawstring(const char* input)
{
	drawstring(x_, y_, input);
}

Re: Resolution seems to be cut off

Posted: Mon Sep 08, 2014 1:26 am
by b.zaar
remyabel wrote:For some reason I can only draw up to a certain point.

Code: Select all

int x_ = 0, y_ = font.Height;

void putpixel(int x, int y, int color) {
    unsigned char* screen = (unsigned char*) 0xA0000;
    // Hard-coded
    unsigned where = x*2 + y*1280;
    screen[where] = color & 255;              // BLUE
    screen[where + 1] = (color >> 8) & 255;   // GREEN
    screen[where + 2] = (color >> 16) & 255;  // RED
}
Would this be better to use screen as an int pointer?

Also you're multiplying for a 16 bit pixel but then putting 3 bytes at where.

Re: Resolution seems to be cut off

Posted: Mon Sep 08, 2014 4:04 am
by Combuster
Two things:
- Your text look stretched, as if you're using the wrong bpp
- You're using the VGA window rather than the LFB. Without bank switching calls that gives you roughly 50 lines of pixels to write to. (you're probably writing into the BIOS area, and possibly your kernel in this fashion)