lib/DSK.rb in dsktool-0.1.6 vs lib/DSK.rb in dsktool-0.2.1
- old
+ new
@@ -20,10 +20,15 @@
# bytes 1/2/3 are a track number, sector number and DOS version number
# see if these are reasonable values
(@file_bytes[0x11001]<=34) && (@file_bytes[0x11002]<=15) && (@file_bytes[0x11003]==3)
end
+
+ def is_nadol?
+ # track $00, sector $02 , bytes $11 - "NADOL"
+ (@file_bytes[0x00211..0x00215]=="NADOL")
+ end
#create a new DSK structure (in memory, not on disk)
def initialize(file_bytes="\0"*DSK_FILE_LENGTH)
if (file_bytes.length!=DSK_FILE_LENGTH) then
@@ -49,10 +54,16 @@
dsk=DSK.new(file_bytes)
if (dsk.is_dos33?)
require 'DOSDisk'
dsk=DOSDisk.new(file_bytes)
end
+
+ if (dsk.is_nadol?)
+ require 'NADOLDisk'
+ dsk=NADOLDisk.new(file_bytes)
+ end
+
dsk
end
def get_sector(track,sector)
start_byte=track*16*256+sector*256
@@ -61,50 +72,59 @@
def files
@files
end
- #print to stdout a formatted hex dump of a single 256 byte sector
+ #return a formatted hex dump of a single 256 byte sector
def dump_sector(track,sector)
-
- start_byte=track*16*256+sector*256
- s=@file_bytes[start_byte..start_byte+255]
-
- print_hline
- printf("TRACK: $%02X SECTOR $%02X\ OFFSET $%04X\n",track,sector,start_byte)
- printf "\t"
-
- (0..15).each {|x| printf("%02X ",x) }
- puts
- print_hline
+ start_byte=track.to_i*16*256+sector.to_i*256
+ s=hline
+ s<<sprintf("TRACK: $%02X SECTOR $%02X\ OFFSET $%04X\n",track,sector,start_byte)
+ s<< "\t"
+ sector_data=get_sector(track,sector)
+ (0..15).each {|x| s<<sprintf("%02X ",x) }
+ s<<"\n"
+ s<<hline
(0..15).each {|line_number|
lhs=""
rhs=""
start_byte=line_number*16
- line=s[start_byte..start_byte+15]
+ line=sector_data[start_byte..start_byte+15]
line.each_byte {|byte|
- lhs+= sprintf("%02X ", byte)
- rhs+= (byte%128).chr.sub(/[\x00-\x1f]/,'.')
+ lhs<< sprintf("%02X ", byte)
+ rhs<< (byte%128).chr.sub(/[\x00-\x1f]/,'.')
}
- printf("%02X\t%s %s\n",start_byte,lhs,rhs)
+ s<<sprintf("%02X\t%s %s\n",start_byte,lhs,rhs)
}
+ s
+ end
+ #return a formatted hex dump of a single 256 byte sector
+ def disassemble_sector(track,sector)
+ require 'D65'
+ sector_data=get_sector(track,sector)
+ if (track==0) && (sector==0) then
+ return D65.disassemble(sector_data[1..255],0x801)
+ else
+ return D65.disassemble(sector_data)
+ end
end
- #print to stdout a formatted hex dump of all sectors on all tracks
+ #return a formatted hex dump of all sectors on all tracks
def dump_disk
-
+ s=""
(0..34).each {|track|
(0..15).each {|sector|
- dump_sector(track,sector)
+ s<<dump_sector(track,sector)
}
}
+ s
end
private
- def print_hline
- puts "-"*79
+ def hline
+ "-"*79+"\n"
end
end
# == Author