?login_element?

Subversion Repositories NedoOS

Rev

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