stimmer / DueVGA

Arduino Due VGA library
92 stars 30 forks source link

VGA.clear() not working for VGA_COLOUR #6

Open robinhedwards opened 10 years ago

robinhedwards commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

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);
    }

}