예제 #1
0
t_get_champion	*get_champion(char **av, int ac, t_get_champion *prev, int *i)
{
  t_get_champion	*link;

  link = xmalloc(sizeof(*link));
  if (MATCH(av[*i], PLACE))
    link->nb = gplace(av, i, ac, prev);
  else
    link->nb = AFFECT_LATER;
  if (0[i] > ac)
    lerror(USAGE);
  if (MATCH(av[0[i]], LOAD))
    link->load = gload(av, i, ac);
  else
    link->load = AFFECT_LATER;
  if (0[i] > ac)
    lerror(USAGE);
  if ((link->champ = open(av[(*i)++], O_RDONLY)) == -1)
    lerror(USAGE);
  link->next = prev;
  return (link);
}
예제 #2
0
파일: vgs2a.c 프로젝트: kentaurus/vgs2
/*
 *----------------------------------------------------------------------------
 * initialize rom data
 *----------------------------------------------------------------------------
 */
JNIEXPORT jint JNICALL Java_com_{Company} _{Project} _{Project} _setRomData(JNIEnv* env, jclass jc, jbyteArray src)
{
    jboolean b;
    int fsize;
    char* bin;
    int i,j;
    int cn,pn;
    char s[4];
    char path[16];

    putlog(__FILE__,__LINE__,"*** SUZUKI PLAN - Video Game System mk-II (GameDaddy) ***");

    /* get romdata from raw area */
    BN=0;
    BR=NULL;
    bin=(char*)((*env)->GetByteArrayElements(env,src,&b));
    fsize=(int)((*env)->GetArrayLength(env,src));

    /* get number of files */
    memcpy(&BN,bin,sizeof(BN));
    bin+=sizeof(BN);

    /* allocate buffer */
    if(NULL==(BR=(struct _BINREC*)malloc(BN * sizeof(struct _BINREC)))) {
        putlog(__FILE__,__LINE__,"Could not allocate ROM data area: errno=%d",errno);
        return -1;
    }
    memset(BR,0,BN * sizeof(struct _BINREC));

    /* read filename */
    for(i=0; i<BN; i++) {
        memset(BR[i].name,0,16);
        memcpy(BR[i].name,bin,16);
        bin+=16;
        for(j=0; '\0'!=BR[i].name[j]; j++) {
            if(15==j) {
                putlog(__FILE__,__LINE__,"ROM data is broken.");
                return -1;
            }
            BR[i].name[j]^=0xAA;
        }
    }

    /* read data */
    for(i=0; i<BN; i++) {
        memcpy(s,bin,4);
        bin+=4;
        BR[i].size=s[0];
        BR[i].size<<=8;
        BR[i].size|=s[1];
        BR[i].size<<=8;
        BR[i].size|=s[2];
        BR[i].size<<=8;
        BR[i].size|=s[3];
        if(NULL==(BR[i].data=(char*)malloc(BR[i].size))) {
            putlog(__FILE__,__LINE__,"Could not allocate ROM data area: errno=%d",errno);
            return -1;
        }
        memcpy(BR[i].data,bin,BR[i].size);
        bin+=BR[i].size;
    }
    putlog(__FILE__,__LINE__,"ROMDATA has extracted.");

    cn=0;
    pn=0;
    for(i=0; i<256; i++) {
        sprintf(path,"GSLOT%03d.CHR",i);
        if(0==gload(i,path)) cn++;
        sprintf(path,"ESLOT%03d.PCM",i);
        if(0==eload(i,path)) pn++;
    }
    putlog(__FILE__,__LINE__,"Data has extracted. (CHR=%d, PCM=%d)",cn,pn);
    return 0;
}
예제 #3
0
파일: vgs2l.c 프로젝트: suzukiplan/vgs2
int main(int argc,char* argv[])
{
	SDL_Surface* surface;
	SDL_Event event;
	FILE* fp;
	int i,j;
	unsigned char s[4];
	char path[16];
	int cn,pn,bn;
	unsigned short* ptr;
	int vx,vy,vp,pp;
	unsigned int n;
	unsigned int ticks;
	int mx;
	int my;
	pthread_t tid;

	puts("Start VGS mk-II SR for Linux.");

	/* Load ROMDATA.BIN */
	fp=fopen("ROMDATA.BIN","rb");
	if(NULL==fp) {
		fprintf(stderr,"ROMDATA.BIN was not found.\n");
		return 1;
	}

	/* allocate table */
	BN=0;
	BR=NULL;
	fread(&BN,sizeof(BN),1,fp);
	if(BN<1) {
		fprintf(stderr,"Inalid ROMDATA.BIN: record number\n");
		fclose(fp);
		return 1;
	}
	if(NULL==(BR=(struct _BINREC*)malloc(BN * sizeof(struct _BINREC)))) {
		fprintf(stderr,"No memory.\n");
		fclose(fp);
		return 1;
	}
	memset(BR,0,BN * sizeof(struct _BINREC));

	/* read filename */
	for(i=0;i<BN;i++) {
		memset(BR[i].name,0,16);
		fread(&BR[i].name,16,1,fp);
		for(j=0;'\0'!=BR[i].name[j];j++) {
			if(15==j) {
				fprintf(stderr,"ROM data is broken.\n");
				fclose(fp);
				return 1;
			}
			BR[i].name[j]^=0xAA;
		}
	}

	/* read data */
	for(i=0;i<BN;i++) {
		fread(s,4,1,fp);
		BR[i].size=s[0];
		BR[i].size<<=8;
		BR[i].size|=s[1];
		BR[i].size<<=8;
		BR[i].size|=s[2];
		BR[i].size<<=8;
		BR[i].size|=s[3];
		if(NULL==(BR[i].data=(char*)malloc(BR[i].size))) {
			fprintf(stderr,"Could not allocate ROM data area: errno=%d (size=%d)\n",errno,BR[i].size);
			fclose(fp);
			return 1;
		}
		fread(BR[i].data,BR[i].size,1,fp);
	}

	fclose(fp);

	/* Extract data */
	cn=0;
	pn=0;
	bn=0;
	for(i=0;i<256;i++) {
		sprintf(path,"GSLOT%03d.CHR",i);
		if(0==gload(i,path)) cn++;
		sprintf(path,"ESLOT%03d.PCM",i);
		if(0==eload(i,path)) pn++;
		sprintf(path,"BSLOT%03d.BGM",i);
		if(0==bload(i,path)) bn++;
	}

	printf("Extracted ROM data: CHR=%d PCM=%d BGM=%d\n",cn,pn,bn);

	/* Initialize SDL */
	if(SDL_Init(SDL_INIT_VIDEO)) {
		fprintf(stderr,"Failed: SDL_Init(SDL_INIT_VIDEO)\n");
		return 1;
	}
	SDL_WM_SetCaption("VGS mk-II SR for Linux",NULL);

	/* Initialize Surface */
	surface=SDL_SetVideoMode(XSIZE*2,YSIZE*2,16,SDL_SWSURFACE);
	if(NULL==surface) {
		fprintf(stderr,"Could not create the surface.\n");
		return 1;
	}
	if(2!=surface->format->BytesPerPixel) {
		fprintf(stderr,"This display does not support 16bit color.\n");
		return 1;
	}
	printf("Created surface: %dx%d\n",surface->w,surface->h);

	/* Initialize sound system */
	if(init_sound()) {
		fprintf(stderr,"Could not create the sound thread.\n");
		return 1;
	}

	/* Initialize user program */
	if(vgs2_init()) {
		fprintf(stderr,"Initialization of the app has failed.\n");
		return 2;
	}
	make_pallet();

	n=0;
	while(1) {
		ticks=SDL_GetTicks();
		SDL_PollEvent(&event);
		if(event.type==SDL_QUIT) break;
		if(SDL_GetMouseState(&mx,&my)&SDL_BUTTON(1)) {
			mx/=2;
			my/=2;
			if(!_touch.s) {
				_touch.dx=0;
				_touch.dy=0;
				_touch.px=mx;
				_touch.py=my;
				_touch.cx=mx;
				_touch.cy=my;
			} else {
				_touch.dx=mx-_touch.px;
				_touch.dy=my-_touch.py;
				_touch.px=_touch.cx;
				_touch.py=_touch.cy;
				_touch.cx=mx;
				_touch.cy=my;
			}
			_touch.s=1;
			_touch.t++;
		} else {
			_touch.s=0;
			_touch.t=0;
		}
		if(_pause) {
			if(vgs2_pause()) break;
		} else {
			if(vgs2_loop()) break;
		}
		if(SDL_MUSTLOCK(surface) && SDL_LockSurface(surface)<0) {
			fprintf(stderr,"Skip frame: could not locked surface.\n");
			usleep(100000);
			continue;
		}
		ptr=(unsigned short*)surface->pixels;
		vp=0;
		pp=0;
		if(_interlace) {
			for(vy=0;vy<YSIZE;vy++) {
				for(vx=0;vx<XSIZE;vx++) {
					if(_vram.sp[vp]) {
						ptr[pp]=ADPAL[_vram.sp[vp]];
						ptr[pp+1]=ADPAL[_vram.sp[vp]];
						ptr[pp+320]=0;
						ptr[pp+321]=0;
						_vram.sp[vp]=0;
					} else {
						ptr[pp]=ADPAL[_vram.bg[vp]];
						ptr[pp+1]=ADPAL[_vram.bg[vp]];
						ptr[pp+320]=0;
						ptr[pp+321]=0;
					}
					vp++;
					pp+=2;
				}
				pp+=320;
			}
		} else {
			for(vy=0;vy<YSIZE;vy++) {
				for(vx=0;vx<XSIZE;vx++) {
					if(_vram.sp[vp]) {
						ptr[pp]=ADPAL[_vram.sp[vp]];
						ptr[pp+1]=ADPAL[_vram.sp[vp]];
						ptr[pp+320]=ADPAL[_vram.sp[vp]];
						ptr[pp+321]=ADPAL[_vram.sp[vp]];
						_vram.sp[vp]=0;
					} else {
						ptr[pp]=ADPAL[_vram.bg[vp]];
						ptr[pp+1]=ADPAL[_vram.bg[vp]];
						ptr[pp+320]=ADPAL[_vram.bg[vp]];
						ptr[pp+321]=ADPAL[_vram.bg[vp]];
					}
					vp++;
					pp+=2;
				}
				pp+=320;
			}
		}
		if(SDL_MUSTLOCK(surface)) SDL_UnlockSurface(surface);
		SDL_UpdateRect(surface,0,0,320,400);
		n++;
		ticks=SDL_GetTicks()-ticks;
		switch(n%3) {
			case 0:
			case 1:
				if(ticks<17) {
					msleep(17-ticks);
				}
				break;
			case 2:
				if(ticks<16) {
					msleep(16-ticks);
				}
				break;
		}
	}
	vgs2_term();
	SDL_Quit();
	term_sound();
	puts("End.");
	return 0;
}