# File lib/native_file_types/coco/CocoBasic.rb, line 146
def to_listing  
  return contents if aux_code==0xFF #Aux Code is "ASCII FLAG"
        s=""
        p=0
        
        if contents[p] == 0xff then
                p+=1
                file_size = contents[p]<<8
                p+=1
                file_size += contents[p]
                p+=1
#               raise "Binary CoCo BASIC file format inconsistant (file size record was = $#{"%X" % file_size}, real file size=$#{"%X" % (contents.length-3)}" if file_size != (contents.length-3)
        end
        
        value = contents[p]<<8
        p+=1
        value += contents[p]
        p+=1
        
        while (p<contents.length-2) && (value != 0)
                line_number = contents[p]<<8
                p+=1
                line_number += contents[p]
                p+=1

                s+= "#{line_number} "
                
                character = contents[p]
                p+=1
                
                while (p<contents.length-1) && (character != 0)
                        if character == 0xff then
                                character = contents[p]
                                p+=1
                                s+=FUNCTION_TOKENS[character]
                        elsif character >= 0x80
                                s+=COMMAND_TOKENS[character]
                        elsif character == 0x3a && (contents[p] == 0x83 || contents[p] == 0x84 )
                                #When colon-apostrophe is encountered, the colon is dropped. */
                                #When colon-ELSE is encountered, the colon is dropped. */
                        else
                                s+=(character % 0x80).chr
                        end
                        
                        character = contents[p]
                        p+=1
                end

                s+="\n"

                value = contents[p]<<8
                p+=1
                value += contents[p] unless contents[p].nil?
                p+=1
        end
        s      
end