What's with this ClearScreen() function?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Crazed123

What's with this ClearScreen() function?

Post by Crazed123 »

My console function to clear the screen based on the desired attribute is for some reason, glitching up the screen with strange colors and symbols before finally crashing Bochs. I'm wondering why. I would attempt to extract information from an exception handler, but when I clear the screen they're not set up yet.

Code: Select all

type
 TAttrChar = packed record
  chChar: Char;
  btAttribute: Byte;
 end;
 PAttrChar = ^TAttrChar;

var
 btAttribute: Byte;

procedure ClearScreen();
var
acChar: TAttrChar;
begin
acChar.chChar:= Char($20);
acChar.btAttribute:= btAttribute;
FillWord(pVideoMemory^,25*80,Word(acChar));
end;
I don't see what's wrong with this, but I noticed that Bran's tutorial says

Code: Select all

void cls()
{
    unsigned blank;
    int i;

    /* Again, we need the 'short' that will be used to
    *  represent a space with color */
    blank = 0x20 | (attrib << 8);

    /* Sets the entire screen to spaces in our current
    *  color */
    for(i = 0; i < 25; i++)
        memsetw (textmemptr + i * 80, blank, 80);

    /* Update out virtual cursor, and then move the
    *  hardware cursor */
    csr_x = 0;
    csr_y = 0;
    move_csr();
}
And I'm wondering if it has something to do with the rows not being arranged directly after one another. Sorry about so much code, but I'm not good at explaining programming issues without it.
AR

Re:What's with this ClearScreen() function?

Post by AR »

Is btAttribute initalised? Other than that, does "FillWord" work?

Yes, the frame buffer is linear, it starts at 0xB8000 and is 4000 bytes long (80*25*2)
Crazed123

Re:What's with this ClearScreen() function?

Post by Crazed123 »

Yeah, the line before ClearScreen() is "btAttribute:= $07;". Fillword should work since I compiled the RTL correctly and it doesn't rely on any of my kernel functions, so what's going on darnit?!
smiddy

Re:What's with this ClearScreen() function?

Post by smiddy »

AR wrote: Is btAttribute initalised? Other than that, does "FillWord" work?

Yes, the frame buffer is linear, it starts at 0xB8000 and is 4000 bytes long (80*25*2)
Sorry to interject, but since y'all are using specifics I wanted to just point out that you can have multiple text modes. So the buffer is more specifically:

Code: Select all

Bytes = (Columns x Rows x (CharacterByte + AttributeByte [ or 2 bytes])) per video page, with page 0 (the first page) starting at 0B8000h for Color and 0B0000h for monochrome.
Sorry to be so anal, but it could be useful to know this down the road when you're switching text modes and pages.
Crazed123

Re:What's with this ClearScreen() function?

Post by Crazed123 »

Yeah, when I'm switching modes and pages instead of trying to make the thing go through its first steps of booting up.
Post Reply