Class: AppleWorksWP

Inherits:
NativeFileType show all
Defined in:
lib/native_file_types/apple2/AppleWorksWP.rb

Instance Attribute Summary

Attributes inherited from NativeFileType

#aux_code, #contents, #file_system_image, #file_type, #filename, #meta_data

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NativeFileType

#<=>, #==, all_native_file_types, best_fit, code_for_tests, compatability_score, #data_without_header, file_type_matches?, #full_filename, #header_length, #initialize, is_valid_file_if, #load_address, load_address, matching_score, native_file_types_possible_on_file_system, non_matching_score, #to_hex_dump, #to_info_dump, #type_description

Methods included from SubclassTracking

extended

Constructor Details

This class inherits a constructor from NativeFileType

Class Method Details

.file_system_file_typesObject



4
5
6
7
8
# File 'lib/native_file_types/apple2/AppleWorksWP.rb', line 4

def self.file_system_file_types
  {
    ProDos=>0x1A
  }
end

Instance Method Details

#to_textObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/native_file_types/apple2/AppleWorksWP.rb', line 11

def to_text
    s=""
    i=300 #skip 300 byte header

    i+=2 if contents[183]>3 #skip the first invalid line if SFMInVers non-zero

    while i<contents.length-4 do
      command_byte_0=contents[i]
      command_byte_1=contents[i+1]
      i+=2
      if command_byte_1==0xD0 then #it's a carriage return line - do nothing

      elsif command_byte_1>0xD0 then #it's a command line - do nothing

      else #it's a text record

        bytes_in_line=command_byte_0
        control_byte=contents[i+1]
        chars_remaining=control_byte%0x80
        contents[i+2..i+2+chars_remaining-1].each_byte do |b|
          if b==0x16 then #tab char

            s<<"\t"
          elsif b==0x17 then
            s<<" "
          elsif b>=0x20 then
            s<<b.chr
          end
        end
        i+=bytes_in_line
        s<<"\n"
      end
    end   
    s

end