├── .gitignore ├── README.md ├── fluximage.py ├── adpll.py ├── dfi.py ├── modulation.py ├── crc.py ├── imagedisk.py ├── kfsf.py ├── fluxtoimd.py └── gpl-3.0.txt /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | images 3 | *.imd 4 | *.bin 5 | arch255* 6 | documentation.txt 7 | imd.txt 8 | notes.txt 9 | __pycache__ 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | fluxtoimd.py is a Python 3 program to read floppy disk flux transitions 2 | images, demodulate the data, and write the data to an ImageDisk image file. 3 | DiscFerret (.dfi) images and ZIP files of KryoFlux Stream File images are 4 | supported as input. 5 | 6 | Copyright © 2016 Eric Smith 7 | 8 | This program is free software: you can redistribute it and/or 9 | modify it under the terms of version 3 of the GNU General Public 10 | License as published by the Free Software Foundation. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see 19 | . 20 | 21 | Currently fluxtoimd.py supports 8-inch floppy disks in the following 22 | formats: 23 | 24 | * IBM 3740 FM single-density 25 | (industry-standard single density as used by most floppy controllers) 26 | 27 | * Intel M2FM double-density 128 byte/sector format 28 | (used by SBC 202 floppy controller in Intel MDS 800/Series II/Series III 29 | development systems) 30 | 31 | * HP M2FM double-density 256 byte/sector format 32 | (used by HP 7902, 9885, 9895) 33 | 34 | There is untested code to support the following formats: 35 | 36 | * IBM System/34 MFM double-density 37 | (industry standard double-density as used by most floppy controllers) 38 | 39 | In principle the code should work with images of 5¼ inch and 3½ inch 40 | floppy disks, but that has not been tested. 41 | 42 | USAGE: 43 | 44 | To use with kryoflux to read Intel m2fm and fm disks (MDS/ISIS) 45 | 46 | Read 8" single sided disk as stream file. Use -g2 to read double sided disks. 47 | This reads each track about five times to allow error recovery. 48 | ./dtc -fdirname/track -g0 -i0 -d0 -p -e76 -dd0 49 | 50 | Zip up the output directory 51 | zip -rj filename.zip dirname/* 52 | 53 | Process the files 54 | ./fluxtoimd -F ksf --intelm2fm filename.zip filename.imd -C "Description of disk" 55 | 56 | Uncorrectable read errors will generate this message if all reads of sector 57 | had data CRC error 58 | *** BAD: track 21 sector 46 59 | 60 | If the sector was not found or had header CRC error for all reads this error 61 | will be generated. 62 | *** BAD nodata: track 03 sector 26 63 | 64 | Summary of errors are printed at the end of the conversion. 65 | 66 | To extract the files with isisutils into a directory 67 | ./isis.py -x -d output_dir file.imd 68 | 69 | To extract into a zip file 70 | ./isis.py -x -z output.zip file.imd 71 | 72 | To view directory 73 | ./isis.py -v file.imd 74 | 75 | For CP/M disks cpmtools can extract with this diskdef for double density 76 | disks. 77 |
 78 | # Intel MDS/22 8" Double Density
 79 | diskdef mds-dd
 80 |   seclen 128
 81 |   tracks 77
 82 |   sectrk 52
 83 |   blocksize 2048
 84 |   maxdir 128
 85 |   skew 0
 86 |   boottrk 2
 87 |   os 2.2
 88 | end
 89 | 
 90 | Untested single density
 91 | # Intel MDS/22 8" Single Density
 92 | diskdef mds-sd
 93 |   seclen 128
 94 |   tracks 77
 95 |   sectrk 26
 96 |   blocksize 1024
 97 |   maxdir 64
 98 |   skew 0
 99 |   boottrk 2
100 |   os 2.2
101 | end
102 | 
103 | 104 | For cpmtools the .imd files need to be converted to raw .img file. 105 | Libdsk can convert 106 | ./libdsk-1.5.12/tools/dskconv -otype raw filename.imd filename.img 107 | And disk utilities 108 | ./Disk-Utilities/disk-analyse/disk-analyse filename.imd filename.img 109 | 110 | For directory 111 | ./cpmtools/cpmls -f mds-dd filename.img 112 | 113 | To extract 114 | ./cpmcp -f mds-dd filename.img '0:*' output-directory 115 | 116 | -------------------------------------------------------------------------------- /fluximage.py: -------------------------------------------------------------------------------- 1 | from collections import Counter, namedtuple 2 | import operator 3 | import struct 4 | 5 | CHS = namedtuple('CHS', ['cylinder', 'head', 'sector']) 6 | 7 | '''A FluxImageBlock represents one flux image, which is a single track 8 | for a soft-sectored disk, or a single sector for a hard-sectored disk''' 9 | class FluxImageBlock: 10 | def __init__(self, fluximagefile, debug = False): 11 | self.fluximagefile = fluximagefile 12 | self.debug = debug 13 | self.stream_offset = 0 14 | 15 | def chs(self): 16 | return CHS(self.cylinder, self.head, self.sector) 17 | 18 | def read(self, count): 19 | d = self.fluximagefile.read(count) 20 | if len(d) != count: 21 | raise EOFError() 22 | self.stream_offset += count 23 | return d 24 | 25 | def read_integer(self, count, signed = False, big_endian = False): 26 | fmt = '<>' [big_endian] 27 | fmt += { 1: 'b', 28 | 2: 'h', 29 | 4: 'i', 30 | 8: 'q' } [count] 31 | if not signed: 32 | fmt = fmt.upper() 33 | d = self.read(count) 34 | return struct.unpack(fmt, d) [0] 35 | 36 | def read_u8(self): 37 | return self.read_integer(1) 38 | 39 | def read_s8(self): 40 | return self.read_integer(1, signed = True) 41 | 42 | def read_u16_le(self): 43 | return self.read_integer(2) 44 | 45 | def read_u16_be(self): 46 | return self.read_integer(2, big_endian = True) 47 | 48 | def read_s16_le(self): 49 | return self.read_integer(2, signed = True) 50 | 51 | def read_s16_be(self): 52 | return self.read_integer(2, signed = True, big_endian = True) 53 | 54 | def read_u32_le(self): 55 | return self.read_integer(4) 56 | 57 | def read_u32_be(self): 58 | return self.read_integer(4, big_endian = True) 59 | 60 | def read_s32_le(self): 61 | return self.read_integer(4, signed = True) 62 | 63 | def read_s32_be(self): 64 | return self.read_integer(4, signed = True, big_endian = True) 65 | 66 | class __DeltaIter: 67 | def __init__(self, block): 68 | block.generate_flux_trans_rel() 69 | self.block = block 70 | self.index = 0 71 | 72 | def __iter__(self): 73 | return self 74 | 75 | def __next__(self): 76 | try: 77 | v = self.block.flux_trans_rel[self.index] / self.block.frequency 78 | self.index += 1 79 | return v 80 | except IndexError: 81 | raise StopIteration 82 | 83 | def generate_flux_trans_rel(self): 84 | if hasattr(self, 'flux_trans_rel'): 85 | return 86 | self.flux_trans_rel = [self.flux_trans_abs[i] - self.flux_trans_abs[i-1] for i in range(1, len(self.flux_trans_abs))] 87 | 88 | def get_delta_iter(self): 89 | return self.__DeltaIter(self) 90 | 91 | def print_hist(self, bucket_size = 2.5): 92 | self.generate_flux_trans_rel() 93 | counts = Counter(self.flux_trans_rel) 94 | hist = { } 95 | for i in counts.keys(): 96 | bucket = int((i + bucket_size / 2) // bucket_size) 97 | hist[bucket] = hist.get(bucket, 0) + counts[i] 98 | 99 | # maximum value 100 | m = max(hist.items(), key=operator.itemgetter(1))[1] 101 | 102 | # minimum, maximum keys 103 | f = min(hist.items(), key=operator.itemgetter(0))[0] 104 | l = max(hist.items(), key=operator.itemgetter(0))[0] 105 | 106 | for i in range(f, l + 1): 107 | c = hist.get(i, 0) 108 | s = '*' * int(65*c/m) 109 | if len(s) == 0 and c != 0: 110 | s = '.' 111 | print("%3.2f: %5d %s" % (i * bucket_size / (self.frequency / 1.0e6), c, s)) 112 | 113 | 114 | class FluxImage: 115 | def __init__(self, fluximagefile, debug = False): 116 | self.fluximagefile = fluximagefile 117 | self.debug = debug 118 | self.blocks = { } 119 | 120 | -------------------------------------------------------------------------------- /adpll.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # ADPLL for floppy disk data separator 3 | # Copyright 2016 Eric Smith 4 | 5 | # This program is free software: you can redistribute it and/or 6 | # modify it under the terms of version 3 of the GNU General Public 7 | # License as published by the Free Software Foundation. 8 | 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # General Public License for more details. 13 | 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see 16 | # . 17 | 18 | import argparse 19 | import re 20 | 21 | 22 | class ADPLL(): 23 | def __init__(self, 24 | di, 25 | osc_period, 26 | max_adj_pct, 27 | window_pct, 28 | freq_adj_factor, 29 | phase_adj_factor, 30 | debug = False): 31 | self.di = di 32 | self.osc_period = osc_period 33 | self.window_frac = window_pct / 100 34 | self.freq_adj_factor = freq_adj_factor 35 | self.phase_adj_factor = phase_adj_factor 36 | 37 | self.debug = debug 38 | self.debug_all = False 39 | 40 | self.min_osc_period = self.osc_period * (100 - max_adj_pct) / 100 41 | self.max_osc_period = self.osc_period * (100 + max_adj_pct) / 100 42 | 43 | self.zero_bits = 0 44 | 45 | # start oscillator locked to first transition 46 | self.trans_time = di.__next__() 47 | self.osc_time = self.trans_time 48 | #print("first transition at %g" % self.trans_time) 49 | 50 | def __iter__(self): 51 | return self 52 | 53 | def __next__(self): 54 | if self.zero_bits != 0: 55 | self.zero_bits -= 1 56 | return 0 57 | 58 | # We're going to return a one. Now deal with the next transition 59 | hbi = 0 60 | 61 | while hbi <= 0: 62 | self.trans_time += self.di.__next__() 63 | q = (self.trans_time - self.osc_time) / self.osc_period 64 | hbi = int(q + 0.5) 65 | self.osc_time += hbi * self.osc_period 66 | error = (self.trans_time - self.osc_time) 67 | 68 | # if (hbi <= 0): 69 | # # Hopefully this only happens outside ID & data fields, 70 | # # e.g., in write splices 71 | # print("transition too soon") 72 | # print("%g, %d, %g" % (q, hbi, error)) 73 | 74 | #print("%g, %d, %g" % (q, hbi, error)) 75 | if self.debug_all or (self.debug and (abs(error) > (self.osc_period * self.window_frac))): 76 | print("transition outside window") 77 | print("transition at time %g us" % (self.trans_time * 1.0e6)) 78 | print("oscillator at time %g us" % (self.osc_time * 1.0e6)) 79 | print("q = %f" % q) 80 | print("hbi = %f" % hbi) 81 | print("new osc time %g us" % (self.osc_time * 1.0e6)) 82 | print("error %g" % error) 83 | print("osc period %g us " % (self.osc_period * 1.0e6)) 84 | print("error limit %g us" % (self.osc_period * self.window_frac * 1.0e6)) 85 | if True: # was else for previous if statement 86 | if self.freq_adj_factor != 0: 87 | adj = error * self.freq_adj_factor 88 | self.osc_period += adj 89 | if self.osc_period < self.min_osc_period: 90 | self.osc_period = self.min_osc_period 91 | #print("osc period clipped to min") 92 | elif self.osc_period > self.max_osc_period: 93 | self.osc_period = self.max_osc_period 94 | #print("osc period clipped to max") 95 | #print("osc period adjusted by %g to %g" % (adj, self.osc_period)) 96 | if self.phase_adj_factor != 0: 97 | adj = error * self.phase_adj_factor 98 | self.osc_time += adj 99 | 100 | self.zero_bits = hbi - 1 101 | #print("hbi=%d, %d zeros" % (hbi, self.zero_bits)) 102 | 103 | return 1 104 | 105 | 106 | -------------------------------------------------------------------------------- /dfi.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # DFI disk image format library 3 | # Copyright 2016 Eric Smith 4 | 5 | # File format documentation is at: 6 | # http://www.discferret.com/wiki/DFI_image_format 7 | 8 | # This program is free software: you can redistribute it and/or 9 | # modify it under the terms of version 3 of the GNU General Public 10 | # License as published by the Free Software Foundation. 11 | 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | # General Public License for more details. 16 | 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see 19 | # . 20 | 21 | import argparse 22 | 23 | from fluximage import CHS, FluxImage, FluxImageBlock 24 | 25 | class DFIBlock(FluxImageBlock): 26 | def parse_data_version_1(self, data): 27 | time_inc = 0 28 | for b in data: 29 | if (b & 0x7f) == 0x00: 30 | time_inc += 127 31 | else: 32 | time_inc += (b & 0x7f) 33 | self.flux_trans_abs.append(time_inc) 34 | self.end_time = time_inc 35 | 36 | def parse_data_version_2(self, data): 37 | time_inc = 0 38 | for b in data: 39 | if (b & 0x7f) == 0x00: 40 | continue # why should there ever be a zero byte??? 41 | if (b & 0x7f) == 0x7f: 42 | time_inc += 127 43 | elif (b & 0x80) != 0: 44 | time_inc += (b & 0x7f) 45 | self.index_pos.append(time_inc) 46 | # break # XXX break here to only use first revolution 47 | else: 48 | time_inc += (b & 0x7f) 49 | self.flux_trans_abs.append(time_inc) 50 | self.end_time = time_inc 51 | 52 | _parse_data = { 1: parse_data_version_1, 53 | 2: parse_data_version_2 } 54 | 55 | def __init__(self, fluximagefile, version, frequency, debug = False): 56 | super().__init__(fluximagefile, debug) 57 | self.version = version 58 | self.frequency = frequency 59 | self.cylinder = self.read_u16_be() 60 | self.head = self.read_u16_be() 61 | self.sector = self.read_u16_be() 62 | 63 | if self.debug: 64 | print('version %d, freq %f' % (version, frequency)) 65 | print('head %d, cylinder %d, sector %d' % (self.head, 66 | self.cylinder, 67 | self.sector)) 68 | 69 | self.data_len = self.read_u32_be() 70 | self.raw_data = self.read(self.data_len) 71 | 72 | self.index_pos = [] 73 | self.flux_trans_abs = [] 74 | self._parse_data[self.version](self, self.raw_data) 75 | 76 | 77 | class DFI(FluxImage): 78 | magic_to_version = { b'DFER' : 1, 79 | b'DFE2' : 2 } 80 | 81 | def __init__(self, fluximagefile, debug = False, frequency = 25.0e6): 82 | super().__init__(fluximagefile, debug) 83 | self.frequency = frequency 84 | magic = self.fluximagefile.read(4) 85 | if magic not in self.magic_to_version: 86 | raise Exception('bad magic ' + str(magic)) 87 | version = self.magic_to_version[magic] 88 | 89 | self.blocks = {} 90 | while True: 91 | try: 92 | block = DFIBlock(fluximagefile, version, frequency, debug = self.debug) 93 | self.blocks[block.chs()] = block 94 | except EOFError: 95 | break 96 | 97 | 98 | # test program accepts command line arguments for 99 | if __name__ == "__main__": 100 | parser = argparse.ArgumentParser(description = 'DFI library test, prints flux transition time histogram for a chosen track', 101 | formatter_class = argparse.ArgumentDefaultsHelpFormatter) 102 | parser.add_argument('image', type=argparse.FileType('rb', 0)) 103 | parser.add_argument('-s', '--side', type=int, help = 'head', default=0) # head 104 | parser.add_argument('-t', '--track', type=int, help = 'cylinder', default=0) # cylinder 105 | parser.add_argument('-f', '--frequency', type=float, help = 'sample rate in MHz', default=25.0) 106 | parser.add_argument('-r', '--resolution', type=float, help = 'histogram resolution in us', default=0.2) 107 | parser.add_argument('-d', '--debug', action='store_true', help = 'print debugging information') 108 | args = parser.parse_args() 109 | image = DFI(args.image, frequency = args.frequency * 1.0e6, debug = args.debug) 110 | 111 | block = image.blocks[(args.track, args.side, 1)] 112 | 113 | bucket_size = int(block.frequency * args.resolution / 1.0e6) 114 | block.print_hist(bucket_size = bucket_size) 115 | -------------------------------------------------------------------------------- /modulation.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Magnetic disk modulation schemes 3 | # Copyright 2016 Eric Smith 4 | 5 | # This program is free software: you can redistribute it and/or 6 | # modify it under the terms of version 3 of the GNU General Public 7 | # License as published by the Free Software Foundation. 8 | 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # General Public License for more details. 13 | 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see 16 | # . 17 | 18 | 19 | class Modulation: 20 | # bits is a string of channel bits ('0' or '1'), which are nominally 21 | # pairs of (clock, data) 22 | # XXX this presently doesn't verify that the clock bits meet the 23 | # encoding rules 24 | @classmethod 25 | def decode(cls, channel_bits): 26 | bytes = [] 27 | bits = '' 28 | for i in range(0, len(channel_bits), 2): 29 | clock = int(channel_bits[i]) 30 | data = int(channel_bits[i+1]) 31 | if cls.lsb_first: 32 | bits = '01'[data] + bits 33 | else: 34 | bits += '01'[data] 35 | if len(bits) == 8: 36 | bytes.append(int(bits, 2)) 37 | bits = '' 38 | return bytes 39 | 40 | 41 | # FM is IBM 3740 single-density format 42 | # standards, single-sided: ECMA 54, ISO 5654, ANSI X3.73 43 | # standards, double-sided: ECMA 59 44 | 45 | class FM(Modulation): 46 | 47 | default_bit_rate_kbps = 250 48 | default_first_sector = 1 49 | default_sectors_per_track = 26 50 | expected_sector_sizes = [128, 256, 512, 1024, 2048, 4096] 51 | default_bytes_per_sector = 128 52 | lsb_first = False 53 | imagedisk_mode = 0x00 54 | 55 | id_field_length = 4 56 | crc_init = 0xffff 57 | crc_includes_address_mark = True 58 | 59 | id_to_data_half_bits = 400 60 | 61 | # Would prefer to use a more general @staticmethod encode, but then can't call in 62 | # class initialization 63 | def encode_mark(data, clock): 64 | bits = '' 65 | for i in range(7, -1, -1): 66 | c = (clock >> i) & 1 67 | d = (data >> i) & 1 68 | bits += ('%d%d' % (c, d)) 69 | return bits 70 | 71 | index_address_mark = encode_mark(0xfc, clock = 0xd7) 72 | id_address_mark = encode_mark(0xfe, clock = 0xc7) 73 | data_address_mark = encode_mark(0xfb, clock = 0xc7) 74 | deleted_data_address_mark = encode_mark(0xf8, clock = 0xc7) 75 | 76 | del encode_mark 77 | 78 | 79 | # MFM is IBM System/34 double-density format 80 | # standards: ECMA 69, ISO 7065, ANSI X3.121 81 | 82 | class MFM(Modulation): 83 | 84 | default_bit_rate_kbps = 500 85 | default_first_sector = 1 86 | default_sectors_per_track = 26 87 | expected_sector_sizes = [128, 256, 512, 1024, 2048, 4096, 8192] # 128 is uncommon 88 | default_bytes_per_sector = 256 89 | lsb_first = False 90 | imagedisk_mode = 0x03 91 | 92 | id_field_length = 4 93 | crc_init = 0xffff 94 | crc_includes_address_mark = True 95 | 96 | # Would prefer to use a more general @staticmethod encode, but then can't call in 97 | # class initialization 98 | # missing_clock1 bit comes after data1 bit numbered with leftmost bit 0 99 | def encode_mark(data1, missing_clock1, data2): 100 | prev_d = 0 101 | bits = '' 102 | for i in range(7, -1, -1): 103 | d = (data1 >> i) & 1 104 | if (prev_d == 0) and (d == 0) and (i != (6 - missing_clock1)): 105 | c = 1 106 | else: 107 | c = 0 108 | bits += ('%d%d' % (c, d)) 109 | prev_d = d 110 | for i in range(7, -1, -1): 111 | d = (data2 >> i) & 1 112 | if prev_d == 0 and d == 0: 113 | c = 1 114 | else: 115 | c = 0 116 | bits += ('%d%d' % (c, d)) 117 | prev_d = d 118 | return bits 119 | 120 | index_address_mark = encode_mark(0xc2, 5, 0xfc) 121 | id_address_mark = encode_mark(0xa1, 4, 0xfe) 122 | data_address_mark = encode_mark(0xa1, 4, 0xfb) 123 | deleted_data_address_mark = encode_mark(0xa1, 4, 0xf8) 124 | 125 | del encode_mark 126 | 127 | 128 | 129 | # An Intel-proprietary M2FM floppy format, used by the Intel SBC 202 130 | # floppy controller in Intel MDS 800, Series II, and Series III development 131 | # systems. 132 | # Documentation: 133 | # SBC 202 Double Density Diskette Controller Hardware Reference Manual, 134 | # Intel 1977, Order Number 9800420A 135 | # Intelled Double Density Diskette Operating System Hardware Reference Manual, 136 | # Intel 1977, Order Number 98-422A 137 | 138 | class IntelM2FM(Modulation): 139 | 140 | default_bit_rate_kbps = 500 141 | default_first_sector = 1 142 | default_sectors_per_track = 52 143 | expected_sector_sizes = [128] 144 | default_bytes_per_sector = 128 145 | lsb_first = False 146 | imagedisk_mode = 0x03 # ImageDisk doesn't (yet?) have a defined mode for 147 | # Intel M2FM 148 | 149 | id_field_length = 4 150 | crc_init = 0x0000 151 | crc_includes_address_mark = True 152 | 153 | id_to_data_half_bits = 600 154 | 155 | # Would prefer to use a more general @staticmethod encode, but then can't call in 156 | # class initialization 157 | def encode_mark(data, clock): 158 | bits = '' 159 | for i in range(7, -1, -1): 160 | c = (clock >> i) & 1 161 | d = (data >> i) & 1 162 | bits += ('%d%d' % (c, d)) 163 | return bits 164 | 165 | index_address_mark = encode_mark(0x0c, clock = 0x71) 166 | id_address_mark = encode_mark(0x0e, clock = 0x70) 167 | data_address_mark = encode_mark(0x0b, clock = 0x70) 168 | deleted_data_address_mark = encode_mark(0x08, clock = 0x72) 169 | 170 | del encode_mark 171 | 172 | 173 | # An HP-proprietary M2FM floppy format, used by the HP 7902, 9885, 174 | # and 9895 Flexible Disc Drives. 175 | # Documentation: 176 | # 9885 Flexible Disk Drive Service Manual 177 | # Hewlett-Packard, September 1976, part number 09885-90030 178 | # 7902A Disc Drive Preliminary Service Manual 179 | # Hwelett Packard, May 1979, part number 07902-90060 180 | # 7902A & C/9895K Flexible Disc Drive Service Documentation 181 | # Hewlett-Packard, January 1981, part number 07902-90030 182 | # 9895A Flexible Disc Memory Service Manual, 183 | # Hewlett-Packard, February 1981, part number 09895-90030 184 | # 9885: single-sided, 67 track, M2FM format only 185 | # 7902: double-sided, 77 track, M2FM or IBM 3740 FM formats 186 | # 9895: double-siced, 77 track, M2FM or IBM 3740 FM formats 187 | 188 | class HPM2FM(Modulation): 189 | 190 | default_bit_rate_kbps = 500 191 | default_first_sector = 0 192 | default_sectors_per_track = 30 193 | expected_sector_sizes = [256] 194 | default_bytes_per_sector = 256 195 | lsb_first = True 196 | imagedisk_mode = 0x03 # ImageDisk doesn't (yet?) have a defined mode for 197 | # Intel M2FM 198 | 199 | id_field_length = 2 200 | crc_init = 0xffff 201 | crc_includes_address_mark = False 202 | 203 | id_to_data_half_bits = 480 204 | 205 | # Would prefer to use a more general @staticmethod encode, but then can't call in 206 | # class initialization 207 | def encode_mark(data, clock): 208 | bits = '' 209 | for i in range(0, 8): 210 | c = (clock >> i) & 1 211 | d = (data >> i) & 1 212 | bits += ('%d%d' % (c, d)) 213 | return bits 214 | 215 | id_address_mark = encode_mark(0x70, clock = 0x0e) 216 | defective_track_address_mark = encode_mark(0xf0, clock = 0x0e) 217 | data_address_mark = encode_mark(0x50, clock = 0x0e) 218 | ecc_data_address_mark = encode_mark(0xd0, clock = 0x0e) 219 | 220 | del encode_mark 221 | 222 | 223 | if __name__ == '__main__': 224 | for modulation in (FM, MFM, IntelM2FM, HPM2FM): 225 | print('modulation: ', modulation.__name__) 226 | if hasattr(modulation, 'index_address_mark'): 227 | print(' index address mark: ', modulation.index_address_mark) 228 | print(' ID address mark: ', modulation.id_address_mark) 229 | if hasattr(modulation, 'defective_track_address_mark'): 230 | print(' defective track address mark: ', modulation.defective_track_address_mark) 231 | print(' data address mark: ', modulation.data_address_mark) 232 | if hasattr(modulation, 'deleted_data_address_mark'): 233 | print(' deleted data address mark: ', modulation.deleted_data_address_mark) 234 | if hasattr(modulation, 'ecc_data_address_mark'): 235 | print(' ecc data address mark: ', modulation.ecc_data_address_mark) 236 | print() 237 | -------------------------------------------------------------------------------- /crc.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # parameterized CRC implementation 3 | # Copyright 2016 Eric Smith 4 | 5 | # supports operation on arbitrary data word widths 6 | 7 | # supports table-driven operation with selectable table size(s) 8 | # for common 8-bit use, after instantiation, call make_table(8) 9 | 10 | # Algorithms defined per section 14 of "A Painless Guide to CRC 11 | # Error Detection Algorithms" by Ross N. Williams: 12 | # http://www.ross.net/crc/download/crc_v3.txt 13 | 14 | # This program is free software: you can redistribute it and/or 15 | # modify it under the terms of version 3 of the GNU General Public 16 | # License as published by the Free Software Foundation. 17 | 18 | # This program is distributed in the hope that it will be useful, 19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 21 | # General Public License for more details. 22 | 23 | # You should have received a copy of the GNU General Public License 24 | # along with this program. If not, see 25 | # . 26 | 27 | from collections import namedtuple 28 | import struct 29 | 30 | class CRC: 31 | 32 | CRCParam = namedtuple('CRCParam', 33 | ['name', 34 | 'order', 35 | 'poly', 36 | 'init', 37 | 'xorot', 38 | 'refin', # reflect input data 39 | 'refot']) # reflect output word 40 | 41 | crc16_ccitt_param = CRCParam(name = 'CRC-16-CCITT', 42 | order = 16, 43 | poly = 0x1021, 44 | init = 0xffff, 45 | xorot = 0x0000, 46 | refin = False, 47 | refot = False) 48 | 49 | crc32_param = CRCParam(name = 'CRC-32', 50 | order = 32, 51 | poly = 0x04c11db7, 52 | init = 0xffffffff, 53 | xorot = 0xffffffff, 54 | refin = True, 55 | refot = True) 56 | 57 | crc32_bzip2_param = CRCParam(name = 'CRC-32/BZIP2', 58 | order = 32, 59 | poly = 0x04c11db7, 60 | init = 0xffffffff, 61 | xorot = 0xffffffff, 62 | refin = False, 63 | refot = False) 64 | 65 | # Catagnoli polynomial 66 | crc32c_param = CRCParam(name = 'CRC-32C', 67 | order = 32, 68 | poly = 0x1edc6f41, 69 | init = 0xffffffff, 70 | xorot = 0xffffffff, 71 | refin = True, 72 | refot = True) 73 | 74 | def __init__(self, 75 | param): 76 | self.tables = { } 77 | self.cache = { } 78 | self.param = param 79 | self.reg = param.init 80 | self.widmask = (1 << self.param.order) - 1 81 | self.topbit = 1 << (self.param.order - 1) 82 | 83 | def reset(self): 84 | self.reg = self.param.init 85 | 86 | def reflect(self, data, bit_count): 87 | d1 = data 88 | d2 = 0 89 | for b in range(bit_count): 90 | d2 <<= 1 91 | if d1 & 1: 92 | d2 |= 1 93 | d1 >>= 1 94 | #print("%02x %02x" % (data, d2)) 95 | return d2 96 | 97 | # this one works only for bit_count <= self.param.order 98 | def comp1(self, data, bit_count = 8): 99 | if self.param.refin: 100 | data = self.reflect(data, bit_count) 101 | self.reg ^= data << (self.param.order - bit_count) 102 | for b in range(bit_count): 103 | if self.reg & self.topbit: 104 | self.reg = (self.reg << 1) ^ self.param.poly 105 | else: 106 | self.reg <<= 1 107 | self.reg &= self.widmask 108 | 109 | # this one doesn't restrict bit_count 110 | def comp2(self, data, bit_count = 8): 111 | if self.param.refin: 112 | r = range(bit_count) 113 | else: 114 | r = range(bit_count - 1, -1, -1) 115 | for b in r: 116 | self.reg ^= ((data >> b) & 1) << (self.param.order - 1) 117 | if self.reg & self.topbit: 118 | self.reg = (self.reg << 1) ^ self.param.poly 119 | else: 120 | self.reg <<= 1 121 | self.reg &= self.widmask 122 | 123 | def find_table(self, bit_count): 124 | self.cache[bit_count] = 0 # assume no suitable table 125 | for i in range(bit_count, 1, -1): 126 | if i in self.tables: 127 | self.cache[bit_count] = i 128 | return 129 | 130 | def comp_int(self, data, bit_count = 8): 131 | if self.param.refin: 132 | data = self.reflect(data, bit_count) 133 | while bit_count > 0: 134 | if bit_count not in self.cache: 135 | self.find_table(bit_count) 136 | table_size = self.cache[bit_count] 137 | if table_size: 138 | b = data >> (bit_count - table_size) & ((1 << table_size) - 1) 139 | 140 | self.reg = self.tables[table_size][(self.reg >> (self.param.order - table_size)) ^ b] ^ (self.reg << table_size) 141 | self.reg &= self.widmask 142 | bit_count -= table_size 143 | else: 144 | b = (data >> bit_count - 1) & 1 145 | self.reg ^= b << (self.param.order - 1) 146 | if self.reg & self.topbit: 147 | self.reg = (self.reg << 1) ^ self.param.poly 148 | else: 149 | self.reg <<= 1 150 | self.reg &= self.widmask 151 | bit_count -= 1 152 | 153 | def comp(self, data, bit_count = 8): 154 | try: 155 | for b in data: 156 | self.comp_int(b, bit_count) 157 | except TypeError: 158 | self.comp_int(data, bit_count) 159 | 160 | def make_table_entry(self, d, bit_count): 161 | v = 0 162 | for b in range(bit_count - 1, -1, -1): 163 | b = (d >> bit_count - 1) & 1 164 | v ^= b << (self.param.order - 1) 165 | if v & self.topbit: 166 | v = (v << 1) ^ self.param.poly 167 | else: 168 | v <<= 1 169 | v &= self.widmask 170 | bit_count -= 1 171 | return v 172 | 173 | def make_table(self, bit_count = 8): 174 | if bit_count in self.tables: 175 | return 176 | assert bit_count > 1 177 | 178 | self.cache = { } 179 | 180 | self.tables[bit_count] = [self.make_table_entry(i, bit_count) for i in range(1 << bit_count)] 181 | 182 | #for i in range(len(self.tables[bit_count])): 183 | # print("%02x: %08x" % (i, self.tables[bit_count][i])) 184 | 185 | def get(self): 186 | if self.param.refot: 187 | return self.reflect(self.reg ^ self.param.xorot, self.param.order) 188 | else: 189 | return self.reg ^ self.param.xorot 190 | 191 | def crc(self, data): 192 | self.reset() 193 | self.comp(data) 194 | return self.get() 195 | 196 | 197 | if __name__ == '__main__': 198 | 199 | pass_count = 0 200 | fail_count = 0 201 | 202 | def test(param, data, expected_value, use_table = True): 203 | global pass_count, fail_count 204 | crc = CRC(param) 205 | if use_table: 206 | crc.make_table(5) 207 | crc.make_table(3) 208 | for b in data: 209 | crc.comp(b) 210 | v = crc.get() 211 | if v == expected_value: 212 | print('%s OK' % param.name) 213 | pass_count += 1 214 | else: 215 | print('%s crc result %08x, expected %08x' % (param.name, v, expected_value)) 216 | fail_count += 1 217 | 218 | 219 | def swap32(i): 220 | return struct.unpack("I", i))[0] 221 | 222 | 223 | # http://reveng.sourceforge.net/crc-catalogue/17plus.htm 224 | # http://stackoverflow.com/questions/1918090/crc-test-vectors-for-crc16-ccitt 225 | vector = [ord(c) for c in '123456789'] 226 | test(CRC.crc16_ccitt_param, vector, 0x29b1) 227 | test(CRC.crc32_param, vector, 0xcbf43926) 228 | test(CRC.crc32_bzip2_param, vector, 0xfc891918) 229 | test(CRC.crc32c_param, vector, 0xe3069283) 230 | 231 | 232 | # Test vectors for CRC-32C from RFC3270: 233 | # https://tools.ietf.org/html/rfc3720#appendix-B.4 234 | test(CRC.crc32c_param, [0x00] * 32, swap32(0xaa36918a)) 235 | test(CRC.crc32c_param, [0xff] * 32, swap32(0x43aba862)) 236 | test(CRC.crc32c_param, range(32), swap32(0x4e79dd46)) 237 | test(CRC.crc32c_param, range(31, -1, -1), swap32(0x5cdb3f11)) 238 | 239 | print("%d passed, %d failed" % (pass_count, fail_count)) 240 | 241 | -------------------------------------------------------------------------------- /imagedisk.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # ImageDisk library 3 | # Copyright 2016 Eric Smith 4 | 5 | # ImageDisk software and documentation can be found at: 6 | # http://www.classiccmp.org/dunfield/img/index.htm 7 | # The ImageDisk file format is documented in chapter 6 8 | # of IMD.TXT in the ImageDisk binary ZIP archive. 9 | 10 | # This program is free software: you can redistribute it and/or 11 | # modify it under the terms of version 3 of the GNU General Public 12 | # License as published by the Free Software Foundation. 13 | 14 | # This program is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | # General Public License for more details. 18 | 19 | # You should have received a copy of the GNU General Public License 20 | # along with this program. If not, see 21 | # . 22 | 23 | import argparse 24 | import datetime 25 | from collections import OrderedDict 26 | 27 | from modulation import FM, MFM, IntelM2FM 28 | 29 | 30 | class ImageDisk: 31 | class NotImageDiskFileException(Exception): 32 | pass 33 | 34 | class DuplicateSectorException(Exception): 35 | pass 36 | 37 | class MixedModeTrackException(Exception): 38 | pass 39 | 40 | class InvalidSectorSizeException(Exception): 41 | pass 42 | 43 | class NonexistentSectorException(Exception): 44 | pass 45 | 46 | class Sector: 47 | def __init__(self, mode, deleted, size_code, data, bad): 48 | self.mode = mode 49 | self.deleted = deleted 50 | self.size_code = size_code 51 | self.data = data 52 | self.bad = bad 53 | 54 | __sector_size_map = { 128: 0, 55 | 256: 1, 56 | 512: 2, 57 | 1024: 3, 58 | 2048: 4, 59 | 4096: 5 } 60 | 61 | 62 | def write_sector(self, mode, cylinder, head, sector, data, deleted = False, replace_ok = False, bad = False): 63 | track_coord = (cylinder, head) 64 | if track_coord not in self.tracks: 65 | self.tracks[track_coord] = OrderedDict() 66 | if (not replace_ok) and (sector in self.tracks[track_coord]): 67 | raise DuplicateSectorException('duplicate sector, cyl=%d, head=%d, sector=%d' % (cylinder, head, sector)) 68 | if len(data) not in self.__sector_size_map: 69 | raise InvalidSectorSizeException('invalid sector size, cyl=%d, head=%d, sector=%d, size=%d' % (cylinder, head, sector, len(data))) 70 | self.tracks[track_coord][sector] = ImageDisk.Sector(mode, deleted, self.__sector_size_map[len(data)], data, bad) 71 | 72 | 73 | def __read_track(self, f): 74 | header = f.read(5) 75 | if len(header) != 5: 76 | raise EOFError() 77 | mode = header[0] 78 | cylinder = header[1] 79 | head = header[2] 80 | sector_count = header[3] 81 | sector_size_code = header[4] 82 | sector_size_codes = [sector_size_code] * sector_count 83 | sector_numbers = f.read(sector_count) 84 | # XXX optional cylinder map not yet supported 85 | # XXX optional head map not yet supported 86 | if sector_size_code == 0xff: 87 | sector_size_codes = f.read(sector_count) 88 | for i in range(sector_count): 89 | data_type = f.read(1)[0] 90 | assert data_type <= 0x08 91 | bad = data_type in [0x00, 0x05, 0x06, 0x07, 0x08] 92 | deleted = data_type in [0x03, 0x04, 0x07, 0x08] 93 | compressed = data_type in [0x02, 0x04, 0x06, 0x08] 94 | if compressed: 95 | data = f.read(1) * (128 << sector_size_codes[i]) 96 | else: 97 | data = f.read(128 << sector_size_codes[i]) 98 | self.write_sector(mode, cylinder, head, sector_numbers[i], data) 99 | 100 | 101 | # if a file or filename is specified as f, will read that image 102 | def __init__(self, f = None, comment = None, timestamp = None): 103 | self.tracks = { } 104 | if f: 105 | do_close = False 106 | if type(f) is str: 107 | f = open(f, 'rb') 108 | # XXX read header 109 | s = f.read(4) 110 | if s != b'IMD ': 111 | raise NotImageDiskFileException() 112 | c = 0 113 | while c != bytes([0x1a]): 114 | c = f.read(1) 115 | while True: 116 | try: 117 | self.__read_track(f) 118 | except EOFError: 119 | break 120 | if do_close: 121 | f.close() 122 | self.comment = comment 123 | if timestamp is None: 124 | self.timestamp = datetime.datetime.utcnow() 125 | else: 126 | self.timestamp = timestamp 127 | 128 | def read_sector(self, cylinder, head, sector): 129 | try: 130 | data = self.tracks[(cylinder, head)][sector].data 131 | except KeyError: 132 | raise NonexistentSectorException() 133 | return data 134 | 135 | def __write_track(self, f, tc): 136 | mode = None 137 | track = self.tracks[tc] 138 | sector_count = len(track) 139 | sector_size_code = None 140 | for sector_number in track: 141 | sector = track[sector_number] 142 | if mode is None: 143 | mode = sector.mode 144 | elif mode != sector.mode: 145 | raise MixedModeTrackException('mixed modes, cyl=%d, head=%d' % tc) 146 | if sector_size_code is None: 147 | sector_size_code = sector.size_code 148 | elif sector_size_code != sector.size_code: 149 | sector_size_code = 0xff # indicate mixed sector sizes 150 | 151 | f.write(bytes([mode, 152 | tc[0], # cylinder 153 | tc[1], # head 154 | sector_count, 155 | sector_size_code])) 156 | f.write(bytes(track.keys())) # sector map 157 | # XXX doesn't currently support the optional cylinder map 158 | # XXX doesn't currently support the optional head map 159 | if sector_size_code == 0xff: 160 | # write sector size map 161 | f.write(bytes([sector.size_code for sector in track])) 162 | for sector_number in track: 163 | if track[sector_number].deleted: 164 | data_code = 0x03 165 | else: 166 | data_code = 0x01 167 | if track[sector_number].bad: 168 | data_code = data_code + 0x04; 169 | data = track[sector_number].data 170 | compress = data[1:] == data[:-1] 171 | if compress: 172 | f.write(bytes([data_code + 1])) 173 | f.write(data[0:1]) 174 | else: 175 | f.write(bytes([data_code])) 176 | f.write(data) 177 | 178 | 179 | def write(self, f): 180 | do_close = False 181 | if type(f) is str: 182 | f = open(f, 'wb') 183 | do_close = True 184 | 185 | # write header 186 | dt = self.timestamp.strftime('%d/%m/%Y %H:%M:%S') 187 | f.write(bytes('IMD 1.18 %s\r\n' % dt, encoding='ascii')) 188 | if self.comment is not None: 189 | f.write(bytes(self.comment + '\r\n', 'utf-8')) 190 | f.write(bytes([0x1a])) 191 | 192 | tl = sorted(self.tracks.keys()) 193 | for tc in tl: 194 | self.__write_track(f, tc) 195 | 196 | if do_close: 197 | f.close() 198 | 199 | 200 | def auto_int(x): 201 | return int(x, 0) 202 | 203 | 204 | if __name__ == '__main__': 205 | parser = argparse.ArgumentParser(description = 'ImageDisk library test, writes an empty disk image', 206 | formatter_class = argparse.ArgumentDefaultsHelpFormatter) 207 | parser.add_argument('image', type=argparse.FileType('wb')) 208 | 209 | parser_modulation = parser.add_mutually_exclusive_group(required = False) 210 | parser_modulation.add_argument('--fm', action = 'store_const', const = FM, dest = 'modulation', help = 'FM modulation, IBM 3740 single density') 211 | parser_modulation.add_argument('--mfm', action = 'store_const', const = MFM, dest = 'modulation', help = 'MFM modulation, IBM System/34 double density') 212 | parser_modulation.add_argument('--m2fm', action = 'store_const', const = IntelM2FM, dest = 'modulation', help = 'M2FM modulation, Intel MDS, SBC 202 double density') 213 | 214 | parser.add_argument('-t', '--tracks', type = int, default = 77, help = 'tracks per side') 215 | parser.add_argument('-s', '--sectors', type = int, help = 'sectors per track') 216 | parser.add_argument('-b', '--bytes', type = int, help = 'bytes per sector') 217 | parser.add_argument('-d', '--data', type = auto_int, default = 0xe5, help = 'data byte to fill sectors') 218 | 219 | parser.set_defaults(modulation = FM) 220 | 221 | args = parser.parse_args() 222 | 223 | sectors = args.sectors 224 | if sectors is None: 225 | sectors = args.modulation.default_sectors_per_track 226 | 227 | bytes_per_sector = args.bytes 228 | if bytes_per_sector is None: 229 | bytes_per_sector = args.modulation.default_bytes_per_sector 230 | 231 | imd = ImageDisk() # no file, so creating a new image 232 | 233 | head = 0 234 | for track in range(args.tracks): 235 | for sector in range(1, sectors + 1): 236 | imd.write_sector(args.modulation.imagedisk_mode, track, head, sector, bytes([args.data] * bytes_per_sector)) 237 | imd.write(args.image) 238 | -------------------------------------------------------------------------------- /kfsf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # KryoFlux stream file library 3 | # Copyright 2016 Eric Smith 4 | 5 | # KryoFlux stream file format is documented in: 6 | # http://www.kryoflux.com/download/kryoflux_stream_protocol_rev1.1.pdf 7 | 8 | # This program is free software: you can redistribute it and/or 9 | # modify it under the terms of version 3 of the GNU General Public 10 | # License as published by the Free Software Foundation. 11 | 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | # General Public License for more details. 16 | 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see 19 | # . 20 | 21 | import argparse 22 | import re 23 | import zipfile 24 | 25 | from fluximage import FluxImage, FluxImageBlock 26 | 27 | class KyroFluxStreamOOBBlock: 28 | def __init__(self, kfs, length): 29 | self.kfs = kfs 30 | self.length = length 31 | 32 | self.read_oob_payload() 33 | 34 | read_length = (kfs.stream_offset - kfs.block_offset) - 4 35 | if (not kfs.logical_eof) and (self.length != read_length): 36 | raise Exception('Internal error: OOB block length %d, but expected %d bytes' % (self.length, read_length)) 37 | 38 | # OOB blockfs don't count toward stream offset! 39 | kfs.stream_offset = kfs.block_offset 40 | 41 | oob_type_map = { } 42 | 43 | @classmethod 44 | def register_subclass(cls, val): 45 | def inner(subclass): 46 | cls.oob_type_map[val] = subclass 47 | return subclass 48 | return inner 49 | 50 | @classmethod 51 | def factory(cls, kfs): 52 | oob_type = kfs.read_u8() 53 | oob_length = kfs.read_u16_le() 54 | if oob_type not in cls.oob_type_map: 55 | raise Exception('Unknown OOB block type %02x' % oob_type) 56 | return cls.oob_type_map[oob_type](kfs, oob_length) 57 | 58 | @KyroFluxStreamOOBBlock.register_subclass(0x01) 59 | class KyroFluxStreamInfo(KyroFluxStreamOOBBlock): 60 | def read_oob_payload(self): 61 | self.stream_pos = self.kfs.read_u32_le() 62 | pos_error = self.kfs.block_offset - self.stream_pos 63 | self.xfer_time = self.kfs.read_u32_le() 64 | 65 | if (self.kfs.debug): 66 | print('StreamInfo at %d' % self.kfs.block_offset) 67 | print(' stream_pos: %d' % self.stream_pos, end='') 68 | if pos_error: 69 | print(' (error %d)' % pos_error, end='') 70 | print() 71 | print(' xfer_time: %d' % self.xfer_time) 72 | 73 | @KyroFluxStreamOOBBlock.register_subclass(0x02) 74 | class KyroFluxIndex(KyroFluxStreamOOBBlock): 75 | def read_oob_payload(self): 76 | self.index_number = self.kfs.index_count 77 | self.kfs.index_count += 1 78 | 79 | self.next_flux_stream_pos = self.kfs.read_u32_le() 80 | self.sample_counter = self.kfs.read_u32_le() 81 | self.index_counter = self.kfs.read_u32_le() 82 | 83 | if self.kfs.debug: 84 | print('Index %d at stream %d' % (self.index_number, self.kfs.block_offset)) 85 | print(' next_flux_stream_pos: %d' % self.next_flux_stream_pos) 86 | print(' sample_counter: %d' % self.sample_counter) 87 | print(' index_counter: %d' % self.index_counter) 88 | 89 | def found_target_flux(self, prev_flux_sample_counter, flux_sample_counter): 90 | self.index_abs = prev_flux_sample_counter + self.sample_counter 91 | self.kfs.index_abs.append(self.index_abs) 92 | if self.kfs.debug: 93 | print('post index %d flux transition found at sample count %d' % (self.index_number, self.index_abs)) 94 | 95 | 96 | @KyroFluxStreamOOBBlock.register_subclass(0x03) 97 | class KyroFluxStreamEnd(KyroFluxStreamOOBBlock): 98 | def read_oob_payload(self): 99 | self.stream_pos = self.kfs.read_u32_le() 100 | pos_error = self.kfs.block_offset - self.stream_pos 101 | self.result_code = self.kfs.read_u32_le() 102 | self.kfs.stream_end = True 103 | 104 | if self.kfs.debug: 105 | print('StreamEnd at %d' % self.kfs.block_offset) 106 | print(' stream_pos: %d' % self.stream_pos, end='') 107 | if pos_error: 108 | print(' (error %d)' % pos_error, end='') 109 | print() 110 | print(' result_code: %d' % self.result_code) 111 | 112 | @KyroFluxStreamOOBBlock.register_subclass(0x04) 113 | class KyroFluxInfo(KyroFluxStreamOOBBlock): 114 | def read_oob_payload(self): 115 | text = self.kfs.read(self.length).decode('ascii') 116 | if text[-1] != '\x00': 117 | raise Exception('Info text not null-terminated') 118 | fields = [i.split('=') for i in text[:-1].split(', ')] 119 | self.kfs.info.update(dict(fields)) 120 | 121 | if self.kfs.debug: 122 | print('Info at %d' % self.kfs.block_offset) 123 | for (k, v) in fields: 124 | print(' %s=%s' % (k, v)) 125 | 126 | @KyroFluxStreamOOBBlock.register_subclass(0x0d) 127 | class KyroFluxEOF(KyroFluxStreamOOBBlock): 128 | def read_oob_payload(self): 129 | self.kfs.logical_eof = True 130 | 131 | if self.kfs.debug: 132 | print('Logical EOF at %d' % self.kfs.block_offset) 133 | 134 | class KyroFluxStream(FluxImageBlock): 135 | def flux_change(self, offset): 136 | # record flux change here 137 | self.flux_sample_counter += self.overflow + offset 138 | self.overflow = 0 139 | 140 | # Discard all flux transitions before index pulse 141 | if self.index_abs and self.flux_sample_counter > self.index_abs[0]: 142 | self.flux_trans_abs.append(self.flux_sample_counter) 143 | 144 | if self.stream_offset in self.pending_index_blocks: 145 | index = self.pending_index_blocks[self.stream_offset] 146 | index.found_target_flux(self.prev_flux_sample_counter, 147 | self.flux_sample_counter) 148 | del self.pending_index_blocks[self.stream_offset] 149 | 150 | self.prev_flux_sample_counter = self.flux_sample_counter 151 | 152 | if self.debug: 153 | print('flux at %d' % self.flux_sample_counter) 154 | 155 | def get_block(self): 156 | self.block_offset = self.stream_offset 157 | try: 158 | bt = self.read_u8() 159 | except EOFError: 160 | print('unexpected EOF') 161 | self.logical_eof = True 162 | return 163 | if bt != 0x0d and self.stream_end: 164 | raise Exception('In-band data past stream end') 165 | if bt <= 0x07: # Flux2 166 | self.flux_change((bt << 8) + self.read_u8()) 167 | elif bt == 0x08: # Nop1 168 | pass 169 | elif bt == 0x09: # Nop2 170 | self.read(1) 171 | elif bt == 0x0a: # Nop3 172 | self.read(2) 173 | elif bt == 0x0b: # Ovl16 174 | self.overflow += 0x10000 175 | if self.debug: 176 | print('overflow') 177 | elif bt == 0x0c: # Flux3 178 | self.flux_change(self.read_u16_le) 179 | elif bt == 0x0d: # OOB 180 | block = KyroFluxStreamOOBBlock.factory(self) 181 | self.oob_blocks.append(block) 182 | if isinstance(block, KyroFluxIndex): 183 | self.pending_index_blocks[block.next_flux_stream_pos] = block 184 | else: # 0x0e..0xff: Flux1 185 | self.flux_change(bt) 186 | 187 | def __init__(self, fluximagefile, debug = False): 188 | super().__init__(fluximagefile, debug) 189 | self.info = { } 190 | self.overflow = 0 191 | self.stream_end = False 192 | self.logical_eof = False 193 | 194 | self.prev_flux_sample_counter = 0 195 | self.flux_sample_counter = 0 196 | self.flux_trans_abs = [ ] 197 | 198 | self.oob_blocks = [ ] 199 | 200 | self.index_count = 0 201 | self.pending_index_blocks = { } 202 | self.index_abs = [ ] 203 | 204 | while not self.logical_eof: 205 | self.get_block() 206 | 207 | try: 208 | self.frequency = float(self.info['sck']) 209 | except: 210 | self.frequency = 18.432e6 * 73 / 56 211 | 212 | if self.pending_index_blocks: 213 | print('%d unresolved index blocks' % len(self.pending_index_blocks)) 214 | 215 | 216 | class KFSF(FluxImage): 217 | def __init__(self, fluximagefile, debug = False): 218 | super().__init__(fluximagefile, debug) 219 | 220 | try: 221 | zf = zipfile.ZipFile(fluximagefile) 222 | except: 223 | zf = None 224 | 225 | if zf is None: 226 | head = 0 227 | track = 0 228 | fluximagefile.seek(0) 229 | self.blocks[(track, head, 1)] = KyroFluxStream(fluximagefile, debug = debug) 230 | else: 231 | for fn in zf.namelist(): 232 | #print(fn) 233 | m = re.match('.*track([0-9]{2})\.([0-9])\.raw$', fn) 234 | if m: 235 | head = int(m.group(2)) 236 | track = int(m.group(1)) 237 | if True: 238 | print('reading head %d track %02d' % (head, track)) 239 | try: 240 | with zf.open(fn) as f: 241 | self.blocks[(track, head, 1)] = KyroFluxStream(f, debug = debug) 242 | except Exception as e: 243 | print('%s reading head %d track %02d' % (str(e), head, track)) 244 | 245 | 246 | # test program accepts command line arguments for 247 | if __name__ == "__main__": 248 | parser = argparse.ArgumentParser(description = 'KFSF library test, prints flux transition time histogram for a chosen track', 249 | formatter_class = argparse.ArgumentDefaultsHelpFormatter) 250 | parser.add_argument('image', type=argparse.FileType('rb', 0)) 251 | parser.add_argument('-s', '--side', type=int, help = 'head', default=0) # head 252 | parser.add_argument('-t', '--track', type=int, help = 'cylinder', default=0) # cylinder 253 | parser.add_argument('-r', '--resolution', type=float, help = 'histogram resolution in us', default=0.2) 254 | parser.add_argument('-d', '--debug', action='store_true', help = 'print debugging information') 255 | args = parser.parse_args() 256 | 257 | image = KFSF(args.image, debug = args.debug) 258 | 259 | block = image.blocks[(args.track, args.side, 1)] 260 | 261 | bucket_size = int(block.frequency * args.resolution / 1.0e6) 262 | block.print_hist(bucket_size = bucket_size) 263 | -------------------------------------------------------------------------------- /fluxtoimd.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # data extraction from floppy disk flux transition images 3 | # Copyright 2016 Eric Smith 4 | 5 | # This program is free software: you can redistribute it and/or 6 | # modify it under the terms of version 3 of the GNU General Public 7 | # License as published by the Free Software Foundation. 8 | 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # General Public License for more details. 13 | 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see 16 | # . 17 | 18 | import argparse 19 | import re 20 | from collections import OrderedDict 21 | 22 | from dfi import DFI # DiscFerret image format 23 | from kfsf import KFSF # KryoFlux stream format 24 | from adpll import ADPLL 25 | from crc import CRC 26 | from modulation import FM, MFM, IntelM2FM, HPM2FM 27 | from imagedisk import ImageDisk 28 | 29 | 30 | def hex_dump(b, prefix = ''): 31 | for i in range(0, len(b), 16): 32 | print(prefix + '%02x: ' % i, end='') 33 | for j in range(16): 34 | if (i + j) < len(b): 35 | print('%02x ' % b[i+j], end='') 36 | else: 37 | print(' ', end='') 38 | for j in range(16): 39 | if (i + j) < len(b): 40 | if 0x20 <= b[i+j] <= 0x7e: 41 | print('%c' % b[i+j], end='') 42 | else: 43 | print('.', end='') 44 | print() 45 | 46 | 47 | def dump_track(modulation, 48 | image, 49 | track, 50 | side, # 0 or 1 51 | sectors_per_track = None, 52 | require_index_mark = False): 53 | 54 | if sectors_per_track is None: 55 | sectors_per_track = modulation.default_sectors_per_track 56 | 57 | sectors = OrderedDict() 58 | 59 | block = image.blocks[(track, side, 1)] 60 | 61 | di = block.get_delta_iter() 62 | 63 | adpll = ADPLL(di, 64 | osc_period = hbc, 65 | max_adj_pct = 3.0, 66 | window_pct = 50.0, 67 | freq_adj_factor = 0.005, 68 | phase_adj_factor = 0.1) 69 | 70 | 71 | bits = '' 72 | for b in adpll: 73 | bits += '01'[b] 74 | #print(len(bits)) 75 | #print(bits) 76 | 77 | if require_index_mark: 78 | index_address_mark_locs = [m.start() for m in re.finditer(modulation.index_address_mark, bits)] 79 | if not index_address_mark_locs: 80 | print('track %d: no index address mark found' % track) 81 | return sectors 82 | 83 | id_address_mark_locs = [m.start() for m in re.finditer(modulation.id_address_mark, bits)] 84 | #print('id address marks at: ', id_address_mark_locs) 85 | 86 | for id_pos in id_address_mark_locs: 87 | #print('id address mark at channel bit %d' % id_pos) 88 | id_field = modulation.decode(bits[id_pos: id_pos + len(modulation.id_address_mark) + 16 * (modulation.id_field_length + 2)]) 89 | crc.reset() 90 | if (modulation.crc_includes_address_mark): 91 | crc.comp(id_field) 92 | else: 93 | crc.comp(id_field[1:]) 94 | if crc.get() != 0: 95 | print("*** bad ID field CRC %04x" % crc.get()) 96 | hex_dump(id_field) 97 | continue 98 | if modulation.id_field_length == 2: 99 | # HP M2FM ID field only contains two bytes for track and sector 100 | id_track, id_sector = id_field[1:3] 101 | if id_sector < 0x80: 102 | id_head = 0 103 | else: 104 | id_sector -= 0x80 105 | id_head = 1 106 | id_size = 1 107 | else: 108 | id_track, id_head, id_sector, id_size = id_field[1:5] 109 | #print('head %d track %02d sector %02d' % (id_head, id_track, id_sector)) 110 | if id_head != side: 111 | print("*** ID field with wrong head number") 112 | hex_dump(id_field) 113 | continue 114 | if id_track != track: 115 | print("*** ID field with wrong track number") 116 | hex_dump(id_field) 117 | continue 118 | 119 | bc = 128 << id_size 120 | if bc not in modulation.expected_sector_sizes: 121 | print("*** ID field with unexpected sector size") 122 | hex_dump(id_field) 123 | if (id_sector in sectors) and (sectors[id_sector][1] is not None) and not sectors[id_sector][2]: 124 | continue # already have this one and it was a good read 125 | # Mark sector bad to start with 126 | sectors[id_sector] = [False, None, True] 127 | 128 | deleted = False 129 | data_pos = bits.find(modulation.data_address_mark, id_pos + len(modulation.id_address_mark) + 16 * (modulation.id_field_length + 2)) 130 | if (modulation.id_to_data_half_bits - 50) <= (data_pos - id_pos) <= (modulation.id_to_data_half_bits + 50): 131 | #print(' data address mark at channel bit offset %d' % (data_pos - id_pos)) 132 | pass 133 | elif hasattr(modulation, 'deleted_data_address_mark'): 134 | data_pos = bits.find(modulation.deleted_data_address_mark, id_pos + len(modulation.id_address_mark) + 96) 135 | if (modulation.id_to_data_half_bits - 50) <= (data_pos - id_pos) <= (modulation.id_to_data_half_bits + 50): 136 | #print(' deleted data address mark at channel bit offset %d' % (deleted_data_pos - id_pos)) 137 | deleted = True 138 | else: 139 | print('*** ID field without data field ***') 140 | hex_dump(id_field) 141 | continue 142 | else: 143 | print('*** ID field without data field ***') 144 | hex_dump(id_field) 145 | continue 146 | 147 | data_field = modulation.decode(bits[data_pos: data_pos + len(modulation.id_address_mark) + (bc + 2) * 16]) 148 | crc.reset() 149 | if (modulation.crc_includes_address_mark): 150 | crc.comp(data_field) 151 | else: 152 | crc.comp(data_field[1:]) 153 | if crc.get() == 0: 154 | sectors [id_sector] = (deleted, data_field[1:bc+1], False) 155 | else: 156 | print("*** bad data field CRC track %d side %d sector %d" % (track, side, id_sector)) 157 | # Only update sector if bad to prevent overwriting good with bad 158 | if sectors[id_sector][2]: 159 | sectors [id_sector] = (deleted, data_field[1:bc+1], True) 160 | 161 | return sectors 162 | 163 | 164 | parser = argparse.ArgumentParser(description = 'DFI library test, prints flux transition time histogram for a chosen track', 165 | formatter_class = argparse.ArgumentDefaultsHelpFormatter) 166 | parser.add_argument('flux_image', type=argparse.FileType('rb')) 167 | parser.add_argument('imagedisk_image', type=argparse.FileType('wb')) 168 | parser.add_argument('-C', '--comment', action = 'store') 169 | 170 | parser.add_argument('-F', '--flux_format', choices=['dfi', 'ksf'], default = 'dfi') 171 | 172 | parser_modulation = parser.add_mutually_exclusive_group(required = False) 173 | parser_modulation.add_argument('--fm', action = 'store_const', const = FM, dest = 'modulation', help = 'FM modulation, IBM 3740 single density') 174 | parser_modulation.add_argument('--mfm', action = 'store_const', const = MFM, dest = 'modulation', help = 'MFM modulation, IBM System/34 double density') 175 | parser_modulation.add_argument('--intelm2fm', action = 'store_const', const = IntelM2FM, dest = 'modulation', help = 'M2FM modulation, Intel MDS, SBC 202 double density') 176 | parser_modulation.add_argument('--hpm2fm', action = 'store_const', const = HPM2FM, dest = 'modulation', help = 'M2FM modulation, HP 7902/9885/9895 double density') 177 | 178 | parser.set_defaults(modulation = FM) 179 | 180 | parser.add_argument('-s', '--sides', type=int, default = 1, choices = [1, 2], help='number of sides') 181 | parser.add_argument('-t', '--tracks', type=int, default = 77, help='number of tracks') 182 | 183 | parser.add_argument('-f', '--frequency', type=float, help = 'sample rate in MHz', default=25.0) 184 | parser.add_argument('-b', '--bit-rate', type=float, help = 'bit rate in Kbps') 185 | parser.add_argument('--index', action = 'store_true', help = 'require tracks to have index address marks') 186 | parser.add_argument('-v', '--verbose', action = 'store_true') 187 | args = parser.parse_args() 188 | 189 | if args.flux_format == 'dfi': 190 | flux_image = DFI(args.flux_image, frequency = args.frequency * 1.0e6) 191 | elif args.flux_format == 'ksf': 192 | flux_image = KFSF(args.flux_image) 193 | 194 | if args.modulation == HPM2FM and args.index: 195 | print("index mark option ignored, as HP M2FM doesn't use index marks") 196 | args.index = False 197 | 198 | if args.imagedisk_image is not None: 199 | if args.comment is not None: 200 | imd = ImageDisk(comment=args.comment) 201 | else: 202 | imd = ImageDisk() 203 | 204 | if args.bit_rate is None: 205 | args.bit_rate = args.modulation.default_bit_rate_kbps 206 | 207 | 208 | crc_param = CRC.CRCParam(name = 'CRC-16-CCITT', 209 | order = 16, 210 | poly = 0x1021, 211 | init = args.modulation.crc_init, 212 | xorot = 0x0000, 213 | refin = args.modulation.lsb_first, 214 | refot = False) 215 | 216 | 217 | crc = CRC(crc_param) 218 | crc.make_table(8) 219 | 220 | 221 | hbr = args.bit_rate * 2000 # half-bit rate in Hz 222 | hbc = 1/hbr # half-bit cycle in s 223 | 224 | 225 | first_sector = args.modulation.default_first_sector 226 | sectors_per_track = args.modulation.default_sectors_per_track 227 | 228 | bad_sectors = 0 229 | data_sectors = 0 230 | deleted_sectors = 0 231 | total_sectors = 0 232 | 233 | 234 | #tracks = { } 235 | for track_num in range(args.tracks): 236 | for side_num in range(args.sides): 237 | track = dump_track(args.modulation, flux_image, track_num, side_num, require_index_mark = args.index) 238 | #tracks[(track_num, side_num)] = track 239 | if args.verbose: 240 | print('track %2d' % track_num, end='') 241 | if args.sides > 1: 242 | print(' side %d' % side_num, end='') 243 | print(': ', end='') 244 | for sector_num in range(first_sector, first_sector + sectors_per_track): 245 | total_sectors += 1 246 | # If sector not found or bad data (CRC error) 247 | if sector_num not in track or track[sector_num][2]: 248 | if args.verbose: 249 | print('*', end='') 250 | bad_sectors += 1 251 | continue 252 | sector = track[sector_num] 253 | if sector[0]: 254 | if args.verbose: 255 | print('D', end='') 256 | deleted_sectors += 1 257 | else: 258 | if args.verbose: 259 | print('.', end='') 260 | data_sectors += 1 261 | if args.verbose: 262 | print() 263 | 264 | if args.imagedisk_image is not None: 265 | for sector_num in range(first_sector, first_sector + sectors_per_track): 266 | if sector_num not in track: 267 | print('*** BAD nodata: track %02d sector %02d\n' % (track_num, sector_num)) 268 | for sector_num in track: 269 | deleted = track[sector_num][0] 270 | data = track[sector_num][1] 271 | bad = track[sector_num][2] 272 | if data is not None: 273 | #print('writing track %02d sector %02d\n' % (track_num, sector_num)) 274 | if bad: 275 | print('*** BAD: track %02d sector %02d\n' % (track_num, sector_num)) 276 | imd.write_sector(args.modulation.imagedisk_mode, 277 | track_num, # cylinder 278 | side_num, # head 279 | sector_num, 280 | bytes(data), 281 | deleted = deleted, 282 | bad = bad) 283 | else: 284 | # If sector not found then no data written to file for sector 285 | print('*** BAD nodata: track %02d sector %02d\n' % (track_num, sector_num)) 286 | pass 287 | 288 | if args.imagedisk_image is not None: 289 | imd.write(args.imagedisk_image) 290 | 291 | print('%d data sectors, %d deleted data sectors, %d bad sectors, out of %d' % (data_sectors, deleted_sectors, bad_sectors, total_sectors)) 292 | 293 | -------------------------------------------------------------------------------- /gpl-3.0.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------