?login_element?

Subversion Repositories NedoOS

Rev

Rev 1403 | Rev 1647 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. //#include <mem.h>
  4. #include <string.h>
  5.  
  6. #define _STRMAX 79
  7.  
  8. #define BYTE unsigned char
  9. #define UINT unsigned int
  10. #define MAXDEFB 8
  11.  
  12. #define MASKCOLOR 0x00
  13.  
  14. BYTE filebuf[65536];
  15. char labelbuf[_STRMAX+1];
  16. char formatlabelbuf[_STRMAX+1];
  17. char commentlabelbuf[_STRMAX+1];
  18. BYTE sizeword[4];
  19. BYTE pic[1024][1024];
  20. BYTE pixrow[1024/8+1][1024+1024];
  21. #define PIXROWSHIFT 1024
  22. BYTE maskrow[1024/8+1][1024];
  23. //BYTE pixrowshift[1024/8][1024]; //>>4
  24. BYTE attrrow[1024/8+1];
  25. BYTE pal[64];
  26.  
  27. #define CONVORDERSZ 1024
  28.  
  29. int convorderx[CONVORDERSZ]; //фы  ърцфюую эюьхЁр Єрщыр ъююЁфшэрЄ√
  30. int convordery[CONVORDERSZ]; //фы  ърцфюую эюьхЁр Єрщыр ъююЁфшэрЄ√
  31.  
  32. int sprcount;
  33. int vertsprcount;
  34.  
  35. BYTE numok;
  36.  
  37. BYTE ink;
  38. BYTE paper;
  39. BYTE curink;
  40. BYTE curpaper;
  41. BYTE defaultcolor;
  42.  
  43. char sprformat;
  44.  
  45. int hgt;
  46. int wid;
  47. int bpp;
  48.  
  49. void skiplf(FILE * fin)
  50. { //тючьюцэю, 0x0d єцх яЁюўшЄрэ, ЄхяхЁ№ яЁюяєёърхь 0x0a
  51. char c;
  52.   do{
  53.     if (!fread(&c,1,1,fin)) break;
  54.   }while (c!=0x0a);
  55. }
  56.  
  57. void readcomment(FILE * fin, char * s)
  58. { //тючьюцэю, 0x0d єцх яЁюўшЄрэ, ЄхяхЁ№ яЁюяєёърхь 0x0a
  59. char c;
  60. unsigned int i;
  61.   i = 0;
  62.   do{
  63.     if (!fread(&c,1,1,fin)) break;
  64.     if (i==_STRMAX) break;
  65.     s[i] = c;
  66.     i++;
  67.   }while (c!=0x0a);
  68.   s[i] = '\0';
  69. }
  70.  
  71. int readnum(FILE * fin)
  72. {
  73. char c;
  74. int num;
  75. int sign=1;
  76.   num = 0;
  77.   do{
  78.     if (!fread(&c,1,1,fin)) break;
  79.     if (c==' ') goto skip;
  80.     //if (c == 0x0d) goto skip;
  81.     //if (c == 0x0a) break;
  82.     if (c=='-') {sign = -1; goto skip;};
  83.     if ((c<'0')||(c>'9')) break; //т Єюь ўшёых 0x0a
  84.     num = num*10 + (int)(c-'0');
  85.     numok = 0xff;
  86. skip:
  87.         ;
  88.   }while(1);
  89.   num = num*sign;
  90. return num;
  91. }
  92.  
  93. unsigned int readlabel(FILE * fin, char * s)
  94. {
  95. char c;
  96. unsigned int i;
  97. int iscomment;
  98.   sprcount = 0;
  99.   vertsprcount = 0;
  100.   do{
  101.     i = 0;
  102.     iscomment = 0;
  103.     do{
  104.       if (!fread(&c,1,1,fin)) break;
  105.       if (c == ';') iscomment = -1;
  106.       if (c=='$') { //фры№°х ўшёыю ёяЁрщЄют тхЁЄшъры№эю
  107.         if (iscomment) continue; //т ъюььхэЄрї ьюцэю $
  108.         while (1) {
  109.           if (!fread(&c,1,1,fin)) return 0;
  110.           if ((c < '0') || (c > '9')) break;
  111.           vertsprcount = vertsprcount*10;
  112.           vertsprcount = vertsprcount + (int)(c-'0');
  113.         };
  114.       };
  115.       if (c=='#') { //фры№°х ўшёыю ёяЁрщЄют
  116.         if (iscomment) continue; //т ъюььхэЄрї ьюцэю #
  117.         while (1) {
  118.           if (!fread(&c,1,1,fin)) return 0;
  119.           if ((c < '0') || (c > '9')) break;
  120.           sprcount = sprcount*10;
  121.           sprcount = sprcount + (int)(c-'0');
  122.         };
  123.       };
  124.       if ((c=='=')||(c==',')) {
  125.         if (iscomment) continue; //т ъюььхэЄрї ьюцэю =
  126.         break;
  127.       };
  128.       if (c == 0x0d) continue;
  129.       if (c == 0x0a) {
  130.         if (iscomment) break; //ъюььхэЄ√ ъюэўр■Єё  яю ъюэЎє ёЄЁюъш
  131.         continue;
  132.       };
  133.       if (i==_STRMAX) break;
  134.       s[i] = c;
  135.       i++;
  136.     }while(1);
  137.     s[i] = '\0';
  138.   }while(iscomment);
  139. return i;
  140. }
  141.  
  142. int read4b(FILE * fin)
  143. {
  144.   fread(sizeword, 4, 1, fin);
  145. return sizeword[0] + (sizeword[1]<<8) + (sizeword[2]<<16) + (sizeword[3]<<24);
  146. }
  147.  
  148. BYTE colstat[256];
  149.  
  150. char numbuf[256];
  151.  
  152. UINT maxsprcount;
  153. UINT cursprcount;
  154. UINT maxvertsprcount;
  155. UINT curvertsprcount;
  156.  
  157. void putlabel(char * labelbuf, FILE * fout)
  158. {
  159. UINT num;
  160. UINT i;
  161.         fputs(labelbuf, fout);
  162.         if (maxvertsprcount != 0) {
  163.           fputc('_', fout);
  164.           fputc('_', fout);
  165.           num = curvertsprcount;
  166.  
  167.           i = 0;
  168.           do {
  169.             numbuf[i] = (char)((UINT)'0' + (num - (num/10)*10));
  170.             num = num/10;
  171.             i++;
  172.           } while (num != 0);
  173.  
  174.           do {
  175.             i--;
  176.             fputc(numbuf[i], fout);
  177.           } while (i != 0);
  178.         };
  179.         if (maxsprcount != 0) {
  180.           fputc('_', fout);
  181.           num = cursprcount;
  182.  
  183.           i = 0;
  184.           do {
  185.             numbuf[i] = (char)((UINT)'0' + (num - (num/10)*10));
  186.             num = num/10;
  187.             i++;
  188.           } while (num != 0);
  189.  
  190.           do {
  191.             i--;
  192.             fputc(numbuf[i], fout);
  193.           } while (i != 0);
  194.         };
  195. return;
  196. }
  197.  
  198. void findinkpaper(int x, int y) //ьрёър 0x00 эх ёўшЄрхЄё  ЎтхЄюь
  199. {
  200. //BYTE b;
  201. int i;
  202. int j;
  203. BYTE col1;
  204. BYTE col1stat;
  205. BYTE col2;
  206. BYTE col2stat;
  207. BYTE col3;
  208. BYTE col3stat;
  209. BYTE col4;
  210. BYTE col4stat; //эр ёыєўрщ Єръющ ёЄрЄшёЄшъш: MASKCOLOR, RED, red, anothercolor
  211.   i = 0; do {colstat[i] = 0x00; i++;}while (i!=256);
  212.  
  213.   //col1 = pic[x][y];
  214.   j = y;
  215.   while (j < (y+8)) {
  216. //    b = 0x00;
  217.     i = x;
  218.     while (i < (x+8)) {
  219.       colstat[pic[i][j]]++;
  220.       //b = pic[i][j];
  221.       //if (b!=col1) col2 = b;
  222.       i++;
  223.     };
  224.     j++;
  225.   };
  226.  
  227. //ьрёър MASKCOLOR эх ёўшЄрхЄё  ЎтхЄюь
  228.   col1 = MASKCOLOR; col1stat = 0; //fix 27.12.2018
  229.   col2 = MASKCOLOR; col2stat = 0; //fix 27.12.2018
  230.   col3 = MASKCOLOR; col3stat = 0; //fix 27.12.2018
  231.   col4 = MASKCOLOR; col3stat = 0; //fix 27.12.2018
  232.   i = 0; do { //fix 27.12.2018 (эр ёыєўрщ MASKCOLOR!=0)
  233.     if (colstat[i] > col1stat) {
  234.       col4 = col3;
  235.       col4stat = col3stat;
  236.       col3 = col2;
  237.       col3stat = col2stat;
  238.       col2 = col1;
  239.       col2stat = col1stat;
  240.       col1 = (BYTE)i;
  241.       col1stat = colstat[i];
  242.     }else if (colstat[i] > col2stat) {
  243.       col4 = col3;
  244.       col4stat = col3stat;
  245.       col3 = col2;
  246.       col3stat = col2stat;
  247.       col2 = (BYTE)i;
  248.       col2stat = colstat[i];
  249.     }else if (colstat[i] > col3stat) {
  250.       col4 = col3;
  251.       col4stat = col3stat;
  252.       col3 = (BYTE)i;
  253.       col3stat = colstat[i];
  254.     }else if (colstat[i] > col4stat) {
  255.       col4 = (BYTE)i;
  256.       col4stat = colstat[i];
  257.     };
  258.     i++;
  259.   }while (i!=16); //fix 27.12.2018
  260.  
  261. //MASKCOLOR эхы№ч  ёрь√ь ўрёЄ√ь, ёюЁЄшЁєхь хую т ъюэхЎ
  262.   if (col1==MASKCOLOR) {
  263.     col1 = col2;
  264.     col2 = MASKCOLOR;
  265.   };
  266.   if (col2==MASKCOLOR) {
  267.     col2 = col3;
  268.     col3 = MASKCOLOR;
  269.   };
  270.   if (col3==MASKCOLOR) {
  271.     col3 = col4;
  272.     col4 = MASKCOLOR;
  273.   };
  274.  
  275. //col1 ьюцхЄ с√Є№ MASKCOLOR Єюы№ъю фы  чэръюьхёЄр, яюыэюёЄ№■ чрышЄюую MASKCOLOR
  276. //ьрёър 0x00 эх ёўшЄрхЄё  ЎтхЄюь, яю¤Єюьє 0x08 яхЁхтюфшЄё  т 0x00 ё фхЇюыЄэющ  ЁъюёЄ№■ (ўЄюс√ эх тыш Є№ эр bright)
  277.   //if ((col1&0x07)==0x00) col1 = (BYTE)(defaultcolor&0x08); //fix 27.12.2018
  278.   //if ((col2&0x07)==0x00) col2 = (BYTE)(defaultcolor&0x08); //fix 27.12.2018
  279. /**  if (col2 == MASKCOLOR) {
  280.     if (col1 == MASKCOLOR) {
  281.       col2 = (BYTE)((col1&0x08) | (defaultcolor&0x07));
  282.     }else {
  283.       col2 = (BYTE)((col1&0x08) | (defaultcolor&0x07));
  284.     };
  285.   };*/ //fix 27.12.2018
  286.   if (((col2&0x07)==(col1&0x07)) /**&& (col2!=0x00)*/) col2 = col3; //same colour with another bright
  287.   ink = col1;
  288.   paper = col2; //Ёхцх
  289.   //paper Ёхцх ш ьюцхЄ с√Є№ MASKCOLOR (эхЄ тЄюЁюую ЎтхЄр, эрфю сЁрЄ№ фхЇюыЄэ√щ)
  290.   //ink ьюцхЄ с√Є№ MASKCOLOR Єюы№ъю фы  чэръюьхёЄр, яюыэюёЄ№■ чрышЄюую MASKCOLOR
  291. }
  292.  
  293. void setcurinkpaper(BYTE* pcurink, BYTE* pcurpaper)
  294. //paper Ёхцх ш ьюцхЄ с√Є№ MASKCOLOR (эхЄ тЄюЁюую ЎтхЄр, эрфю сЁрЄ№ фхЇюыЄэ√щ)
  295. //ink ьюцхЄ с√Є№ MASKCOLOR Єюы№ъю фы  чэръюьхёЄр, яюыэюёЄ№■ чрышЄюую MASKCOLOR
  296. //*pcurink, *curpaper шчэрўры№эю ёюфхЁцрЄ рЄЁшсєЄ√ яЁхф√фє∙хую чэръюьхёЄр
  297. //тючтЁр∙рхЄ *pcurink, *curpaper, яЁшў╕ь тьхёЄю 0x08 ёЄртшЄ 0x00 (ўЄюс√ эх тыш ыю эр  ЁъюёЄ№)
  298. {
  299. BYTE t;
  300.   if ((sprformat == 's')||(sprformat == 'w')) {
  301.     paper = 0x08;
  302.     ink = 0x0f;
  303.   }; //фы  ёяЁрщЄют Їюэ ў╕Ёэ√щ (р ьрёър 0x00)
  304.  
  305. //27.02.2019:
  306. //Їюэ фы  чрышЄ√ї чэръюьхёЄ эрўшэр  ё чхы╕эюую ЄхяхЁ№ ў╕Ёэ√щ[шыш эрфю яЁхф√фє∙шщ?]
  307. //Їюэ фы  ў╕Ёэ√ї чэръюьхёЄ схЁ╕Є  ЁъюёЄ№ юЄ defaultcolor, р фы  чрышЄ√ї чэръюьхёЄ ьхэхх чхы╕эюую эх схЁ╕Є
  308. #define MINCOLORWITHBLACKBG 0x04
  309. //fix 27.12.2018:
  310.   if (((ink&0x07)==(*pcurink&0x07)) && (ink!=MASKCOLOR)) { //ink ёююЄтхЄёЄтєхЄ яЁхф√фє∙хьє
  311.     *pcurink = ink;
  312.     if (paper==MASKCOLOR) {
  313.       *pcurpaper = ((ink&0x07)<MINCOLORWITHBLACKBG) ? ((ink&0x07)?((defaultcolor&0x07)|(ink&0x08)):defaultcolor) : 0x00;
  314.     }else {
  315.       *pcurpaper = paper;
  316.     };
  317.   }else if (((paper&0x07)==(*pcurpaper&0x07)) && (paper!=MASKCOLOR)) { //paper ёююЄтхЄёЄтєхЄ яЁхф√фє∙хьє
  318.     *pcurpaper = paper;
  319.     if (ink==MASKCOLOR) {
  320.       *pcurink = ((paper&0x07)<MINCOLORWITHBLACKBG) ? ((paper&0x07)?((defaultcolor&0x07)|(paper&0x08)):defaultcolor) : 0x00;
  321.     }else {
  322.       *pcurink = ink;
  323.     };
  324.   }else if (((paper&0x07)==(*pcurink&0x07)) && (paper!=MASKCOLOR)) { //paper ёююЄтхЄёЄтєхЄ яЁхф√фє∙хьє ink
  325.     *pcurink = paper;
  326.     if (ink==MASKCOLOR) {
  327.       *pcurpaper = ((paper&0x07)<MINCOLORWITHBLACKBG) ? ((paper&0x07)?((defaultcolor&0x07)|(paper&0x08)):defaultcolor) : 0x00;
  328.     }else {
  329.       *pcurpaper = ink;
  330.     };
  331.   }else if (((ink&0x07)==(*pcurpaper&0x07)) && (ink!=MASKCOLOR)) { //ink ёююЄтхЄёЄтєхЄ яЁхф√фє∙хьє paper
  332.     *pcurpaper = ink;
  333.     if (paper==MASKCOLOR) {
  334.       *pcurink = ((ink&0x07)<MINCOLORWITHBLACKBG) ? ((ink&0x07)?((defaultcolor&0x07)|(ink&0x08)):defaultcolor) : 0x00;
  335.     }else {
  336.       *pcurink = paper;
  337.     };
  338.   }else if ((ink==MASKCOLOR)&&(paper==MASKCOLOR)) { //юср ЎтхЄр MASKCOLOR
  339.     ink = defaultcolor;
  340.     paper = 0x08;
  341.   }else { //юср ЎтхЄр эх ёююЄтхЄёЄтє■Є яЁхф√фє∙хьє чэръюьхёЄє, эю эх юср MASKCOLOR
  342.     if (ink == MASKCOLOR) ink = ((paper&0x07)<MINCOLORWITHBLACKBG) ? ((paper&0x07)?((defaultcolor&0x07)|(paper&0x08)):defaultcolor) : 0x00;
  343.     if (paper == MASKCOLOR) paper = ((ink&0x07)<MINCOLORWITHBLACKBG) ? ((ink&0x07)?((defaultcolor&0x07)|(ink&0x08)):defaultcolor) : 0x00;
  344.     if (ink > paper) {
  345.       *pcurink = ink;
  346.       *pcurpaper = paper;
  347.     }else {
  348.       *pcurink = paper;
  349.       *pcurpaper = ink;
  350.     };
  351.   };
  352.  
  353.     //*pcurink = ink;
  354.     //*pcurpaper = paper;
  355.  
  356.   if (*pcurpaper==0x08) *pcurpaper = 0x00; //ўЄюс√ эх тыш ыю эр  ЁъюёЄ№ //fix 27.12.2018
  357.   if (*pcurink==0x08) *pcurink = 0x00; //ўЄюс√ эх тыш ыю эр  ЁъюёЄ№ //fix 27.12.2018
  358.   //эр ў╕Ёэюь/ёшэхь Їюэх ink фюыцхэ с√Є№  Ёўх paper'р (юЄфхы№э√щ ёыєўрщ, Є.ъ. юёЄры№э√х, фрцх яєёЄ√х, чэръюьхёЄр ьюуєЄ єўрёЄтютрЄ№ т юЄЁшёютъх ёъЁюыышЁєхь√ї Їюэют ё эхяЁхЁ√тэ√ьш Ўхяюўърьш ink-paper)
  359.   //Єю хёЄ№ эхы№ч  ink=0, р 1 Єюы№ъю т ёыєўрх paper=0
  360.   if (((*pcurink&0x07)<=0x01) && ((*pcurpaper&0x07)>(*pcurink&0x07))) { //ў╕Ёэюх/ёшэхх яєёЄюх чэръюьхёЄю (юЄфхы№э√щ ёыєўрщ, Є.ъ. юёЄры№э√х яєёЄ√х ьюуєЄ єўрёЄтютрЄ№ т юЄЁшёютъх ёъЁюыышЁєхь√ї Їюэют ё эхяЁхЁ√тэ√ьш Ўхяюўърьш ink-paper)
  361.     t = *pcurpaper;
  362.     *pcurpaper = *pcurink;
  363.     *pcurink = t;
  364.   };
  365. }
  366.  
  367. void emitdb(BYTE b, FILE * fout)
  368. {
  369.   fputs("\tdb ", fout);
  370.   fprintf(fout, "0x%x%x", b>>4, b&0x0f);
  371.   fputs("\n", fout);
  372. }
  373.  
  374. void emitdw(UINT u, FILE * fout)
  375. {
  376.   fputs("\tdw ", fout);
  377.   fprintf(fout, "0x%x%x%x%x", (u>>12)&0x0f, (u>>8)&0x0f, (u>>4)&0x0f, u&0x0f);
  378.   fputs("\n", fout);
  379. }
  380.  
  381. void emitnops(BYTE count, FILE * fout)
  382. {
  383.   fputs("\tds ", fout);
  384.   fprintf(fout, "0x%x%x", count>>4, count&0x0f);
  385.   fputs("\n", fout);
  386. }
  387.  
  388. void emitspr(int xchr, int y, int sprwid8, int sprhgt, FILE * fout)
  389. {
  390. BYTE b;
  391. int i;
  392. int j;
  393.   j = y;
  394.   while (1) {
  395.     fputs("\tdb ", fout);
  396.     i = xchr;
  397.     while (1) {
  398.       b = maskrow[i][j];
  399.       fprintf(fout, "0x%x%x", b>>4, b&0x0f);
  400.       fputs(",", fout);
  401.       b = b^pixrow[i][j];
  402.       fprintf(fout, "0x%x%x", b>>4, b&0x0f);
  403.       i++;
  404.       if (i >= (xchr+sprwid8)) break;
  405.       fputs(",", fout);
  406.     };
  407.     fputs("\n", fout);
  408.     j++;
  409.     if (j >= (y+sprhgt)) break;
  410.   };
  411. }
  412.  
  413. void emitsprw(int xchr, int y, int sprwid8, int sprhgt, FILE * fout)
  414. { //antipixelsw, antimaskw
  415. BYTE b;
  416. int i;
  417. int j;
  418.   j = y;
  419.   while (1) {
  420.     fputs("\tdb ", fout);
  421.     i = xchr+sprwid8;
  422.     while (1) {
  423.       i--;
  424.       b = ~maskrow[i][j];
  425.       fprintf(fout, "0x%x%x", b>>4, b&0x0f);
  426.       if (i == xchr) break;
  427.       fputs(",", fout);
  428.     };
  429.     fputs("\n", fout);
  430.     fputs("\tdb ", fout);
  431.     i = xchr+sprwid8;
  432.     while (1) {
  433.       i--;
  434.       b = ~maskrow[i][j];
  435.       b ^= pixrow[i][j];
  436.       fprintf(fout, "0x%x%x", b>>4, b&0x0f);
  437.       if (i == xchr) break;
  438.       fputs(",", fout);
  439.     };
  440.     fputs("\n", fout);
  441.     j++;
  442.     if (j >= (y+sprhgt)) break;
  443.   };
  444. }
  445.  
  446. void emitsprwnomask(int xchr, int y, int sprwid8, int sprhgt, FILE * fout)
  447. { //antipixelsw
  448. BYTE b;
  449. int i;
  450. int j;
  451.   j = y;
  452.   while (1) {
  453.     fputs("\tdb ", fout);
  454.     i = xchr;
  455.     while (1) {
  456.       b = ~maskrow[i][j];
  457.       fprintf(fout, "0x%x%x", b>>4, b&0x0f);
  458.       i++;
  459.       if (i == xchr+sprwid8) break;
  460.       fputs(",", fout);
  461.     };
  462.     fputs("\n", fout);
  463.     j++;
  464.     if (j >= (y+sprhgt)) break;
  465.   };
  466. }
  467.  
  468. void emitsprwnomaskback(int xchr, int y, int sprwid8, int sprhgt, FILE * fout)
  469. { //antipixelsw
  470. BYTE b;
  471. int i;
  472. int j;
  473.   j = y;
  474.   while (1) {
  475.     fputs("\tdb ", fout);
  476.     i = xchr+sprwid8;
  477.     while (1) {
  478.       i--;
  479.       b = ~maskrow[i][j];
  480.       fprintf(fout, "0x%x%x", b>>4, b&0x0f);
  481.       if (i == xchr) break;
  482.       fputs(",", fout);
  483.     };
  484.     fputs("\n", fout);
  485.     j++;
  486.     if (j >= (y+sprhgt)) break;
  487.   };
  488. }
  489.  
  490. void emitimgW(int xchr, int y, int sprwid8, int sprhgt, FILE * fout)
  491. { //by columns
  492. BYTE b;
  493. int i;
  494. int j;
  495.   i = xchr;
  496.   while (1) {
  497.     fputs("\tdb ", fout);
  498.     j = y;
  499.     while (1) {
  500.       b = maskrow[i][j];
  501.                   //fprintf(fout, "0x%x%x ", i>>4, i&0x0f);
  502.                   //fprintf(fout, "0x%x%x ", j>>4, j&0x0f);
  503.       fprintf(fout, "0x%x%x", b>>4, b&0x0f);
  504.       j++;
  505.       if (j >= (y+sprhgt)) break;
  506.       fputs(",", fout);
  507.     };
  508.     fputs("\n", fout);
  509.     i++;
  510.     if (i == (xchr+sprwid8)) break;
  511.   };
  512. }
  513.  
  514. void emitchr_(int xchr, int y, FILE * fout)
  515. {
  516. BYTE b;
  517. int j;
  518.   fputs("\tdb ", fout);
  519.   j = y;
  520.   while (1) {
  521.     b = pixrow[xchr][j];
  522.     fprintf(fout, "0x%x%x", b>>4, b&0x0f);
  523.     j++;
  524.     if (j >= (y+8)) break;
  525.     fputs(",", fout);
  526.   };
  527.   if (sprformat < 'a') { //capital letter format => attr used
  528.     b = attrrow[xchr]; //0x07;
  529.     fputs(",", fout);
  530.     fprintf(fout, "0x%x%x", b>>4, b&0x0f);
  531.   };
  532.   fputs("\n", fout);
  533. }
  534.  
  535. void emitchr(int xchr, int y, FILE * fout)
  536. {
  537.   emitchr_(xchr, y, fout);
  538. }
  539.  
  540. void emitchrshift(int xchr, int y, FILE * fout)
  541. {
  542.   emitchr_(xchr, y+PIXROWSHIFT, fout);
  543. }
  544.  
  545. //ёфтшурхь Ё ф чэръюьхёЄ >>shiftbits, Ёхчєы№ЄрЄ т pixrow[sprx][y+PIXROWSHIFT]
  546. void shiftrow(int sprx, int y, int sprwid, int rowhgt, int pixrowshift, BYTE shiftbits)
  547. {
  548. int j;
  549. int x;
  550. BYTE b;
  551. BYTE b0;
  552. BYTE shiftmask;
  553.   shiftmask = (BYTE)(0xff>>(0x08-shiftbits)); //хёыш shiftbits==0x01, Єю shiftmask==0x01
  554.   j = y;
  555.   while (j < (y+rowhgt)) {
  556.     b = 0x00;
  557.     x = sprx;
  558.     while (x < (sprx+sprwid+8)) {
  559.       b0 = pixrow[x/8][j];
  560.       pixrow[x/8][j+pixrowshift] = (BYTE)((b<<(0x08-shiftbits)) + (b0>>shiftbits));
  561.       b = (BYTE)(b0&shiftmask/**0x0f*/); //хёыш shiftbits==0x01, Єю shiftmask==0x01
  562.       x = x+8;
  563.     };
  564.     j++;
  565.   };
  566. }
  567.  
  568. //data: wid8, hgt8, chrgfx, chrgfx...
  569. void resfile(char * finname, char * fintxtname, char * foutname)
  570. {
  571. FILE* fin;
  572. FILE* fintxt;
  573. FILE* fout;
  574. int i;
  575. int j;
  576. int size;
  577. int y;
  578. int x;
  579. int n;
  580. int tiles;
  581.  
  582. BYTE b;
  583. BYTE bmask;
  584. BYTE b0;
  585.  
  586. int sprx;
  587. int startsprx;
  588. int spry;
  589. int sprwid;
  590. int sprhgt;
  591. int rowhgt; //8 for tiles, sprhgt for sprites
  592.  
  593. UINT color;
  594.  
  595.   fin = fopen(finname, "rb");
  596.   if (fin) {
  597.     fread(filebuf, 10, 1, fin); //skip to 10 (header size)
  598.     size = read4b(fin); //10 (header size)
  599.     fread(filebuf, 4, 1, fin); //skip to 18
  600.     wid = read4b(fin); //18
  601.     hgt = read4b(fin); //22
  602.     fread(filebuf, 2, 1, fin); //skip to 28
  603.     fread(&bpp, 1, 1, fin); //28
  604.     fread(filebuf, 1, 54-29, fin); //skip to pal
  605.     fread(pal, 1, 64, fin); //ярышЄЁр (B, G, R, 0)
  606.     if (size > (54+64)) {fread(filebuf, 1, size-(54+64), fin);}; //skip to pic
  607.     if ((wid>0)&&(wid<=1024)&&(hgt>0)&&(hgt<=1024)&&((wid&7)==0)&&((hgt&7)==0)) {
  608.       y = hgt;
  609.       while (y>0) {
  610.         y--;
  611.         x = 0;
  612.         while (x<wid) {
  613.           fread(&b, 1, 1, fin);
  614.           if (bpp == 8) {
  615.             pic[x][y] = b;
  616.             x++;
  617.           }else {
  618.             pic[x][y] = (BYTE)((b&0xf0)>>4);
  619.             x++;
  620.             pic[x][y] = (BYTE)(b&0x0f);
  621.             x++;
  622.           };
  623.         };
  624.       };
  625.  
  626.       fintxt = fopen(fintxtname, "rb");
  627.       if (fintxt) {
  628.         fout = fopen(foutname, "wb");
  629.         if (fout) {
  630. /**          if (labelname[0]!='\0') {
  631.             fputs(labelname, fout);
  632.             fputs("\n", fout);
  633.           };*/
  634.           while (1) {
  635.             size = readlabel(fintxt, labelbuf); //fread(filebuf, 1, MAXDEFB, fin);
  636.            maxvertsprcount = vertsprcount;
  637.            maxsprcount = sprcount;
  638.             if (size == 0) break;
  639.             readlabel(fintxt, formatlabelbuf); //format
  640.             sprformat = *formatlabelbuf;
  641.             startsprx = readnum(fintxt);
  642.             spry = readnum(fintxt);
  643.             sprwid = readnum(fintxt);
  644.             sprhgt = readnum(fintxt);
  645.             numok = 0x00;
  646.             tiles = readnum(fintxt); //юЄёєЄёЄтєхЄ т x
  647.             defaultcolor = (BYTE)tiles; //фы  тёхї, ъЁюьх L
  648.             *commentlabelbuf = '\0';
  649.             if ((numok != 0x00) && (sprformat != 'L')) readcomment(fintxt, commentlabelbuf);
  650.            curvertsprcount = 0;
  651.            do { //vertsprcount
  652.            cursprcount = 0;
  653.            sprx = startsprx;
  654.            do { //sprcount
  655.             if ((sprformat == 'B')||(sprformat == 'b')) {
  656.               putlabel(labelbuf, fout);
  657.               fputs("\n", fout);
  658.               //emitdb((BYTE)(sprwid>>3), fout);
  659.               //emitdb((BYTE)(sprhgt>>3), fout);
  660.               rowhgt = 8;
  661.             }else if (sprformat == 'T') { //эрсюЁ Єрщыют
  662.               fputs("\tds (-$)&0xff\n", fout);
  663.               putlabel(labelbuf, fout);
  664.               fputs("\n", fout);
  665.               rowhgt = 8;
  666.             }else if (sprformat == 'x') { //ёяЁрщЄ 16c
  667.               fputs("\n", fout);
  668.               putlabel(labelbuf, fout);
  669.               fputs("=$+4\n", fout);
  670.               fputs("\n", fout);
  671.               emitdb((BYTE)(sprwid>>1), fout);
  672.               emitdb((BYTE)(sprhgt), fout);
  673.               rowhgt = sprhgt;
  674.             }else if (sprformat == 'i') { //ърЁЄшэър 16c яю ёЄюысЎрь
  675.               fputs("\n", fout);
  676.               putlabel(labelbuf, fout);
  677.               fputs("\n", fout);
  678.               rowhgt = sprhgt;
  679.             }else if (sprformat == 'L') { //LAND ъръ т ╫┬, фры№°х ёыхфєхЄ ЄрсышЎр - эюьхЁ Єрщыр фы  ърцфющ ъыхЄъш
  680.               fputs("\n", fout);
  681.               putlabel(labelbuf, fout);
  682.               fputs("\n", fout);
  683.               rowhgt = sprhgt;
  684.             }else if (sprformat == 'P') { //DDp palette
  685.               fputs("\n", fout);
  686.               putlabel(labelbuf, fout);
  687.               fputs("\n", fout);
  688.               i = 0;
  689.               while (i < 64) { //DDp palette: %grbG11RB(low),%grbG11RB(high), шэтхЁёэ√х //color = highlow
  690.                 color = 0; //pal = ярышЄЁр (B, G, R, 0)
  691.                 if (pal[i]&0x80) color = color | 0x0100;
  692.                 if (pal[i]&0x40) color = color | 0x2000;
  693.                 if (pal[i]&0x20) color = color | 0x0001;
  694.                 if (pal[i]&0x10) color = color | 0x0020;
  695.                 i++;
  696.                 if (pal[i]&0x80) color = color | 0x1000;
  697.                 if (pal[i]&0x40) color = color | 0x8000;
  698.                 if (pal[i]&0x20) color = color | 0x0010;
  699.                 if (pal[i]&0x10) color = color | 0x0080;
  700.                 i++;
  701.                 if (pal[i]&0x80) color = color | 0x0200;
  702.                 if (pal[i]&0x40) color = color | 0x4000;
  703.                 if (pal[i]&0x20) color = color | 0x0002;
  704.                 if (pal[i]&0x10) color = color | 0x0040;
  705.                 i++;
  706.                 emitdw(~color, fout);
  707.                 i++;
  708.               };
  709.               fputs("\n", fout);
  710.               rowhgt = sprhgt;
  711.             }else if ((sprformat == 'w')||(sprformat == 'z')||(sprformat == 'Z')) {
  712.               putlabel(labelbuf, fout);
  713.               fputs("\n", fout);
  714.               rowhgt = sprhgt;
  715.             }else if (sprformat == 'W') {
  716.               putlabel(labelbuf, fout);
  717.               fputs("\n", fout);
  718.               rowhgt = sprhgt;
  719.             }else { //'s'
  720.               putlabel(labelbuf, fout);
  721.               fputs("\n", fout);
  722.               emitdb((BYTE)(sprwid>>3), fout);
  723.               emitdb((BYTE)(sprhgt), fout);
  724.               rowhgt = sprhgt;
  725.             };
  726.  
  727. //copy comment as code line
  728.               fputs(commentlabelbuf, fout);
  729.               //fputs("\n", fout);
  730.  
  731.             y = spry;
  732.             while (y < (spry+sprhgt)) {
  733.               //яхЁхъюфшЁєхь Ё ф чэръюьхёЄ т√ёюЄющ rowhgt
  734.               curink = 0x0f;
  735.               curpaper = 0x08;
  736.               x = 0;//sprx;
  737.               while (x < (sprx+sprwid)) {
  738.                 findinkpaper(x, y);
  739.                 setcurinkpaper(&curink, &curpaper);
  740.               //curink = 0x0f;
  741.               //curpaper = 0x08;
  742. //  if (sprformat == 'W') {
  743. //    curpaper = 0;
  744. //    curink = 1;
  745. //  };
  746.                 j = y;
  747.                 while (j < (y+rowhgt)) {
  748.                   b = 0x00;
  749.                   bmask = 0x00;
  750.                   i = x;
  751.                   while (i < (x+8)) {
  752.                     b = (BYTE)(b<<1);
  753.                     bmask = (BYTE)(bmask<<1);
  754.                     //if (sprformat != 'B') {fprintf(fout, "0x%x%x\n", (pic[i][j])>>4, (pic[i][j])&0x0f);};
  755.                     if (pic[i][j]==curink) b++;
  756.                     if (pic[i][j]!=0x00) bmask++;
  757.                     i++;
  758.                   };
  759.                   pixrow[x/8][j] = b;
  760.                   maskrow[x/8][j] = bmask;
  761.                   //fprintf(fout, "0x%x%x ", x>>4, x&0x0f);
  762.                   //fprintf(fout, "0x%x%x ", j>>4, j&0x0f);
  763.                   //fprintf(fout, "0x%x%x ", b>>4, b&0x0f);
  764.                   //fprintf(fout, "0x%x%x\n", bmask>>4, bmask&0x0f);
  765.                   pixrow[(x/8)+1][j] = 0x00; //ўЄюс√ ёфтшурЄ№
  766.                   j++;
  767.                 };
  768. //ьрёър 0x00 эх ёўшЄрхЄё  ЎтхЄюь, яю¤Єюьє 0x08 яхЁхтюфшЄё  т 0x00 (ўЄюс√ эх тыш Є№ эр bright)
  769.                 b = 0x00; if (curink!=0x08) b = curink;
  770.                 b0 = 0x00; if (curpaper!=0x08) b0 = curpaper;
  771.                 attrrow[x/8    ] = (BYTE)( (((b|b0)&0x08)<<3)+((curpaper&0x07)<<3)+(curink&0x07) );
  772.                 attrrow[(x/8)+1] = (BYTE)( (((b|b0)&0x08)<<3)+((curpaper&0x07)<<3)+(curink&0x07) ); //ўЄюс√ ёфтшурЄ№
  773.                 x = x+8;
  774.               };
  775.   //            shiftrow(sprx, y, sprwid, rowhgt, PIXROWSHIFT, 0x04); //ёфтшурхь Ё ф чэръюьхёЄ >>4, Ёхчєы№ЄрЄ т pixrow[sprx][y+PIXROWSHIFT]
  776.  
  777.               //т√тюфшь т рёь
  778.               if ((sprformat == 'B')||(sprformat == 'b')) { //tiles or bw tiles
  779.                 x = sprx;
  780.                 while (x < (sprx+sprwid)) {
  781.   //                emitchrshift(x/8,y,fout);
  782.                   emitchr(x/8,y,fout); //checks for capital letter in sprformat
  783.                   x = x+8;
  784.                 };
  785.   //              emitchrshift(x/8,y,fout);
  786.               }else if (sprformat == 'T') {
  787.                 x = sprx;
  788.                 while (x < (sprx+sprwid)) {
  789.                   emitchr(x/8,y,fout);
  790.                   x = x+8;
  791.                 };
  792.                 emitnops((BYTE)(0x100-((BYTE)(sprwid>>3)*0x09)),fout);
  793.               }else if (sprformat == 's') { //sprite
  794.                 emitspr(sprx/8,y,sprwid/8,sprhgt,fout);
  795.               }else if (sprformat == 'w') { //sprite antipixels16, antimask16
  796.                 emitsprw(sprx/8,y,sprwid/8,sprhgt,fout);
  797.               }else if (sprformat == 'z') { //unmasked sprite right to left
  798.                 emitsprwnomaskback(sprx/8,y,sprwid/8,sprhgt,fout);
  799.               }else if (sprformat == 'Z') { //unmasked sprite
  800.                 emitsprwnomask(sprx/8,y,sprwid/8,sprhgt,fout);
  801.               }else if (sprformat == 'W') { //b/w image by columns
  802.                 emitimgW(sprx/8,y,sprwid/8,sprhgt,fout);
  803.                 //emitimgW(0,0,128,128,fout);
  804.               };
  805.               y = y+rowhgt;
  806.             }; //while y
  807.  
  808.             if (sprformat == 'x') {
  809.               x = sprx;
  810.               while (x < (sprx+sprwid)) {
  811.                 y = spry;
  812.                 while (y < (spry+sprhgt)) {
  813.                   b = pic[x][y]; //L
  814.                   b0 = pic[x+1][y]; //R
  815.                   bmask = 0; //0x47(L) ш 0xb8(R) т Єхї ьхёЄрї, уфх ЎтхЄ=16:
  816.                   if (b == 16) {bmask = bmask + 0x47; b = 0x00;};
  817.                   if (b0 == 16) {bmask = bmask + 0xb8; b0 = 0x00;};
  818.                   b = ((b&0x08)<<3) + (b&0x07) + ((b0&0x08)<<4) + ((b0&0x07)<<3);
  819.                   fputs("\tdb ", fout);
  820.                   fprintf(fout, "0x%x%x", bmask>>4, bmask&0x0f);
  821.                   fprintf(fout, ",0x%x%x", b>>4, b&0x0f);
  822.                   fputs("\n", fout);
  823.                   y = y+1;
  824.                 };
  825.                 x = x+2;
  826.                 if (x < (sprx+sprwid)) {
  827.                   emitdw(0x4000-((sprhgt-1)*40), fout);
  828.                 }else {
  829.                   emitdw(0xffff, fout);
  830.                 };
  831.                 fputs("\n", fout);
  832.               };
  833.               fputs("\tdw prsprqwid\n", fout);
  834.             };
  835.  
  836.             if (sprformat == 'i') {
  837.               x = sprx;
  838.               while (x < (sprx+sprwid)) {
  839.                 y = spry;
  840.                 while (y < (spry+sprhgt)) {
  841.                   b = pic[x][y]; //L
  842.                   b0 = pic[x+1][y]; //R
  843.                   b = ((b&0x08)<<3) + (b&0x07) + ((b0&0x08)<<4) + ((b0&0x07)<<3);
  844.                   fprintf(fout, "\tdb 0x%x%x", b>>4, b&0x0f);
  845.                   fputs("\n", fout);
  846.                   y = y+1;
  847.                 };
  848.                 x = x+2;
  849.                 fputs("\n", fout);
  850.               };
  851.             };
  852.  
  853.             if (sprformat == 'L') { //фрыхх ЄхъёЄ Єшяр (-1=яЁюяєёъ):
  854. //   -1, -1, -1,114,116,119,121,124,126,-1,-1,-1,-1,-1,-1,-1,
  855. //  113,118,123,115,117,120,122,125,127,-1,-1,-1,-1,-1,-1,-1
  856. //фы  ърцфющ  ўхщъш ърЁЄшэъш єърчрэ эюьхЁ Єрщыр
  857. //р эрь эрфю чряюыэшЄ№ ьрёёшт√ convorderx,y - ъююЁфшэрЄ√ фы  ърцфюую эюьхЁр Єрщыр
  858. //тёх фюыцэ√ с√Є№ т юфэющ ърЁЄшэъх, шэрўх эх яюыєўшЄё  (яхЁхьх°рэ√ эюьхЁр Єрщыют юс∙шх фы  тёхї ыюърЎшщ ш фы  ъюэъЁхЄэющ)
  859.               n = 0;
  860.               while (n < CONVORDERSZ) {
  861.                 convorderx[n] = 0;
  862.                 convordery[n] = 0;
  863.                 n = n+1;
  864.               };
  865.  
  866.                 skiplf(fintxt);
  867.               //tiles = 0;
  868.  
  869.               y = spry;
  870.               while (y < (spry+sprhgt)) {
  871.                 x = sprx;
  872.                 while (x < (sprx+sprwid)) {
  873.                   n = readnum(fintxt);
  874.                   if (n != -1) {
  875.                     convorderx[n] = x;
  876.                     convordery[n] = y;
  877.                   };
  878.                   //fprintf(fout, "\tdb %d\n", n);
  879.                   //tiles = tiles + 1;
  880.                   x = x+16;
  881.                 };
  882.                 skiplf(fintxt);
  883.                 //fputs("\n", fout);
  884.                 y = y+16;
  885.               };
  886.  
  887.               n = 0;
  888.               while (n < tiles) {
  889.                 x = convorderx[n];
  890.                 while (x < (convorderx[n]+16)) {
  891.                   fputs(" db ", fout);
  892.                   y = convordery[n];
  893.                   while (1) {
  894.                     b = pic[x][y]; //L
  895.                     b0 = pic[x+1][y]; //R
  896.                     b = ((b&0x08)<<3) + (b&0x07) + ((b0&0x08)<<4) + ((b0&0x07)<<3);
  897.                     fprintf(fout, "0x%x%x", b>>4, b&0x0f);
  898.                     y = y+1;
  899.                     if (y == (convordery[n]+16)) break;
  900.                     fputs(",", fout);
  901.                   };
  902.                   fputs("\n", fout);
  903.                   x = x+2;
  904.                 };
  905.                 n = n+1;
  906.               };
  907.  
  908.             };
  909.             sprx = sprx + sprwid;
  910.             cursprcount++;
  911.            } while (cursprcount<maxsprcount); //while (sprcount)
  912.             spry = spry + sprhgt;
  913.             curvertsprcount++;
  914.            } while (curvertsprcount<maxvertsprcount); //while (vertsprcount)
  915.           }; //while (1)
  916.           fclose(fout);
  917.         }else {printf("can't open %s",foutname);};
  918.         fclose(fintxt);
  919.       }else {printf("can't open %s",fintxtname);};
  920.     };
  921.     fclose(fin);
  922.   }else {printf("can't open %s",finname);};
  923. }
  924.  
  925. int main(int argc,char* argv[])
  926. {
  927. //  int i;
  928.   char *finname;
  929.   char *fintxtname;
  930.   char *foutname;
  931.   finname = "testpic.bmp";
  932.   fintxtname = "testpic.txt";
  933.   foutname = "testpic.asm";
  934.  
  935.   if (argc<4) {
  936.     printf(
  937.       "NedoRes\n"
  938.       "\tnedores.exe file.bmp file.dat(=txt) file.ast(=asm)\n"
  939.       "4bpp or 8bpp\n"
  940.     );
  941.   }else {
  942.     finname = argv[1];
  943.     fintxtname = argv[2];
  944.     foutname = argv[3];
  945.   };
  946.  
  947.   resfile(finname, fintxtname, foutname);
  948.  
  949.   return 0;
  950. }