OSDev.org
https://forum.osdev.org/

[C]Print something on the screen
https://forum.osdev.org/viewtopic.php?f=13&t=31162
Page 1 of 1

Author:  leosa99 [ Wed Jan 04, 2017 7:34 am ]
Post subject:  [C]Print something on the screen

Hi !
I'm trying to print a 'B' on the screen but it keeps showing garbage value.
Kernel main entry point :
Code:
#include "kernel_func.h"
void kmain()
{
char character = 'B';
printCharacter(character);
while(1){}; // Loop.
}

kernel_func file :
Code:
#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 !

Author:  bauen1 [ Wed Jan 04, 2017 8:25 am ]
Post subject:  Re: [C]Print something on the screen

Afaik the attribute comes first in video memory so you have to switch them around in your code.

Author:  iansjack [ Wed Jan 04, 2017 8:37 am ]
Post subject:  Re: [C]Print something on the screen

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.

Author:  iansjack [ Wed Jan 04, 2017 8:42 am ]
Post subject:  Re: [C]Print something on the screen

bauen1 wrote:
Afaik the attribute comes first in video memory so you have to switch them around in your code.
Incorrect.

Author:  leosa99 [ Wed Jan 04, 2017 9:38 am ]
Post subject:  Re: [C]Print something on the screen

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:
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.

Author:  iansjack [ Wed Jan 04, 2017 10:15 am ]
Post subject:  Re: [C]Print something on the screen

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.

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/