Rev 1085 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
/********************************************reading.c******************************/
#include <kernel/func.h>
#include <drivers/glib.h>
#include <ll/i386/x-dos.h>
#include <stdlib.h>
#include <string.h>
#include "include/constant.h"
#define rgb rgb16
DWORD macchine
[ROW
][COL
][NCAR
];
DWORD strada
[H
][W
];
DWORD sprites
[ROW
][COL
][NO_SPRITE
];
DWORD y_sem
[4][SH
][SW
];
DWORD r_sem
[4][SH
][SW
];
DWORD g_sem
[4][SH
][SW
];
DWORD faces
[2][74][47];
extern tl_data tl_data_array
[MAX_TL
];
char nomefile
[17];
char nomestrada
[17];
char nomesem
[17];
char nomesprite
[16];
void getSem
() {
int i
,j
,k
,count
;
BYTE colore
[3];
DOS_FILE
*fp
;
char letter
[5];
strcpy(letter
,"lrud");
strcpy(nomesem
,"sem/green_ .raw");
//green traffic light....
for(k
=0;k
<4;k
++) {
nomesem
[10]=letter
[k
];
fp
=DOS_fopen
(nomesem
,"r");
if(!fp
) {
perror(nomesem
);
sys_abort
(1);
}
for(i
=0;i
<SH
;i
++) {
for(j
=0;j
<SW
;j
++) {
count
=DOS_fread
(&colore
,sizeof(BYTE
),3,fp
);
if(count
!=3) break;
g_sem
[k
][i
][j
]=rgb
(colore
[0],colore
[1],colore
[2]);
}
}
DOS_fclose
(fp
);
fp
=0;
}
//red traffic light...
strcpy(nomesem
,"sem/red_ .raw");
for(k
=0;k
<4;k
++) {
nomesem
[8]=letter
[k
];
fp
=DOS_fopen
(nomesem
,"r");
if(!fp
) {
perror(nomesem
);
sys_abort
(1);
}
for(i
=0;i
<SH
;i
++) {
for(j
=0;j
<SW
;j
++) {
count
=DOS_fread
(&colore
,sizeof(BYTE
),3,fp
);
if(count
!=3) break;
r_sem
[k
][i
][j
]=rgb
(colore
[0],colore
[1],colore
[2]);
}
}
DOS_fclose
(fp
);
fp
=0;
}
//yellow traffic light...
strcpy(nomesem
,"sem/yellow_ .raw");
for(k
=0;k
<4;k
++) {
nomesem
[11]=letter
[k
];
fp
=DOS_fopen
(nomesem
,"r");
if(!fp
) {
perror(nomesem
);
sys_abort
(1);
}
for(i
=0;i
<SH
;i
++) {
for(j
=0;j
<SW
;j
++) {
count
=DOS_fread
(&colore
,sizeof(BYTE
),3,fp
);
if(count
!=3) break;
y_sem
[k
][i
][j
]=rgb
(colore
[0],colore
[1],colore
[2]);
}
}
DOS_fclose
(fp
);
fp
=0;
}
}
void getCars
() {
int i
,j
,k
,l
,index
;
int tmp
;
char id_car
[3];
BYTE colore
[3];
DOS_FILE
*fp
;
strcpy(nomefile
,"img/car_XXXn.raw");
k
=0;
for (index
=0;index
<360;index
+=15) {
tmp
=index
;
for (l
=2;l
>=0;l
--) {
id_car
[l
]=tmp
%10+'0';
tmp
/=10;
}
nomefile
[8]=id_car
[0];
nomefile
[9]=id_car
[1];
nomefile
[10]=id_car
[2];
fp
=DOS_fopen
(nomefile
,"r");
if (!fp
) {
perror(nomefile
);
sys_abort
(1);
}
for (i
=0;i
<ROW
;i
++) {
for (j
=0;j
<COL
;j
++) {
DOS_fread
(&colore
,sizeof(BYTE
),3,fp
);
macchine
[i
][j
][k
]=rgb
(colore
[0],colore
[1],colore
[2]);
}
}
DOS_fclose
(fp
);
fp
=0;
k
++;
}
}
void getRoad
() {
DOS_FILE
*fp
;
int i
,j
,test
;
BYTE colore
[3];
strcpy(nomestrada
,"img/street.raw");
fp
=DOS_fopen
(nomestrada
,"r");
if (!fp
) {
perror(nomestrada
);
sys_abort
(1);
}
for (i
=0;i
<H
;i
++) {
for (j
=0;j
<W
;j
++) {
test
=DOS_fread
(&colore
,sizeof(BYTE
),3,fp
);
if(test
!=3) {
perror("Few bytes read!!!!!!\n");
}
strada
[i
][j
]=rgb
(colore
[0],colore
[1],colore
[2]);
}
}
DOS_fclose
(fp
);
}
void getSprites
(void) {
int i
,j
,k
;
DOS_FILE
*fp
;
BYTE colore
[3];
strcpy(nomesprite
,"sprite/sp_X.raw");
for (k
=0;k
<NO_SPRITE
;k
++) {
nomesprite
[10]=k
+'0';
fp
=DOS_fopen
(nomesprite
,"r");
if (!fp
) {
perror(nomesprite
);
sys_abort
(1);
}
for (i
=0;i
<ROW
;i
++) {
for (j
=0;j
<COL
;j
++) {
DOS_fread
(&colore
,sizeof(BYTE
),3,fp
);
sprites
[i
][j
][k
]=rgb
(colore
[0],colore
[1],colore
[2]);
}
}
DOS_fclose
(fp
);
fp
=0;
}
}
void tl_pos
(void) {
DOS_FILE
*fp
;
int i
;
char buf
[7];
int dimx
,dimy
;
fp
=DOS_fopen
("sem.raw","r");
if (!fp
) {
perror("sem.raw");
sys_abort
(1);
}
buf
[6]='\0';
for (i
=0;i
<MAX_TL
;i
++) {
DOS_fread
(&buf
,sizeof(char),6,fp
);
dimx
=(buf
[0]-'0')*100+(buf
[1]-'0')*10+(buf
[2]-'0');
dimy
=(buf
[3]-'0')*100+(buf
[4]-'0')*10+(buf
[5]-'0');
tl_data_array
[i
].
u.
x=dimx
;
tl_data_array
[i
].
u.
y=dimy
;
DOS_fread
(&buf
,sizeof(char),6,fp
);
dimx
=(buf
[0]-'0')*100+(buf
[1]-'0')*10+(buf
[2]-'0');
dimy
=(buf
[3]-'0')*100+(buf
[4]-'0')*10+(buf
[5]-'0');
tl_data_array
[i
].
d.
x=dimx
;
tl_data_array
[i
].
d.
y=dimy
;
DOS_fread
(&buf
,sizeof(char),6,fp
);
dimx
=(buf
[0]-'0')*100+(buf
[1]-'0')*10+(buf
[2]-'0');
dimy
=(buf
[3]-'0')*100+(buf
[4]-'0')*10+(buf
[5]-'0');
tl_data_array
[i
].
l.
x=dimx
;
tl_data_array
[i
].
l.
y=dimy
;
DOS_fread
(&buf
,sizeof(char),6,fp
);
dimx
=(buf
[0]-'0')*100+(buf
[1]-'0')*10+(buf
[2]-'0');
dimy
=(buf
[3]-'0')*100+(buf
[4]-'0')*10+(buf
[5]-'0');
tl_data_array
[i
].
r.
x=dimx
;
tl_data_array
[i
].
r.
y=dimy
;
}
DOS_fclose
(fp
);
}
void getFaces
(void) {
int i
,j
,k
;
DOS_FILE
*fp
;
BYTE colore
[3];
strcpy(nomesprite
,"img/bbX.raw");
for (k
=0;k
<2;k
++) {
nomesprite
[6]=k
+'0';
fp
=DOS_fopen
(nomesprite
,"r");
if (!fp
) {
perror(nomesprite
);
sys_abort
(1);
}
for (i
=0;i
<74;i
++) {
for (j
=0;j
<47;j
++) {
DOS_fread
(&colore
,sizeof(BYTE
),3,fp
);
faces
[k
][i
][j
]=rgb
(colore
[0],colore
[1],colore
[2]);
}
}
DOS_fclose
(fp
);
fp
=0;
}
}