/*SCCS header - %W% %G% */ /************************************************************************ * * * Filename: x2x_main.c * * Version: 0.0 * * Author : Gary Duncan * * 24 Inkster St * * Kambah ACT 2902 * * Australia * * * *-----------------------------------------------------------------------*/ #include "x2x_amiga.h" #include "x2x_data.c" extern uchar Ichar(); extern char *MakeDate[] ; /************************************************************************* * * Modification record * ------------------- * * Date By whom Change * ---- ------- ------ * * 12 Apr 89 GMD AMIGA'd * *------------------------------------------------------------------------ * * This program will convert a given file in Down-Line Load (DLL) format * to another (or the same) DLL format . * * The DLL formats are the usual ASCII_hex formats of * INTEL / TEKTRONIX ( and extended) / MOTOROLA (S1-3) * * If no input params , the program solicits for :- * * 1) Input File name ( which it then scans to determine DLL format) * 2) Output file DLL format * 3) Output DLL record DATA length ( 0 < len < 256 ) * * ( In MOTOROLA format , prompts are made for addr length , ie 2,3, 4 bytes) * * else ( if there are params ) , it is invoked as follows :- * * x2x -Ifilename -Otype [-Srecord_data_length] * * type : I=INTEL , T=TEKTRONIX ,t= TEKTRONIX (extended) * M1=MOTOROLA (S1) , M2=MOTOROLA (S2) M3=MOTOROLA (S3) * * * Output file name generation *----------------------------- * * VAX * * The input file name then has ".xi / .xt / .xm2,3,or4 / or .xq appended * to form the output file name. Note that no overwrite check is done. * e.g fred.xi -> fred.xi.xi -> fred.xi.xi.x(whatever) etc * * PC * * A filename in wonderful MS_DOS is limited to the form of :- * <8 charas max>.< 3 charas max> thus appending ( appension ?) to * avoid ambiguity is not possible thus we progressively "backspace" * from the "." separator looking for a non-'&' chara which is then * transformed to '&'. * e.g (INTEL to INTEL ) , abcdef.xi -> abcde&.xi -> abcd&&.xi etc * * Note that there is no restriction on cross-conversion ; ie you can * use this program to produce a file of the same format but of a different * data length. ( This could be useful because utilities such as AZTEC * 'hex86' program only create DLL records with the boring length of 16) * * Whilst running , the program displays dots before the eyes to soothe * those who are nervous about silent programs. * * * On Completion * ------------- * ... some nice stats are presented. Note that the * checksum is a one_byte_sum_with_carry_wrap of the data * bytes ( a la MICE ) so if using the MICE you can verify * the Down Line Load with its memory checksum command (T). * ( valid only for contiguous load , of course ) * ************************************************************************* * * * * This program will run on a uVAX or IBM PC * * * * VAX build : cc -o x2x x2x.c ( produces x2x* ) * * * * IBM PC " : cc -DAMIGA x2x.c * * ln x2x.o \lib\c.lib \lib\s.lib * * ( produces x2x.exe ) * * * * * ************************************************************************* * ############################################################################# # # Examples of ACSII-hex formats for :- # # INTEL # MOTOROLA # TEKTRONIX ( inc extended format ) # # # Note: the INTEL example (data length 16dec bytes) is the reference. # : in following "byte" = binary value of 2 ASCII-hex charas # hi nibble = 1st byte # ############################################################################# # # Format : INTEL # :LLAAAATTdd..ddCC LL = # of data bytes AAAA = 16 bit address TT = type 0 = data 1 = end record 2 = Upper Segment Base Address (USBA) 3 = start address record ( data length = 4 bytes) CC = checksum ( = -ve sum of record : ie sum of all byte-pairs = 0 ) dd = ASCII-hex charas USBA format = :02000002ssssCC ( following data records will be have (16 * ssss) added to their load addr) ---------------------------------------------------------------------------- :020000020500?? # type 2 record , base = 500H :1012340090FAFCE96B002020202020202020202090 # type 0 record (data) # (load addr = 1234H) :00000001FF # type 1 record (end) # above converted to :- :1062340090FAFCE96B002020202020202020202040 <| S1LLAAAAdd..ddCC << Format LL = 2 + (# of data bytes) + 1 AAAA = address CC = ~( LL + (AA .. + AA) + ( data bytes )) : Note 1's complement! S1LLAAAAdd..ddCC << Format S113623490FAFCE96B00202020202020202020203C <> 4) & 0xF ; /* MS nibble */ (cc < 0xA) ? ( cc = cc + '0') : ( cc = cc + 'A' - 10 ) ; chch = (int) cc << 8 ; /*Hi nibble */ cc = k & 0xF ; (cc < 0xA) ? ( cc = cc + '0') : ( cc = cc + 'A' - 10 ) ; return ( chch | cc ) ; } /*************************************************************************** Function : get_hex Purpose : Returns with given ASCII hex chara de-ASCIIed Entry : chara Returns : - 1 , error , else chara ( 0 > 15 ) **************************************************************************/ int get_hex ( bite ) uchar bite ; { if ( isdigit (bite) ) return ( bite & 0xF ) ; /* number */ bite |= 0x20 ; if ( islower (bite) && ( bite < 'g') ) return ( (bite & 0xF) + 9 ) ; /* A _ F */ return ( -1 ) ; /* error */ } /*************************************************************************** Function : Ichar Purpose : Returns with chara from input file Entry : chara Returns : - 1 , error , else chara **************************************************************************/ uchar Ichar () { int ch ; if ( boffs == -1 ) return ( -1 ) ; /* File empty */ if ( !disclen ) { disclen = read (iffp , dbuf , 1024 ) ; /* read a block of file */ boffs = 0 ; } if ( !disclen ) return ( -1 ) ; ch = dbuf[ boffs ] &0xFF ; xchek += ch ; /* accum a checksum for ext use */ if ( ++boffs != disclen ) return ( ch ) ; else if ( boffs == 1024 ) disclen = 0 ; /* flag buffer empty */ else boffs = -1 ; /* flag file empty */ return ( ch ) ; }