?login_element?

Subversion Repositories NedoOS

Rev

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