# File lib/host_systems/C64.rb, line 156
def self.line_count(text,screen_width=default_screen_width)
  max_line=self.screen_rows
  current_line=0
  col=0
  text.each_byte do |char|
    case char
      #colours first

      when 5,28 ,30,31,129,144,149,150,151,152,153,154,155,156,158,159
      #fonts

      when 8,9,14,142,18,146
      #movement

      when 10
      when 13 , 141 #return

        col=0
        current_line+=1
      when 17 then current_line+=1
      when 147 #clr/home

        col=0
        current_line=0
        #cls

      when 19 #home

        col=0
        current_line=0
      when 20 #delete

        col-=1
      when 157 then col-=1
      when 29 then col+=1
      when 145 then current_line-=1
      when 148 # insert ?


      #now fonts

      when 8 then enable_shift_cbm=false
      when 9 then enable_shift_cbm=true
      when 14 then mode=:lowercase if enable_shift_cbm
      when 142 then mode=:graphics if enable_shift_cbm
      when 18 then reverse=true
      when 146 then reverse=false      
      
    else
      col+=1     
    end    
    if (col>=screen_width) then
      current_line+=1
      col=0
    end
    if (col<0) then
      current_line-=1
      col=screen_width-1
    end
    current_line=0 if current_line<0
    max_line=current_line if current_line>max_line
  end 
  max_line
end