#include <stdio.h>
#include <stdlib.h>
//#include <mem.h>
#include <string.h>
#define _STRMAX 79
#define BYTE unsigned char
#define UINT unsigned int
#define MAXDEFB 8
#define MASKCOLOR 0x00
BYTE filebuf[65536];
char labelbuf[_STRMAX+1];
char formatlabelbuf[_STRMAX+1];
char commentlabelbuf[_STRMAX+1];
BYTE sizeword[4];
BYTE pic[1024][1024];
BYTE pixrow[1024/8+1][1024+1024];
#define PIXROWSHIFT 1024
BYTE maskrow[1024/8+1][1024];
//BYTE pixrowshift[1024/8][1024]; //>>4
BYTE attrrow[1024/8+1];
BYTE pal[64];
#define CONVORDERSZ 1024
int convorderx[CONVORDERSZ]; //фы ърцфюую эюьхЁр Єрщыр ъююЁфшэрЄ√
int convordery[CONVORDERSZ]; //фы ърцфюую эюьхЁр Єрщыр ъююЁфшэрЄ√
int sprcount;
int vertsprcount;
BYTE numok;
BYTE ink;
BYTE paper;
BYTE curink;
BYTE curpaper;
BYTE defaultcolor;
char sprformat;
int hgt;
int wid;
int bpp;
void skiplf(FILE * fin)
{ //тючьюцэю, 0x0d єцх яЁюўшЄрэ, ЄхяхЁ№ яЁюяєёърхь 0x0a
char c;
do{
if (!fread(&c
,1,1,fin
)) break;
}while (c!=0x0a);
}
void readcomment(FILE * fin, char * s)
{ //тючьюцэю, 0x0d єцх яЁюўшЄрэ, ЄхяхЁ№ яЁюяєёърхь 0x0a
char c;
unsigned int i;
i = 0;
do{
if (!fread(&c
,1,1,fin
)) break;
if (i==_STRMAX) break;
s[i] = c;
i++;
}while (c!=0x0a);
s[i] = '\0';
}
int readnum(FILE * fin)
{
char c;
int num;
int sign=1;
num = 0;
do{
if (!fread(&c
,1,1,fin
)) break;
if (c==' ') goto skip;
//if (c == 0x0d) goto skip;
//if (c == 0x0a) break;
if (c=='-') {sign = -1; goto skip;};
if ((c<'0')||(c>'9')) break; //т Єюь ўшёых 0x0a
num = num*10 + (int)(c-'0');
numok = 0xff;
skip:
;
}while(1);
num = num*sign;
return num;
}
unsigned int readlabel(FILE * fin, char * s)
{
char c;
unsigned int i;
int iscomment;
sprcount = 0;
vertsprcount = 0;
do{
i = 0;
iscomment = 0;
do{
if (!fread(&c
,1,1,fin
)) break;
if (c == ';') iscomment = -1;
if (c=='$') { //фры№°х ўшёыю ёяЁрщЄют тхЁЄшъры№эю
if (iscomment) continue; //т ъюььхэЄрї ьюцэю $
while (1) {
if (!fread(&c
,1,1,fin
)) return 0;
if ((c < '0') || (c > '9')) break;
vertsprcount = vertsprcount*10;
vertsprcount = vertsprcount + (int)(c-'0');
};
};
if (c=='#') { //фры№°х ўшёыю ёяЁрщЄют
if (iscomment) continue; //т ъюььхэЄрї ьюцэю #
while (1) {
if (!fread(&c
,1,1,fin
)) return 0;
if ((c < '0') || (c > '9')) break;
sprcount = sprcount*10;
sprcount = sprcount + (int)(c-'0');
};
};
if ((c=='=')||(c==',')) {
if (iscomment) continue; //т ъюььхэЄрї ьюцэю =
break;
};
if (c == 0x0d) continue;
if (c == 0x0a) {
if (iscomment) break; //ъюььхэЄ√ ъюэўр■Єё яю ъюэЎє ёЄЁюъш
continue;
};
if (i==_STRMAX) break;
s[i] = c;
i++;
}while(1);
s[i] = '\0';
}while(iscomment);
return i;
}
int read4b(FILE * fin)
{
fread(sizeword
, 4, 1, fin
);
return sizeword[0] + (sizeword[1]<<8) + (sizeword[2]<<16) + (sizeword[3]<<24);
}
BYTE colstat[256];
char numbuf[256];
UINT maxsprcount;
UINT cursprcount;
UINT maxvertsprcount;
UINT curvertsprcount;
void putlabel(char * labelbuf, FILE * fout)
{
UINT num;
UINT i;
if (maxvertsprcount != 0) {
num = curvertsprcount;
i = 0;
do {
numbuf[i] = (char)((UINT)'0' + (num - (num/10)*10));
num = num/10;
i++;
} while (num != 0);
do {
i--;
} while (i != 0);
};
if (maxsprcount != 0) {
num = cursprcount;
i = 0;
do {
numbuf[i] = (char)((UINT)'0' + (num - (num/10)*10));
num = num/10;
i++;
} while (num != 0);
do {
i--;
} while (i != 0);
};
return;
}
void findinkpaper(int x, int y) //ьрёър 0x00 эх ёўшЄрхЄё ЎтхЄюь
{
//BYTE b;
int i;
int j;
BYTE col1;
BYTE col1stat;
BYTE col2;
BYTE col2stat;
BYTE col3;
BYTE col3stat;
BYTE col4;
BYTE col4stat; //эр ёыєўрщ Єръющ ёЄрЄшёЄшъш: MASKCOLOR, RED, red, anothercolor
i = 0; do {colstat[i] = 0x00; i++;}while (i!=256);
//col1 = pic[x][y];
j = y;
while (j < (y+8)) {
// b = 0x00;
i = x;
while (i < (x+8)) {
colstat[pic[i][j]]++;
//b = pic[i][j];
//if (b!=col1) col2 = b;
i++;
};
j++;
};
//ьрёър MASKCOLOR эх ёўшЄрхЄё ЎтхЄюь
col1 = MASKCOLOR; col1stat = 0; //fix 27.12.2018
col2 = MASKCOLOR; col2stat = 0; //fix 27.12.2018
col3 = MASKCOLOR; col3stat = 0; //fix 27.12.2018
col4 = MASKCOLOR; col3stat = 0; //fix 27.12.2018
i = 0; do { //fix 27.12.2018 (эр ёыєўрщ MASKCOLOR!=0)
if (colstat[i] > col1stat) {
col4 = col3;
col4stat = col3stat;
col3 = col2;
col3stat = col2stat;
col2 = col1;
col2stat = col1stat;
col1 = (BYTE)i;
col1stat = colstat[i];
}else if (colstat[i] > col2stat) {
col4 = col3;
col4stat = col3stat;
col3 = col2;
col3stat = col2stat;
col2 = (BYTE)i;
col2stat = colstat[i];
}else if (colstat[i] > col3stat) {
col4 = col3;
col4stat = col3stat;
col3 = (BYTE)i;
col3stat = colstat[i];
}else if (colstat[i] > col4stat) {
col4 = (BYTE)i;
col4stat = colstat[i];
};
i++;
}while (i!=16); //fix 27.12.2018
//MASKCOLOR эхы№ч ёрь√ь ўрёЄ√ь, ёюЁЄшЁєхь хую т ъюэхЎ
if (col1==MASKCOLOR) {
col1 = col2;
col2 = MASKCOLOR;
};
if (col2==MASKCOLOR) {
col2 = col3;
col3 = MASKCOLOR;
};
if (col3==MASKCOLOR) {
col3 = col4;
col4 = MASKCOLOR;
};
//col1 ьюцхЄ с√Є№ MASKCOLOR Єюы№ъю фы чэръюьхёЄр, яюыэюёЄ№■ чрышЄюую MASKCOLOR
//ьрёър 0x00 эх ёўшЄрхЄё ЎтхЄюь, яю¤Єюьє 0x08 яхЁхтюфшЄё т 0x00 ё фхЇюыЄэющ ЁъюёЄ№■ (ўЄюс√ эх тыш Є№ эр bright)
//if ((col1&0x07)==0x00) col1 = (BYTE)(defaultcolor&0x08); //fix 27.12.2018
//if ((col2&0x07)==0x00) col2 = (BYTE)(defaultcolor&0x08); //fix 27.12.2018
/** if (col2 == MASKCOLOR) {
if (col1 == MASKCOLOR) {
col2 = (BYTE)((col1&0x08) | (defaultcolor&0x07));
}else {
col2 = (BYTE)((col1&0x08) | (defaultcolor&0x07));
};
};*/ //fix 27.12.2018
if (((col2&0x07)==(col1&0x07)) /**&& (col2!=0x00)*/) col2 = col3; //same colour with another bright
ink = col1;
paper = col2; //Ёхцх
//paper Ёхцх ш ьюцхЄ с√Є№ MASKCOLOR (эхЄ тЄюЁюую ЎтхЄр, эрфю сЁрЄ№ фхЇюыЄэ√щ)
//ink ьюцхЄ с√Є№ MASKCOLOR Єюы№ъю фы чэръюьхёЄр, яюыэюёЄ№■ чрышЄюую MASKCOLOR
}
void setcurinkpaper(BYTE* pcurink, BYTE* pcurpaper)
//paper Ёхцх ш ьюцхЄ с√Є№ MASKCOLOR (эхЄ тЄюЁюую ЎтхЄр, эрфю сЁрЄ№ фхЇюыЄэ√щ)
//ink ьюцхЄ с√Є№ MASKCOLOR Єюы№ъю фы чэръюьхёЄр, яюыэюёЄ№■ чрышЄюую MASKCOLOR
//*pcurink, *curpaper шчэрўры№эю ёюфхЁцрЄ рЄЁшсєЄ√ яЁхф√фє∙хую чэръюьхёЄр
//тючтЁр∙рхЄ *pcurink, *curpaper, яЁшў╕ь тьхёЄю 0x08 ёЄртшЄ 0x00 (ўЄюс√ эх тыш ыю эр ЁъюёЄ№)
{
BYTE t;
if ((sprformat == 's')||(sprformat == 'w')) {
paper = 0x08;
ink = 0x0f;
}; //фы ёяЁрщЄют Їюэ ў╕Ёэ√щ (р ьрёър 0x00)
//27.02.2019:
//Їюэ фы чрышЄ√ї чэръюьхёЄ эрўшэр ё чхы╕эюую ЄхяхЁ№ ў╕Ёэ√щ[шыш эрфю яЁхф√фє∙шщ?]
//Їюэ фы ў╕Ёэ√ї чэръюьхёЄ схЁ╕Є ЁъюёЄ№ юЄ defaultcolor, р фы чрышЄ√ї чэръюьхёЄ ьхэхх чхы╕эюую эх схЁ╕Є
#define MINCOLORWITHBLACKBG 0x04
//fix 27.12.2018:
if (((ink&0x07)==(*pcurink&0x07)) && (ink!=MASKCOLOR)) { //ink ёююЄтхЄёЄтєхЄ яЁхф√фє∙хьє
*pcurink = ink;
if (paper==MASKCOLOR) {
*pcurpaper = ((ink&0x07)<MINCOLORWITHBLACKBG) ? ((ink&0x07)?((defaultcolor&0x07)|(ink&0x08)):defaultcolor) : 0x00;
}else {
*pcurpaper = paper;
};
}else if (((paper&0x07)==(*pcurpaper&0x07)) && (paper!=MASKCOLOR)) { //paper ёююЄтхЄёЄтєхЄ яЁхф√фє∙хьє
*pcurpaper = paper;
if (ink==MASKCOLOR) {
*pcurink = ((paper&0x07)<MINCOLORWITHBLACKBG) ? ((paper&0x07)?((defaultcolor&0x07)|(paper&0x08)):defaultcolor) : 0x00;
}else {
*pcurink = ink;
};
}else if (((paper&0x07)==(*pcurink&0x07)) && (paper!=MASKCOLOR)) { //paper ёююЄтхЄёЄтєхЄ яЁхф√фє∙хьє ink
*pcurink = paper;
if (ink==MASKCOLOR) {
*pcurpaper = ((paper&0x07)<MINCOLORWITHBLACKBG) ? ((paper&0x07)?((defaultcolor&0x07)|(paper&0x08)):defaultcolor) : 0x00;
}else {
*pcurpaper = ink;
};
}else if (((ink&0x07)==(*pcurpaper&0x07)) && (ink!=MASKCOLOR)) { //ink ёююЄтхЄёЄтєхЄ яЁхф√фє∙хьє paper
*pcurpaper = ink;
if (paper==MASKCOLOR) {
*pcurink = ((ink&0x07)<MINCOLORWITHBLACKBG) ? ((ink&0x07)?((defaultcolor&0x07)|(ink&0x08)):defaultcolor) : 0x00;
}else {
*pcurink = paper;
};
}else if ((ink==MASKCOLOR)&&(paper==MASKCOLOR)) { //юср ЎтхЄр MASKCOLOR
ink = defaultcolor;
paper = 0x08;
}else { //юср ЎтхЄр эх ёююЄтхЄёЄтє■Є яЁхф√фє∙хьє чэръюьхёЄє, эю эх юср MASKCOLOR
if (ink == MASKCOLOR) ink = ((paper&0x07)<MINCOLORWITHBLACKBG) ? ((paper&0x07)?((defaultcolor&0x07)|(paper&0x08)):defaultcolor) : 0x00;
if (paper == MASKCOLOR) paper = ((ink&0x07)<MINCOLORWITHBLACKBG) ? ((ink&0x07)?((defaultcolor&0x07)|(ink&0x08)):defaultcolor) : 0x00;
if (ink > paper) {
*pcurink = ink;
*pcurpaper = paper;
}else {
*pcurink = paper;
*pcurpaper = ink;
};
};
if (*pcurpaper==0x08) *pcurpaper = 0x00; //ўЄюс√ эх тыш ыю эр ЁъюёЄ№ //fix 27.12.2018
if (*pcurink==0x08) *pcurink = 0x00; //ўЄюс√ эх тыш ыю эр ЁъюёЄ№ //fix 27.12.2018
//эр ў╕Ёэюь/ёшэхь Їюэх ink фюыцхэ с√Є№ Ёўх paper'р (юЄфхы№э√щ ёыєўрщ, Є.ъ. юёЄры№э√х, фрцх яєёЄ√х, чэръюьхёЄр ьюуєЄ єўрёЄтютрЄ№ т юЄЁшёютъх ёъЁюыышЁєхь√ї Їюэют ё эхяЁхЁ√тэ√ьш Ўхяюўърьш ink-paper)
//Єю хёЄ№ эхы№ч ink=0, р 1 Єюы№ъю т ёыєўрх paper=0
if (((*pcurink&0x07)<=0x01) && ((*pcurpaper&0x07)>(*pcurink&0x07))) { //ў╕Ёэюх/ёшэхх яєёЄюх чэръюьхёЄю (юЄфхы№э√щ ёыєўрщ, Є.ъ. юёЄры№э√х яєёЄ√х ьюуєЄ єўрёЄтютрЄ№ т юЄЁшёютъх ёъЁюыышЁєхь√ї Їюэют ё эхяЁхЁ√тэ√ьш Ўхяюўърьш ink-paper)
t = *pcurpaper;
*pcurpaper = *pcurink;
*pcurink = t;
};
}
void emitdb(BYTE b, FILE * fout)
{
fprintf(fout
, "0x%x%x", b
>>4, b
&0x0f);
}
void emitdw(UINT u, FILE * fout)
{
fprintf(fout
, "0x%x%x%x%x", (u
>>12)&0x0f, (u
>>8)&0x0f, (u
>>4)&0x0f, u
&0x0f);
}
void emitnops(BYTE count, FILE * fout)
{
fprintf(fout
, "0x%x%x", count
>>4, count
&0x0f);
}
void emitspr(int xchr, int y, int sprwid8, int sprhgt, FILE * fout)
{
BYTE b;
int i;
int j;
j = y;
while (1) {
i = xchr;
while (1) {
b = maskrow[i][j];
fprintf(fout
, "0x%x%x", b
>>4, b
&0x0f);
b = b^pixrow[i][j];
fprintf(fout
, "0x%x%x", b
>>4, b
&0x0f);
i++;
if (i >= (xchr+sprwid8)) break;
};
j++;
if (j >= (y+sprhgt)) break;
};
}
void emitsprw(int xchr, int y, int sprwid8, int sprhgt, FILE * fout)
{ //antipixelsw, antimaskw
BYTE b;
int i;
int j;
j = y;
while (1) {
i = xchr+sprwid8;
while (1) {
i--;
b = ~maskrow[i][j];
fprintf(fout
, "0x%x%x", b
>>4, b
&0x0f);
if (i == xchr) break;
};
i = xchr+sprwid8;
while (1) {
i--;
b = ~maskrow[i][j];
b ^= pixrow[i][j];
fprintf(fout
, "0x%x%x", b
>>4, b
&0x0f);
if (i == xchr) break;
};
j++;
if (j >= (y+sprhgt)) break;
};
}
void emitsprwnomask(int xchr, int y, int sprwid8, int sprhgt, FILE * fout)
{ //antipixelsw
BYTE b;
int i;
int j;
j = y;
while (1) {
i = xchr;
while (1) {
b = ~maskrow[i][j];
fprintf(fout
, "0x%x%x", b
>>4, b
&0x0f);
i++;
if (i == xchr+sprwid8) break;
};
j++;
if (j >= (y+sprhgt)) break;
};
}
void emitsprwnomaskback(int xchr, int y, int sprwid8, int sprhgt, FILE * fout)
{ //antipixelsw
BYTE b;
int i;
int j;
j = y;
while (1) {
i = xchr+sprwid8;
while (1) {
i--;
b = ~maskrow[i][j];
fprintf(fout
, "0x%x%x", b
>>4, b
&0x0f);
if (i == xchr) break;
};
j++;
if (j >= (y+sprhgt)) break;
};
}
void emitimgW(int xchr, int y, int sprwid8, int sprhgt, FILE * fout)
{ //by columns
BYTE b;
int i;
int j;
i = xchr;
while (1) {
j = y;
while (1) {
b = maskrow[i][j];
//fprintf(fout, "0x%x%x ", i>>4, i&0x0f);
//fprintf(fout, "0x%x%x ", j>>4, j&0x0f);
fprintf(fout
, "0x%x%x", b
>>4, b
&0x0f);
j++;
if (j >= (y+sprhgt)) break;
};
i++;
if (i == (xchr+sprwid8)) break;
};
}
void emitchr_(int xchr, int y, FILE * fout)
{
BYTE b;
int j;
j = y;
while (1) {
b = pixrow[xchr][j];
fprintf(fout
, "0x%x%x", b
>>4, b
&0x0f);
j++;
if (j >= (y+8)) break;
};
if (sprformat < 'a') { //capital letter format => attr used
b = attrrow[xchr]; //0x07;
fprintf(fout
, "0x%x%x", b
>>4, b
&0x0f);
};
}
void emitchr(int xchr, int y, FILE * fout)
{
emitchr_(xchr, y, fout);
}
void emitchrshift(int xchr, int y, FILE * fout)
{
emitchr_(xchr, y+PIXROWSHIFT, fout);
}
//ёфтшурхь Ё ф чэръюьхёЄ >>shiftbits, Ёхчєы№ЄрЄ т pixrow[sprx][y+PIXROWSHIFT]
void shiftrow(int sprx, int y, int sprwid, int rowhgt, int pixrowshift, BYTE shiftbits)
{
int j;
int x;
BYTE b;
BYTE b0;
BYTE shiftmask;
shiftmask = (BYTE)(0xff>>(0x08-shiftbits)); //хёыш shiftbits==0x01, Єю shiftmask==0x01
j = y;
while (j < (y+rowhgt)) {
b = 0x00;
x = sprx;
while (x < (sprx+sprwid+8)) {
b0 = pixrow[x/8][j];
pixrow[x/8][j+pixrowshift] = (BYTE)((b<<(0x08-shiftbits)) + (b0>>shiftbits));
b = (BYTE)(b0&shiftmask/**0x0f*/); //хёыш shiftbits==0x01, Єю shiftmask==0x01
x = x+8;
};
j++;
};
}
//data: wid8, hgt8, chrgfx, chrgfx...
void resfile(char * finname, char * fintxtname, char * foutname)
{
FILE* fin;
FILE* fintxt;
FILE* fout;
int i;
int j;
int size;
int y;
int x;
int n;
int tiles;
BYTE b;
BYTE bmask;
BYTE b0;
int sprx;
int startsprx;
int spry;
int sprwid;
int sprhgt;
int rowhgt; //8 for tiles, sprhgt for sprites
UINT color;
fin
= fopen(finname
, "rb");
if (fin) {
fread(filebuf
, 10, 1, fin
); //skip to 10 (header size)
size = read4b(fin); //10 (header size)
fread(filebuf
, 4, 1, fin
); //skip to 18
wid = read4b(fin); //18
hgt = read4b(fin); //22
fread(filebuf
, 2, 1, fin
); //skip to 28
fread(&bpp
, 1, 1, fin
); //28
fread(filebuf
, 1, 54-29, fin
); //skip to pal
fread(pal
, 1, 64, fin
); //ярышЄЁр (B, G, R, 0)
if (size
> (54+64)) {fread(filebuf
, 1, size
-(54+64), fin
);}; //skip to pic
if ((wid>0)&&(wid<=1024)&&(hgt>0)&&(hgt<=1024)&&((wid&7)==0)&&((hgt&7)==0)) {
y = hgt;
while (y>0) {
y--;
x = 0;
while (x<wid) {
if (bpp == 8) {
pic[x][y] = b;
x++;
}else {
pic[x][y] = (BYTE)((b&0xf0)>>4);
x++;
pic[x][y] = (BYTE)(b&0x0f);
x++;
};
};
};
fintxt
= fopen(fintxtname
, "rb");
if (fintxt) {
fout
= fopen(foutname
, "wb");
if (fout) {
/** if (labelname[0]!='\0') {
fputs(labelname, fout);
fputs("\n", fout);
};*/
while (1) {
size = readlabel(fintxt, labelbuf); //fread(filebuf, 1, MAXDEFB, fin);
maxvertsprcount = vertsprcount;
maxsprcount = sprcount;
if (size == 0) break;
readlabel(fintxt, formatlabelbuf); //format
sprformat = *formatlabelbuf;
startsprx = readnum(fintxt);
spry = readnum(fintxt);
sprwid = readnum(fintxt);
sprhgt = readnum(fintxt);
numok = 0x00;
tiles = readnum(fintxt); //юЄёєЄёЄтєхЄ т x
defaultcolor = (BYTE)tiles; //фы тёхї, ъЁюьх L
*commentlabelbuf = '\0';
if ((numok != 0x00) && (sprformat != 'L')) readcomment(fintxt, commentlabelbuf);
curvertsprcount = 0;
do { //vertsprcount
cursprcount = 0;
sprx = startsprx;
do { //sprcount
if ((sprformat == 'B')||(sprformat == 'b')) {
putlabel(labelbuf, fout);
//emitdb((BYTE)(sprwid>>3), fout);
//emitdb((BYTE)(sprhgt>>3), fout);
rowhgt = 8;
}else if (sprformat == 'T') { //эрсюЁ Єрщыют
fputs("\tds (-$)&0xff\n", fout
);
putlabel(labelbuf, fout);
rowhgt = 8;
}else if (sprformat == 'x') { //ёяЁрщЄ 16c
putlabel(labelbuf, fout);
emitdb((BYTE)(sprwid>>1), fout);
emitdb((BYTE)(sprhgt), fout);
rowhgt = sprhgt;
}else if (sprformat == 'i') { //ърЁЄшэър 16c яю ёЄюысЎрь
putlabel(labelbuf, fout);
rowhgt = sprhgt;
}else if (sprformat == 'L') { //LAND ъръ т ╫┬, фры№°х ёыхфєхЄ ЄрсышЎр - эюьхЁ Єрщыр фы ърцфющ ъыхЄъш
putlabel(labelbuf, fout);
rowhgt = sprhgt;
}else if (sprformat == 'P') { //DDp palette
putlabel(labelbuf, fout);
i = 0;
while (i < 64) { //DDp palette: %grbG11RB(low),%grbG11RB(high), шэтхЁёэ√х //color = highlow
color = 0; //pal = ярышЄЁр (B, G, R, 0)
if (pal[i]&0x80) color = color | 0x0100;
if (pal[i]&0x40) color = color | 0x2000;
if (pal[i]&0x20) color = color | 0x0001;
if (pal[i]&0x10) color = color | 0x0020;
i++;
if (pal[i]&0x80) color = color | 0x1000;
if (pal[i]&0x40) color = color | 0x8000;
if (pal[i]&0x20) color = color | 0x0010;
if (pal[i]&0x10) color = color | 0x0080;
i++;
if (pal[i]&0x80) color = color | 0x0200;
if (pal[i]&0x40) color = color | 0x4000;
if (pal[i]&0x20) color = color | 0x0002;
if (pal[i]&0x10) color = color | 0x0040;
i++;
emitdw(~color, fout);
i++;
};
rowhgt = sprhgt;
}else if ((sprformat == 'w')||(sprformat == 'z')||(sprformat == 'Z')) {
putlabel(labelbuf, fout);
rowhgt = sprhgt;
}else if (sprformat == 'W') {
putlabel(labelbuf, fout);
rowhgt = sprhgt;
}else { //'s'
putlabel(labelbuf, fout);
emitdb((BYTE)(sprwid>>3), fout);
emitdb((BYTE)(sprhgt), fout);
rowhgt = sprhgt;
};
//copy comment as code line
fputs(commentlabelbuf
, fout
);
//fputs("\n", fout);
y = spry;
while (y < (spry+sprhgt)) {
//яхЁхъюфшЁєхь Ё ф чэръюьхёЄ т√ёюЄющ rowhgt
curink = 0x0f;
curpaper = 0x08;
x = 0;//sprx;
while (x < (sprx+sprwid)) {
findinkpaper(x, y);
setcurinkpaper(&curink, &curpaper);
//curink = 0x0f;
//curpaper = 0x08;
// if (sprformat == 'W') {
// curpaper = 0;
// curink = 1;
// };
j = y;
while (j < (y+rowhgt)) {
b = 0x00;
bmask = 0x00;
i = x;
while (i < (x+8)) {
b = (BYTE)(b<<1);
bmask = (BYTE)(bmask<<1);
//if (sprformat != 'B') {fprintf(fout, "0x%x%x\n", (pic[i][j])>>4, (pic[i][j])&0x0f);};
if (pic[i][j]==curink) b++;
if (pic[i][j]!=0x00) bmask++;
i++;
};
pixrow[x/8][j] = b;
maskrow[x/8][j] = bmask;
//fprintf(fout, "0x%x%x ", x>>4, x&0x0f);
//fprintf(fout, "0x%x%x ", j>>4, j&0x0f);
//fprintf(fout, "0x%x%x ", b>>4, b&0x0f);
//fprintf(fout, "0x%x%x\n", bmask>>4, bmask&0x0f);
pixrow[(x/8)+1][j] = 0x00; //ўЄюс√ ёфтшурЄ№
j++;
};
//ьрёър 0x00 эх ёўшЄрхЄё ЎтхЄюь, яю¤Єюьє 0x08 яхЁхтюфшЄё т 0x00 (ўЄюс√ эх тыш Є№ эр bright)
b = 0x00; if (curink!=0x08) b = curink;
b0 = 0x00; if (curpaper!=0x08) b0 = curpaper;
attrrow[x/8 ] = (BYTE)( (((b|b0)&0x08)<<3)+((curpaper&0x07)<<3)+(curink&0x07) );
attrrow[(x/8)+1] = (BYTE)( (((b|b0)&0x08)<<3)+((curpaper&0x07)<<3)+(curink&0x07) ); //ўЄюс√ ёфтшурЄ№
x = x+8;
};
// shiftrow(sprx, y, sprwid, rowhgt, PIXROWSHIFT, 0x04); //ёфтшурхь Ё ф чэръюьхёЄ >>4, Ёхчєы№ЄрЄ т pixrow[sprx][y+PIXROWSHIFT]
//т√тюфшь т рёь
if ((sprformat == 'B')||(sprformat == 'b')) { //tiles or bw tiles
x = sprx;
while (x < (sprx+sprwid)) {
// emitchrshift(x/8,y,fout);
emitchr(x/8,y,fout); //checks for capital letter in sprformat
x = x+8;
};
// emitchrshift(x/8,y,fout);
}else if (sprformat == 'T') {
x = sprx;
while (x < (sprx+sprwid)) {
emitchr(x/8,y,fout);
x = x+8;
};
emitnops((BYTE)(0x100-((BYTE)(sprwid>>3)*0x09)),fout);
}else if (sprformat == 's') { //sprite
emitspr(sprx/8,y,sprwid/8,sprhgt,fout);
}else if (sprformat == 'w') { //sprite antipixels16, antimask16
emitsprw(sprx/8,y,sprwid/8,sprhgt,fout);
}else if (sprformat == 'z') { //unmasked sprite right to left
emitsprwnomaskback(sprx/8,y,sprwid/8,sprhgt,fout);
}else if (sprformat == 'Z') { //unmasked sprite
emitsprwnomask(sprx/8,y,sprwid/8,sprhgt,fout);
}else if (sprformat == 'W') { //b/w image by columns
emitimgW(sprx/8,y,sprwid/8,sprhgt,fout);
//emitimgW(0,0,128,128,fout);
};
y = y+rowhgt;
}; //while y
if (sprformat == 'x') {
x = sprx;
while (x < (sprx+sprwid)) {
y = spry;
while (y < (spry+sprhgt)) {
b = pic[x][y]; //L
b0 = pic[x+1][y]; //R
bmask = 0; //0x47(L) ш 0xb8(R) т Єхї ьхёЄрї, уфх ЎтхЄ=16:
if (b == 16) {bmask = bmask + 0x47; b = 0x00;};
if (b0 == 16) {bmask = bmask + 0xb8; b0 = 0x00;};
b = ((b&0x08)<<3) + (b&0x07) + ((b0&0x08)<<4) + ((b0&0x07)<<3);
fprintf(fout
, "0x%x%x", bmask
>>4, bmask
&0x0f);
fprintf(fout
, ",0x%x%x", b
>>4, b
&0x0f);
y = y+1;
};
x = x+2;
if (x < (sprx+sprwid)) {
emitdw(0x4000-((sprhgt-1)*40), fout);
}else {
emitdw(0xffff, fout);
};
};
fputs("\tdw prsprqwid\n", fout
);
};
if (sprformat == 'i') {
x = sprx;
while (x < (sprx+sprwid)) {
y = spry;
while (y < (spry+sprhgt)) {
b = pic[x][y]; //L
b0 = pic[x+1][y]; //R
b = ((b&0x08)<<3) + (b&0x07) + ((b0&0x08)<<4) + ((b0&0x07)<<3);
fprintf(fout
, "\tdb 0x%x%x", b
>>4, b
&0x0f);
y = y+1;
};
x = x+2;
};
};
if (sprformat == 'L') { //фрыхх ЄхъёЄ Єшяр (-1=яЁюяєёъ):
// -1, -1, -1,114,116,119,121,124,126,-1,-1,-1,-1,-1,-1,-1,
// 113,118,123,115,117,120,122,125,127,-1,-1,-1,-1,-1,-1,-1
//фы ърцфющ ўхщъш ърЁЄшэъш єърчрэ эюьхЁ Єрщыр
//р эрь эрфю чряюыэшЄ№ ьрёёшт√ convorderx,y - ъююЁфшэрЄ√ фы ърцфюую эюьхЁр Єрщыр
//тёх фюыцэ√ с√Є№ т юфэющ ърЁЄшэъх, шэрўх эх яюыєўшЄё (яхЁхьх°рэ√ эюьхЁр Єрщыют юс∙шх фы тёхї ыюърЎшщ ш фы ъюэъЁхЄэющ)
n = 0;
while (n < CONVORDERSZ) {
convorderx[n] = 0;
convordery[n] = 0;
n = n+1;
};
skiplf(fintxt);
//tiles = 0;
y = spry;
while (y < (spry+sprhgt)) {
x = sprx;
while (x < (sprx+sprwid)) {
n = readnum(fintxt);
if (n != -1) {
convorderx[n] = x;
convordery[n] = y;
};
//fprintf(fout, "\tdb %d\n", n);
//tiles = tiles + 1;
x = x+16;
};
skiplf(fintxt);
//fputs("\n", fout);
y = y+16;
};
n = 0;
while (n < tiles) {
x = convorderx[n];
while (x < (convorderx[n]+16)) {
y = convordery[n];
while (1) {
b = pic[x][y]; //L
b0 = pic[x+1][y]; //R
b = ((b&0x08)<<3) + (b&0x07) + ((b0&0x08)<<4) + ((b0&0x07)<<3);
fprintf(fout
, "0x%x%x", b
>>4, b
&0x0f);
y = y+1;
if (y == (convordery[n]+16)) break;
};
x = x+2;
};
n = n+1;
};
};
sprx = sprx + sprwid;
cursprcount++;
} while (cursprcount<maxsprcount); //while (sprcount)
spry = spry + sprhgt;
curvertsprcount++;
} while (curvertsprcount<maxvertsprcount); //while (vertsprcount)
}; //while (1)
}else {printf("can't open %s",foutname
);};
}else {printf("can't open %s",fintxtname
);};
};
}else {printf("can't open %s",finname
);};
}
int main(int argc,char* argv[])
{
// int i;
char *finname;
char *fintxtname;
char *foutname;
finname = "testpic.bmp";
fintxtname = "testpic.txt";
foutname = "testpic.asm";
if (argc<4) {
"NedoRes\n"
"\tnedores.exe file.bmp file.dat(=txt) file.ast(=asm)\n"
"4bpp or 8bpp\n"
);
}else {
finname = argv[1];
fintxtname = argv[2];
foutname = argv[3];
};
resfile(finname, fintxtname, foutname);
return 0;
}