Resolution seems to be cut off

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
goku420
Member
Member
Posts: 51
Joined: Wed Jul 10, 2013 9:11 am

Resolution seems to be cut off

Post 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);
}
User avatar
b.zaar
Member
Member
Posts: 294
Joined: Wed May 21, 2008 4:33 am
Location: Mars MTC +6:00
Contact:

Re: Resolution seems to be cut off

Post 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.
"God! Not Unix" - Richard Stallman

Website: venom Dev
OS project: venom OS
Hexadecimal Editor: hexed
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Resolution seems to be cut off

Post 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)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply