Page 1 of 2

Clear Screen

Posted: Thu Apr 24, 2003 3:44 pm
by pskyboy
Hey Guys

I have a clear screen function that used to work fine. I then changed my code to be linked at 3GB and load at 1Mb using the GDT trick. Now my clear screen function won't work and just sits there clearing the first character on the screen Any Ideas? Here is the code im using

Code: Select all

void clear_screen() // clear the entire text screen
{
   char *vidmem = (char *) 0xC00b8000;
   unsigned int i=0;
   while(i < (80*25*2))
   {
      vidmem[i]=' ';
      i++;
      vidmem[i]=WHITE_TXT;
      i++;
   };
}

Re:Clear Screen

Posted: Thu Apr 24, 2003 7:23 pm
by slacker
try this declaration for vidmem:

char *vidmem = (char *) 0xb8000;

-i dont know what that C00 is for...

Re:Clear Screen

Posted: Thu Apr 24, 2003 8:35 pm
by Curufir
Hmm, you mention a GDT trick.

Have you changed the base address on the selector? If so your pointer to video memory will be translated from logical->physical by adding that base address to the pointer, and end up pointing to the wrong place.

Just something I thought of when I read the message, could be completely wrong of course ;D.

Re:Clear Screen

Posted: Fri Apr 25, 2003 1:51 am
by Pype.Clicker
i think we can't find out what's wrong until you give us the base and limit for your data segment as well as the page mapping you use ...

Re:Clear Screen

Posted: Fri Apr 25, 2003 5:05 am
by pskyboy
Sorry, I ment to post that completly slipped my mind.

I have a base of 0x40000000 and a limit of 0xFFFF (4Gb as granuality bit is high) for my code and data segment. Then i have a selector of 0x0 and a limit of 0xFF for my Stack.

The C00 is to make it so that it translates to 0xB8000 when added to teh selector. This seems to work as i can write to the screen but i can't get a loop to go through and access each byte one after the other. I am wondering if this is a problem between with the way an index for an array is added to the base to calculae the address and the GDT?

Peter

Re:Clear Screen

Posted: Fri Apr 25, 2003 5:48 am
by Pype.Clicker
the GDT content is only used when the segment is loaded. The translation is applied only once the effective address has been computed (so it's independent from the actual addressing mode: based, indexed, indirect, direct, whatever ...)

what do the disassembled code look like ?

Re:Clear Screen

Posted: Fri Apr 25, 2003 11:21 am
by pskyboy
Is there anyway to get ndisasmw.exe to output to a file. I don't really fancy typing it out. Also how do you know how much is data of the COFF files that are output and how much is code?

Peter

Re:Clear Screen

Posted: Fri Apr 25, 2003 11:45 am
by pskyboy
Hey Guys

This code works and clears the first 3 Characters on the screen.

Code: Select all

   char *vidmem = (char *) 0xC00b8000;
   unsigned int i=0;

   *(char*)0xC00b8000 = ' ';
   *(char*)0xC00b8001 = WHITE_TXT;
   *(char*)0xC00b8002 = ' ';
   *(char*)0xC00b8003 = WHITE_TXT;
   *(char*)0xC00b8004 = ' ';
   *(char*)0xC00b8005 = WHITE_TXT;
This code however doesn't work, So its seems as though array indexing is causing problems.

Code: Select all

   char *vidmem = (char *) 0xC00b8000;
   unsigned int i=0;
   
   vidmem[i] = ' ';
   i++;
   vidmem[i] = WHITE_TXT;
   i++;
   vidmem[i] = ' ';
   i++;
   vidmem[i] = WHITE_TXT;
   i++;
   vidmem[i] = ' ';
   i++;
   vidmem[i] = WHITE_TXT;
   i++;

Re:Clear Screen

Posted: Fri Apr 25, 2003 12:10 pm
by Tim
You should definitely get a disassembly, and a register dump from Bochs -- it would be useful to find the value of ESP, and all the segment base addresses, limits and flags.

If you're disassembling COFF or other files, objdump is better, as long as you don't mind reading AT&T syntax. ndisasm gets confused by the file headers.

Re:Clear Screen

Posted: Fri Apr 25, 2003 1:04 pm
by _mark
You - now that you put it that way, I had the same problem when I did array indexing for the video memory. As in your case, this also worked fine:
char *vidmem = (char *)0XB8000;

for ( i=0; i <= 25*80*2; i++ )
{
*vidmem++= somechar;
*vidmem++= someattr;
}
Just like you, when indexing by array vidmem, yeilded unpredictable results. But just incrementing the pointer worked fine. Until now, I never gave a second thought about it. This was quite awhile ago when I was still getting used to realmode addressing, and I chalked my error up as a "realmode addressing quirk" I did not understand. Now looking back, I guess I understand realmode addressing pretty well, but I still do not understand why the array indexing did not work.

Tim is right, the asm results should yield some answers, but I do not have time to look right now. If noone else comes up with the answer I'll try and look this weekend.


_mark()

Re:Clear Screen

Posted: Fri Apr 25, 2003 1:55 pm
by shad
Declare your video memory as an unsigned short *.

Re:Clear Screen

Posted: Fri Apr 25, 2003 3:15 pm
by _mark
short vs. char does not explain the issue here. A short would just index you through the array in character+attribute pairs instead of indexing each one indavidually (char, attr, char, attr...etc.). They are each 8 bit values.

_mark()

Re:Clear Screen

Posted: Fri Apr 25, 2003 3:17 pm
by Pype.Clicker
probably your code is damaging something as it advances or maybe your timer interrupt is damaging some of your register ...

Re:Clear Screen

Posted: Fri Apr 25, 2003 3:37 pm
by _mark
Now that I re-read the post, I think my problem was different. My problem had to be real-mode addressing related. That does not explain anything about the problem this post is about. Sorry for screwing up the conversation flow there.

_mark()

Re:Clear Screen

Posted: Fri Apr 25, 2003 4:15 pm
by pskyboy
hey Guys

I finally figured out how to get it to output to a file. I knew there was a way to redirect output i just couldn't remeber how to do it but sorted that now.

anyway this code

Code: Select all

void clear_screen() // clear the entire text screen
{   
   char *pVidmem = (char *)0xC00b8000;
   unsigned int i=0;

   while(i < (80*25*2))
   {
      pVidmem[i]=' ';
      i++;
      pVidmem[i]=WHITE_TXT;
      i++;
   };
}
dissasembles to

Code: Select all

00000000 <__Z12clear_screenv>:
   0:   55                      push   %ebp
   1:   89 e5                   mov    %esp,%ebp
   3:   83 ec 08                sub    $0x8,%esp
   6:   c7 45 fc 00 80 0b c0    movl   $0xc00b8000,0xfffffffc(%ebp)
   d:   c7 45 f8 00 00 00 00    movl   $0x0,0xfffffff8(%ebp)
  14:   81 7d f8 9f 0f 00 00    cmpl   $0xf9f,0xfffffff8(%ebp)
  1b:   76 02                   jbe    1f <__Z12clear_screenv+0x1f>
  1d:   eb 1e                   jmp    3d <__Z12clear_screenv+0x3d>
  1f:   8b 45 f8                mov    0xfffffff8(%ebp),%eax
  22:   03 45 fc                add    0xfffffffc(%ebp),%eax
  25:   c6 00 20                movb   $0x20,(%eax)
  28:   8d 45 f8                lea    0xfffffff8(%ebp),%eax
  2b:   ff 00                   incl   (%eax)
  2d:   8b 45 f8                mov    0xfffffff8(%ebp),%eax
  30:   03 45 fc                add    0xfffffffc(%ebp),%eax
  33:   c6 00 07                movb   $0x7,(%eax)
  36:   8d 45 f8                lea    0xfffffff8(%ebp),%eax
  39:   ff 00                   incl   (%eax)
  3b:   eb d7                   jmp    14 <__Z12clear_screenv+0x14>
  3d:   c9                      leave  
  3e:   c3                      ret    
  3f:   90                      nop