Class: DSKFile

Inherits:
Object
  • Object
show all
Defined in:
lib/DSKFile.rb

Overview

Generic Apple II file

Direct Known Subclasses

CPMFile, DOSFile, NADOLFile, PascalFile, ProDOSFile

Constant Summary collapse

APPLESOFT_TOKENS =

Adapted from FID.C – a utility to browse Apple II .DSK image files by Paul Schlyter ([email protected])

Applesoft file format: <Length_of_file> (16-bit little endian) <Line> .….. <Line> where <Line> is: <Next addr> (16-bit little endian) <Line no> (16-bit little endian: 0-65535) <Tokens and/or characters> <End-of-line marker: $00 >

[
	       "END","FOR","NEXT","DATA","INPUT","DEL","DIM","READ",
		"GR","TEXT","PR#","IN#","CALL","PLOT","HLIN","VLIN",
		"HGR2","HGR","HCOLOR=","HPLOT","DRAW","XDRAW","HTAB",
		"HOME","ROT=","SCALE=","SHLOAD","TRACE","NOTRACE",
		"NORMAL","INVERSE","FLASH","COLOR=","POP","VTAB",
		"HIMEM=","LOMEM=","ONERR","RESUME","RECALL","STORE",
		"SPEED=","LET","GOTO","RUN","IF","RESTORE","&","GOSUB",
		"RETURN","REM","STOP","ON","WAIT","LOAD","SAVE","DEF",
		"POKE","PRINT","CONT","LIST","CLEAR","GET","NEW",
		"TAB(","TO","FN","SPC(","THEN","AT","NOT","STEP","+",
		"-","*","/","^","AND","OR",">","=","<","SGN","INT",
		"ABS","USR","FRE","SCRN(","PDL","POS","SQR","RND",
		"LOG","EXP","COS","SIN","TAN","ATN","PEEK","LEN",
		"STR$","VAL","ASC","CHR$", "LEFT$","RIGHT$","MID$","?",
		"?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?"
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, contents) ⇒ DSKFile

Returns a new instance of DSKFile.



9
10
11
12
# File 'lib/DSKFile.rb', line 9

def initialize(filename,contents)
	@filename=filename
	@contents=contents
end

Instance Attribute Details

#contentsObject

Returns the value of attribute contents.



8
9
10
# File 'lib/DSKFile.rb', line 8

def contents
  @contents
end

#filenameObject

Returns the value of attribute filename.



8
9
10
# File 'lib/DSKFile.rb', line 8

def filename
  @filename
end

Instance Method Details

#==(other_object) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/DSKFile.rb', line 27

def ==(other_object)
  if  !other_object.kind_of? DSKFile then
    return false
  end
   if self.filename!=other_object.filename then
     return false
   end
  
  return self.to_s==other_object.to_s
end

#buffer_as_applesoft_file(buffer) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/DSKFile.rb', line 88

def buffer_as_applesoft_file(buffer)

	length=buffer[0]+buffer[1]*256
	index=2
	s=""
	while (index<length)
		index+=2 #skip over the "next address" field
		break if buffer[index].nil?
		break if buffer[index+1].nil?
		line_no=buffer[index]+buffer[index+1]*256
		index+=2 #skip over the "line number" field
		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        # skip over "end of line" marker
	end
       s
end

#can_be_picture?Boolean

default is files can NOT be displayed as a picture

Returns:

  • (Boolean)


47
48
49
# File 'lib/DSKFile.rb', line 47

def can_be_picture?
	false
end

#file_extensionObject



38
39
40
# File 'lib/DSKFile.rb', line 38

def file_extension
	".bin"
end

#hex_dumpObject



42
43
44
# File 'lib/DSKFile.rb', line 42

def hex_dump
   DumpUtilities.hex_dump(@contents)
end

#length_in_sectorsObject

how many 256 byte sectors does this file require? excludes any catalog entry or T/S list



53
54
55
# File 'lib/DSKFile.rb', line 53

def length_in_sectors
  ((255+contents.length)/256)
end

#to_asciiObject



18
19
20
21
22
23
24
25
# File 'lib/DSKFile.rb', line 18

def to_ascii
  s=""
@contents.each_byte do |b|
    s+=(b%0x80).chr.gsub(0x0D.chr,"\r\n")#.gsub(0x0A.chr,"\n")
  end
  return s.gsub(/\0/," ")
  #return s.sub(/\0*$/,"")
end

#to_sObject



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

def to_s
	@contents
end