Thread: Print finction not working?

  1. #1
    stovellp
    Guest

    Print finction not working?

    I have the following code:
    Code:
    void Print(char Text[10])
    {
    	char *vidmem = (char *) 0xb8002;
    	int I = 0;
    	while (I != 5)
    		{
    		if (Text[I] == '\n')
    			{
    			CurrentPosition = CurrentPosition + 80;
    			}
    		else            {
    			vidmem[CurrentPosition] = Text[I];
    			}
    		I++;
    		CurrentPosition = CurrentPosition + 2;
    		}
    	return;
    }
    This code is intended to be part of my "kernel" for my "OS".
    The idea of the function is that it takes a message and prints the letters on the screen. I get no errors compiling.

    When I go to run the code though, the program doesn't even seem to print anything, it just shutsdown. I know that it should work because the following code
    Code:
    char *vidmem = (char *) 0xb8002;
    vidmem = 'A';
    Works just fine. So I think the problem is that somehow my loop is stuffing me up. Any ideas?

  2. #2
    Registered User Azuth's Avatar
    Join Date
    Feb 2002
    Posts
    236
    OK. So how about a bit of debugging on your part...? Like putting a cout statement inside your loop to output your counter value as it increments (if it increments) or something along those lines.
    Demonographic rhinology is not the only possible outcome, but why take the chance

  3. #3
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    I cant, I cannot use ANY header files that I havent created myself.

    I know that theres nothing wrong with getting the letter to the script so I expect that theres something wrong with the way the statment assigns the letters to the addresses (The addresses are locations in video memory as far as I know).

  4. #4
    Registered User Azuth's Avatar
    Join Date
    Feb 2002
    Posts
    236
    You may not be able to use any headers that aren't your own for the finished product, but you would make your life a lot easier when it comes to debugging if you use a couple of standard ones while you're in the development stage.
    Demonographic rhinology is not the only possible outcome, but why take the chance

  5. #5
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Well my problem is that I write this in windows and I have no way of testing weather the code works within windows (protection and all that). So when I test I have to boot into DOS to test what I've written.

    I will use your Idea though and print out a letter the way I have been before to test that it works, thanks! (Y)

    I just hoped that there was an easier way, as I expect its because I'm using pointers and I dont have a great deal of knowledge about them, but thanks anyway (Y).

    Paul

  6. #6
    Registered User Azuth's Avatar
    Join Date
    Feb 2002
    Posts
    236
    O.K.

    So is the CurrentPosition variable global? Where's the rest of your code? Or at least the main that calls this function.
    Demonographic rhinology is not the only possible outcome, but why take the chance

  7. #7
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Yes, CurrentPosition is a global variable of type int, which is set to 0 by default.

    CurrentPosition is used to determine the position of the cursor.

    Main() Calls the function like this: Print("Hello");

  8. #8
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    You have a few problems. I dont know why you stop writing characters at 5. You must keep writing until you hit a null, which is a zero value.

    Code:
    void Print(char *Text)
    {
    	char *vidmem = (char *) 0xb8002;
    	char *position=Text;
    
    	while (position)
    	{
    		if (position == '\n')
    			CurrentPosition += 80;
    		else
    		{
    			vidmem[CurrentPosition++] = position;
    			vidmem[CurrentPosition++] = 7;
    		}
    	}
    }
    Second, do you know why you're skipping a byte (CurrentPosition+=2)? Well I've never written an OS or anything of that nature but I do know that when printing to the screen using that method, the format is: byte 1=character, byte 2=color. You should probably put a value of 7 for white on black or experiment to get nice colors. Go make a search on the web. Maybe that's why you didn't see anything, it was there but not visible.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. merging linked lists
    By scwizzo in forum C++ Programming
    Replies: 15
    Last Post: 09-14-2008, 05:07 PM
  2. Print out first N lines
    By YoYayYo in forum C Programming
    Replies: 1
    Last Post: 02-21-2008, 12:58 AM
  3. Retail Outlet Managment System - the 4th
    By Presidentofusa in forum C Programming
    Replies: 3
    Last Post: 11-10-2007, 10:44 PM
  4. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM
  5. How to print out the data throw printer.Attn Salem
    By Jason in forum C Programming
    Replies: 2
    Last Post: 09-23-2001, 05:58 AM