?login_element?

Subversion Repositories NedoOS

Rev

Rev 400 | Rev 922 | 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') {
  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 emitchr_(int xchr, int y, FILE * fout)
  320. {
  321. BYTE b;
  322. int j;
  323.   fputs("\tdb ", fout);
  324.   j = y;
  325.   while (1) {
  326.     b = pixrow[xchr][j];
  327.     fprintf(fout, "0x%x%x", b>>4, b&0x0f);
  328.     j++;
  329.     if (j >= (y+8)) break;
  330.     fputs(",", fout);
  331.   };
  332.   if (sprformat < 'a') { //capital letter format => attr used
  333.     b = attrrow[xchr]; //0x07;
  334.     fputs(",", fout);
  335.     fprintf(fout, "0x%x%x", b>>4, b&0x0f);
  336.   };
  337.   fputs("\n", fout);
  338. }
  339.  
  340. void emitchr(int xchr, int y, FILE * fout)
  341. {
  342.   emitchr_(xchr, y, fout);
  343. }
  344.  
  345. void emitchrshift(int xchr, int y, FILE * fout)
  346. {
  347.   emitchr_(xchr, y+PIXROWSHIFT, fout);
  348. }
  349.  
  350. //ёфтшурхь Ё ф чэръюьхёЄ >>shiftbits, Ёхчєы№ЄрЄ т pixrow[sprx][y+PIXROWSHIFT]
  351. void shiftrow(int sprx, int y, int sprwid, int rowhgt, int pixrowshift, BYTE shiftbits)
  352. {
  353. int j;
  354. int x;
  355. BYTE b;
  356. BYTE b0;
  357. BYTE shiftmask;
  358.   shiftmask = (BYTE)(0xff>>(0x08-shiftbits)); //хёыш shiftbits==0x01, Єю shiftmask==0x01
  359.   j = y;
  360.   while (j < (y+rowhgt)) {
  361.     b = 0x00;
  362.     x = sprx;
  363.     while (x < (sprx+sprwid+8)) {
  364.       b0 = pixrow[x/8][j];
  365.       pixrow[x/8][j+pixrowshift] = (BYTE)((b<<(0x08-shiftbits)) + (b0>>shiftbits));
  366.       b = (BYTE)(b0&shiftmask/**0x0f*/); //хёыш shiftbits==0x01, Єю shiftmask==0x01
  367.       x = x+8;
  368.     };
  369.     j++;
  370.   };
  371. }
  372.  
  373. //data: wid8, hgt8, chrgfx, chrgfx...
  374. void resfile(char * finname, char * fintxtname, char * foutname)
  375. {
  376. FILE* fin;
  377. FILE* fintxt;
  378. FILE* fout;
  379. int i;
  380. int j;
  381. int size;
  382. int y;
  383. int x;
  384. int n;
  385. int tiles;
  386.  
  387. BYTE b;
  388. BYTE bmask;
  389. BYTE b0;
  390.  
  391. int sprx;
  392. int spry;
  393. int sprwid;
  394. int sprhgt;
  395. int rowhgt; //8 for tiles, sprhgt for sprites
  396.  
  397. UINT color;
  398.  
  399.   fin = fopen(finname, "rb");
  400.   if (fin) {
  401.     fread(filebuf, 10, 1, fin); //skip to 10 (header size)
  402.     size = read4b(fin); //10 (header size)
  403.     fread(filebuf, 4, 1, fin); //skip to 18
  404.     wid = read4b(fin); //18
  405.     hgt = read4b(fin); //22
  406.     fread(filebuf, 2, 1, fin); //skip to 28
  407.     fread(&bpp, 1, 1, fin); //28
  408.     fread(filebuf, 1, 54-29, fin); //skip to pal
  409.     fread(pal, 1, 64, fin); //ярышЄЁр (B, G, R, 0)
  410.     if (size > (54+64)) {fread(filebuf, 1, size-(54+64), fin);}; //skip to pic
  411.     if ((wid>0)&&(wid<=1024)&&(hgt>0)&&(hgt<=1024)&&((wid&7)==0)&&((hgt&7)==0)) {
  412.       y = hgt;
  413.       while (y>0) {
  414.         y--;
  415.         x = 0;
  416.         while (x<wid) {
  417.           fread(&b, 1, 1, fin);
  418.           if (bpp == 8) {
  419.             pic[x][y] = b;
  420.             x++;
  421.           }else {
  422.             pic[x][y] = (BYTE)((b&0xf0)>>4);
  423.             x++;
  424.             pic[x][y] = (BYTE)(b&0x0f);
  425.             x++;
  426.           };
  427.         };
  428.       };
  429.  
  430.       fintxt = fopen(fintxtname, "rb");
  431.       if (fintxt) {
  432.         fout = fopen(foutname, "wb");
  433.         if (fout) {
  434. /**          if (labelname[0]!='\0') {
  435.             fputs(labelname, fout);
  436.             fputs("\n", fout);
  437.           };*/
  438.           while (1) {
  439.             size = readlabel(fintxt, labelbuf); //fread(filebuf, 1, MAXDEFB, fin);
  440.             if (size == 0) break;
  441.             readlabel(fintxt, formatlabelbuf); //format
  442.             sprformat = *formatlabelbuf;
  443.             sprx = readnum(fintxt);
  444.             spry = readnum(fintxt);
  445.             sprwid = readnum(fintxt);
  446.             sprhgt = readnum(fintxt);
  447.             tiles = readnum(fintxt); //юЄёєЄёЄтєхЄ т x
  448.             defaultcolor = (BYTE)tiles; //фы  тёхї, ъЁюьх L
  449.  
  450.             if (sprformat == 'B') {
  451.               fputs(labelbuf, fout);
  452.               fputs("\n", fout);
  453.               emitdb((BYTE)(sprwid>>3), fout);
  454.               emitdb((BYTE)(sprhgt>>3), fout);
  455.               rowhgt = 8;
  456.             }else if (sprformat == 'T') { //эрсюЁ Єрщыют
  457.               fputs("\tds (-$)&0xff\n", fout);
  458.               fputs(labelbuf, fout);
  459.               fputs("\n", fout);
  460.               rowhgt = 8;
  461.             }else if (sprformat == 'x') { //ёяЁрщЄ 16c
  462.               fputs("\n", fout);
  463.               fputs(labelbuf, fout);
  464.               fputs("=$+4\n", fout);
  465.               fputs("\n", fout);
  466.               emitdb((BYTE)(sprwid>>1), fout);
  467.               emitdb((BYTE)(sprhgt), fout);
  468.               rowhgt = sprhgt;
  469.             }else if (sprformat == 'i') { //ърЁЄшэър 16c яю ёЄюысЎрь
  470.               fputs("\n", fout);
  471.               fputs(labelbuf, fout);
  472.               fputs("\n", fout);
  473.               rowhgt = sprhgt;
  474.             }else if (sprformat == 'L') { //LAND ъръ т ╫┬, фры№°х ёыхфєхЄ ЄрсышЎр - эюьхЁ Єрщыр фы  ърцфющ ъыхЄъш
  475.               fputs("\n", fout);
  476.               fputs(labelbuf, fout);
  477.               fputs("\n", fout);
  478.               rowhgt = sprhgt;
  479.             }else if (sprformat == 'P') { //DDp palette
  480.               fputs("\n", fout);
  481.               fputs(labelbuf, fout);
  482.               fputs("\n", fout);
  483.               i = 0;
  484.               while (i < 64) { //DDp palette: %grbG11RB(low),%grbG11RB(high), шэтхЁёэ√х //color = highlow
  485.                 color = 0; //pal = ярышЄЁр (B, G, R, 0)
  486.                 if (pal[i]&0x80) color = color | 0x0100;
  487.                 if (pal[i]&0x40) color = color | 0x2000;
  488.                 if (pal[i]&0x20) color = color | 0x0001;
  489.                 if (pal[i]&0x10) color = color | 0x0020;
  490.                 i++;
  491.                 if (pal[i]&0x80) color = color | 0x1000;
  492.                 if (pal[i]&0x40) color = color | 0x8000;
  493.                 if (pal[i]&0x20) color = color | 0x0010;
  494.                 if (pal[i]&0x10) color = color | 0x0080;
  495.                 i++;
  496.                 if (pal[i]&0x80) color = color | 0x0200;
  497.                 if (pal[i]&0x40) color = color | 0x4000;
  498.                 if (pal[i]&0x20) color = color | 0x0002;
  499.                 if (pal[i]&0x10) color = color | 0x0040;
  500.                 i++;
  501.                 emitdw(~color, fout);
  502.                 i++;
  503.               };
  504.               fputs("\n", fout);
  505.               rowhgt = sprhgt;
  506.             }else { //'s'
  507.               fputs(labelbuf, fout);
  508.               fputs("\n", fout);
  509.               emitdb((BYTE)(sprwid>>3), fout);
  510.               emitdb((BYTE)(sprhgt), fout);
  511.               rowhgt = sprhgt;
  512.             };
  513.  
  514.             y = spry;
  515.             while (y < (spry+sprhgt)) {
  516.               //яхЁхъюфшЁєхь Ё ф чэръюьхёЄ т√ёюЄющ rowhgt
  517.               curink = 0x0f;
  518.               curpaper = 0x08;
  519.               x = sprx;
  520.               while (x < (sprx+sprwid)) {
  521.                 findinkpaper(x, y);
  522.                 setcurinkpaper(&curink, &curpaper);
  523.               //curink = 0x0f;
  524.               //curpaper = 0x08;
  525.                 j = y;
  526.                 while (j < (y+rowhgt)) {
  527.                   b = 0x00;
  528.                   bmask = 0x00;
  529.                   i = x;
  530.                   while (i < (x+8)) {
  531.                     b = (BYTE)(b<<1);
  532.                     bmask = (BYTE)(bmask<<1);
  533.                     //if (sprformat != 'B') {fprintf(fout, "0x%x%x\n", (pic[i][j])>>4, (pic[i][j])&0x0f);};
  534.                     if (pic[i][j]==curink) b++;
  535.                     if (pic[i][j]!=0x00) bmask++;
  536.                     i++;
  537.                   };
  538.                   pixrow[x/8][j] = b;
  539.                   maskrow[x/8][j] = bmask;
  540.                   pixrow[(x/8)+1][j] = 0x00; //ўЄюс√ ёфтшурЄ№
  541.                   j++;
  542.                 };
  543. //ьрёър 0x00 эх ёўшЄрхЄё  ЎтхЄюь, яю¤Єюьє 0x08 яхЁхтюфшЄё  т 0x00 (ўЄюс√ эх тыш Є№ эр bright)
  544.                 b = 0x00; if (curink!=0x08) b = curink;
  545.                 b0 = 0x00; if (curpaper!=0x08) b0 = curpaper;
  546.                 attrrow[x/8    ] = (BYTE)( (((b|b0)&0x08)<<3)+((curpaper&0x07)<<3)+(curink&0x07) );
  547.                 attrrow[(x/8)+1] = (BYTE)( (((b|b0)&0x08)<<3)+((curpaper&0x07)<<3)+(curink&0x07) ); //ўЄюс√ ёфтшурЄ№
  548.                 x = x+8;
  549.               };
  550.   //            shiftrow(sprx, y, sprwid, rowhgt, PIXROWSHIFT, 0x04); //ёфтшурхь Ё ф чэръюьхёЄ >>4, Ёхчєы№ЄрЄ т pixrow[sprx][y+PIXROWSHIFT]
  551.  
  552.               //т√тюфшь т рёь
  553.               if (sprformat == 'B') { //tiles
  554.                 x = sprx;
  555.                 while (x < (sprx+sprwid)) {
  556.   //                emitchrshift(x/8,y,fout);
  557.                   emitchr(x/8,y,fout);
  558.                   x = x+8;
  559.                 };
  560.   //              emitchrshift(x/8,y,fout);
  561.               }else if (sprformat == 'T') {
  562.                 x = sprx;
  563.                 while (x < (sprx+sprwid)) {
  564.                   emitchr(x/8,y,fout);
  565.                   x = x+8;
  566.                 };
  567.                 emitnops((BYTE)(0x100-((BYTE)(sprwid>>3)*0x09)),fout);
  568.               }else if (sprformat == 's') { //sprite
  569.                 emitspr(sprx/8,y,sprwid/8,sprhgt,fout);
  570.               };
  571.               y = y+rowhgt;
  572.             }; //while y
  573.  
  574.             if (sprformat == 'x') {
  575.               x = sprx;
  576.               while (x < (sprx+sprwid)) {
  577.                 y = spry;
  578.                 while (y < (spry+sprhgt)) {
  579.                   b = pic[x][y]; //L
  580.                   b0 = pic[x+1][y]; //R
  581.                   bmask = 0; //0x47(L) ш 0xb8(R) т Єхї ьхёЄрї, уфх ЎтхЄ=16:
  582.                   if (b == 16) {bmask = bmask + 0x47; b = 0x00;};
  583.                   if (b0 == 16) {bmask = bmask + 0xb8; b0 = 0x00;};
  584.                   b = ((b&0x08)<<3) + (b&0x07) + ((b0&0x08)<<4) + ((b0&0x07)<<3);
  585.                   fputs("\tdb ", fout);
  586.                   fprintf(fout, "0x%x%x", bmask>>4, bmask&0x0f);
  587.                   fprintf(fout, ",0x%x%x", b>>4, b&0x0f);
  588.                   fputs("\n", fout);
  589.                   y = y+1;
  590.                 };
  591.                 x = x+2;
  592.                 if (x < (sprx+sprwid)) {
  593.                   emitdw(0x4000-((sprhgt-1)*40), fout);
  594.                 }else {
  595.                   emitdw(0xffff, fout);
  596.                 };
  597.                 fputs("\n", fout);
  598.               };
  599.               fputs("\tdw prsprqwid\n", fout);
  600.             };
  601.  
  602.             if (sprformat == 'i') {
  603.               x = sprx;
  604.               while (x < (sprx+sprwid)) {
  605.                 y = spry;
  606.                 while (y < (spry+sprhgt)) {
  607.                   b = pic[x][y]; //L
  608.                   b0 = pic[x+1][y]; //R
  609.                   b = ((b&0x08)<<3) + (b&0x07) + ((b0&0x08)<<4) + ((b0&0x07)<<3);
  610.                   fprintf(fout, "\tdb 0x%x%x", b>>4, b&0x0f);
  611.                   fputs("\n", fout);
  612.                   y = y+1;
  613.                 };
  614.                 x = x+2;
  615.                 fputs("\n", fout);
  616.               };
  617.             };
  618.  
  619.             if (sprformat == 'L') { //фрыхх ЄхъёЄ Єшяр (-1=яЁюяєёъ):
  620. //   -1, -1, -1,114,116,119,121,124,126,-1,-1,-1,-1,-1,-1,-1,
  621. //  113,118,123,115,117,120,122,125,127,-1,-1,-1,-1,-1,-1,-1
  622. //фы  ърцфющ  ўхщъш ърЁЄшэъш єърчрэ эюьхЁ Єрщыр
  623. //р эрь эрфю чряюыэшЄ№ ьрёёшт√ convorderx,y - ъююЁфшэрЄ√ фы  ърцфюую эюьхЁр Єрщыр
  624. //тёх фюыцэ√ с√Є№ т юфэющ ърЁЄшэъх, шэрўх эх яюыєўшЄё  (яхЁхьх°рэ√ эюьхЁр Єрщыют юс∙шх фы  тёхї ыюърЎшщ ш фы  ъюэъЁхЄэющ)
  625.               n = 0;
  626.               while (n < CONVORDERSZ) {
  627.                 convorderx[n] = 0;
  628.                 convordery[n] = 0;
  629.                 n = n+1;
  630.               };
  631.  
  632.                 skiplf(fintxt);
  633.               //tiles = 0;
  634.  
  635.               y = spry;
  636.               while (y < (spry+sprhgt)) {
  637.                 x = sprx;
  638.                 while (x < (sprx+sprwid)) {
  639.                   n = readnum(fintxt);
  640.                   if (n != -1) {
  641.                     convorderx[n] = x;
  642.                     convordery[n] = y;
  643.                   };
  644.                   //fprintf(fout, "\tdb %d\n", n);
  645.                   //tiles = tiles + 1;
  646.                   x = x+16;
  647.                 };
  648.                 skiplf(fintxt);
  649.                 //fputs("\n", fout);
  650.                 y = y+16;
  651.               };
  652.  
  653.               n = 0;
  654.               while (n < tiles) {
  655.                 x = convorderx[n];
  656.                 while (x < (convorderx[n]+16)) {
  657.                   fputs(" db ", fout);
  658.                   y = convordery[n];
  659.                   while (1) {
  660.                     b = pic[x][y]; //L
  661.                     b0 = pic[x+1][y]; //R
  662.                     b = ((b&0x08)<<3) + (b&0x07) + ((b0&0x08)<<4) + ((b0&0x07)<<3);
  663.                     fprintf(fout, "0x%x%x", b>>4, b&0x0f);
  664.                     y = y+1;
  665.                     if (y == (convordery[n]+16)) break;
  666.                     fputs(",", fout);
  667.                   };
  668.                   fputs("\n", fout);
  669.                   x = x+2;
  670.                 };
  671.                 n = n+1;
  672.               };
  673.  
  674.             };
  675.  
  676.           }; //while (1)
  677.           fclose(fout);
  678.         }else {printf("can't open %s",foutname);};
  679.         fclose(fintxt);
  680.       }else {printf("can't open %s",fintxtname);};
  681.     };
  682.     fclose(fin);
  683.   }else {printf("can't open %s",finname);};
  684. }
  685.  
  686. int main(int argc,char* argv[])
  687. {
  688. //  int i;
  689.   char *finname;
  690.   char *fintxtname;
  691.   char *foutname;
  692.   finname = "testpic.bmp";
  693.   fintxtname = "testpic.txt";
  694.   foutname = "testpic.asm";
  695.  
  696.   if (argc<4) {
  697.     printf(
  698.       "NedoRes\n"
  699.       "\tnedores.exe file.bmp file.dat(=txt) file.ast(=asm)\n"
  700.       "4bpp or 8bpp\n"
  701.     );
  702.   }else {
  703.     finname = argv[1];
  704.     fintxtname = argv[2];
  705.     foutname = argv[3];
  706.   };
  707.  
  708.   resfile(finname, fintxtname, foutname);
  709.  
  710.   return 0;
  711. }