Thread: Fast clrscr function

  1. #1
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669

    Exclamation Fast clrscr function

    Hi!

    I want to create a fast clear screen code. This code clears only one row and I don't know why. PLEASE HELP!!!

    Here's my code:
    Code:
    void clrscr (short x, short y, short EraseLength, short NoOfLines)
    {
        short i = 0, j = 0;
        char Clear[30][85];
    
        for (i = 0; i <= NoOfLines; i++)
        {
            for (j = 0; j <= EraseLength; j++)
            {
                Clear[i][j] = ' ';
            }
            Clear[i][j] = '\0';
        }
        Clear[i][j] = '\0';
        gotoxy (x, y);
        printf ("%s", Clear);
    }
    I want that printf will be used only once and that the program will clear the selected rows and cells in one shot.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  2. #2
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    Is this function really faster than 'clrscr()'??? And note that you are only printing the first line! Run a loop if you have to print all the contents in the 'Clear' variable.

    I hope this will help you:
    Code:
    void mclrscr(short x, short y, short EraseLength, short NoOfLines)
    {
    	while(x < EraseLength) {
    		while(y < NoOfLines) {
    			gotoxy(x ++, y ++);
    			putchar(' ');
    		}
    	}
    }
    Last edited by shaik786; 06-08-2002 at 05:34 AM.

  3. #3
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    Your function is slow. Mine is faster but the problem is that clears only one row. But if I put printf into a first for loop, then the printf function will be called NoOfLines times which is not good.

    HELP!

    EDIT:
    shaik786, you did not read my instructions! You must use the printf function and must be used only once.
    Last edited by GaPe; 06-08-2002 at 05:42 AM.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  4. #4
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    Oops, sorry!

    Code:
    void clrscr (short x, short y, short EraseLength, short NoOfLines)
    {
        short i = 0, j = 0;
        char Clear[2500];
        int pos = 0;
    
        for (i = 0; i <= NoOfLines; i++)
        {
            for (j = 0; j <= EraseLength; j++)
            {
                    Clear[pos ++] = ' ';
            }
            Clear[pos ++] = '\n';
        }
        Clear[pos] = '\0';
        gotoxy (x, y);
        printf ("%s", Clear);
    }
    Last edited by shaik786; 06-08-2002 at 06:12 AM.

  5. #5
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    Hm, not good enough. That '\n' is giving me a headache. You know, the x coordinates of the ' ' character must be the same as the first one. How to align it inside the array?
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I want that printf will be used only once and that the program will clear the selected rows and cells in one shot.
    Then you are not clearing the screen. You're clearing a given box on the screen. As such, you cannot simply use printf to do the job. You need to basicly buffer what is on the screen and manually edit the buffer, changing parts of it.

    Quzah.
    Hope is the first step on the road to disappointment.

  7. #7
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    How do I do that?
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  8. #8
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    Here's a hint: The Video RAM is at: 0xB800
    And I'll assure you, this will be real fast!

  9. #9
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    That's cool but I don't know how to program with asm.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  10. #10
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    You don't need to. You can do it in C as well. Just declare a FAR pointer to this address. and write to this location, as simple as that.

    Code:
    main()
    {
             unsigned char far *addr = 0xB800;
    
             *(addr + 0) = 'S';   /*   ODD Bytes are for colour: *(addr + 1) = 1   */
             *(addr + 2) = 'H';
             *(addr + 4) = 'A';
             *(addr + 6) = 'I';
             *(addr + 8) = 'K';
    }
    But check to see if your compiler allows for direct access of this memory.

  11. #11
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    ........ or check to see if your compiler provides pokeb()

  12. #12
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    No, my VC++.NET does not allow that. I need this function to clear the box of a screen for a console program.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  13. #13
    Unregistered
    Guest
    if code for windows use this :

    Code:
    #include <windows.h> 
    #include <conio.h> 
    
    int clrscr() 
    { 
    
      HANDLE hndl = GetStdHandle(STD_OUTPUT_HANDLE); 
      CONSOLE_SCREEN_BUFFER_INFO csbi; 
      GetConsoleScreenBufferInfo(hndl, &csbi); 
      DWORD written; 
      DWORD N = csbi.dwSize.X * csbi.dwCursorPosition.Y + 
                csbi.dwCursorPosition.X + 1; 
      COORD curhome = {0,0}; 
    
      FillConsoleOutputCharacter(hndl, ' ', N, curhome, &written); 
      csbi.srWindow.Bottom -= csbi.srWindow.Top; 
      csbi.srWindow.Top = 0; 
      SetConsoleWindowInfo(hndl, TRUE, &csbi.srWindow); 
      SetConsoleCursorPosition(hndl, curhome); 
    
      return 0; 
    }

  14. #14
    Registered User
    Join Date
    Jun 2002
    Posts
    14

    Thumbs up HERE"S THE BEST WAY TO DO SO!

    being a senior member u must be familiar with the 'int68()'
    function in 'C'

    just save this function 'cls' in any C file out it in the include folder of your Tc and enjoy it!

    this is the fastest onr ,& i mean it.
    i have used it.

    please don't tell me that u don't know this one.....

    void cls()
    {
    union REGS i,o;

    i.h.ah = 6;
    i.h.bh = 7;
    i.h.ch = 0;
    i.h.dh = 24;
    i.h.al = 0;
    i.h.cl = 0;
    i.h.dl = 79;

    int86(16,&i,&o);
    gotoxy(1,1);
    }
    Ruchit,
    think big,think ahead,
    go big,go ahead,

    ISN'T IT TOO FUNNY ABOUT MICROSOFT WINDOWS,THAT
    WHENEVER YOU WANT TO DO SOMETHING YOU CLICK ON "START" BUTTON AND THE FIRST OPTION YOU ARE HAVING IS
    "SHUT DOWN"...

  15. #15
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    Unregistered:

    This code is for clearing the whole screen. Not good. PLEASE, read my instructions. I need function which will only clear some selected box.

    s_ruchit:
    READ MY INSTRUCTIONS. Your code is for DOS.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Bisection Method function value at root incorrect
    By mr_glass in forum C Programming
    Replies: 3
    Last Post: 11-10-2005, 09:10 AM
  4. Replies: 4
    Last Post: 11-23-2003, 07:15 AM
  5. Replies: 5
    Last Post: 02-08-2003, 07:42 PM