/*************************************************************************** * Copyright (C) 2009-2022 by SEMIKO * * mail@semico.ru * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifdef HAVE_CONFIG_H #include #endif #include #include #include /* Коды выхода BSD from @(#)sysexits.h 8.1 (Berkeley) 6/2/93 */ /* Copyright (c) 1987, 1993 */ /* The Regents of the University of California. All rights reserved. */ #define EX_USAGE 64 /* command line usage error */ #define EX_DATAERR 65 /* data format error */ #define EX_NOINPUT 66 /* cannot open input */ #define EX_NOUSER 67 /* addressee unknown */ #define EX_NOHOST 68 /* host name unknown */ #define EX_UNAVAILABLE 69 /* service unavailable */ #define EX_SOFTWARE 70 /* internal software error */ #define EX_OSERR 71 /* system error (e.g., can't fork) */ #define EX_OSFILE 72 /* critical OS file missing */ #define EX_CANTCREAT 73 /* can't create (user) output file */ #define EX_IOERR 74 /* input/output error */ #define EX_TEMPFAIL 75 /* temp failure; user is invited to retry */ #define EX_PROTOCOL 76 /* remote error in protocol */ #define EX_NOPERM 77 /* permission denied */ #define EX_CONFIG 78 /* configuration error */ /* end sysexits.h */ char version[]="Version 0.13"; /* 0.11 от 02.01.10 - добавлен параметр ключа -b и возможность формирования файлов 256x128 (-b2) и 264x136 (-b3) - корректное задание имени формируемого BMP файла в параметрах строки 0.12 от 12.10.11 - исправлена ошибка в позиции вывода изображения для -b2 и -b3 - добавлен параметр -b4 - файл 264x136 с двойной рамкой - цвет для ключа -c по умолчанию изменен с #80FF00 на #70D000 0.13 от 25.08.22 - исправлена ошибка в заголовке файла 264x136 */ int dos=2; /* 0-GNU/Linux 1-DOS 2-Win32 */ char fname[4][256]; /* 0-MKI без расширения 1-MKI исходный 2-BMP */ int fname_vsego; /* всего файлов в строке аргументов */ int kluch_b=0; /* ключ -b - генерировать файл размера 132x68 (-b1) 256x128 (-b2) и 264x136 (-b3)*/ int kluch_c=0; /* ключ -сRRGGBB - цвет фона по умолчанию */ int cr=255,cg=255,cb=255; /* цвет фона - по умолчанию белый */ FILE *fp1,*fp2; /* потоки 1-MKI 2-BMP */ char mes0[8]; /* ВК ПС для DOS или ВК для Linux */ char pict[160][72]; /* массив точек */ int mkifile[1030]; /* считанный файл MKI */ int bmpfile[6144]; /* формируемый BMP (6144 - с v0.11) */ /* функции */ int mkiload(void); int mki2pict(void); int pict2bmp(void); int mki2bmp(void); int hex2int(char); /*-----*/ int mkiload(void) { /* считывает MKI-файл в mkifile[] */ int i,j; int re=EOF; for (i=0; i<1030; i++) mkifile[i]=0; i=fseek(fp1,0,0); /* от начала файла - SEEK_SET==0 */ if (i!=0) goto end; for (i=0; i<1028; i++) /* заголовок MKI файла для МК-152/161 */ { j=fgetc(fp1); if (j==EOF) goto end; if (j<0) j+=256; mkifile[i]=j%256; } if ((mkifile[2]!=128)||(mkifile[3]!=64)) {re=1; goto end;} /* ошибка формата файла */ re=0; end: return(re); } int mki2pict(void) { /* разбор mkifile[] и перемещение в pict[][] с учётом размера BMP */ int i,j,k; int x,y; int dx,dy; int re=0; if ((kluch_b<0)||(kluch_b>4)) kluch_b=0; /* v0.12 */ if ((kluch_b==0)||(kluch_b==2)) dx=dy=0; /* смещение изображения для 128x64, 256x128 */ if ((kluch_b==1)||(kluch_b==3)||(kluch_b==4)) dx=dy=2; /* смещение изображения для 132x68, 264x136 */ for (x=0; x<160; x++) {for (y=0; y<68; y++) pict[x][y]=0;} /* очистить pict[][] */ for (j=0; j<8; j++) { for (i=0; i<128; i++) { k=mkifile[128*j+i+4]; if ((k & 1)==1) pict[i+dx][8*j+dy]=1; if ((k & 2)==2) pict[i+dx][8*j+dy+1]=1; if ((k & 4)==4) pict[i+dx][8*j+dy+2]=1; if ((k & 8)==8) pict[i+dx][8*j+dy+3]=1; if ((k & 16)==16) pict[i+dx][8*j+dy+4]=1; if ((k & 32)==32) pict[i+dx][8*j+dy+5]=1; if ((k & 64)==64) pict[i+dx][8*j+dy+6]=1; if ((k & 128)==128) pict[i+dx][8*j+dy+7]=1; } } end: return(re); } int pict2bmp(void) { int i,k,x,y; int k1,k2; /* v0.11 */ int xmax,ymax; int re=0; for (i=0; i<62; i++) bmpfile[i]=0; /* очистить область заголовка */ for (i=62; i<6144; i++) bmpfile[i]=0xFF; /* очистить область изображения v0.11 */ if ((kluch_b<0)||(kluch_b>4)) kluch_b=0; /* v0.12 */ /* сформировать заголовок монохромного BMP */ bmpfile[0]=0x42; bmpfile[1]=0x4D; bmpfile[10]=0x3E; bmpfile[14]=0x28; bmpfile[26]=0x01; bmpfile[28]=0x01; bmpfile[38]=0x13; bmpfile[39]=0x0B; bmpfile[42]=0x13; bmpfile[43]=0x0B; bmpfile[46]=0x02; bmpfile[50]=0x02; if (kluch_b==0) { /* 128x64 */ bmpfile[2]=0x3E; bmpfile[3]=0x04; bmpfile[18]=0x80; bmpfile[22]=0x40; bmpfile[35]=0x04; goto p1; } if (kluch_b==1) { /* 132x68 */ bmpfile[2]=0x8E; bmpfile[3]=0x05; bmpfile[18]=0x84; bmpfile[22]=0x44; bmpfile[34]=0x50; bmpfile[35]=0x05; goto p1; } if (kluch_b==2) { /* 256x128 v0.11 */ bmpfile[2]=0x3E; bmpfile[3]=0x10; bmpfile[19]=0x01; bmpfile[22]=0x80; bmpfile[35]=0x10; goto p1; } if ((kluch_b==3)||(kluch_b==4)) { /* 264x136 v0.11 */ /* и -b4 v0.12 */ /* исправлено значение [2] и [3] v0.13*/ bmpfile[2]=0x5E; bmpfile[3]=0x13; bmpfile[18]=0x08; bmpfile[19]=0x01; bmpfile[22]=0x88; bmpfile[34]=0x20; bmpfile[35]=0x13; } p1: /* создать палитру */ bmpfile[58]=cb%256; bmpfile[59]=cg%256; bmpfile[60]=cr%256; /* перенести данные из pict[][] */ if ((kluch_b==0)||(kluch_b==1)) { if (kluch_b==0) {ymax=64; xmax=16; i=16;} else {ymax=68; xmax=17; i=20;} for (y=0; y2) j=2; strncpy(fname[j+1],argv[i],255); if (j<2) fname_vsego++; } else { c=argv[i][1]; k=1; /* есть ключ */ if (c=='-') c=argv[i][2]; /* для --help и т.п.*/ if ((c=='h')||(c=='H')||(c=='?')) { /* help */ printf("mki2bmp - converter MKI to BMP file %s",mes0); printf("mki2bmp MKIfile [key] [BMPfile] %s",mes0); /* v0.11 */ printf("\t-h,-H,-?\tthis help; %s",mes0); printf("\t-v,-V\tversion; %s",mes0); printf("\t-w,-W\twarranty and copyright; %s",mes0); printf("\t-b,-B\tBMP size: %s",mes0); /* v0.11 */ printf("\t\t\t-b0: 128x64 (default), %s",mes0); /* v0.11 */ printf("\t\t\t-b,-b1: 132x68, %s",mes0); /* v0.11 */ printf("\t\t\t-b2: 256x128, %s",mes0); /* v0.11 */ printf("\t\t\t-b3: 264x136, %s",mes0); /* v0.11 */ printf("\t\t\t-b4: 264x136, border; %s",mes0); /* v0.12 */ printf("\t-c,-C\tcolor (-cRRGGBB - hex)"); goto end; } if ((c=='v')||(c=='V')) { /* version */ printf(version); if (dos==0) printf(" (GNU/Linux)"); if (dos==1) printf(" (DOS)"); if (dos==2) printf(" (Win32)"); goto end; } if ((c=='w')||(c=='W')) { /* copyleft & warranty */ printf("Copyright (C) 2009-2010 by NPP SEMIKO (Russia, Novosibirsk) %s%s",mes0,mes0); printf("This program is free software; you can redistribute it and/or modify %s",mes0); printf("it under the terms of the GNU General Public License as published by %s",mes0); printf("the Free Software Foundation; either version 2 of the License, or %s",mes0); printf("(at your option) any later version. %s%s",mes0,mes0); printf("This program is distributed in the hope that it will be useful, %s",mes0); printf("but WITHOUT ANY WARRANTY; without even the implied warranty of %s",mes0); printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the %s",mes0); printf("GNU General Public License for more details. %s%s",mes0,mes0); printf("You should have received a copy of the GNU General Public License %s",mes0); printf("along with this program; if not, write to the Free Software %s",mes0); printf("Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA"); goto end; } if ((c=='b')||(c=='B')) { /* kluch_b */ switch (argv[i][2]) { case '0': kluch_b=0; break; case '1': kluch_b=1; break; case '2': kluch_b=2; break; case '3': kluch_b=3; break; case '4': kluch_b=4; break; //v0.12 default: kluch_b=1; } k=0; } if ((c=='c')||(c=='C')) { /* kluch_c */ /* если ключ есть - цвет по умолчанию жёлто-зелёный */ cr=0x70; // v0.12 (v0.11=0.80) cg=0xD0; // v0.12 (v0.11=0xFF) cb=0; if (argv[i][2]!=0) { cr=(16*hex2int(argv[i][2]) + hex2int(argv[i][3]))%256; cg=(16*hex2int(argv[i][4]) + hex2int(argv[i][5]))%256; cb=(16*hex2int(argv[i][6]) + hex2int(argv[i][7]))%256; } kluch_c=1; k=0; } else {if (k!=0) {printf("mki2bmp -h for help"); goto end;}} /* ключ не опознан */ } } nach: if (fname_vsego<=0) {re=EX_USAGE; goto end;} /* нет файла */ fp1=fopen(fname[1],"rb"); /* открыть MKI как двоичный для чтения */ if (fp1==NULL) {re=EX_NOINPUT; printf("MKI not found"); printf(mes0); goto end;} /* файл MKI не открыт */ k=strlen(fname[1]); for (i=k; i>0; i--) { if ( (fname[1][i]=='.')&&(i0)&&(i