# File lib/host_systems/Coco.rb, line 78
def self.to_screendump(text,screen_width)
  lines=split_into_lines(text,screen_width)  
  canvas = PNG::Canvas.new font_width*screen_width, (pixels_between_characters+font_height)*[lines.length,screen_rows].max, default_background_colour
  line_number=0
  lines.each do |line|
    col=0
    line.each_byte do |char|
      if (char>=0x80) then
        colour_mask=((char & 0b01110000)>>4)
        foreground_colour=COCO_COLOURS[colour_mask]
        4.times do |quadrant|
          quadrant_mask=1<<quadrant
          if (char & quadrant_mask)>0 then
            block_colour=foreground_colour
          else 
            block_colour=PNG::Color::Black
          end
        
          start_x=(col*8)+COCO_BLOCK_QUADRANT_OFFSETS[quadrant][0]
          start_y=(line_number*12)+COCO_BLOCK_QUADRANT_OFFSETS[quadrant][1]
          6.times do |y_offset|
            4.times do |x_offset|
                canvas[start_x+x_offset, start_y+y_offset]=block_colour
              end
            end
        end
      else #if char is 0..0x3F it's an inverse uppercase char
        case char
        when 0x00..0x3F then
          draw_char_at(canvas,char,line_number,col,default_background_colour,default_foreground_colour) 
        else
          draw_char_at(canvas,char-0x40,line_number,col,default_foreground_colour,default_background_colour) 
        end
      end     
     col+=1 
    end    
    line_number+=1
  end  
  PNG.new(canvas).raw_bytes
end