flat assembler
Message board for the users of flat assembler.

Index > High Level Languages > [C] Better Printc implementation.

Author
Thread Post new topic Reply to topic
nerdguy



Joined: 24 Nov 2013
Posts: 7
nerdguy 24 Nov 2013, 10:47
Hi,
This is my first post on FASM Forums,
Hello to the whole FASM community!
I've been working on a 64 bit Kernel recently,
(github.com/nerdguy12/core64),
I've implemented the putchar functions as follows,
Code:
unsigned int putch(unsigned char string,int y)
{
        char *vgamem = (char *) 0xb8000; // Need a pointer to the VGA Memory
        unsigned int i2= 0;
        i2=(y*80*2);
        vgamem[i2]= string; // Put the string in the VGA Memory
        i2++;
        vgamem[i2]= 0x2F; // And the color
        i2++;
}
    

The problem starts when I need to print the string at a certain X Position,
I use the line variable to set the Y Position of the text cursor and print the string
there.
I've read the bkerndev and I sum up to this equation.
VGA_MEM = 0xB8000 + (Y*80 + X)
Now if I put the character at this memory location, it would be at (X,Y),
So I change the function to :
Code:
usigned int putch(int X,int Y,char *string)
{
 char *vgamem = (char *) 0xb8000 + (Y*80 + X); // Need a pointer to the VGA Memory
//
// Same code
//
}
    

I'm doing something wrong here that it doesn't even print to the screen,
What do you think is the problem?
Also a better printc implementation could help.
Post 24 Nov 2013, 10:47
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 24 Nov 2013, 12:59
Welcome Cool

Each character cell is actually two bytes so you need to do:
Code:
char *vgamem = (char *) 0xB8000 + ((Y*80 + X) * 2);
// or
short *vgamem = (short *) 0xB8000 + (Y*80 + X);    
The upper 8 bits hold the fore- and back- ground colour codes (4 bits each) while the lower 8 bits are the character code.
Post 24 Nov 2013, 12:59
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.