Class: JvcDsk

Inherits:
ImageFormat show all
Defined in:
lib/image_formats/JvcDsk.rb

Overview

Color Computer DSK in JVC format - tlindner.macmess.org/?page_id=86 This in an incomplete implementation

Instance Attribute Summary

Attributes inherited from ImageFormat

#file_bytes

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ImageFormat

all_image_formats, all_possible_extensions, code_for_tests, #compatability_score, #end_track, #host_system, is_valid_image_if, possible_file_systems, #start_track, #to_s, #track_list

Methods included from SubclassTracking

extended

Constructor Details

#initialize(file_bytes) ⇒ JvcDsk

JVC format has a variable length header, and a variable number of tracks, with a variable number of sectors, with a variable length.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/image_formats/JvcDsk.rb', line 21

def initialize(file_bytes)
  @file_bytes=file_bytes
  @sectors_per_track = 18
  @side_count = 1
  @sectors_size_code = 1
  @first_sector_id = 1

  @header_size = file_bytes.length % 256
  
  if @header_size == 0 then
  elsif @header_size == 1 then
  	@sectors_per_track = file_bytes.unpack("C")
  elsif @header_size == 2 then
  	@sectors_per_track, @side_count= file_bytes.unpack("CC")
  elsif @header_size == 3 then
  	@sectors_per_track, @side_count, @sectors_size_code = file_bytes.unpack("CCC")
  elsif @header_size == 4 then
  	@sectors_per_track, @side_count, @sectors_size_code, @first_sector_id = file_bytes.unpack("CCCC")
  else
  end

	@sector_length = 128 << @sectors_size_code
	@track_count = (file_bytes.length - @header_size) / (@sectors_per_track * @sector_length) / @side_count 
end

Class Method Details

.host_systemObject



55
56
57
# File 'lib/image_formats/JvcDsk.rb', line 55

def self.host_system
    Coco
end

.possible_extensionsObject



14
15
16
# File 'lib/image_formats/JvcDsk.rb', line 14

def self.possible_extensions
    ['.dsk']
end

Instance Method Details

#get_sector(track, sector) ⇒ Object



68
69
70
71
72
73
74
# File 'lib/image_formats/JvcDsk.rb', line 68

def get_sector(track,sector)  
  start_byte=track*@sectors_per_track*@sector_length+(sector-@first_sector_id)*@sector_length
  start_byte += @header_size
  
  #puts "Track: #{track}, sector: #{sector}, start_byte: #{start_byte}"
  @file_bytes[start_byte,@sector_length]
end

#sectors_in_track(track_no) ⇒ Object



59
60
61
# File 'lib/image_formats/JvcDsk.rb', line 59

def sectors_in_track(track_no)
  (@first_sector_id..@sectors_per_track).collect
end

#track_countObject

how many tracks could be interpreted by this image format?



64
65
66
# File 'lib/image_formats/JvcDsk.rb', line 64

def track_count
  @track_count
end