// make103.cpp : définit le point d'entrée pour l'application console. // #include "stdio.h" #include "stdlib.h" #include "string.h" #define ISIZE 710374 #define LSIZE 77 #define HSIZE 17 #define OFFSET_HEADER1 0x4D126 #define OFFSET_DATA1 (OFFSET_HEADER1+HSIZE) #define OFFSET_HEADER2 0x56B37 int shex2int(char c) { if(c>='0' && c<='9') return c-'0'; if(c>='A' && c<='F') return 10+c-'A'; if(c>='a' && c<='f') return 10+c-'f'; return 0; } void fixlcrc(char* buf,int size) { int sum=0; char tmp[3]; for(int i=1;i=0x100) sum=0; sprintf(tmp,"%02X",sum); buf[size-4]=tmp[0]; buf[size-3]=tmp[1]; } int main(int argc, char* argv[]) { char ibuf[ISIZE]; char lbuf[LSIZE]; char tmp[4]; if(argc<2) { printf("Error: not enough arguments\nUsage: make103 \n"); return 1; } FILE* hi = fopen(argv[1],"rb"); if(!hi) { printf("Error opening %s\n",argv[1]); return 1; } FILE* ho; if(argc==2) ho = fopen(argv[1],"wb"); else ho = fopen(argv[2],"wb"); int size = fread(ibuf,1,ISIZE,hi); fclose(hi); ibuf[0x80]=0x36; fixlcrc(ibuf+0x4E,67); fwrite(ibuf,1,OFFSET_HEADER1,ho); fwrite(":020000020010EC\x0D\x0A",1,HSIZE,ho); memcpy(lbuf,":20400000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC0\x0D\x0A",LSIZE); for(int i=0x400;i<0x800;i+=2) { sprintf(tmp,"%X",i); memcpy(lbuf+3,tmp,3); fixlcrc(lbuf,LSIZE); fwrite(lbuf,1,LSIZE,ho); } fwrite(":020000020011EB\x0D\x0A",1,HSIZE,ho); fwrite(ibuf+OFFSET_DATA1,1,OFFSET_HEADER2-OFFSET_DATA1,ho); fwrite(":020000020012EA\x0D\x0A",1,HSIZE,ho); memcpy(lbuf,":20400000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC0\x0D\x0A",LSIZE); for(int i=0x400;i<0x800;i+=2) { sprintf(tmp,"%X",i); memcpy(lbuf+3,tmp,3); fixlcrc(lbuf,LSIZE); fwrite(lbuf,1,LSIZE,ho); } fwrite(":020000020013E9\x0D\x0A",1,HSIZE,ho); fwrite(":2040000091900000000000000000000000000000000000000000000000000000000000007F\x0D\x0A",1,LSIZE,ho); memcpy(lbuf,":2040000000000000000000000000000000000000000000000000000000000000000000007F\x0D\x0A",LSIZE); for(int i=0x402;i<=0x462;i+=2) { sprintf(tmp,"%X",i); memcpy(lbuf+3,tmp,3); fixlcrc(lbuf,LSIZE); fwrite(lbuf,1,LSIZE,ho); } fwrite(":2046400000000000000000000000000000000000000000000000F3FD21F08931C5FF3E7F1E\x0D\x0A:20466000CD9792D3063E81D307DB02CB7F2802D305210040444D3EC9EDB12B22F484CD1C64\x0D\x0A:2046800093218291CD2C93AF065A115600CD0C93CD18933E7ACD979221A582110041010024\x0D\x0A:2046A00001CDC692CD1893CD9191CD2492CD18933AF384CDD292CD18933AF384473E74CDA1\x0D\x0A:2046C0009792CD5792CD18933E74CD9792CDD292CD18933E75CD9792473AF3843C0E03CD77\x0D\x0A:2046E0005992CD18933E74CD9792473E71CD9792CD6692CD18933AF384CDD292CD18933AF2\x0D\x0A:20470000F384473E70CD9792CD5792CD18933E70CD9792CDD292CD18933E73CD9792473A94\x0D\x0A:20472000F384CD6692CD18933AF384CDD2923AF38411004006FECD0C93CD1893CDCC92CD01\x0D\x0A:204740009991AFD307C35300436C65616E696E672075702E2E2E00FDCB1B6E2001C9C93E9E\x0D\x0A:2047600001D3203E06D304AFD3003E81D307CD1392FD21F089CD1C93CDE691210080110193\x0D\x0A:204780008011707E3600EDB03E02D354FDCB43CEFDCB4286110A01ED53A090ED5394903EC9\x0D\x0A:2047A0001432A890AF32A99032A590C93E40CD48943E05CD48943E01CD48943E03CD48944C\x0D\x0A:2047C0003E17CD48943E0BCD48943E173247843A4784C618F6C0C3489497F53E08D303F1C6\x0D\x0A:2047E000D30397D331D334D337C93E08F5210040CD1293FEFE2821F1C604CDAE9238ED3EF0\x0D\x0A:2048000008F5210040CD1293FEFF280CF1C604CDAE9238ED3E081801F132F384C90E04F5E1\x0D\x0A:20482000C5CD6692C1F13C040D20F4C94FDB06F579210040F5C5D306110080010001E5C543\x0D\x0A:20484000EDB0C1E1D1D57AEB210080D5C5CDC692C1E109C1F1CB7C28DBF1D306C9C547DB8D\x0D\x0A:2048600002CB7F200578E61FC1C9DB21E60378C1C0E63FC947DB02CB7F200478E61FC9DB41\x0D\x0A:2048800021E603782803FE6AC9FE2AC9DD21C940180ADD2199401804DD218440E5E3F5DBD3\x0D\x0A:2048A0000667F1E3E5E3210293E3E5E32AF484E3E5F53E7FD306DD6E00DD6601DD7E02D3DA\x0D\x0A:2048C00006F1E5DDE1E1DDE9E3F57CD306F1E33333C9DD21214018C4DD21514018BE3E2E5B\x0D\x0A:2048E000181906803E20CD359310F9210000224B84C97EB7C823CD359318F7F5E5CD6393C9\x0D\x0A:20490000214C84347EFE10D44793E1F1C9F5C5D5E5DDE597324C84214B847E3CFE083801E5\x0D\x0A:20492000AF77DDE1E1D1C1F1C9F3F5C5D5E5DDE5B72804FEF238023ED06F2600292929CD45\x0D\x0A:204940001794E5DDE13A4B84CD3F943251843A4C84C62047AFCD3694D3103A5184CD459444\x0D\x0A:20496000CD3694D310CD4F9478CD3694D3100608AF052805DD7E00DD2304CB27FDCB055EB0\x0D\x0A:204980002828EE3EF53A4C84B7281EC61FCD3694D310CDF993F601CD3694D3113A4C84C6A5\x0D\x0A:2049A00020CD3694D310CD0394F1CD3694D31110BF3E01CD3694D310DDE1E1D1C1F1C9CD4D\x0D\x0A:2049C0003694DB11CD3694DB11F53A5184C60890CD4594CD3694D310CD4F94F1C9114D94C0\x0D\x0A:2049E00019115A84CD2594215A84C9EDA0EDA0EDA0EDA0EDA0EDA0EDA0EDA0C9F5DB02E678\x0D\x0A:204A00000228FAF1C9878787C680C9F53E07CD3694D310F1C9F53E0518F405000016090935\x0D\x0A:204A20001212050000111111130D05000011110A0A04050000111115150A0500080C0E0C2D\x0D\x0A:204A4000080005040E1F0E0E00000500000E0E1F0E0405020504040414080500110A040A48\x0D\x0A:204A60001100050000000E0A0E0005000000040E04000500000000040000050000001C08AD\x0D\x0A:204A80000808050C020C020C0000051F18181E1818180507040404140C04050301190101BF\x0D\x0A:204AA0000000050C0204080E0000050000010204081F050C12120C00000005161810100002\x0D\x0A:204AC0000000050E040404040000050106180601001F0502021F041F080805100C030C10CE\x0D\x0A:204AE000001F05000007000000000500000F080E080F050004021F020400050000171515D4\x0D\x0A:204B0000151705040E15040404040504040404150E040500000000000000050404040400D7\x0D\x0A:204B20000404050A0A0A00000000050A0A1F0A1F0A0A05080A0E0202000005181902040868\x0D\x0A:204B40001303050814140815120D050404040000000005020408080804020508040202027D\x0D\x0A:204B60000408050004150E150400050004041F04040005000000000C0408050000001F006F\x0D\x0A:204B800000000500000000000C0C0500010204081000050E11131519110E05040C0404042F\x0D\x0A:204BA000040E050E11010204081F051F02040201110E0502060A121F0202051F101E0101A5\x0D\x0A:204BC000110E050608101E11110E051F010204080808050E11110E11110E050E11110F014A\x0D\x0A:204BE000020C05000C0C000C0C0005000C0C000C040805020408100804020500001F001FC9\x0D\x0A:204C000000000508040201020408050E110102040004050E11151714100F050E11111F115B\x0D\x0A:204C20001111051E11111E11111E050E11101010110E051E11111111111E051F10101E1034\x0D\x0A:204C4000101F051F10101E101010050E11101711110F051111111F111111050E040404046A\x0D\x0A:204C6000040E050702020202120C0511121418141211051010101010101F05111B15151175\x0D\x0A:204C800011110511111915131111050E11111111110E051E11111E101010050E1111111504\x0D\x0A:204CA000120D051E11111E141211050F10100E01011E051F04040404040405111111111143\x0D\x0A:204CC000110E05111111110A0A04051111111515150A0511110A040A1111051111110A042C\x0D\x0A:204CE0000404051F01020408101F050609111F11120C0500100804020100050C0404040492\x0D\x0A:204D0000040C05040A1100000000050000000000001F05040402000000000500000E010F09\x0D\x0A:204D2000110F051010161911111E0500000E1010110E0501010D1311110F0500000E111FD2\x0D\x0A:204D4000100E050609081C08080805000F11110F010E05101016191111110504000C0404ED\x0D\x0A:204D6000040E050200060202120C050808090A0C0A09050C04040404040E0500001A15152F\x0D\x0A:204D8000111105000016191111110500000E1111110E0500001E111E10100500000D130F90\x0D\x0A:204DA000010105000016191010100500000E100E011E0508081C08080906050000111111B5\x0D\x0A:204DC000130D0500001111110A04050000111115150A050000110A040A1105000011110F9D\x0D\x0A:204DE000010E0500001F0204081F05030404080404030504040404040404051804040204E4\x0D\x0A:204E000004180500081502000000051F1F111F111F1F0500000E0A0A0A0E050000040C0438\x0D\x0A:204E200004040500000C0204080E0500000C0204020C050000080A0E02020500000E080CC8\x0D\x0A:204E4000020C05000006080E0A0E0500000E020408080500000E0A0E0A0E0500000E0A0E74\x0D\x0A:204E6000020C0502040E11111F110508040E11111F1105040A000E111F11050A000E1111A7\x0D\x0A:204E80001F110502040E010F110F0508040E010F110F05040A0E010F110F050A000E010FCC\x0D\x0A:204EA000110F0502041F101E101F0508041F101E101F05040A1F101E101F050A001F101ED3\x0D\x0A:204EC000101F0502040E111F100E0508040E111F100E05040A0E111F100E050A000E111F13\x0D\x0A:204EE000100E0502040E0404040E0508040E0404040E05040A0E0404040E050A000E0404C8\x0D\x0A:204F0000040E050204000C04040E050804000C04040E05040A000C04040E050A00000C04CB\x0D\x0A:204F2000040E0502040E1111110E0508040E1111110E05040A0E1111110E050A000E111104\x0D\x0A:204F4000110E050204000E11110E050804000E11110E05040A000E11110E050A00000E111B\x0D\x0A:204F6000110E050204111111110E050804111111110E05040A001111110E050A00111111BC\x0D\x0A:204F8000110E050204111111130D050804111111130D05040A001111130D050A0011111199\x0D\x0A:204FA000130D050E1110110E041C0500000E10110E1C05050A111915131105050A00161946\x0D\x0A:204FC00011110501020400000000051008040000000005000A00000000000504000408104E\x0D\x0A:204FE000110E05040400040404040500000D1212120D050609090E090916050000091502A8\x0D\x0A:20500000020205000000040A111F05060804020F110E0500000E101E100E05060404040488\x0D\x0A:20502000040605000804020609110500001212121D100500001F0A0A0A1305000609090E4B\x0D\x0A:205040000810051F08040204081F0500000F1212120C0500000F140405020504040E150E14\x0D\x0A:205060000404050E1111110A0A1B051F00110A040A11051F0011110F010E050502050000E0\x0D\x0A:2050800000000500000000000015050002060E0602000500001C1C1C000005020202040863\x0D\x0A:2050A0000808050000000E000000050E020E080E0000050E0A0E00000000050C0204020C44\x0D\x0A:2050C000000000000000000000000508001808080A0405040A1E111E10100510090A040AD7\x0D\x0A:2050E0001201051F11141C1410100500000E111E100C05000004040404070511191D1F1708\x0D\x0A:20510000131105140A0505050A140500081C1E1C0800051F1F1F1F1F1F1F051F1B110A1B5D\x0D\x0A:205120001B1B051F1B151115151F051F1B1D1915191F050000000000001F05040E15040471\x0D\x0A:20514000001F05040A0E0A0A001F050402060A06001F050000080402010005181C0E070337\x0D\x0A:205160000100051F0F070301000005000010181C1E1F050002051D0502000500040A0A0A13\x0D\x0A:205180000400050010000400010005040E1F0E0E0E0005000E0E0E1F0E0405150A150A15D9\x0D\x0A:2051A0000A15FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEE\x0D\x0A",1,7084,ho); memcpy(lbuf,":20400000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC0\x0D\x0A",LSIZE); for(int i=0x51C;i<0x800;i+=2) { sprintf(tmp,"%X",i); memcpy(lbuf+3,tmp,3); fixlcrc(lbuf,LSIZE); fwrite(lbuf,1,LSIZE,ho); } fwrite(":020000020014E8\x0D\x0A",1,HSIZE,ho); memcpy(lbuf,":204000009090909090909090909090909090909090909090909090909090909090909090A0\x0D\x0A",LSIZE); for(int i=0x400;i<0x800;i+=2) { sprintf(tmp,"%X",i); memcpy(lbuf+3,tmp,3); fixlcrc(lbuf,LSIZE); fwrite(lbuf,1,LSIZE,ho); } fwrite(ibuf+OFFSET_HEADER2,1,ISIZE-OFFSET_HEADER2,ho); fclose(ho); return 0; }