def buffer_as_applesoft_file(buffer)
length=buffer[0]+buffer[1]*256
index=2
s=""
while (index<length)
index+=2
break if buffer[index].nil?
break if buffer[index+1].nil?
line_no=buffer[index]+buffer[index+1]*256
index+=2
s+=sprintf("%u",line_no)
done_line=false
last_char_space=false
while (!done_line)
b=buffer[index]
break if b.nil?
if b>=0x80 then
if !last_char_space then
s+=" "
end
s+=APPLESOFT_TOKENS[b-0x80]+" "
last_char_space=true
else
s+=b.chr
last_char_space=false
end
index+=1
done_line=(index>=length)||(buffer[index]==0)
end
s+="\n"
index+=1
end
s
end