Class: C64GeosFile

Inherits:
CbmFile show all
Defined in:
lib/native_file_types/c64/C64GeosFile.rb

Instance Attribute Summary

Attributes inherited from NativeFileType

#aux_code, #file_system_image, #file_type, #filename

Instance Method Summary collapse

Methods inherited from CbmFile

file_system_file_types

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, matching_score, native_file_types_possible_on_file_system, non_matching_score, #to_info_dump

Methods included from SubclassTracking

extended

Constructor Details

This class inherits a constructor from NativeFileType

Instance Method Details

#contentsObject



36
37
38
39
40
41
42
# File 'lib/native_file_types/c64/C64GeosFile.rb', line 36

def contents
	if @contents.kind_of?(Array) then  	
		@contents[1,@contents.length].join("")		
	else
		@contents
	end
end

#header_filenameObject



22
23
24
25
# File 'lib/native_file_types/c64/C64GeosFile.rb', line 22

def header_filename
	return nil unless @contents.kind_of?(Array) && !info_block.nil?
	info_block[0x4d,16].unpack("A*")[0]
end

#icon_backgroundObject



29
30
31
# File 'lib/native_file_types/c64/C64GeosFile.rb', line 29

def icon_background
	C64::COLOR_LTGRAY
end

#icon_bitmapObject



69
70
71
72
# File 'lib/native_file_types/c64/C64GeosFile.rb', line 69

def icon_bitmap
	return nil unless @contents.kind_of?(Array)
	return @contents[0][5,63]
end

#icon_foregroundObject



26
27
28
# File 'lib/native_file_types/c64/C64GeosFile.rb', line 26

def icon_foreground
	C64::COLOR_BLACK
end

#icon_formatObject



105
106
107
# File 'lib/native_file_types/c64/C64GeosFile.rb', line 105

def icon_format
  :png
end

#icon_heightObject



102
103
104
# File 'lib/native_file_types/c64/C64GeosFile.rb', line 102

def icon_height
  21
end

#icon_tagObject

icon tag is used to allow the same icon in different files to be recognised as identical



110
111
112
113
114
115
# File 'lib/native_file_types/c64/C64GeosFile.rb', line 110

def icon_tag
	return nil if icon_bitmap.nil?
	require 'digest/md5'
  	return Digest::MD5.hexdigest(icon_bitmap)
	
end

#icon_widthObject



99
100
101
# File 'lib/native_file_types/c64/C64GeosFile.rb', line 99

def icon_width
  8*3
end

#info_blockObject



32
33
34
# File 'lib/native_file_types/c64/C64GeosFile.rb', line 32

def info_block
	@contents[0]
end

#load_addressObject



44
45
46
# File 'lib/native_file_types/c64/C64GeosFile.rb', line 44

def load_address
	info_block[0x47]+(0x100*info_block[0x48])
end

#meta_dataObject



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/native_file_types/c64/C64GeosFile.rb', line 117

def 
	return super unless @contents.kind_of?(Array) && !info_block.nil?
	@meta_data["geos_vlir_records"]=record_nos.join(",")
	@meta_data["geos_header_icon_width"]="$%02x" % info_block[0x02]
	@meta_data["geos_header_icon_height"]="$%02x" % info_block[0x03]
	@meta_data["geos_header_bitmap_data_type"]="$%02x" % info_block[0x04]
	@meta_data["geos_header_c64_file_type"]="$%02x" % info_block[0x44]
	@meta_data["geos_header_geos_file_type"]="$%02x" % info_block[0x45]
	@meta_data["geos_header_geos_file_structure_type"]="$%02x" % info_block[0x46]
	@meta_data["geos_header_load_address"]="$%04x" % load_address
	@meta_data["geos_header_end_address"]="$%04x" % (info_block[0x49]+(0x100*info_block[0x4a]))
	@meta_data["geos_header_init_address"]="$%04x" % (info_block[0x4b]+(0x100*info_block[0x4c]))
	@meta_data["geos_header_filename"]=header_filename
	@meta_data["geos_header_author"]=info_block[0x61,20].dump
	@meta_data["geos_header_parent_application"]=parent_application
	@meta_data["geos_header_application_specific_data"]=info_block[137..159].dump
	@meta_data["geos_header_getinfo_caption"]=info_block[160..255].unpack("A*")[0]

	super
end

#parent_applicationObject



17
18
19
20
# File 'lib/native_file_types/c64/C64GeosFile.rb', line 17

def parent_application
	return nil unless @contents.kind_of?(Array) && !info_block.nil?
	info_block[0x75,16].unpack("A*")[0]
end

#record_nosObject



48
49
50
51
52
53
54
# File 'lib/native_file_types/c64/C64GeosFile.rb', line 48

def record_nos
	r=[]
	@contents.length.times do |record_no|
			r<<record_no unless @contents[record_no].nil?
	end
	r
end

#to_hex_dumpObject



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/native_file_types/c64/C64GeosFile.rb', line 56

def to_hex_dump
	s=""
	if @contents.kind_of?(Array) then  	
record_nos.each do |record_no|
	s<<((record_no==0) ? "INFO BLOCK\n" : "RECORD $#{"%02x" % record_no}\n")
	s<<HostSystem.hex_dump(@contents[record_no])
end
  else
  	s<<s<<HostSystem.hex_dump(@contents)
  end
  s
end

#to_iconObject



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

def to_icon
  canvas = PNG::Canvas.new icon_width, icon_height, PNG::Color::Green

  buffer=icon_bitmap
  icon_height.times do |y|
    row_data=buffer[y*3,3]
    x=0
    row_data.each_byte do |byte|
      8.times do |bit_offset|        
        bitmask=0b10000000>>bit_offset    
#        puts "y #{y} x #{x} byte #{"%08b" % byte} bit #{bit_offset} #{"%08b" % bitmask}"
        if ((byte & bitmask)==bitmask) then
          canvas[x, y]= icon_foreground
        else
          canvas[x, y]= icon_background
        end
        x+=1
      end
    end
  end
  png = PNG.new canvas
  result=png.raw_bytes
  result
end

#type_descriptionObject



13
14
15
# File 'lib/native_file_types/c64/C64GeosFile.rb', line 13

def type_description
  "#{ aux_code.to_s}" + ((aux_code==:application_data) ? " (#{parent_application}/#{header_filename})" : ""   )
end