require 'NativeFileType' #for breakdown of CMD format, see http://www.tim-mann.org/trs80/doc/ldosq1-4.txt ( Roy's Technical Corner P42) # # files consist of unordered records. # reach record consists of a one byte record type, followed by a 2 byte record length field, followed by a data area (who's length is specified by the 'record length' field # # TYPE DATA AREA # ---- --------- # 01 object code (load block) # 02 transfer address # 04 end of partitioned data set member # 05 load module header # 06 partitioned data set header # 07 patch name header # 08 ISAM directory entry # 0A end of ISAM directory # 0C PDS directory entry # 0E end of PDS directory # 10 yanked load block # 1F copyright block class Trs80Cmd:any } end def to_listing s="" records.each do |record| record_type=record[:record_type] data_area=record[:data_area] record_length=data_area.length s+= ";RECORD TYPE $#{"%02X" %record_type} OFFSET $#{"%02X" % p} LENGTH $#{"%2X" % record_length}\n" case record_type when 0x01 then #load object code load_address=data_area[0]+data_area[1]*256 s+= ";\tLOAD $#{"%02X" % (data_area.length-2)} BYTES OF OBJECT CODE TO $#{"%02X" % load_address}\n" when 0x02 then #transfer transfer_address=data_area[0]+data_area[1]*256 s+= ";\tTRANSFER ADDRESS $#{"%02X" % transfer_address}\n" when 0x05 then #load module s+= ";\tMODULE HEADER #{data_area}\n" end end s end private def parse_records @records=[] p=0 done=false while p=0x20 then break end record_length=contents[p+1] record_length=256 if record_length==0 #if this is a 'load' record, the following two bytes are the address to load the data record into # in order to allow up to 256 bytes to be load, lengths of 1 & 2 really mean lengths of 257 and 258 respecitively. if (record_type==0x01) then record_length=case record_length when 1 then 257 when 2 then 258 else record_length end end data_area=contents[p+2,record_length] @records<<{:record_type=>record_type,:data_area=>data_area} done=([0x00,0x02].include?(record_type)) p+=(record_length+2) end end end # == Author # Jonno Downes (jonno@jamtronix.com) # # == Copyright # Copyright (c) 2008 Jonno Downes (jonno@jamtronix.com) # #Permission is hereby granted, free of charge, to any person obtaining #a copy of this software and associated documentation files (the #"Software"), to deal in the Software without restriction, including #without limitation the rights to use, copy, modify, merge, publish, #distribute, sublicense, and/or sell copies of the Software, and to #permit persons to whom the Software is furnished to do so, subject to #the following conditions: # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.