[C]Print something on the screen

Programming, for all ages and all languages.
Post Reply
leosa99
Posts: 21
Joined: Tue Aug 30, 2016 9:34 am
Libera.chat IRC: leosa99

[C]Print something on the screen

Post 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 !
User avatar
bauen1
Member
Member
Posts: 29
Joined: Sun Dec 11, 2016 3:31 am
Libera.chat IRC: bauen1
Location: In your computer
Contact:

Re: [C]Print something on the screen

Post by bauen1 »

Afaik the attribute comes first in video memory so you have to switch them around in your code.
myunix (version 3) (name suggestions are welcome!)
GPG Key fingerprint: 5ED6 D826 ACD4 3F8E D9D4 FBB2 FF0A AF5E 0812 BA9C
User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: [C]Print something on the screen

Post 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.
User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: [C]Print something on the screen

Post by iansjack »

bauen1 wrote:Afaik the attribute comes first in video memory so you have to switch them around in your code.
Incorrect.
leosa99
Posts: 21
Joined: Tue Aug 30, 2016 9:34 am
Libera.chat IRC: leosa99

Re: [C]Print something on the screen

Post 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.
User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: [C]Print something on the screen

Post 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.
Post Reply