Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VGA.clear() not working for VGA_COLOUR #6

Open
robinhedwards opened this issue Nov 23, 2013 · 2 comments
Open

VGA.clear() not working for VGA_COLOUR #6

robinhedwards opened this issue Nov 23, 2013 · 2 comments

Comments

@robinhedwards
Copy link

There's a little bug in the clear() method, which just clears the monochrome framebuffer (I guess memset does a null pointer check, preventing a crash if called in colour mode).

Think it needs to be something like the below (I've added a parameter to set the colour).

// VGA.h
void clear(int c = 0);
// Graphics.cpp
void Vga::clear(int c){
if(mode&VGA_COLOUR)
    memset(cb,c,cbsize);
else
  memset(pb,0,2*pbsize);
}

P.S. Thanks for an amazing library!

@stimmer
Copy link
Owner

stimmer commented Nov 24, 2013

Thanks for the message, I am looking into it. It's definitely a bug.

Memset doesn't do a null pointer check, I think the reason it doesn't crash might be that there's nothing in the memory map at address 0, I can't remember. It should be OK to set the screen to a colour using memset but you can't use memset to set a mono screen to white (as it has a black guard band at the end of each line)

@stimmer
Copy link
Owner

stimmer commented Nov 27, 2013

OK I think I've fixed this. I added the colour parameter and colour setting code as you suggested and added a correct way to set the background in mono mode so both black and white work.

void Vga::clear(int c){
    if(mode==VGA_MONO){
        for(int y=0;y<ysize;y++){
         memset(pb+y*pw,(c&1)?0xff:0,xsize/8);
        }
    }
    else if(mode&VGA_COLOUR){
      memset(cb,c,cbsize);
    }

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants