Subversion Repositories NedoOS

Rev

Rev 930 | Rev 1033 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. //#include <mem.h>
  4. #include <string.h>
  5.  
  6. #define _STRMAX 79
  7.  
  8. #define BYTE unsigned char
  9. #define UINT unsigned int
  10. #define MAXDEFB 8
  11.  
  12. #define MASKCOLOR 0x00
  13.  
  14. BYTE filebuf[65536];
  15. char labelbuf[_STRMAX+1];
  16. char formatlabelbuf[_STRMAX+1];
  17. BYTE sizeword[4];
  18. BYTE pic[1024][1024];
  19. BYTE pixrow[1024/8+1][1024+1024];
  20. #define PIXROWSHIFT 1024
  21. BYTE maskrow[1024/8+1][1024];
  22. //BYTE pixrowshift[1024/8][1024]; //>>4
  23. BYTE attrrow[1024/8+1];
  24. BYTE pal[64];
  25.  
  26. #define CONVORDERSZ 1024
  27.  
  28. int convorderx[CONVORDERSZ]; //фы  ърцфюую эюьхЁр Єрщыр ъююЁфшэрЄ√
  29. int convordery[CONVORDERSZ]; //фы  ърцфюую эюьхЁр Єрщыр ъююЁфшэрЄ√
  30.  
  31. 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 emitimgW(int xchr, int y, int sprwid8, int sprhgt, FILE * fout)
  353. { //by columns
  354. BYTE b;
  355. int i;
  356. int j;
  357.   i = xchr;
  358.   while (1) {
  359.     fputs("\tdb ", fout);
  360.     j = y;
  361.     while (1) {
  362.       b = maskrow[i][j];
  363.                   //fprintf(fout, "0x%x%x ", i>>4, i&0x0f);
  364.                   //fprintf(fout, "0x%x%x ", j>>4, j&0x0f);
  365.       fprintf(fout, "0x%x%x", b>>4, b&0x0f);
  366.       j++;
  367.       if (j >= (y+sprhgt)) break;
  368.       fputs(",", fout);
  369.     };
  370.     fputs("\n", fout);
  371.     i++;
  372.     if (i == (xchr+sprwid8)) break;
  373.   };
  374. }
  375.  
  376. void emitchr_(int xchr, int y, FILE * fout)
  377. {
  378. BYTE b;
  379. int j;
  380.   fputs("\tdb ", fout);
  381.   j = y;
  382.   while (1) {
  383.     b = pixrow[xchr][j];
  384.     fprintf(fout, "0x%x%x", b>>4, b&0x0f);
  385.     j++;
  386.     if (j >= (y+8)) break;
  387.     fputs(",", fout);
  388.   };
  389.   if (sprformat < 'a') { //capital letter format => attr used
  390.     b = attrrow[xchr]; //0x07;
  391.     fputs(",", fout);
  392.     fprintf(fout, "0x%x%x", b>>4, b&0x0f);
  393.   };
  394.   fputs("\n", fout);
  395. }
  396.  
  397. void emitchr(int xchr, int y, FILE * fout)
  398. {
  399.   emitchr_(xchr, y, fout);
  400. }
  401.  
  402. void emitchrshift(int xchr, int y, FILE * fout)
  403. {
  404.   emitchr_(xchr, y+PIXROWSHIFT, fout);
  405. }
  406.  
  407. //ёфтшурхь Ё ф чэръюьхёЄ >>shiftbits, Ёхчєы№ЄрЄ т pixrow[sprx][y+PIXROWSHIFT]
  408. void shiftrow(int sprx, int y, int sprwid, int rowhgt, int pixrowshift, BYTE shiftbits)
  409. {
  410. int j;
  411. int x;
  412. BYTE b;
  413. BYTE b0;
  414. BYTE shiftmask;
  415.   shiftmask = (BYTE)(0xff>>(0x08-shiftbits)); //хёыш shiftbits==0x01, Єю shiftmask==0x01
  416.   j = y;
  417.   while (j < (y+rowhgt)) {
  418.     b = 0x00;
  419.     x = sprx;
  420.     while (x < (sprx+sprwid+8)) {
  421.       b0 = pixrow[x/8][j];
  422.       pixrow[x/8][j+pixrowshift] = (BYTE)((b<<(0x08-shiftbits)) + (b0>>shiftbits));
  423.       b = (BYTE)(b0&shiftmask/**0x0f*/); //хёыш shiftbits==0x01, Єю shiftmask==0x01
  424.       x = x+8;
  425.     };
  426.     j++;
  427.   };
  428. }
  429.  
  430. //data: wid8, hgt8, chrgfx, chrgfx...
  431. void resfile(char * finname, char * fintxtname, char * foutname)
  432. {
  433. FILE* fin;
  434. FILE* fintxt;
  435. FILE* fout;
  436. int i;
  437. int j;
  438. int size;
  439. int y;
  440. int x;
  441. int n;
  442. int tiles;
  443.  
  444. BYTE b;
  445. BYTE bmask;
  446. BYTE b0;
  447.  
  448. int sprx;
  449. int spry;
  450. int sprwid;
  451. int sprhgt;
  452. int rowhgt; //8 for tiles, sprhgt for sprites
  453.  
  454. UINT color;
  455.  
  456.   fin = fopen(finname, "rb");
  457.   if (fin) {
  458.     fread(filebuf, 10, 1, fin); //skip to 10 (header size)
  459.     size = read4b(fin); //10 (header size)
  460.     fread(filebuf, 4, 1, fin); //skip to 18
  461.     wid = read4b(fin); //18
  462.     hgt = read4b(fin); //22
  463.     fread(filebuf, 2, 1, fin); //skip to 28
  464.     fread(&bpp, 1, 1, fin); //28
  465.     fread(filebuf, 1, 54-29, fin); //skip to pal
  466.     fread(pal, 1, 64, fin); //ярышЄЁр (B, G, R, 0)
  467.     if (size > (54+64)) {fread(filebuf, 1, size-(54+64), fin);}; //skip to pic
  468.     if ((wid>0)&&(wid<=1024)&&(hgt>0)&&(hgt<=1024)&&((wid&7)==0)&&((hgt&7)==0)) {
  469.       y = hgt;
  470.       while (y>0) {
  471.         y--;
  472.         x = 0;
  473.         while (x<wid) {
  474.           fread(&b, 1, 1, fin);
  475.           if (bpp == 8) {
  476.             pic[x][y] = b;
  477.             x++;
  478.           }else {
  479.             pic[x][y] = (BYTE)((b&0xf0)>>4);
  480.             x++;
  481.             pic[x][y] = (BYTE)(b&0x0f);
  482.             x++;
  483.           };
  484.         };
  485.       };
  486.  
  487.       fintxt = fopen(fintxtname, "rb");
  488.       if (fintxt) {
  489.         fout = fopen(foutname, "wb");
  490.         if (fout) {
  491. /**          if (labelname[0]!='\0') {
  492.             fputs(labelname, fout);
  493.             fputs("\n", fout);
  494.           };*/
  495.           while (1) {
  496.             size = readlabel(fintxt, labelbuf); //fread(filebuf, 1, MAXDEFB, fin);
  497.             if (size == 0) break;
  498.             readlabel(fintxt, formatlabelbuf); //format
  499.             sprformat = *formatlabelbuf;
  500.             sprx = readnum(fintxt);
  501.             spry = readnum(fintxt);
  502.             sprwid = readnum(fintxt);
  503.             sprhgt = readnum(fintxt);
  504.             tiles = readnum(fintxt); //юЄёєЄёЄтєхЄ т x
  505.             defaultcolor = (BYTE)tiles; //фы  тёхї, ъЁюьх L
  506.  
  507.             if (sprformat == 'B') {
  508.               fputs(labelbuf, fout);
  509.               fputs("\n", fout);
  510.               emitdb((BYTE)(sprwid>>3), fout);
  511.               emitdb((BYTE)(sprhgt>>3), fout);
  512.               rowhgt = 8;
  513.             }else if (sprformat == 'T') { //эрсюЁ Єрщыют
  514.               fputs("\tds (-$)&0xff\n", fout);
  515.               fputs(labelbuf, fout);
  516.               fputs("\n", fout);
  517.               rowhgt = 8;
  518.             }else if (sprformat == 'x') { //ёяЁрщЄ 16c
  519.               fputs("\n", fout);
  520.               fputs(labelbuf, fout);
  521.               fputs("=$+4\n", fout);
  522.               fputs("\n", fout);
  523.               emitdb((BYTE)(sprwid>>1), fout);
  524.               emitdb((BYTE)(sprhgt), fout);
  525.               rowhgt = sprhgt;
  526.             }else if (sprformat == 'i') { //ърЁЄшэър 16c яю ёЄюысЎрь
  527.               fputs("\n", fout);
  528.               fputs(labelbuf, fout);
  529.               fputs("\n", fout);
  530.               rowhgt = sprhgt;
  531.             }else if (sprformat == 'L') { //LAND ъръ т ╫┬, фры№°х ёыхфєхЄ ЄрсышЎр - эюьхЁ Єрщыр фы  ърцфющ ъыхЄъш
  532.               fputs("\n", fout);
  533.               fputs(labelbuf, fout);
  534.               fputs("\n", fout);
  535.               rowhgt = sprhgt;
  536.             }else if (sprformat == 'P') { //DDp palette
  537.               fputs("\n", fout);
  538.               fputs(labelbuf, fout);
  539.               fputs("\n", fout);
  540.               i = 0;
  541.               while (i < 64) { //DDp palette: %grbG11RB(low),%grbG11RB(high), шэтхЁёэ√х //color = highlow
  542.                 color = 0; //pal = ярышЄЁр (B, G, R, 0)
  543.                 if (pal[i]&0x80) color = color | 0x0100;
  544.                 if (pal[i]&0x40) color = color | 0x2000;
  545.                 if (pal[i]&0x20) color = color | 0x0001;
  546.                 if (pal[i]&0x10) color = color | 0x0020;
  547.                 i++;
  548.                 if (pal[i]&0x80) color = color | 0x1000;
  549.                 if (pal[i]&0x40) color = color | 0x8000;
  550.                 if (pal[i]&0x20) color = color | 0x0010;
  551.                 if (pal[i]&0x10) color = color | 0x0080;
  552.                 i++;
  553.                 if (pal[i]&0x80) color = color | 0x0200;
  554.                 if (pal[i]&0x40) color = color | 0x4000;
  555.                 if (pal[i]&0x20) color = color | 0x0002;
  556.                 if (pal[i]&0x10) color = color | 0x0040;
  557.                 i++;
  558.                 emitdw(~color, fout);
  559.                 i++;
  560.               };
  561.               fputs("\n", fout);
  562.               rowhgt = sprhgt;
  563.             }else if (sprformat == 'w') {
  564.               fputs(labelbuf, fout);
  565.               fputs("\n", fout);
  566.               rowhgt = sprhgt;
  567.             }else if (sprformat == 'W') {
  568.               fputs(labelbuf, fout);
  569.               fputs("\n", fout);
  570.               rowhgt = sprhgt;
  571.             }else { //'s'
  572.               fputs(labelbuf, fout);
  573.               fputs("\n", fout);
  574.               emitdb((BYTE)(sprwid>>3), fout);
  575.               emitdb((BYTE)(sprhgt), fout);
  576.               rowhgt = sprhgt;
  577.             };
  578.  
  579.             y = spry;
  580.             while (y < (spry+sprhgt)) {
  581.               //яхЁхъюфшЁєхь Ё ф чэръюьхёЄ т√ёюЄющ rowhgt
  582.               curink = 0x0f;
  583.               curpaper = 0x08;
  584.               x = 0;//sprx;
  585.               while (x < (sprx+sprwid)) {
  586.                 findinkpaper(x, y);
  587.                 setcurinkpaper(&curink, &curpaper);
  588.               //curink = 0x0f;
  589.               //curpaper = 0x08;
  590. //  if (sprformat == 'W') {
  591. //    curpaper = 0;
  592. //    curink = 1;
  593. //  };
  594.                 j = y;
  595.                 while (j < (y+rowhgt)) {
  596.                   b = 0x00;
  597.                   bmask = 0x00;
  598.                   i = x;
  599.                   while (i < (x+8)) {
  600.                     b = (BYTE)(b<<1);
  601.                     bmask = (BYTE)(bmask<<1);
  602.                     //if (sprformat != 'B') {fprintf(fout, "0x%x%x\n", (pic[i][j])>>4, (pic[i][j])&0x0f);};
  603.                     if (pic[i][j]==curink) b++;
  604.                     if (pic[i][j]!=0x00) bmask++;
  605.                     i++;
  606.                   };
  607.                   pixrow[x/8][j] = b;
  608.                   maskrow[x/8][j] = bmask;
  609.                   //fprintf(fout, "0x%x%x ", x>>4, x&0x0f);
  610.                   //fprintf(fout, "0x%x%x ", j>>4, j&0x0f);
  611.                   //fprintf(fout, "0x%x%x ", b>>4, b&0x0f);
  612.                   //fprintf(fout, "0x%x%x\n", bmask>>4, bmask&0x0f);
  613.                   pixrow[(x/8)+1][j] = 0x00; //ўЄюс√ ёфтшурЄ№
  614.                   j++;
  615.                 };
  616. //ьрёър 0x00 эх ёўшЄрхЄё  ЎтхЄюь, яю¤Єюьє 0x08 яхЁхтюфшЄё  т 0x00 (ўЄюс√ эх тыш Є№ эр bright)
  617.                 b = 0x00; if (curink!=0x08) b = curink;
  618.                 b0 = 0x00; if (curpaper!=0x08) b0 = curpaper;
  619.                 attrrow[x/8    ] = (BYTE)( (((b|b0)&0x08)<<3)+((curpaper&0x07)<<3)+(curink&0x07) );
  620.                 attrrow[(x/8)+1] = (BYTE)( (((b|b0)&0x08)<<3)+((curpaper&0x07)<<3)+(curink&0x07) ); //ўЄюс√ ёфтшурЄ№
  621.                 x = x+8;
  622.               };
  623.   //            shiftrow(sprx, y, sprwid, rowhgt, PIXROWSHIFT, 0x04); //ёфтшурхь Ё ф чэръюьхёЄ >>4, Ёхчєы№ЄрЄ т pixrow[sprx][y+PIXROWSHIFT]
  624.  
  625.               //т√тюфшь т рёь
  626.               if (sprformat == 'B') { //tiles
  627.                 x = sprx;
  628.                 while (x < (sprx+sprwid)) {
  629.   //                emitchrshift(x/8,y,fout);
  630.                   emitchr(x/8,y,fout);
  631.                   x = x+8;
  632.                 };
  633.   //              emitchrshift(x/8,y,fout);
  634.               }else if (sprformat == 'T') {
  635.                 x = sprx;
  636.                 while (x < (sprx+sprwid)) {
  637.                   emitchr(x/8,y,fout);
  638.                   x = x+8;
  639.                 };
  640.                 emitnops((BYTE)(0x100-((BYTE)(sprwid>>3)*0x09)),fout);
  641.               }else if (sprformat == 's') { //sprite
  642.                 emitspr(sprx/8,y,sprwid/8,sprhgt,fout);
  643.               }else if (sprformat == 'w') { //sprite antipixels16, antimask16
  644.                 emitsprw(sprx/8,y,sprwid/8,sprhgt,fout);
  645.               }else if (sprformat == 'W') { //b/w image by columns
  646.                 emitimgW(sprx/8,y,sprwid/8,sprhgt,fout);
  647.                 //emitimgW(0,0,128,128,fout);
  648.               };
  649.               y = y+rowhgt;
  650.             }; //while y
  651.  
  652.             if (sprformat == 'x') {
  653.               x = sprx;
  654.               while (x < (sprx+sprwid)) {
  655.                 y = spry;
  656.                 while (y < (spry+sprhgt)) {
  657.                   b = pic[x][y]; //L
  658.                   b0 = pic[x+1][y]; //R
  659.                   bmask = 0; //0x47(L) ш 0xb8(R) т Єхї ьхёЄрї, уфх ЎтхЄ=16:
  660.                   if (b == 16) {bmask = bmask + 0x47; b = 0x00;};
  661.                   if (b0 == 16) {bmask = bmask + 0xb8; b0 = 0x00;};
  662.                   b = ((b&0x08)<<3) + (b&0x07) + ((b0&0x08)<<4) + ((b0&0x07)<<3);
  663.                   fputs("\tdb ", fout);
  664.                   fprintf(fout, "0x%x%x", bmask>>4, bmask&0x0f);
  665.                   fprintf(fout, ",0x%x%x", b>>4, b&0x0f);
  666.                   fputs("\n", fout);
  667.                   y = y+1;
  668.                 };
  669.                 x = x+2;
  670.                 if (x < (sprx+sprwid)) {
  671.                   emitdw(0x4000-((sprhgt-1)*40), fout);
  672.                 }else {
  673.                   emitdw(0xffff, fout);
  674.                 };
  675.                 fputs("\n", fout);
  676.               };
  677.               fputs("\tdw prsprqwid\n", fout);
  678.             };
  679.  
  680.             if (sprformat == 'i') {
  681.               x = sprx;
  682.               while (x < (sprx+sprwid)) {
  683.                 y = spry;
  684.                 while (y < (spry+sprhgt)) {
  685.                   b = pic[x][y]; //L
  686.                   b0 = pic[x+1][y]; //R
  687.                   b = ((b&0x08)<<3) + (b&0x07) + ((b0&0x08)<<4) + ((b0&0x07)<<3);
  688.                   fprintf(fout, "\tdb 0x%x%x", b>>4, b&0x0f);
  689.                   fputs("\n", fout);
  690.                   y = y+1;
  691.                 };
  692.                 x = x+2;
  693.                 fputs("\n", fout);
  694.               };
  695.             };
  696.  
  697.             if (sprformat == 'L') { //фрыхх ЄхъёЄ Єшяр (-1=яЁюяєёъ):
  698. //   -1, -1, -1,114,116,119,121,124,126,-1,-1,-1,-1,-1,-1,-1,
  699. //  113,118,123,115,117,120,122,125,127,-1,-1,-1,-1,-1,-1,-1
  700. //фы  ърцфющ  ўхщъш ърЁЄшэъш єърчрэ эюьхЁ Єрщыр
  701. //р эрь эрфю чряюыэшЄ№ ьрёёшт√ convorderx,y - ъююЁфшэрЄ√ фы  ърцфюую эюьхЁр Єрщыр
  702. //тёх фюыцэ√ с√Є№ т юфэющ ърЁЄшэъх, шэрўх эх яюыєўшЄё  (яхЁхьх°рэ√ эюьхЁр Єрщыют юс∙шх фы  тёхї ыюърЎшщ ш фы  ъюэъЁхЄэющ)
  703.               n = 0;
  704.               while (n < CONVORDERSZ) {
  705.                 convorderx[n] = 0;
  706.                 convordery[n] = 0;
  707.                 n = n+1;
  708.               };
  709.  
  710.                 skiplf(fintxt);
  711.               //tiles = 0;
  712.  
  713.               y = spry;
  714.               while (y < (spry+sprhgt)) {
  715.                 x = sprx;
  716.                 while (x < (sprx+sprwid)) {
  717.                   n = readnum(fintxt);
  718.                   if (n != -1) {
  719.                     convorderx[n] = x;
  720.                     convordery[n] = y;
  721.                   };
  722.                   //fprintf(fout, "\tdb %d\n", n);
  723.                   //tiles = tiles + 1;
  724.                   x = x+16;
  725.                 };
  726.                 skiplf(fintxt);
  727.                 //fputs("\n", fout);
  728.                 y = y+16;
  729.               };
  730.  
  731.               n = 0;
  732.               while (n < tiles) {
  733.                 x = convorderx[n];
  734.                 while (x < (convorderx[n]+16)) {
  735.                   fputs(" db ", fout);
  736.                   y = convordery[n];
  737.                   while (1) {
  738.                     b = pic[x][y]; //L
  739.                     b0 = pic[x+1][y]; //R
  740.                     b = ((b&0x08)<<3) + (b&0x07) + ((b0&0x08)<<4) + ((b0&0x07)<<3);
  741.                     fprintf(fout, "0x%x%x", b>>4, b&0x0f);
  742.                     y = y+1;
  743.                     if (y == (convordery[n]+16)) break;
  744.                     fputs(",", fout);
  745.                   };
  746.                   fputs("\n", fout);
  747.                   x = x+2;
  748.                 };
  749.                 n = n+1;
  750.               };
  751.  
  752.             };
  753.  
  754.           }; //while (1)
  755.           fclose(fout);
  756.         }else {printf("can't open %s",foutname);};
  757.         fclose(fintxt);
  758.       }else {printf("can't open %s",fintxtname);};
  759.     };
  760.     fclose(fin);
  761.   }else {printf("can't open %s",finname);};
  762. }
  763.  
  764. int main(int argc,char* argv[])
  765. {
  766. //  int i;
  767.   char *finname;
  768.   char *fintxtname;
  769.   char *foutname;
  770.   finname = "testpic.bmp";
  771.   fintxtname = "testpic.txt";
  772.   foutname = "testpic.asm";
  773.  
  774.   if (argc<4) {
  775.     printf(
  776.       "NedoRes\n"
  777.       "\tnedores.exe file.bmp file.dat(=txt) file.ast(=asm)\n"
  778.       "4bpp or 8bpp\n"
  779.     );
  780.   }else {
  781.     finname = argv[1];
  782.     fintxtname = argv[2];
  783.     foutname = argv[3];
  784.   };
  785.  
  786.   resfile(finname, fintxtname, foutname);
  787.  
  788.   return 0;
  789. }