Skip to content

Commit 9fca070

Browse files
author
roudoudou
committed
windows trouble + HSP
1 parent ccfeef6 commit 9fca070

File tree

3 files changed

+36
-94
lines changed

3 files changed

+36
-94
lines changed

libgfx.c

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -90,28 +90,6 @@ initial release v001:
9090
#define Z_DEFAULT_COMPRESSION 7
9191
#endif
9292

93-
typedef int v4si __attribute__ ((vector_size (4*sizeof(int))));
94-
typedef int v4ui __attribute__ ((vector_size (4*sizeof(unsigned short int))));
95-
typedef float v4df __attribute__ ((vector_size (4*sizeof(float))));
96-
97-
union i4vector
98-
{
99-
v4si v;
100-
int i[4];
101-
};
102-
103-
union u4vector
104-
{
105-
v4ui v;
106-
unsigned short int i[4];
107-
};
108-
109-
union f4vector
110-
{
111-
v4df v;
112-
float f[4];
113-
};
114-
11593
/*
11694
Thread management functions
11795
*/
@@ -2985,9 +2963,9 @@ static void bmpReadPixels8( FILE *file, unsigned char *dest, bmp_palette_element
29852963
static void bmpReadPixels4( FILE *file, unsigned char *dest, bmp_palette_element_t *palette, int w, int h )
29862964
{
29872965
int size = (w + 1)/2; /* byte alignment */
2988-
unsigned char row_stride[size]; /* not C90 but convenient here */
29892966
unsigned char index, byte, *p;
29902967
unsigned char bitmask = 0x0F; /* bit mask : 00001111 */
2968+
unsigned char row_stride[8192]; /* not C90 but convenient here */
29912969

29922970
p = dest;
29932971
for( int i=0; i < h; i++ ) {
@@ -3008,7 +2986,7 @@ static void bmpReadPixels4( FILE *file, unsigned char *dest, bmp_palette_element
30082986
static void bmpReadPixels1( FILE *file, unsigned char *dest, bmp_palette_element_t *palette, int w, int h )
30092987
{
30102988
int size = (w + 7) / 8; /* byte alignment */
3011-
unsigned char row_stride[size]; /* not C90 but convenient here */
2989+
unsigned char row_stride[8192]; /* not C90 but convenient here */
30122990
unsigned char index, byte, *p;
30132991
unsigned char bitmask = 0x01; /* bit mask : 00000001 */
30142992
int bit;
@@ -3041,9 +3019,10 @@ int loadBMP( const char *filename, unsigned char **data, int *width, int *height
30413019
bmp_palette_element_t *palette = NULL;
30423020
unsigned char *buf;
30433021

3044-
file = fopen( filename, "rb");
3022+
file = fopen( filename, "r");
30453023
#ifdef OS_WIN
3046-
_setmode(_fileno(last_id), _O_BINARY );
3024+
_set_fmode(_O_BINARY);
3025+
_setmode(_fileno(file), _O_BINARY );
30473026
#endif
30483027
if( !file ) {
30493028
printf("Error : could not open file %s\n", filename );

library.c

Lines changed: 16 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,6 @@ initial release v001:
335335

336336
#include<stddef.h>
337337
#include<stdint.h>
338-
#include<unistd.h>
339338
#include<setjmp.h>
340339

341340
#include<string.h>
@@ -435,7 +434,11 @@ false=0,
435434
true
436435
};
437436

437+
#ifndef OS_WIN
438438
extern char **environ;
439+
#else
440+
char **environ=NULL;
441+
#endif
439442

440443
#define INTERNAL_ERROR 7
441444
#define ABORT_ERROR 1
@@ -799,6 +802,7 @@ void _internal_put2log(char *logtype, char *cursource, int curline, char *curfun
799802
void CSVFreeFields(char **fields);
800803
#define FreeFields(fields) CSVFreeFields(fields)
801804

805+
#ifndef OS_WIN
802806
mode_t FileGetMode(char *filename);
803807
#define FileIsSocket(filename) ((FileGetMode(filename) & S_IFSOCK)==S_IFSOCK)
804808
#define FileIsLink(filename) ((FileGetMode(filename) & S_IFLNK)==S_IFLNK)
@@ -807,7 +811,10 @@ mode_t FileGetMode(char *filename);
807811
#define FileIsDir(filename) ((FileGetMode(filename) & S_IFDIR)==S_IFDIR)
808812
#define FileIsCharacterDevice(filename) ((FileGetMode(filename) & S_IFCHR)==S_IFCHR)
809813
#define FileIsFifo(filename) ((FileGetMode(filename) & S_IFIFO)==S_IFIFO)
810-
814+
#else
815+
#define FileIsDir(filename) printf(filename)
816+
#define FileIsRegular(filename) printf(filename)
817+
#endif
811818
long long FileGetSize(char *filename);
812819
char **_internal_DirReadAllGlob(char *dirname,int globflag,int recurseflag,int sortflag);
813820
#define DirReadEntry(dirname) _internal_DirReadGlob(dirname,0,0)
@@ -3908,8 +3915,9 @@ FILE *FileOpen(char *filename, char *opening_type)
39083915
return curfile->file_id;
39093916
}
39103917
}
3911-
3918+
_set_fmode(_O_BINARY);
39123919
curfile->file_id=fopen(filename,opening_type);
3920+
_set_fmode(_O_BINARY);
39133921
if (!curfile->file_id)
39143922
{
39153923
if (errno==EMFILE) {
@@ -4304,7 +4312,7 @@ int FileReadBinary(char *filename,char *data,int n)
43044312
int nn;
43054313

43064314
last_id=FileOpen(filename,"r");
4307-
4315+
_set_fmode(_O_BINARY);
43084316
if (data==NULL)
43094317
{
43104318
FileClose(last_id);
@@ -4355,6 +4363,7 @@ int FileWriteBinary(char *filename,char *data,int n)
43554363
int nn;
43564364

43574365
last_id=FileOpen(filename,"a+");
4366+
_set_fmode(_O_BINARY);
43584367
if (data!=NULL)
43594368
{
43604369
nn=fwrite(data,1,n,last_id);
@@ -4784,53 +4793,7 @@ struct stat *FileGetStat(char *filename)
47844793
{
47854794
#undef FUNC
47864795
#define FUNC "FileGetStat"
4787-
struct stat *filestat;
4788-
#ifdef OS_WIN
4789-
struct _stat winstat;
4790-
#endif
4791-
4792-
if (!filename)
4793-
{
4794-
logerr("filename must not be NULL");
4795-
exit(ABORT_ERROR);
4796-
}
4797-
/* check after by the system but... */
4798-
if (strnlen(filename,PATH_MAX)==PATH_MAX)
4799-
{
4800-
logerr("cannot open this file because the argument size is bigger than PATH_MAX (%d)",PATH_MAX);
4801-
logerr("[%s]",filename);
4802-
exit(ABORT_ERROR);
4803-
}
4804-
4805-
filestat=MemCalloc(sizeof(struct stat));
4806-
#ifdef OS_WIN
4807-
if (_stat(filename,&winstat)!=0)
4808-
#else
4809-
if (stat(filename,filestat) && errno!=ENOENT)
4810-
#endif
4811-
{
4812-
logerr("stat %s failed",filename);
4813-
switch (errno)
4814-
{
4815-
case EACCES:logerr("Search permission is denied for one of the directories in the path prefix of path.");break;
4816-
case EBADF:logerr("filedes is bad.");break;
4817-
case EFAULT:logerr("Bad address.");break;
4818-
case ELOOP:logerr("Too many symbolic links encountered while traversing the path.");break;
4819-
case ENAMETOOLONG:logerr("File name too long.");break;
4820-
case ENOMEM:logerr("Out of memory (i.e. kernel memory).");break;
4821-
case ENOTDIR:logerr("A component of the path is not a directory.");break;
4822-
default:logerr("Unknown error %d during stat: %s",errno,strerror(errno));
4823-
}
4824-
exit(ABORT_ERROR);
4825-
}
4826-
#ifdef OS_WIN
4827-
filestat->st_size=winstat.st_size;
4828-
filestat->st_mode=winstat.st_mode;
4829-
filestat->st_atime=winstat.st_atime; /* last access */
4830-
filestat->st_mtime=winstat.st_mtime; /* last modification */
4831-
filestat->st_ctime=winstat.st_ctime; /* time of creation */
4832-
#endif
4833-
return filestat;
4796+
return NULL;
48344797
}
48354798

48364799
/***
@@ -4843,13 +4806,8 @@ long long FileGetSize(char *filename)
48434806
{
48444807
#undef FUNC
48454808
#define FUNC "FileGetSize"
4846-
struct stat *filestat;
4847-
long long nn;
4809+
long long nn=0;
48484810

4849-
filestat=FileGetStat(filename);
4850-
nn=filestat->st_size;
4851-
MemFree(filestat);
4852-
logdebug("size of %s = %d (%dkb)",filename,nn,nn/1024);
48534811
return nn;
48544812
}
48554813
/***
@@ -4862,13 +4820,7 @@ mode_t FileGetMode(char *filename)
48624820
{
48634821
#undef FUNC
48644822
#define FUNC "FileGetMode"
4865-
struct stat *filestat;
4866-
mode_t nn;
4867-
4868-
filestat=FileGetStat(filename);
4869-
nn=filestat->st_mode;
4870-
MemFree(filestat);
4871-
return nn;
4823+
return 0;
48724824
}
48734825

48744826
/***

splitsdl.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,8 @@ unsigned char clipped[384]; // HSP index +1 ou zero si rien
283283
int adr;
284284
};
285285

286-
286+
//#define DBG printf("line %d\n",__LINE__);
287+
#define DBG ;
287288

288289
int compare_hsp(const void * a, const void * b)
289290
{
@@ -452,7 +453,7 @@ enum e_module {
452453
TxtReplace(scrfilename1,".bmp",".sc1",0);
453454
strcpy(scrfilename2,filename);
454455
TxtReplace(scrfilename2,".bmp",".sc2",0);
455-
456+
printf("load BMP file\n");
456457
if (loadBMP(filename,&bpixels,&bwidth,&bheight)) {
457458
logerr("cannot read BMP");
458459
exit(ABORT_ERROR);
@@ -462,6 +463,7 @@ enum e_module {
462463
photo->color_type=PNG_COLOR_TYPE_RGB;
463464
photo->width=bwidth;
464465
photo->height=bheight;
466+
photo->bit_depth=8;
465467
photo->data=MemMalloc(bwidth*bheight*3);
466468
// from RGBA to RGB
467469
for (l=0;l<bwidth*bheight;l++) {
@@ -478,7 +480,7 @@ enum e_module {
478480
logerr("cannot read BMP");
479481
exit(ABORT_ERROR);
480482
}
481-
loginfo("PNG image is %dx%dx%d",photo->width,photo->height,photo->bit_depth);
483+
loginfo("BMP image is %dx%dx%d",photo->width,photo->height,photo->bit_depth);
482484
if (photo->color_type!=PNG_COLOR_TYPE_RGB) {
483485
logerr("PNG image must be RGB without transparency",filename);
484486
exit(ABORT_ERROR);
@@ -744,6 +746,7 @@ enum e_module {
744746
}
745747
}
746748
}
749+
DBG
747750
/************************************ compute GFX colorz ***********************************/
748751
if (computeglobal) {
749752
unsigned char *newpix;
@@ -804,6 +807,7 @@ enum e_module {
804807
if (wasmoving) wasmoving=1+curhsp;
805808
}
806809
}
810+
DBG
807811

808812
/* on découpe en groupes selon l'espacement vertical entre les sprites hards */
809813
group=0;
@@ -854,7 +858,7 @@ enum e_module {
854858
rawinfo.nbcolor++;
855859
}
856860
/* on met à jour le clipped mask de l'écran */
857-
for (i=0;i<nbhsp;i++) {
861+
for (i=lastsp=0;i<nbhsp;i++) {
858862
if (hsp[i].group==igroup) {
859863
memcpy(hsp[i].palette,tmppalette,sizeof(tmppalette));
860864
lasty=hsp[i].y+16;
@@ -880,6 +884,7 @@ enum e_module {
880884
x++;
881885
}
882886
} else {
887+
DBG
883888
/* insert colors in rastamix */
884889
asicad=0x6422;
885890
x=0;
@@ -893,8 +898,10 @@ enum e_module {
893898
}
894899
}
895900
previouslasty=lasty;
901+
DBG
896902
ImageRAWFreeStruct(&rawinfo);
897903
}
904+
DBG
898905

899906
/*************************************************************************************************************
900907
**************************************************************************************************************
@@ -914,6 +921,7 @@ enum e_module {
914921
scanline[j*3+1]=(photo->data[j*6+1]+photo->data[j*6+4])*0.5;
915922
scanline[j*3+2]=(photo->data[j*6+2]+photo->data[j*6+5])*0.5;
916923
}
924+
DBG
917925
/*****************************************************************
918926
on élimine les données cachées par les sprites hard
919927
*****************************************************************/
@@ -937,6 +945,7 @@ enum e_module {
937945
refl=rastamix[0].l=colorz_create_palette(clippedscanline,sizeclip,rastamix[0].palette,0);
938946
rastamix[1].l=refl;
939947
memcpy(rastamix[1].palette,rastamix[0].palette,sizeof(rastamix[0].palette));
948+
DBG
940949

941950
/****************************************************************************************
942951
l i g n e s s u i v a n t e s . . .
@@ -957,6 +966,7 @@ enum e_module {
957966
sizeclip++;
958967
}
959968
}
969+
DBG
960970

961971
/****************************************************************************************
962972
on fait une première passe pour avoir une palette complète dès la première ligne
@@ -994,6 +1004,7 @@ enum e_module {
9941004
/****************************************************************************************
9951005
A F T E R R E B O O T
9961006
****************************************************************************************/
1007+
DBG
9971008

9981009
/* on s'fait pas chier, on garde les 12 couleurs les plus utilisées avec la palette de la ligne précédente */
9991010
memset(cptrefpal,0,sizeof(cptrefpal));

0 commit comments

Comments
 (0)