Esempio n. 1
0
/*
 *	Read a file into the memory of the emulated CPU.
 *	The following file formats are supported:
 *
 *		binary images with Mostek header
 *		Intel hex
 */
int load_file(char *s)
{
	char fn[LENCMD];
	BYTE fileb[5];
	register char *pfn = fn;
	int fd;

	while (isspace((int)*s))
		s++;
	while (*s != ',' && *s != '\n' && *s != '\0')
		*pfn++ = *s++;
	*pfn = '\0';
	if (strlen(fn) == 0) {
		puts("no input file given");
		return(1);
	}
	if ((fd	= open(fn, O_RDONLY)) == -1) {
		printf("can't open file %s\n", fn);
		return(1);
	}
	if (*s == ',')
		wrk_ram	= mem_base() + exatoi(++s);
	else
		wrk_ram	= NULL;
	read(fd, (char *) fileb, 5); /*	read first 5 bytes of file */
	if (*fileb == (BYTE) 0xff) {	/* Mostek header ? */
		lseek(fd, 0l, SEEK_SET);
		return (load_mos(fd, fn));
	}
	else {
		close(fd);
		return (load_hex(fn));
	}
}
Esempio n. 2
0
/*
 *	Read a file into the memory of the emulated CPU.
 *	The following file formats are supported:
 *
 *		binary images with Mostek header
 *		Intel hex
 */
int load_file(char *s) {
    char fn[LENCMD];
    BYTE fileb[5];
    register char *pfn = fn;
    //	int fd;
    FSFILE *fd;
    if (!FSInit()) printf("Can't Init FS\n\r");
    while (isspace((int) *s))
        s++;
    while (*s != ',' && *s != '\n' && *s != '\0' && *s != '\r')
        *pfn++ = *s++;
    *pfn = '\0';
    if (strlen(fn) == 0) {
        puts("no input file given");
        return (1);
    }
    if ((fd = FSfopen(fn, "R")) == NULL) {
        printf("can't open file %s\n", fn);
        return (1);
    }
    if (*s == ',')
        wrk_ram = ram +exatoi(++s);
    else
        wrk_ram = NULL;
    FSfread((char *) fileb, 5, 1, fd); /*	read first 5 bytes of file */

    if (*fileb == (BYTE) 0xff) { /* Mostek header ? */
        FSfseek(fd, 0l, 0);
        return (load_mos(fd, fn));
    } else {
        close(fd);
        return (load_hex(fn));
    }

}