⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dciwrap.c

📁 DC记录卡读取程序
💻 C
字号:
/*  dciwrap 1.0  (c)2000 Dan Potter  Please see the file README that came with VMULoad for distribution  and usage information.  Thanks to Marcus Comstedt for the VMU format info.*/#include <stdio.h>#include <malloc.h>typedef unsigned char uint8;typedef unsigned short uint16;typedef unsigned long uint32;/* VMU Directory Entry */typedef struct {	uint8	filetype;	/* 0x00 = no file; 0x33 = data; 0xcc = a game */	uint8	copyprotect;	/* 0x00 = copyable; 0xff = copy protected */	uint16	firstblk;	/* location of the first block in the file */	char	filename[12];	/* there is no null terminator */	uint8	cent;		/* these are all file creation date stuff, in BCD format */	uint8	year;	uint8	month;	uint8	day;	uint8	hour;	uint8	min;	uint8	sec;	uint8	dow;		/* day of week (0 = monday, etc) */	uint16	filesize;	/* size of the file in blocks */	uint16	hdroff;		/* offset of header, in blocks from start of file */	char	dummys[4];	/* unused */} dirent_t;/* ROM menu header */typedef struct {	char	desc_short[16];	char	desc_long[32];	char	app_id[16];	uint16	icon_cnt;	uint16	eyecatch_type;	uint16	crc;	uint32	file_bytes;	char	reserved[20];	uint16	palette[16];	uint8	icon_bitmap[32*32/8];} file_hdr_t;/* DCI header (dirent + Rom menu header) */typedef struct {	dirent_t	dirent;		/* Directory header */	file_hdr_t	filehdr;	/* ROM menu header */} dci_hdr_t;/* The loaded binary */char *binary = NULL;int bin_size = 0;/* Loads the binary input file into 'binary' */int load_bin(char *fn) {	FILE *f;		/* Figure the file size and load the file */	f = fopen(fn, "r");	if (!f) return -1;	fseek(f, 0, SEEK_END); bin_size = ftell(f); fseek(f, 0, SEEK_SET);	binary = malloc(bin_size);	fread(binary, bin_size, 1, f);	fclose(f);		return 0;}/* Copies the binary input data, fills the header structures,   and scrambles the byte order for the Nexus. */int gen_output(char *dcfn) {	char		*rawbin = binary;	int		rawbin_size = bin_size;	dirent_t	*de;	file_hdr_t	*fh;	char		*bindata;	uint32		*bd32;	int		i, c, n, crc;	/* Add the file header size and pad it out */		bin_size = (bin_size + 511) & ~511;	bin_size += (511+sizeof(file_hdr_t)) & ~511;		/* Add dir header size and allocate a new block */	bin_size += 32;	binary = malloc(bin_size);	if (!binary) return -1;	memset(binary, 0, bin_size);	/* Figure out where everything goes */		de = (dirent_t*)(binary + 0);	fh = (file_hdr_t*)(binary + 32);	bindata = binary + 32 + ((511+sizeof(file_hdr_t)) & ~511);	/* Fill out the directory structure */	strcpy(de->filename, dcfn);	de->filetype = 0x33;	de->filesize = (bin_size-32) / 512;	de->hdroff = (bindata - binary) / 512;		/* Fill out the header structure */	strcpy(fh->desc_short, dcfn);	strcpy(fh->desc_long, "VMULoad File");	strcpy(fh->app_id, "VMULoad");	fh->icon_cnt = 1;	fh->file_bytes = rawbin_size;	/* Copy over file data */	memcpy(bindata, rawbin, rawbin_size);	/* Calculate the CRC */	n = 0;	bindata = binary+32;	for (i=0; i<(rawbin_size + ((511+sizeof(file_hdr_t)) & ~511)); i++) {		n ^= ((int)bindata[i] << 8);		for (c=0; c<8; c++)			if (n & 0x8000)				n = (n << 1) ^ 4128;			else				n = (n << 1);	}	n = n & 0xffff;	fh->crc = n;	/* Scramble data (change endianness) */	bd32 = (uint32*)binary;	for (i=32/4; i<bin_size/4; i++) {		bd32[i] = (((bd32[i] >> 24) & 0xff) << 0)			| (((bd32[i] >> 16) & 0xff) << 8)			| (((bd32[i] >> 8)  & 0xff) << 16)			| (((bd32[i] >> 0)  & 0xff) << 24);	}		return 0;}/* Writes a DCI output file */int save_dci(char *fn) {	FILE *f;		f = fopen(fn, "w");	if (!f) return -1;	fwrite(binary, bin_size, 1, f);	fclose(f);		return 0;}int main(int argc, char **argv) {	/* Check arg count */	argc--;	if (argc < 3) {		printf("usage: %s infile.bin outfile.dci DCFILENAME\n", argv[0]);		return 0;	}		/* Load the input binary file */	if (load_bin(argv[1]) < 0)		return -1;		/* Produce the output data */	if (gen_output(argv[3]) < 0)		return -1;		/* Write the output file */	if (save_dci(argv[2]) < 0)		return -1;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -