Class: AppleCPM

Inherits:
FileSystem show all
Defined in:
lib/file_systems/AppleCPM.rb

Constant Summary collapse

RECORD_SIZE =
128
BLOCK_SIZE =
1024
BLOCKS_PER_EXTENT =
16
RECORDS_PER_BLOCK =
BLOCK_SIZE/RECORD_SIZE
RECORDS_PER_EXTENT =
RECORDS_PER_BLOCK*BLOCKS_PER_EXTENT
SECTORS_IN_BLOCK =
[
  [0x00,0x06,0x0C,0x03],  #block 0
  [0x09,0x0F,0x0E,0x05],  #block 1
  [0x0B,0x02,0x08,0x07],  #block 2
  [0x0D,0x04,0x0A,0x01]  #block 3
]

Class Method Summary collapse

Methods inherited from FileSystem

all_file_systems, code_for_tests, compatability_score, is_valid_file_system_if, non_matching_score

Methods included from SubclassTracking

extended

Class Method Details

.files(file_system_image) ⇒ Object

CPM DIR looks like this: $00 User number, or E5h if it’s a free entry $01..0B Filename + extension: 8+3 characters $0C..0D Extent number of this entry $0E ??? $0F Number of 128-byte records allocated in this extant $10..1F Allocation map for this directory entry



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/file_systems/AppleCPM.rb', line 72

def self.files(file_system_image)
  files=FileContainer.new
  catalog=get_block(file_system_image,0)+get_block(file_system_image,1)
  0.upto(63) do |dir_entry_no|
    dir_entry_start=dir_entry_no*0x20
    dir_entry=catalog[dir_entry_start..dir_entry_start+0x1F]      
    if (dir_entry[0]<0x10) then
      file_name=dir_entry[0x01..0x08].gsub(' ','')
      file_ext=dir_entry[0x09..0x0B].gsub(' ','')
      full_filename="#{file_name}.#{file_ext}"
      files<<NativeFileType.best_fit(file_system_image,full_filename,'',file_ext)
      if files[full_filename].nil? then
        files<<file 
      end
      s=""
      0x10.upto(0x1f) do |i|
        block=dir_entry[i]
        s+=get_block(file_system_image,block) unless block==0
      end        
      records_allocated=dir_entry[0x0F]
      files[full_filename].contents+=s[0,(records_allocated*128)]
    end
  end    
  files
end

.get_block(file_system_image, block_no) ⇒ Object



32
33
34
35
36
37
# File 'lib/file_systems/AppleCPM.rb', line 32

def self.get_block(file_system_image,block_no)
  track_no= ((block_no/4)+3)%file_system_image.track_count
  s=""
  SECTORS_IN_BLOCK[block_no%4].each {|sector_no| s+=file_system_image.get_sector(track_no,sector_no)}
  s
end

.host_systemObject



11
12
13
# File 'lib/file_systems/AppleCPM.rb', line 11

def self.host_system
  Apple2
end

.matching_scoreObject



15
16
17
# File 'lib/file_systems/AppleCPM.rb', line 15

def self.matching_score
  20
end