?login_element?

Subversion Repositories NedoOS

Rev

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