OSDev.org

The Place to Start for Operating System Developers
It is currently Sat Nov 18, 2017 4:20 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: [C]Print something on the screen
PostPosted: Wed Jan 04, 2017 7:34 am 
Offline

Joined: Tue Aug 30, 2016 9:34 am
Posts: 15
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 !


Top
 Profile  
 
 Post subject: Re: [C]Print something on the screen
PostPosted: Wed Jan 04, 2017 8:25 am 
Offline
Member
Member

Joined: Sun Dec 11, 2016 3:31 am
Posts: 28
Location: In your computer
Afaik the attribute comes first in video memory so you have to switch them around in your code.

_________________
Working on BrainOS (github)

Push and Pray, Hope the build doesn't fail - bauen1 2017


Top
 Profile  
 
 Post subject: Re: [C]Print something on the screen
PostPosted: Wed Jan 04, 2017 8:37 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 3005
Location: Chichester, UK
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.


Top
 Profile  
 
 Post subject: Re: [C]Print something on the screen
PostPosted: Wed Jan 04, 2017 8:42 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 3005
Location: Chichester, UK
bauen1 wrote:
Afaik the attribute comes first in video memory so you have to switch them around in your code.
Incorrect.


Top
 Profile  
 
 Post subject: Re: [C]Print something on the screen
PostPosted: Wed Jan 04, 2017 9:38 am 
Offline

Joined: Tue Aug 30, 2016 9:34 am
Posts: 15
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.


Top
 Profile  
 
 Post subject: Re: [C]Print something on the screen
PostPosted: Wed Jan 04, 2017 10:15 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 3005
Location: Chichester, UK
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 7 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group