Page 1 of 1

[C]Print something on the screen

Posted: Wed Jan 04, 2017 7:34 am
by leosa99
Hi !
I'm trying to print a 'B' on the screen but it keeps showing garbage value.
Kernel main entry point :

Code: Select all

#include "kernel_func.h"
void kmain()
{
char character = 'B';
printCharacter(character);
while(1){}; // Loop.
}
kernel_func file :

Code: Select all

#define RAMSCREEN 0xB8000 // Video address.

void printCharacter(char whatToPrint)
{
char *ram = (char*)RAMSCREEN;
char text = whatToPrint;
char att = 0xC; // Red on black
*ram=text;
ram = (char*)0xB8001;
*ram=att;
}
Thanks !

Re: [C]Print something on the screen

Posted: Wed Jan 04, 2017 8:25 am
by bauen1
Afaik the attribute comes first in video memory so you have to switch them around in your code.

Re: [C]Print something on the screen

Posted: Wed Jan 04, 2017 8:37 am
by iansjack
Give us a hint or two.

1. Where on the screen does it print?
2. What does it print?
3. Does it consistently print the same wrong value each time you run it.
4. How are you running the code?
5. How do you know that you ever reach the kmain() function?

Have you disassembled your code to see what is happening at assembler level?

Can I also remark that, as this is essentially identical to a previous question from you, it would be more helpful to stick to one thread.

Re: [C]Print something on the screen

Posted: Wed Jan 04, 2017 8:42 am
by iansjack
bauen1 wrote:Afaik the attribute comes first in video memory so you have to switch them around in your code.
Incorrect.

Re: [C]Print something on the screen

Posted: Wed Jan 04, 2017 9:38 am
by leosa99
It prints on the top left corner.
It always prints the same thing, I know that the kmain() function is reached cause this code works :

Code: Select all

void printWhiteCharacter(char whatToPrint) // It print a character at the selected location. ROW=Y
{
char *ram = (char*)RAMSCREEN;
char text = 'A';
char att = 0xC; // Red on black
*ram=text;
ram = (char*)0xB8001;
*ram=att;
}
All i'm trying to do is passing the character as a parameter, and it does not work.
And the text attributes (red background, black text) is ok.

Re: [C]Print something on the screen

Posted: Wed Jan 04, 2017 10:15 am
by iansjack
So, what does it print?

As I suggested in your previous thread, single-step through the code in a debugger and all should become clear.