int sdcard_init ( const char *fn, const char *extd81fn ) { char fnbuf[PATH_MAX + 1]; atexit(sdcard_shutdown); sd_status = 0; sd_is_read_only = 1; d81_is_read_only = 1; mounted = 0; memset(sd_sector_bytes, 0, sizeof sd_sector_bytes); memset(sd_d81_img1_start, 0, sizeof sd_d81_img1_start); sdfd = emu_load_file(fn, fnbuf, -1); // get the file descriptor only ... if (sdfd < 0) { ERROR_WINDOW("Cannot open SD-card image %s, SD-card access won't work! ERROR: %s", fn, strerror(errno)); DEBUG("SDCARD: cannot open image %s" NL, fn); } else { // try to open in R/W mode ... int tryfd = open(fnbuf, O_RDWR | O_BINARY); if (tryfd >= 0) { // use R/W mode descriptor if it was OK! close(sdfd); sdfd = tryfd; DEBUG("SDCARD: image file re-opened in RD/WR mode, good" NL); sd_is_read_only = 0; } else INFO_WINDOW("Image file %s could be open only in R/O mode", fnbuf); // Check size! DEBUG("SDCARD: cool, SD-card image %s (as %s) is open" NL, fn, fnbuf); sd_card_size = lseek(sdfd, 0, SEEK_END); if (sd_card_size == (off_t)-1) { ERROR_WINDOW("Cannot query the size of the SD-card image %s, SD-card access won't work! ERROR: %s", fn, strerror(errno)); close(sdfd); sdfd = -1; return sdfd; } if (sd_card_size > 2147483648UL) { ERROR_WINDOW("SD-card image is too large! Max allowed size is 2Gbytes!"); close(sdfd); sdfd = -1; return sdfd; } if (sd_card_size < 67108864) { ERROR_WINDOW("SD-card image is too small! Min required size is 64Mbytes!"); close(sdfd); sdfd = -1; return sdfd; } DEBUG("SDCARD: detected size in Mbytes: %d" NL, (int)(sd_card_size >> 20)); if (sd_card_size & (off_t)511) { ERROR_WINDOW("SD-card image size is not multiple of 512 bytes!!"); close(sdfd); sdfd = -1; return sdfd; } } if (sdfd >= 0) open_external_d81(extd81fn); return sdfd; }
static int open_external_d81 ( const char *fn ) { char fnbuf[PATH_MAX + 1]; if (!fn) return -1; d81_is_read_only = 1; d81fd = emu_load_file(fn, fnbuf, -1); // get the file descriptor only ... if (d81fd < 0) { ERROR_WINDOW("External D81 image was specified (%s) but it cannot be opened: %s", fn, strerror(errno)); DEBUG("SDCARD: cannot open external D81 image %s" NL, fn); } else { off_t d81_size; // try to open in R/W mode int tryfd = open(fnbuf, O_RDWR | O_BINARY); if (tryfd >= 0) { close(d81fd); d81fd = tryfd; DEBUG("SDCARD: exernal D81 image file re-opened in RD/WR mode, good" NL); d81_is_read_only = 0; } else { INFO_WINDOW("External D81 image file %s could be open only in R/O mode", fnbuf); } d81_size = lseek(d81fd, 0, SEEK_END); if (d81_size == (off_t)-1) { ERROR_WINDOW("Cannot query the size of external D81 image %s, using on-SD images! ERROR: %s", fn, strerror(errno)); close(d81fd); d81fd = -1; return d81fd; } if (d81_size != D81_SIZE) { ERROR_WINDOW("Bad external D81 image size " PRINTF_LLD " for %s, should be %d bytes!", (long long)d81_size, fnbuf, D81_SIZE); close(d81fd); d81fd = -1; return d81fd; } } return d81fd; }
int geos_load_kernal ( void ) { Uint8 buffer[0xB000]; int len = emu_load_file(GEOS_KERNAL_NAME, buffer, sizeof buffer); int addr; if (len < 0) { INFO_WINDOW("Cannot open GEOS kernal (%s), or I/O error", GEOS_KERNAL_NAME); return 1; // file not found, or I/O error } if (len < 0x1000) { INFO_WINDOW("Abnormally short GEOS kernal (%s)", GEOS_KERNAL_NAME); return 1; } if (len == sizeof buffer) { INFO_WINDOW("Abnormally large GEOS kernal (%s)", GEOS_KERNAL_NAME); return 1; } addr = buffer[0] | (buffer[1] << 8); // load address if (addr == 0x5000) { cpu_pc = 0x5000; } else if (addr == 0x801) { int sys = check_basic_stub(buffer + 6, addr); if (sys < 0) { INFO_WINDOW("Invalid BASIC stub for the GEOS kernal (%s)", GEOS_KERNAL_NAME); return 1; } cpu_pc = sys; inject_screencoded_message(6 * 40, "*** Basic stub, you need to wait now ***"); } else { INFO_WINDOW("Invalid GEOS kernal load address ($%04X) in (%s)", addr, GEOS_KERNAL_NAME); return 1; } // OK. Everything seems to be so okey ... memcpy(memory + addr, buffer + 2, len - 2); return 0; }