?login_element?

Subversion Repositories NedoOS

Rev

Rev 1931 | 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[2048][1024];
  20. BYTE pixrow[2048/8+1][1024+1024];
  21. #define PIXROWSHIFT 1024
  22. BYTE maskrow[2048/8+1][1024];
  23. //BYTE pixrowshift[2048/8][1024]; //>>4
  24. BYTE attrrow[2048/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. char globalsprformat;
  45. BYTE invattr;
  46. BYTE forceattr;
  47.  
  48. int hgt;
  49. int wid;
  50. int bpp;
  51.  
  52. void skiplf(FILE * fin)
  53. { //тючьюцэю, 0x0d єцх яЁюўшЄрэ, ЄхяхЁ№ яЁюяєёърхь 0x0a
  54. char c;
  55.   do{
  56.     if (!fread(&c,1,1,fin)) break;
  57.   }while (c!=0x0a);
  58. }
  59.  
  60. void readcomment(FILE * fin, char * s)
  61. { //тючьюцэю, 0x0d єцх яЁюўшЄрэ, ЄхяхЁ№ яЁюяєёърхь 0x0a
  62. char c;
  63. unsigned int i;
  64.   i = 0;
  65.   do{
  66.     if (!fread(&c,1,1,fin)) break;
  67.     if (i==_STRMAX) break;
  68.     s[i] = c;
  69.     i++;
  70.   }while (c!=0x0a);
  71.   s[i] = '\0';
  72. }
  73.  
  74. int readnum(FILE * fin)
  75. {
  76. char c;
  77. int num;
  78. int sign=1;
  79.   num = 0;
  80.   do{
  81.     if (!fread(&c,1,1,fin)) break;
  82.     if (c==' ') goto skip;
  83.     //if (c == 0x0d) goto skip;
  84.     //if (c == 0x0a) break;
  85.     if (c=='!') {forceattr = 0xff; goto skip;};
  86.     if (c=='-') {sign = -1; goto skip;};
  87.     if ((c<'0')||(c>'9')) break; //т Єюь ўшёых 0x0a
  88.     num = num*10 + (int)(c-'0');
  89.     numok = 0xff;
  90. skip:
  91.         ;
  92.   }while(1);
  93.   num = num*sign;
  94. return num;
  95. }
  96.  
  97. unsigned int readlabel(FILE * fin, char * s)
  98. {
  99. char c;
  100. unsigned int i;
  101. int iscomment;
  102.   sprcount = 0;
  103.   vertsprcount = 0;
  104.   do{
  105.     i = 0;
  106.     iscomment = 0;
  107.     do{
  108.       if (!fread(&c,1,1,fin)) break;
  109.       if (c == ';') iscomment = -1;
  110.       if (c == '~') {invattr = 0xff; continue;}
  111.       if (c == '$') { //фры№°х ўшёыю ёяЁрщЄют тхЁЄшъры№эю
  112.         if (iscomment) continue; //т ъюььхэЄрї ьюцэю $
  113.         while (1) {
  114.           if (!fread(&c,1,1,fin)) return 0;
  115.           if ((c < '0') || (c > '9')) break;
  116.           vertsprcount = vertsprcount*10;
  117.           vertsprcount = vertsprcount + (int)(c-'0');
  118.         };
  119.       };
  120.       if (c == '#') { //фры№°х ўшёыю ёяЁрщЄют
  121.         if (iscomment) continue; //т ъюььхэЄрї ьюцэю #
  122.         while (1) {
  123.           if (!fread(&c,1,1,fin)) return 0;
  124.           if ((c < '0') || (c > '9')) break;
  125.           sprcount = sprcount*10;
  126.           sprcount = sprcount + (int)(c-'0');
  127.         };
  128.       };
  129.       if ((c == '=')||(c == ',')) {
  130.         if (iscomment) continue; //т ъюььхэЄрї ьюцэю =
  131.         break;
  132.       };
  133.       if (c == 0x0d) continue;
  134.       if (c == 0x0a) {
  135.         if (iscomment) break; //ъюььхэЄ√ ъюэўр■Єё  яю ъюэЎє ёЄЁюъш
  136.         continue;
  137.       };
  138.       if (i==_STRMAX) break;
  139.       s[i] = c;
  140.       i++;
  141.     }while(1);
  142.     s[i] = '\0';
  143.   }while(iscomment);
  144. return i;
  145. }
  146.  
  147. int read4b(FILE * fin)
  148. {
  149.   fread(sizeword, 4, 1, fin);
  150. return sizeword[0] + (sizeword[1]<<8) + (sizeword[2]<<16) + (sizeword[3]<<24);
  151. }
  152.  
  153. BYTE colstat[256];
  154.  
  155. char numbuf[256];
  156.  
  157. UINT maxsprcount;
  158. UINT cursprcount;
  159. UINT maxvertsprcount;
  160. UINT curvertsprcount;
  161.  
  162. void putlabel(char * labelbuf, FILE * fout)
  163. {
  164. UINT num;
  165. UINT i;
  166.         fputs(labelbuf, fout);
  167.         if (maxvertsprcount != 0) {
  168.           fputc('_', fout);
  169.           fputc('_', fout);
  170.           num = curvertsprcount;
  171.  
  172.           i = 0;
  173.           do {
  174.             numbuf[i] = (char)((UINT)'0' + (num - (num/10)*10));
  175.             num = num/10;
  176.             i++;
  177.           } while (num != 0);
  178.  
  179.           do {
  180.             i--;
  181.             fputc(numbuf[i], fout);
  182.           } while (i != 0);
  183.         };
  184.         if (maxsprcount != 0) {
  185.           fputc('_', fout);
  186.           num = cursprcount;
  187.  
  188.           i = 0;
  189.           do {
  190.             numbuf[i] = (char)((UINT)'0' + (num - (num/10)*10));
  191.             num = num/10;
  192.             i++;
  193.           } while (num != 0);
  194.  
  195.           do {
  196.             i--;
  197.             fputc(numbuf[i], fout);
  198.           } while (i != 0);
  199.         };
  200. return;
  201. }
  202.  
  203. void findinkpaper(int x, int y) //ьрёър 0x00 эх ёўшЄрхЄё  ЎтхЄюь
  204. {
  205. //BYTE b;
  206. int i;
  207. int j;
  208. BYTE col1;
  209. BYTE col1stat;
  210. BYTE col2;
  211. BYTE col2stat;
  212. BYTE col3;
  213. BYTE col3stat;
  214. BYTE col4;
  215. BYTE col4stat; //эр ёыєўрщ Єръющ ёЄрЄшёЄшъш: MASKCOLOR, RED, red, anothercolor
  216.   i = 0; do {colstat[i] = 0x00; i++;}while (i!=256);
  217.  
  218.   //col1 = pic[x][y];
  219.   j = y;
  220.   while (j < (y+8)) {
  221. //    b = 0x00;
  222.     i = x;
  223.     while (i < (x+8)) {
  224.       colstat[pic[i][j]]++;
  225.       //b = pic[i][j];
  226.       //if (b!=col1) col2 = b;
  227.       i++;
  228.     };
  229.     j++;
  230.   };
  231.  
  232. //ьрёър MASKCOLOR эх ёўшЄрхЄё  ЎтхЄюь
  233.   col1 = MASKCOLOR; col1stat = 0; //fix 27.12.2018
  234.   col2 = MASKCOLOR; col2stat = 0; //fix 27.12.2018
  235.   col3 = MASKCOLOR; col3stat = 0; //fix 27.12.2018
  236.   col4 = MASKCOLOR; col3stat = 0; //fix 27.12.2018
  237.   i = 0; do { //fix 27.12.2018 (эр ёыєўрщ MASKCOLOR!=0)
  238.     if (colstat[i] > col1stat) {
  239.       col4 = col3;
  240.       col4stat = col3stat;
  241.       col3 = col2;
  242.       col3stat = col2stat;
  243.       col2 = col1;
  244.       col2stat = col1stat;
  245.       col1 = (BYTE)i;
  246.       col1stat = colstat[i];
  247.     }else if (colstat[i] > col2stat) {
  248.       col4 = col3;
  249.       col4stat = col3stat;
  250.       col3 = col2;
  251.       col3stat = col2stat;
  252.       col2 = (BYTE)i;
  253.       col2stat = colstat[i];
  254.     }else if (colstat[i] > col3stat) {
  255.       col4 = col3;
  256.       col4stat = col3stat;
  257.       col3 = (BYTE)i;
  258.       col3stat = colstat[i];
  259.     }else if (colstat[i] > col4stat) {
  260.       col4 = (BYTE)i;
  261.       col4stat = colstat[i];
  262.     };
  263.     i++;
  264.   }while (i!=16); //fix 27.12.2018
  265.  
  266. //MASKCOLOR эхы№ч  ёрь√ь ўрёЄ√ь, ёюЁЄшЁєхь хую т ъюэхЎ
  267.   if (col1==MASKCOLOR) {
  268.     col1 = col2;
  269.     col2 = MASKCOLOR;
  270.   };
  271.   if (col2==MASKCOLOR) {
  272.     col2 = col3;
  273.     col3 = MASKCOLOR;
  274.   };
  275.   if (col3==MASKCOLOR) {
  276.     col3 = col4;
  277.     col4 = MASKCOLOR;
  278.   };
  279.  
  280. //col1 ьюцхЄ с√Є№ MASKCOLOR Єюы№ъю фы  чэръюьхёЄр, яюыэюёЄ№■ чрышЄюую MASKCOLOR
  281. //ьрёър 0x00 эх ёўшЄрхЄё  ЎтхЄюь, яю¤Єюьє 0x08 яхЁхтюфшЄё  т 0x00 ё фхЇюыЄэющ  ЁъюёЄ№■ (ўЄюс√ эх тыш Є№ эр bright)
  282.   //if ((col1&0x07)==0x00) col1 = (BYTE)(defaultcolor&0x08); //fix 27.12.2018
  283.   //if ((col2&0x07)==0x00) col2 = (BYTE)(defaultcolor&0x08); //fix 27.12.2018
  284. /**  if (col2 == MASKCOLOR) {
  285.     if (col1 == MASKCOLOR) {
  286.       col2 = (BYTE)((col1&0x08) | (defaultcolor&0x07));
  287.     }else {
  288.       col2 = (BYTE)((col1&0x08) | (defaultcolor&0x07));
  289.     };
  290.   };*/ //fix 27.12.2018
  291.   if (((col2&0x07)==(col1&0x07)) /**&& (col2!=0x00)*/) col2 = col3; //same colour with another bright
  292.   ink = col1;
  293.   paper = col2; //Ёхцх
  294.   //paper Ёхцх ш ьюцхЄ с√Є№ MASKCOLOR (эхЄ тЄюЁюую ЎтхЄр, эрфю сЁрЄ№ фхЇюыЄэ√щ)
  295.   //ink ьюцхЄ с√Є№ MASKCOLOR Єюы№ъю фы  чэръюьхёЄр, яюыэюёЄ№■ чрышЄюую MASKCOLOR
  296. }
  297.  
  298. void setcurinkpaper(BYTE* pcurink, BYTE* pcurpaper)
  299. //paper Ёхцх ш ьюцхЄ с√Є№ MASKCOLOR (эхЄ тЄюЁюую ЎтхЄр, эрфю сЁрЄ№ фхЇюыЄэ√щ)
  300. //ink ьюцхЄ с√Є№ MASKCOLOR Єюы№ъю фы  чэръюьхёЄр, яюыэюёЄ№■ чрышЄюую MASKCOLOR
  301. //*pcurink, *curpaper шчэрўры№эю ёюфхЁцрЄ рЄЁшсєЄ√ яЁхф√фє∙хую чэръюьхёЄр
  302. //тючтЁр∙рхЄ *pcurink, *curpaper, яЁшў╕ь тьхёЄю 0x08 ёЄртшЄ 0x00 (ўЄюс√ эх тыш ыю эр  ЁъюёЄ№)
  303. {
  304. BYTE t;
  305.   if ((sprformat == 's')||(sprformat == 'y')||(sprformat == 'Z')||(sprformat == 'z')||(sprformat == 'W')||(sprformat == 'w')) {
  306.     paper = 0x08;
  307.     ink = 0x0f;
  308.   }; //фы  ёяЁрщЄют Їюэ ў╕Ёэ√щ (р ьрёър 0x00)
  309.  
  310. //27.02.2019:
  311. //Їюэ фы  чрышЄ√ї чэръюьхёЄ эрўшэр  ё чхы╕эюую ЄхяхЁ№ ў╕Ёэ√щ[шыш эрфю яЁхф√фє∙шщ?]
  312. //Їюэ фы  ў╕Ёэ√ї чэръюьхёЄ схЁ╕Є  ЁъюёЄ№ юЄ defaultcolor, р фы  чрышЄ√ї чэръюьхёЄ ьхэхх чхы╕эюую эх схЁ╕Є
  313. #define MINCOLORWITHBLACKBG 0x04
  314. //fix 27.12.2018:
  315.   if (((ink&0x07)==(*pcurink&0x07)) && (ink!=MASKCOLOR)) { //ink ёююЄтхЄёЄтєхЄ яЁхф√фє∙хьє
  316.     *pcurink = ink;
  317.     if (paper==MASKCOLOR) {
  318.       *pcurpaper = ((ink&0x07)<MINCOLORWITHBLACKBG) ? ((ink&0x07)?((defaultcolor&0x07)|(ink&0x08)):defaultcolor) : 0x00;
  319.     }else {
  320.       *pcurpaper = paper;
  321.     };
  322.   }else if (((paper&0x07)==(*pcurpaper&0x07)) && (paper!=MASKCOLOR)) { //paper ёююЄтхЄёЄтєхЄ яЁхф√фє∙хьє
  323.     *pcurpaper = paper;
  324.     if (ink==MASKCOLOR) {
  325.       *pcurink = ((paper&0x07)<MINCOLORWITHBLACKBG) ? ((paper&0x07)?((defaultcolor&0x07)|(paper&0x08)):defaultcolor) : 0x00;
  326.     }else {
  327.       *pcurink = ink;
  328.     };
  329.   }else if (((paper&0x07)==(*pcurink&0x07)) && (paper!=MASKCOLOR)) { //paper ёююЄтхЄёЄтєхЄ яЁхф√фє∙хьє ink
  330.     *pcurink = paper;
  331.     if (ink==MASKCOLOR) {
  332.       *pcurpaper = ((paper&0x07)<MINCOLORWITHBLACKBG) ? ((paper&0x07)?((defaultcolor&0x07)|(paper&0x08)):defaultcolor) : 0x00;
  333.     }else {
  334.       *pcurpaper = ink;
  335.     };
  336.   }else if (((ink&0x07)==(*pcurpaper&0x07)) && (ink!=MASKCOLOR)) { //ink ёююЄтхЄёЄтєхЄ яЁхф√фє∙хьє paper
  337.     *pcurpaper = ink;
  338.     if (paper==MASKCOLOR) {
  339.       *pcurink = ((ink&0x07)<MINCOLORWITHBLACKBG) ? ((ink&0x07)?((defaultcolor&0x07)|(ink&0x08)):defaultcolor) : 0x00;
  340.     }else {
  341.       *pcurink = paper;
  342.     };
  343.   }else if ((ink==MASKCOLOR)&&(paper==MASKCOLOR)) { //юср ЎтхЄр MASKCOLOR
  344.     ink = defaultcolor;
  345.     paper = 0x08;
  346.   }else { //юср ЎтхЄр эх ёююЄтхЄёЄтє■Є яЁхф√фє∙хьє чэръюьхёЄє, эю эх юср MASKCOLOR
  347.     if (ink == MASKCOLOR) ink = ((paper&0x07)<MINCOLORWITHBLACKBG) ? ((paper&0x07)?((defaultcolor&0x07)|(paper&0x08)):defaultcolor) : 0x00;
  348.     if (paper == MASKCOLOR) paper = ((ink&0x07)<MINCOLORWITHBLACKBG) ? ((ink&0x07)?((defaultcolor&0x07)|(ink&0x08)):defaultcolor) : 0x00;
  349.     if (ink > paper) {
  350.       *pcurink = ink;
  351.       *pcurpaper = paper;
  352.     }else {
  353.       *pcurink = paper;
  354.       *pcurpaper = ink;
  355.     };
  356.   };
  357.  
  358.     //*pcurink = ink;
  359.     //*pcurpaper = paper;
  360.  
  361.   if (*pcurpaper==0x08) *pcurpaper = 0x00; //ўЄюс√ эх тыш ыю эр  ЁъюёЄ№ //fix 27.12.2018
  362.   if (*pcurink==0x08) *pcurink = 0x00; //ўЄюс√ эх тыш ыю эр  ЁъюёЄ№ //fix 27.12.2018
  363.   //эр ў╕Ёэюь/ёшэхь Їюэх ink фюыцхэ с√Є№  Ёўх paper'р (юЄфхы№э√щ ёыєўрщ, Є.ъ. юёЄры№э√х, фрцх яєёЄ√х, чэръюьхёЄр ьюуєЄ єўрёЄтютрЄ№ т юЄЁшёютъх ёъЁюыышЁєхь√ї Їюэют ё эхяЁхЁ√тэ√ьш Ўхяюўърьш ink-paper)
  364.   //Єю хёЄ№ эхы№ч  ink=0, р 1 Єюы№ъю т ёыєўрх paper=0
  365.   if (((*pcurink&0x07)<=0x01) && ((*pcurpaper&0x07)>(*pcurink&0x07))) { //ў╕Ёэюх/ёшэхх яєёЄюх чэръюьхёЄю (юЄфхы№э√щ ёыєўрщ, Є.ъ. юёЄры№э√х яєёЄ√х ьюуєЄ єўрёЄтютрЄ№ т юЄЁшёютъх ёъЁюыышЁєхь√ї Їюэют ё эхяЁхЁ√тэ√ьш Ўхяюўърьш ink-paper)
  366.     t = *pcurpaper;
  367.     *pcurpaper = *pcurink;
  368.     *pcurink = t;
  369.   };
  370. }
  371.  
  372. void emitdb(BYTE b, FILE * fout)
  373. {
  374.   fputs("\tdb ", fout);
  375.   fprintf(fout, "0x%x%x", b>>4, b&0x0f);
  376.   fputs("\n", fout);
  377. }
  378.  
  379. void emitdw(UINT u, FILE * fout)
  380. {
  381.   fputs("\tdw ", fout);
  382.   fprintf(fout, "0x%x%x%x%x", (u>>12)&0x0f, (u>>8)&0x0f, (u>>4)&0x0f, u&0x0f);
  383.   fputs("\n", fout);
  384. }
  385.  
  386. void emitnops(BYTE count, FILE * fout)
  387. {
  388.   fputs("\tds ", fout);
  389.   fprintf(fout, "0x%x%x", count>>4, count&0x0f);
  390.   fputs("\n", fout);
  391. }
  392.  
  393. void emitspr(int xchr, int y, int sprwid8, int sprhgt, FILE * fout)
  394. { //b/w sprites: wid8, hgt, (antimask, antipixels, ...) ;for DizzySE!
  395. BYTE b;
  396. int i;
  397. int j;
  398.   j = y;
  399.   while (1) {
  400.     fputs("\tdb ", fout);
  401.     i = xchr;
  402.     while (1) {
  403.       b = maskrow[i][j];
  404.       fprintf(fout, "0x%x%x", b>>4, b&0x0f);
  405.       fputs(",", fout);
  406.       b = b^pixrow[i][j];
  407.       fprintf(fout, "0x%x%x", b>>4, b&0x0f);
  408.       i++;
  409.       if (i >= (xchr+sprwid8)) break;
  410.       fputs(",", fout);
  411.     };
  412.     fputs("\n", fout);
  413.     j++;
  414.     if (j >= (y+sprhgt)) break;
  415.   };
  416. }
  417.  
  418. void emitcolorspr(int xchr, int y, int sprwid8, int sprhgt, FILE * fout)
  419. { //coloured sprite, one row of attrchrs: (mask, antipixels, ...),attr
  420. BYTE b;
  421. int i;
  422. int j;
  423.   i = xchr;
  424.   while (1) { //chrs in row
  425.     fputs("\tdb ", fout);
  426.     j = y;
  427.     while (1) { //bytes in chr
  428.       b = ~maskrow[i][j];
  429.       fprintf(fout, "0x%x%x", b>>4, b&0x0f);
  430.       fputs(",", fout);
  431.       b = b ^ pixrow[i][j] ^ invattr;
  432.       fprintf(fout, "0x%x%x", b>>4, b&0x0f);
  433.       j++;
  434.       if (j >= (y+8)) break;
  435.       fputs(",", fout);
  436.     };
  437.     b = attrrow[xchr]; //0x07;
  438.     if (invattr) b = (b&0xc0) + ((b&0x07)<<3) + ((b&0x38)>>3);
  439.     if (forceattr) b = defaultcolor;
  440.     fputs(",", fout);
  441.     fprintf(fout, "0x%x%x", b>>4, b&0x0f);
  442.     fputs("\n", fout);
  443.     i++;
  444.     if (i >= (xchr+sprwid8)) break;
  445.   };
  446. }
  447.  
  448. void emitcolorline(int xchr, int y, int sprwid8, int sprhgt, FILE * fout)
  449. { //for coloured line: 8 lines of pixels (no attrs)
  450. BYTE b;
  451. int i;
  452. int j;
  453.   j = y;
  454.   while (1) { //lines
  455.     fputs("\tdb ", fout);
  456.     i = xchr;
  457.     while (1) { //chrs in row
  458.       b = pixrow[i][j] ^ invattr;
  459.       fprintf(fout, "0x%x%x", b>>4, b&0x0f);
  460.       i++;
  461.       if (i >= (xchr+sprwid8)) break;
  462.       fputs(",", fout);
  463.     };
  464.     fputs("\n", fout);
  465.     j++;
  466.     if (j >= (y+8)) break;
  467.   };
  468. }
  469.  
  470. void emitattrline(int xchr, int y, int sprwid8, int sprhgt, FILE * fout)
  471. {
  472. BYTE b;
  473. int i;
  474.   fputs("\tdb ", fout);
  475.   i = xchr;
  476.   while (1) { //chrs in row
  477.     b = attrrow[i]; //0x07;
  478.     if (invattr) b = (b&0xc0) + ((b&0x07)<<3) + ((b&0x38)>>3);
  479.     if (forceattr) b = defaultcolor;
  480.     fprintf(fout, "0x%x%x", b>>4, b&0x0f);
  481.     i++;
  482.     if (i >= (xchr+sprwid8)) break;
  483.     fputs(",", fout);
  484.   };
  485.   fputs("\n", fout);
  486. }
  487.  
  488. void emitspry(int xchr, int y, int sprwid8, int sprhgt, FILE * fout)
  489. {
  490. BYTE b;
  491. int i;
  492. int j;
  493.   i = xchr;
  494.   while (1) {
  495.     fputs("\tdb ", fout);
  496.     j = y;
  497.     while (1) {
  498.       b = ~maskrow[i][j];
  499.       b = b^pixrow[i][j];
  500.       fprintf(fout, "0x%x%x", b>>4, b&0x0f);
  501.       fputs(",", fout);
  502.       //b = maskrow[i][j];
  503.       b = pixrow[i][j];
  504.       fprintf(fout, "0x%x%x", b>>4, b&0x0f);
  505.       j++;
  506.       if (j >= (y+sprhgt)) break;
  507.       fputs(",", fout);
  508.     };
  509.     fputs("\n", fout);
  510.     i++;
  511.     if (i >= (xchr+sprwid8)) break;
  512.   };
  513. }
  514.  
  515. void emitsprw(int xchr, int y, int sprwid8, int sprhgt, FILE * fout)
  516. { //antipixelsline, antimaskline
  517. BYTE b;
  518. int i;
  519. int j;
  520.   j = y;
  521.   while (1) {
  522.     fputs("\tdb ", fout);
  523.     i = xchr;
  524.     while (1) {
  525.       b = ~maskrow[i][j];
  526.       fprintf(fout, "0x%x%x", b>>4, b&0x0f);
  527.       i++;
  528.       if (i == xchr+sprwid8) break;
  529.       fputs(",", fout);
  530.     };
  531.     fputs("\n", fout);
  532.     fputs("\tdb ", fout);
  533.     i = xchr;
  534.     while (1) {
  535.       b = ~maskrow[i][j];
  536.       b ^= pixrow[i][j];
  537.       fprintf(fout, "0x%x%x", b>>4, b&0x0f);
  538.       i++;
  539.       if (i == xchr+sprwid8) break;
  540.       fputs(",", fout);
  541.     };
  542.     fputs("\n", fout);
  543.     j++;
  544.     if (j >= (y+sprhgt)) break;
  545.   };
  546. }
  547.  
  548. void emitsprwback(int xchr, int y, int sprwid8, int sprhgt, FILE * fout)
  549. { //antipixelsw, antimaskw
  550. BYTE b;
  551. int i;
  552. int j;
  553.   j = y;
  554.   while (1) {
  555.     fputs("\tdb ", fout);
  556.     i = xchr+sprwid8;
  557.     while (1) {
  558.       i--;
  559.       b = ~maskrow[i][j];
  560.       fprintf(fout, "0x%x%x", b>>4, b&0x0f);
  561.       if (i == xchr) break;
  562.       fputs(",", fout);
  563.     };
  564.     fputs("\n", fout);
  565.     fputs("\tdb ", fout);
  566.     i = xchr+sprwid8;
  567.     while (1) {
  568.       i--;
  569.       b = ~maskrow[i][j];
  570.       b ^= pixrow[i][j];
  571.       fprintf(fout, "0x%x%x", b>>4, b&0x0f);
  572.       if (i == xchr) break;
  573.       fputs(",", fout);
  574.     };
  575.     fputs("\n", fout);
  576.     j++;
  577.     if (j >= (y+sprhgt)) break;
  578.   };
  579. }
  580.  
  581. void emitsprwnomask(int xchr, int y, int sprwid8, int sprhgt, FILE * fout)
  582. { //antipixelsw
  583. BYTE b;
  584. int i;
  585. int j;
  586.   j = y;
  587.   while (1) {
  588.     fputs("\tdb ", fout);
  589.     i = xchr;
  590.     while (1) {
  591.       b = ~maskrow[i][j];
  592.       fprintf(fout, "0x%x%x", b>>4, b&0x0f);
  593.       i++;
  594.       if (i == xchr+sprwid8) break;
  595.       fputs(",", fout);
  596.     };
  597.     fputs("\n", fout);
  598.     j++;
  599.     if (j >= (y+sprhgt)) break;
  600.   };
  601. }
  602.  
  603. void emitsprwnomaskback(int xchr, int y, int sprwid8, int sprhgt, FILE * fout)
  604. { //antipixelsw
  605. BYTE b;
  606. int i;
  607. int j;
  608.   j = y;
  609.   while (1) {
  610.     fputs("\tdb ", fout);
  611.     i = xchr+sprwid8;
  612.     while (1) {
  613.       i--;
  614.       b = ~maskrow[i][j];
  615.       fprintf(fout, "0x%x%x", b>>4, b&0x0f);
  616.       if (i == xchr) break;
  617.       fputs(",", fout);
  618.     };
  619.     fputs("\n", fout);
  620.     j++;
  621.     if (j >= (y+sprhgt)) break;
  622.   };
  623. }
  624.  
  625. void emitimgW(int xchr, int y, int sprwid8, int sprhgt, FILE * fout)
  626. { //by columns
  627. BYTE b;
  628. int i;
  629. int j;
  630.   i = xchr;
  631.   while (1) {
  632.     fputs("\tdb ", fout);
  633.     j = y;
  634.     while (1) {
  635.       b = maskrow[i][j];
  636.                   //fprintf(fout, "0x%x%x ", i>>4, i&0x0f);
  637.                   //fprintf(fout, "0x%x%x ", j>>4, j&0x0f);
  638.       fprintf(fout, "0x%x%x", b>>4, b&0x0f);
  639.       j++;
  640.       if (j >= (y+sprhgt)) break;
  641.       fputs(",", fout);
  642.     };
  643.     fputs("\n", fout);
  644.     i++;
  645.     if (i == (xchr+sprwid8)) break;
  646.   };
  647. }
  648.  
  649. void emitchr_(int xchr, int y, FILE * fout)
  650. {
  651. BYTE b;
  652. int j;
  653.   fputs("\tdb ", fout);
  654.   j = y;
  655.   while (1) {
  656.     b = pixrow[xchr][j] ^ invattr;
  657.     fprintf(fout, "0x%x%x", b>>4, b&0x0f);
  658.     j++;
  659.     if (j >= (y+8)) break;
  660.     fputs(",", fout);
  661.   };
  662.   if (sprformat < 'a') { //capital letter format => attr used
  663.     b = attrrow[xchr]; //0x07;
  664.     if (invattr) b = (b&0xc0) + ((b&0x07)<<3) + ((b&0x38)>>3);
  665.     if (forceattr) b = defaultcolor;
  666.     fputs(",", fout);
  667.     fprintf(fout, "0x%x%x", b>>4, b&0x0f);
  668.   };
  669.   fputs("\n", fout);
  670. }
  671.  
  672. void emitchr(int xchr, int y, FILE * fout)
  673. {
  674.   emitchr_(xchr, y, fout);
  675. }
  676.  
  677. void emitchrshift(int xchr, int y, FILE * fout)
  678. {
  679.   emitchr_(xchr, y+PIXROWSHIFT, fout);
  680. }
  681.  
  682. //ёфтшурхь Ё ф чэръюьхёЄ >>shiftbits, Ёхчєы№ЄрЄ т pixrow[sprx][y+PIXROWSHIFT]
  683. void shiftrow(int sprx, int y, int sprwid, int rowhgt, int pixrowshift, BYTE shiftbits)
  684. {
  685. int j;
  686. int x;
  687. BYTE b;
  688. BYTE b0;
  689. BYTE shiftmask;
  690.   shiftmask = (BYTE)(0xff>>(0x08-shiftbits)); //хёыш shiftbits==0x01, Єю shiftmask==0x01
  691.   j = y;
  692.   while (j < (y+rowhgt)) {
  693.     b = 0x00;
  694.     x = sprx;
  695.     while (x < (sprx+sprwid+8)) {
  696.       b0 = pixrow[x/8][j];
  697.       pixrow[x/8][j+pixrowshift] = (BYTE)((b<<(0x08-shiftbits)) + (b0>>shiftbits));
  698.       b = (BYTE)(b0&shiftmask/**0x0f*/); //хёыш shiftbits==0x01, Єю shiftmask==0x01
  699.       x = x+8;
  700.     };
  701.     j++;
  702.   };
  703. }
  704.  
  705. //data: wid8, hgt8, chrgfx, chrgfx...
  706. void resfile(char * finname, char * fintxtname, char * foutname)
  707. {
  708. FILE* fin;
  709. FILE* fintxt;
  710. FILE* fout;
  711. int i;
  712. int j;
  713. int size;
  714. int y;
  715. int x;
  716. int n;
  717. int tiles;
  718. int xi;
  719. int yi;
  720.  
  721. BYTE b;
  722. BYTE bmask;
  723. BYTE b0;
  724.  
  725. int sprx;
  726. int startsprx;
  727. int spry;
  728. int sprwid;
  729. int sprhgt;
  730. int rowhgt; //8 for tiles, sprhgt for sprites
  731.  
  732. UINT color;
  733.  
  734.   fin = fopen(finname, "rb");
  735.   if (fin) {
  736.     fread(filebuf, 10, 1, fin); //skip to 10 (header size)
  737.     size = read4b(fin); //10 (header size)
  738.     fread(filebuf, 4, 1, fin); //skip to 18
  739.     wid = read4b(fin); //18
  740.     hgt = read4b(fin); //22
  741.     fread(filebuf, 2, 1, fin); //skip to 28
  742.     fread(&bpp, 1, 1, fin); //28
  743.     fread(filebuf, 1, 54-29, fin); //skip to pal
  744.     fread(pal, 1, 64, fin); //ярышЄЁр (B, G, R, 0)
  745.     if (size > (54+64)) {fread(filebuf, 1, size-(54+64), fin);}; //skip to pic
  746.     if ((wid>0)&&(wid<=1024)&&(hgt>0)&&(hgt<=1024)&&((wid&7)==0)&&((hgt&7)==0)) {
  747.       y = hgt;
  748.       while (y>0) {
  749.         y--;
  750.         x = 0;
  751.         while (x<wid) {
  752.           fread(&b, 1, 1, fin);
  753.           if (bpp == 8) {
  754.             pic[x][y] = b;
  755.             x++;
  756.           }else {
  757.             pic[x][y] = (BYTE)((b&0xf0)>>4);
  758.             x++;
  759.             pic[x][y] = (BYTE)(b&0x0f);
  760.             x++;
  761.           };
  762.         };
  763.       };
  764.  
  765.       fintxt = fopen(fintxtname, "rb");
  766.       if (fintxt) {
  767.         fout = fopen(foutname, "wb");
  768.         if (fout) {
  769. /**          if (labelname[0]!='\0') {
  770.             fputs(labelname, fout);
  771.             fputs("\n", fout);
  772.           };*/
  773.           while (1) {
  774.             size = readlabel(fintxt, labelbuf); //fread(filebuf, 1, MAXDEFB, fin);
  775.            maxvertsprcount = vertsprcount;
  776.            maxsprcount = sprcount;
  777.             if (size == 0) break;
  778.             invattr = 0x00;
  779.             readlabel(fintxt, formatlabelbuf); //format
  780.             sprformat = *formatlabelbuf;
  781.             if (globalsprformat != '\0') sprformat = globalsprformat;
  782.             startsprx = readnum(fintxt);
  783.             spry = readnum(fintxt);
  784.             sprwid = readnum(fintxt);
  785.             sprhgt = readnum(fintxt);
  786.             numok = 0x00;
  787.             forceattr = 0x00;
  788.             tiles = readnum(fintxt); //юЄёєЄёЄтєхЄ т x
  789.             defaultcolor = (BYTE)tiles; //фы  тёхї, ъЁюьх L
  790.             *commentlabelbuf = '\0';
  791.             if ((numok != 0x00) && (sprformat != 'L')) readcomment(fintxt, commentlabelbuf);
  792.            curvertsprcount = 0;
  793.            do { //vertsprcount
  794.            cursprcount = 0;
  795.            sprx = startsprx;
  796.            do { //sprcount
  797.             if ((sprformat == 'B')||(sprformat == 'b')) {
  798.               putlabel(labelbuf, fout);
  799.               fputs("\n", fout);
  800.               //emitdb((BYTE)(sprwid>>3), fout);
  801.               //emitdb((BYTE)(sprhgt>>3), fout);
  802.               rowhgt = 8;
  803.             }else if (sprformat == 'T') { //эрсюЁ Єрщыют
  804.               fputs("\tds (-$)&0xff\n", fout);
  805.               putlabel(labelbuf, fout);
  806.               fputs("\n", fout);
  807.               rowhgt = 8;
  808.             }else if (sprformat == 'x') { //ёяЁрщЄ 16c
  809.               fputs("\n", fout);
  810.               putlabel(labelbuf, fout);
  811.               fputs("=$+4\n", fout);
  812.               fputs("\n", fout);
  813.               emitdb((BYTE)(sprwid>>1), fout);
  814.               emitdb((BYTE)(sprhgt), fout);
  815.               rowhgt = sprhgt;
  816.             }else if ((sprformat == 'i')||(sprformat == 'I')) { //ърЁЄшэър 16c яю ёЄюысЎрь
  817.               fputs("\n", fout);
  818.               putlabel(labelbuf, fout);
  819.               fputs("\n", fout);
  820.               rowhgt = sprhgt;
  821.             }else if (sprformat == 'L') { //LAND ъръ т ╫┬, фры№°х ёыхфєхЄ ЄрсышЎр - эюьхЁ Єрщыр фы  ърцфющ ъыхЄъш
  822.               fputs("\n", fout);
  823.               putlabel(labelbuf, fout);
  824.               fputs("\n", fout);
  825.               rowhgt = sprhgt;
  826.             }else if (sprformat == 'P') { //DDp palette
  827.               fputs("\n", fout);
  828.               putlabel(labelbuf, fout);
  829.               fputs("\n", fout);
  830.               rowhgt = sprhgt;
  831.               i = 0;
  832.               while (i < 64) { //DDp palette: %grbG11RB(low),%grbG11RB(high), шэтхЁёэ√х //color = highlow
  833.                 color = 0; //pal = ярышЄЁр (B, G, R, 0)
  834.                 if (pal[i]&0x80) color = color | 0x0100;
  835.                 if (pal[i]&0x40) color = color | 0x2000;
  836.                 if (pal[i]&0x20) color = color | 0x0001;
  837.                 if (pal[i]&0x10) color = color | 0x0020;
  838.                 i++;
  839.                 if (pal[i]&0x80) color = color | 0x1000;
  840.                 if (pal[i]&0x40) color = color | 0x8000;
  841.                 if (pal[i]&0x20) color = color | 0x0010;
  842.                 if (pal[i]&0x10) color = color | 0x0080;
  843.                 i++;
  844.                 if (pal[i]&0x80) color = color | 0x0200;
  845.                 if (pal[i]&0x40) color = color | 0x4000;
  846.                 if (pal[i]&0x20) color = color | 0x0002;
  847.                 if (pal[i]&0x10) color = color | 0x0040;
  848.                 i++;
  849.                 emitdw(~color, fout);
  850.                 i++;
  851.               };
  852.               fputs("\n", fout);
  853.             }else if ((sprformat == 'w')||(sprformat == 'W')||(sprformat == 'z')||(sprformat == 'Z')||(sprformat == 'y')) {
  854.               putlabel(labelbuf, fout);
  855.               fputs("\n", fout);
  856.               rowhgt = sprhgt;
  857.             }else if (sprformat == 'c') {
  858.               putlabel(labelbuf, fout);
  859.               fputs("\n", fout);
  860.               rowhgt = sprhgt;
  861.             }else if (sprformat == 's') { //for DizzySE
  862.               putlabel(labelbuf, fout);
  863.               fputs("\n", fout);
  864.               emitdb((BYTE)(sprwid>>3), fout);
  865.               emitdb((BYTE)(sprhgt), fout);
  866.               rowhgt = sprhgt;
  867.             }else if (sprformat == 'S') {
  868.               putlabel(labelbuf, fout);
  869.               fputs("\n", fout);
  870.               rowhgt = 8;
  871.             }else if ((sprformat == 'A')||(sprformat == 'a')) {
  872.               putlabel(labelbuf, fout);
  873.               fputs("\n", fout);
  874.               rowhgt = 8;
  875.             };
  876.  
  877. //copy comment as code line
  878.               fputs(commentlabelbuf, fout);
  879.               //fputs("\n", fout);
  880.  
  881.             y = spry;
  882.             while (y < (spry+sprhgt)) {
  883.               //яхЁхъюфшЁєхь Ё ф чэръюьхёЄ т√ёюЄющ rowhgt
  884.               curink = 0x0f;
  885.               curpaper = 0x08;
  886.               x = 0;//sprx;
  887.               while (x < (sprx+sprwid)) {
  888.                 findinkpaper(x, y);
  889.                 setcurinkpaper(&curink, &curpaper);
  890.               //curink = 0x0f;
  891.               //curpaper = 0x08;
  892. //  if (sprformat == 'c') {
  893. //    curpaper = 0;
  894. //    curink = 1;
  895. //  };
  896.                 j = y;
  897.                 while (j < (y+rowhgt)) {
  898.                   b = 0x00;
  899.                   bmask = 0x00;
  900.                   i = x;
  901.                   while (i < (x+8)) {
  902.                     b = (BYTE)(b<<1);
  903.                     bmask = (BYTE)(bmask<<1);
  904.                     //if (sprformat != 'B') {fprintf(fout, "0x%x%x\n", (pic[i][j])>>4, (pic[i][j])&0x0f);};
  905.                     if (pic[i][j]==curink) b++;
  906.                     if (pic[i][j]!=0x00) bmask++;
  907.                     if (pic[i][j]==0x10) {bmask--; b++;}
  908.                     i++;
  909.                   };
  910.                   pixrow[x/8][j] = b;
  911.                   maskrow[x/8][j] = bmask;
  912.                   //fprintf(fout, "0x%x%x ", x>>4, x&0x0f);
  913.                   //fprintf(fout, "0x%x%x ", j>>4, j&0x0f);
  914.                   //fprintf(fout, "0x%x%x ", b>>4, b&0x0f);
  915.                   //fprintf(fout, "0x%x%x\n", bmask>>4, bmask&0x0f);
  916.                   pixrow[(x/8)+1][j] = 0x00; //ўЄюс√ ёфтшурЄ№
  917.                   j++;
  918.                 };
  919. //ьрёър 0x00 эх ёўшЄрхЄё  ЎтхЄюь, яю¤Єюьє 0x08 яхЁхтюфшЄё  т 0x00 (ўЄюс√ эх тыш Є№ эр bright)
  920.                 b = 0x00; if (curink!=0x08) b = curink;
  921.                 b0 = 0x00; if (curpaper!=0x08) b0 = curpaper;
  922.                 attrrow[x/8    ] = (BYTE)( (((b|b0)&0x08)<<3)+((curpaper&0x07)<<3)+(curink&0x07) );
  923.                 attrrow[(x/8)+1] = (BYTE)( (((b|b0)&0x08)<<3)+((curpaper&0x07)<<3)+(curink&0x07) ); //ўЄюс√ ёфтшурЄ№
  924.                 x = x+8;
  925.               };
  926.   //            shiftrow(sprx, y, sprwid, rowhgt, PIXROWSHIFT, 0x04); //ёфтшурхь Ё ф чэръюьхёЄ >>4, Ёхчєы№ЄрЄ т pixrow[sprx][y+PIXROWSHIFT]
  927.  
  928.               //т√тюфшь т рёь
  929.               if ((sprformat == 'B')||(sprformat == 'b')) { //tiles or bw tiles
  930.                 x = sprx;
  931.                 while (x < (sprx+sprwid)) {
  932.   //                emitchrshift(x/8,y,fout);
  933.                   emitchr(x/8,y,fout); //checks for capital letter in sprformat
  934.                   x = x+8;
  935.                 };
  936.   //              emitchrshift(x/8,y,fout);
  937.               }else if (sprformat == 'T') {
  938.                 x = sprx;
  939.                 while (x < (sprx+sprwid)) {
  940.                   emitchr(x/8,y,fout);
  941.                   x = x+8;
  942.                 };
  943.                 emitnops((BYTE)(0x100-((BYTE)(sprwid>>3)*0x09)),fout);
  944.               }else if (sprformat == '%') { //mirror
  945.                   xi = 0;
  946.                   while (xi < (sprwid/2)) {
  947.                     //fprintf(fout, ";0%x ", sprx+xi);
  948.                     yi = y;
  949.                     while (yi < (y+sprhgt)) {
  950.                       b = pic[sprx+xi][yi]; //L
  951.                       pic[sprx+xi][yi] = pic[sprx+sprwid-1-xi][yi]; //new R
  952.                       pic[sprx+sprwid-1-xi][yi] = b; //new L
  953.                       yi = yi+1;
  954.                     };
  955.                     xi = xi+1;
  956.                   };
  957.                   //fprintf(fout, "\n");
  958.               }else if (sprformat == 'A') { //for coloured lines
  959.                 emitcolorline(sprx/8,y,sprwid/8,sprhgt,fout);
  960.               }else if (sprformat == 'a') { //attr lines
  961.                 emitattrline(sprx/8,y,sprwid/8,sprhgt,fout);
  962.               }else if (sprformat == 's') { //sprite
  963.                 emitspr(sprx/8,y,sprwid/8,sprhgt,fout);
  964.               }else if (sprformat == 'S') { //coloured sprite
  965.                 emitcolorspr(sprx/8,y,sprwid/8,sprhgt,fout);
  966.               }else if (sprformat == 'y') { //spritey
  967.                 emitspry(sprx/8,y,sprwid/8,sprhgt,fout);
  968.               }else if (sprformat == 'w') { //sprite antipixels16, antimask16 right to left
  969.                 emitsprwback(sprx/8,y,sprwid/8,sprhgt,fout);
  970.               }else if (sprformat == 'W') { //sprite antipixels16, antimask16
  971.                 emitsprw(sprx/8,y,sprwid/8,sprhgt,fout);
  972.               }else if (sprformat == 'z') { //unmasked sprite right to left
  973.                 emitsprwnomaskback(sprx/8,y,sprwid/8,sprhgt,fout);
  974.               }else if (sprformat == 'Z') { //unmasked sprite
  975.                 emitsprwnomask(sprx/8,y,sprwid/8,sprhgt,fout);
  976.               }else if (sprformat == 'c') { //b/w image by columns
  977.                 emitimgW(sprx/8,y,sprwid/8,sprhgt,fout);
  978.                 //emitimgW(0,0,128,128,fout);
  979.               };
  980.               y = y+rowhgt;
  981.             }; //while y
  982.  
  983.             if (sprformat == 'x') {
  984.               x = sprx;
  985.               while (x < (sprx+sprwid)) {
  986.                 y = spry;
  987.                 while (y < (spry+sprhgt)) {
  988.                   b = pic[x][y]; //L
  989.                   b0 = pic[x+1][y]; //R
  990.                   bmask = 0; //0x47(L) ш 0xb8(R) т Єхї ьхёЄрї, уфх ЎтхЄ=16:
  991.                   if (b == 16) {bmask = bmask + 0x47; b = 0x00;};
  992.                   if (b0 == 16) {bmask = bmask + 0xb8; b0 = 0x00;};
  993.                   b = ((b&0x08)<<3) + (b&0x07) + ((b0&0x08)<<4) + ((b0&0x07)<<3);
  994.                   fputs("\tdb ", fout);
  995.                   fprintf(fout, "0x%x%x", bmask>>4, bmask&0x0f);
  996.                   fprintf(fout, ",0x%x%x", b>>4, b&0x0f);
  997.                   fputs("\n", fout);
  998.                   y = y+1;
  999.                 };
  1000.                 x = x+2;
  1001.                 if (x < (sprx+sprwid)) {
  1002.                   emitdw(0x4000-((sprhgt-1)*40), fout);
  1003.                 }else {
  1004.                   emitdw(0xffff, fout);
  1005.                 };
  1006.                 fputs("\n", fout);
  1007.               };
  1008.               fputs("\tdw prsprqwid\n", fout);
  1009.             };
  1010.  
  1011.             if (sprformat == 'i') {
  1012.               x = sprx;
  1013.               while (x < (sprx+sprwid)) {
  1014.                 y = spry;
  1015.                 while (y < (spry+sprhgt)) {
  1016.                   b = pic[x][y]; //L
  1017.                   b0 = pic[x+1][y]; //R
  1018.                   b = ((b&0x08)<<3) + (b&0x07) + ((b0&0x08)<<4) + ((b0&0x07)<<3);
  1019.                   fprintf(fout, "\tdb 0x%x%x", b>>4, b&0x0f);
  1020.                   fputs("\n", fout);
  1021.                   y = y+1;
  1022.                 };
  1023.                 x = x+2;
  1024.                 fputs("\n", fout);
  1025.               };
  1026.             };
  1027.  
  1028.             if (sprformat == 'I') {
  1029.               x = sprx;
  1030.               while (x < (sprx+sprwid)) {
  1031.                 BYTE mode = 255;
  1032.                 BYTE newmode = 0;
  1033.                 BYTE transp;
  1034.                 int count = 0;
  1035.                 int sumhgt = 0;
  1036.                 y = spry;
  1037.                 while (1) { //y
  1038.                   //fprintf(fout, "\ty=%d\n", y);
  1039.  
  1040.                   if (y != (spry+sprhgt)) {
  1041.                   //яюёўшЄрЄ№ ўшёыю яЁючЁрўэ√ї яшъёхыхщ
  1042.                     transp = 0;
  1043.                     xi = x;
  1044.                     while (xi < (x+8)) {
  1045.                       if (pic[xi][y] == 16) transp = transp+1;
  1046.                       xi = xi+1;
  1047.                     }
  1048.                     if (transp == 0) { newmode = 1; //ld zone
  1049.                     }else if (transp == 8) { newmode = 0; //empty zone
  1050.                     }else { newmode = 2; //and:or zone
  1051.                     }
  1052.                     if (mode == 255) { mode = newmode; };
  1053.                   };
  1054.  
  1055.                   if (((newmode != mode)||(y == (spry+sprhgt)))&&(count != 0)) {
  1056.                     //fprintf(fout, "\ty=%d, transp=%d, count=%d, mode=%d, newmode=%d\n", y, transp, count, mode, newmode);
  1057.                     fprintf(fout, "\tdb %d,%d\n", mode, count);
  1058.                     sumhgt = sumhgt + count;
  1059.                     yi = y-count;
  1060.                     while (yi != y) {
  1061.                       xi = x;
  1062.                       if (mode == 1) { //ld zone
  1063.                         fprintf(fout, "\tdb ");
  1064.                         while (1) {
  1065.                           b = pic[xi][yi]; //L
  1066.                           b0 = pic[xi+1][yi]; //R
  1067.                           b = ((b&0x08)<<3) + (b&0x07) + ((b0&0x08)<<4) + ((b0&0x07)<<3);
  1068.                           fprintf(fout, "0x%x%x", b>>4, b&0x0f);
  1069.                           xi = xi+2;
  1070.                           if (xi == (x+8)) break;
  1071.                           fputs(",", fout);
  1072.                         }
  1073.                         fputs("\n", fout);
  1074.                       //}else if (mode == 0) { //empty zone
  1075.                       }else if (mode == 2) { //and:or zone
  1076.                         fprintf(fout, "\tdb ");
  1077.                         while (1) {
  1078.                           b = pic[xi][yi]; //L
  1079.                           b0 = pic[xi+1][yi]; //R
  1080.                           bmask = 0; //0x47(L) ш 0xb8(R) т Єхї ьхёЄрї, уфх ЎтхЄ=16:
  1081.                           if (b == 16) {bmask = bmask + 0x47; b = 0x00;};
  1082.                           if (b0 == 16) {bmask = bmask + 0xb8; b0 = 0x00;};
  1083.                           b = ((b&0x08)<<3) + (b&0x07) + ((b0&0x08)<<4) + ((b0&0x07)<<3);
  1084.                           fprintf(fout, "0x%x%x", bmask>>4, bmask&0x0f);
  1085.                           fprintf(fout, ",0x%x%x", b>>4, b&0x0f);
  1086.                           xi = xi+2;
  1087.                           if (xi == (x+8)) break;
  1088.                           fputs(",", fout);
  1089.                         };
  1090.                         fputs("\n", fout);
  1091.                       };
  1092.                       yi = yi+1;
  1093.                     };
  1094.                     mode = newmode;
  1095.                     count = 0;
  1096.                   };
  1097.                   count = count+1;
  1098.  
  1099.                   if (y >= (spry+sprhgt)) break;
  1100.  
  1101.                   y = y+1;
  1102.                 };
  1103.                 x = x+8;
  1104.                 //fprintf(fout, "\tsumhgt=%d\n", sumhgt);
  1105.                 fputs("\n", fout);
  1106.               };
  1107.             };
  1108.  
  1109.             if (sprformat == 'L') { //фрыхх ЄхъёЄ Єшяр (-1=яЁюяєёъ):
  1110. //   -1, -1, -1,114,116,119,121,124,126,-1,-1,-1,-1,-1,-1,-1,
  1111. //  113,118,123,115,117,120,122,125,127,-1,-1,-1,-1,-1,-1,-1
  1112. //фы  ърцфющ  ўхщъш ърЁЄшэъш єърчрэ эюьхЁ Єрщыр
  1113. //р эрь эрфю чряюыэшЄ№ ьрёёшт√ convorderx,y - ъююЁфшэрЄ√ фы  ърцфюую эюьхЁр Єрщыр
  1114. //тёх фюыцэ√ с√Є№ т юфэющ ърЁЄшэъх, шэрўх эх яюыєўшЄё  (яхЁхьх°рэ√ эюьхЁр Єрщыют юс∙шх фы  тёхї ыюърЎшщ ш фы  ъюэъЁхЄэющ)
  1115.               n = 0;
  1116.               while (n < CONVORDERSZ) {
  1117.                 convorderx[n] = 0;
  1118.                 convordery[n] = 0;
  1119.                 n = n+1;
  1120.               };
  1121.  
  1122.                 skiplf(fintxt);
  1123.               //tiles = 0;
  1124.  
  1125.               y = spry;
  1126.               while (y < (spry+sprhgt)) {
  1127.                 x = sprx;
  1128.                 while (x < (sprx+sprwid)) {
  1129.                   n = readnum(fintxt);
  1130.                   if (n != -1) {
  1131.                     convorderx[n] = x;
  1132.                     convordery[n] = y;
  1133.                   };
  1134.                   //fprintf(fout, "\tdb %d\n", n);
  1135.                   //tiles = tiles + 1;
  1136.                   x = x+16;
  1137.                 };
  1138.                 skiplf(fintxt);
  1139.                 //fputs("\n", fout);
  1140.                 y = y+16;
  1141.               };
  1142.  
  1143.               n = 0;
  1144.               while (n < tiles) {
  1145.                 x = convorderx[n];
  1146.                 while (x < (convorderx[n]+16)) {
  1147.                   fputs(" db ", fout);
  1148.                   y = convordery[n];
  1149.                   while (1) {
  1150.                     b = pic[x][y]; //L
  1151.                     b0 = pic[x+1][y]; //R
  1152.                     b = ((b&0x08)<<3) + (b&0x07) + ((b0&0x08)<<4) + ((b0&0x07)<<3);
  1153.                     fprintf(fout, "0x%x%x", b>>4, b&0x0f);
  1154.                     y = y+1;
  1155.                     if (y == (convordery[n]+16)) break;
  1156.                     fputs(",", fout);
  1157.                   };
  1158.                   fputs("\n", fout);
  1159.                   x = x+2;
  1160.                 };
  1161.                 n = n+1;
  1162.               };
  1163.  
  1164.             };
  1165.             sprx = sprx + sprwid;
  1166.             cursprcount++;
  1167.            } while (cursprcount<maxsprcount); //while (sprcount)
  1168.             spry = spry + sprhgt;
  1169.             curvertsprcount++;
  1170.            } while (curvertsprcount<maxvertsprcount); //while (vertsprcount)
  1171.           }; //while (1)
  1172.           fclose(fout);
  1173.         }else {printf("can't open %s",foutname);};
  1174.         fclose(fintxt);
  1175.       }else {printf("can't open %s",fintxtname);};
  1176.     };
  1177.     fclose(fin);
  1178.   }else {printf("can't open %s",finname);};
  1179. }
  1180.  
  1181. int main(int argc,char* argv[])
  1182. {
  1183. //  int i;
  1184.   char *finname;
  1185.   char *fintxtname;
  1186.   char *foutname;
  1187.   finname = "testpic.bmp";
  1188.   fintxtname = "testpic.txt";
  1189.   foutname = "testpic.asm";
  1190.   globalsprformat = '\0';
  1191.  
  1192.   if (argc<4) {
  1193.     printf(
  1194.       "NedoRes\n"
  1195.       "\tnedores.exe file.bmp file.dat(=txt) file.ast(=asm) [-f<format>]\n"
  1196.       "4bpp or 8bpp\n"
  1197.     );
  1198.   }else {
  1199.     finname = argv[1];
  1200.     fintxtname = argv[2];
  1201.     foutname = argv[3];
  1202.     if (argc > 4) if (argv[4][0] == '-') if (argv[4][1] == 'f') globalsprformat = argv[4][2];
  1203.   };
  1204.  
  1205.   resfile(finname, fintxtname, foutname);
  1206.  
  1207.   return 0;
  1208. }