int md_read_rom (const char *filename, unsigned short parport, int size) { FILE *file; unsigned short int id; unsigned char buffer[0x100]; int blocksleft, address = 0; time_t starttime; void (*read_block) (int, unsigned char *) = ttt_read_rom_w; // ttt_read_rom_b if ((file = fopen (filename, "wb")) == NULL) { fprintf (stderr, ucon64_msg[OPEN_WRITE_ERROR], filename); exit (1); } ttt_init_io (parport); id = check_card (); if (id == 0) { fclose (file); remove (filename); exit (1); } if ((id == 0xb0d0 || id == 0x8916) && size > 32 * MBIT) size = 32 * MBIT; // Sharp or Intel 32 Mbit flash card #if 0 // size is set to 64 * MBIT "by default" (in ucon64_opts.c) else if (id == 0x8917 && size > 64 * MBIT) size = 64 * MBIT; // Intel 64 Mbit flash card #endif printf ("Receive: %d Bytes (%.4f Mb)\n\n", size, (float) size / MBIT); blocksleft = size >> 8; eep_reset (); ttt_rom_enable (); if (read_block == ttt_read_rom_w) ttt_set_ai_data (6, 0x94); // rst=1, wei=0(dis.), rdi=0(dis.), inc mode, rom_CS starttime = time (NULL); while (blocksleft-- > 0) { read_block (address, buffer); // 0x100 bytes read if (read_block == ttt_read_rom_b) ucon64_bswap16_n (buffer, 0x100); fwrite (buffer, 1, 0x100, file); address += 0x100; if ((address & 0x3fff) == 0) ucon64_gauge (starttime, address, size); } // original code doesn't call ttt_rom_disable() when byte-size function is // used (ttt_read_rom_b() calls it) if (read_block == ttt_read_rom_w) ttt_rom_disable (); fclose (file); return 0; }
u32 EraseNintendoFlashBlocks (u32 StartAddr, u32 BlockCount) { int i = 0; int j, k; time_t starttime = time (NULL); for (k = 0; k < (int) BlockCount; k++) { i = StartAddr + (k * 32768 * _MEM_INC); do { READ_NTURBO_SR (i, j); } while ((j & 0x80) == 0); WriteFlash (i, SHARP28F_BLOCKERASE); // Erase a 64k byte block WriteFlash (i, SHARP28F_CONFIRM); // Comfirm block erase ucon64_gauge (starttime, (k + 1) * 64 * 1024, BlockCount * 64 * 1024); } do { READ_NTURBO_SR (i, j); } while ((j & 0x80) == 0); WriteFlash (i, SHARP28F_READARRAY); // Set normal read mode return 1; }
int smd_read_sram (const char *filename, unsigned int parport) { FILE *file; unsigned char *buffer; int blocksleft, bytesreceived = 0; unsigned short address; time_t starttime; ffe_init_io (parport); if ((file = fopen (filename, "wb")) == NULL) { fprintf (stderr, ucon64_msg[OPEN_WRITE_ERROR], filename); exit (1); } if ((buffer = (unsigned char *) malloc (BUFFERSIZE)) == NULL) { fprintf (stderr, ucon64_msg[FILE_BUFFER_ERROR], BUFFERSIZE); exit (1); } printf ("Receive: %d Bytes\n", 32 * 1024); memset (buffer, 0, SMD_HEADER_LEN); buffer[8] = 0xaa; buffer[9] = 0xbb; buffer[10] = 7; fwrite (buffer, 1, SMD_HEADER_LEN, file); ffe_send_command0 (0x2001, 4); printf ("Press q to abort\n\n"); blocksleft = 2; // SRAM is 2*16 KB address = 0x4000; starttime = time (NULL); while (blocksleft > 0) { ffe_receive_block (address, buffer, BUFFERSIZE); blocksleft--; address += 0x4000; fwrite (buffer, 1, BUFFERSIZE, file); bytesreceived += BUFFERSIZE; ucon64_gauge (starttime, bytesreceived, 32 * 1024); ffe_checkabort (2); } free (buffer); fclose (file); ffe_deinit_io (); return 0; }
int smd_write_rom (const char *filename, unsigned int parport) { FILE *file; unsigned char *buffer; int bytesread, bytessend, blocksdone = 0, fsize; time_t starttime; ffe_init_io (parport); if ((file = fopen (filename, "rb")) == NULL) { fprintf (stderr, ucon64_msg[OPEN_READ_ERROR], filename); exit (1); } if ((buffer = (unsigned char *) malloc (BUFFERSIZE)) == NULL) { fprintf (stderr, ucon64_msg[FILE_BUFFER_ERROR], BUFFERSIZE); exit (1); } fsize = fsizeof (filename); printf ("Send: %d Bytes (%.4f Mb)\n", fsize, (float) fsize / MBIT); fread (buffer, 1, SMD_HEADER_LEN, file); ffe_send_block (0xdc00, buffer, SMD_HEADER_LEN); // send header bytessend = SMD_HEADER_LEN; ffe_send_command0 (0x2001, 0); printf ("Press q to abort\n\n"); starttime = time (NULL); while ((bytesread = fread (buffer, 1, BUFFERSIZE, file))) { ffe_send_command (5, (unsigned short) blocksdone, 0); ffe_send_block (0x8000, buffer, bytesread); blocksdone++; bytessend += bytesread; ucon64_gauge (starttime, bytessend, fsize); ffe_checkabort (2); } // ROM dump > 128 16 KB blocks? (=16 Mb (=2 MB)) ffe_send_command0 (0x2001, (unsigned char) (blocksdone > 0x80 ? 7 : 3)); free (buffer); fclose (file); ffe_deinit_io (); return 0; }
int msg_write_rom (const char *filename, unsigned short parport) { FILE *file; unsigned char *buffer, emu_mode_select; int bytesread, bytessent = 0, size; time_t starttime; unsigned short blocksdone = 0; ffe_init_io (parport); if ((file = fopen (filename, "rb")) == NULL) { fprintf (stderr, ucon64_msg[OPEN_READ_ERROR], filename); exit (1); } if ((buffer = (unsigned char *) malloc (BUFFERSIZE)) == NULL) { fprintf (stderr, ucon64_msg[FILE_BUFFER_ERROR], BUFFERSIZE); exit (1); } size = ucon64.file_size - MSG_HEADER_LEN; printf ("Send: %d Bytes (%.4f Mb)\n", size, (float) size / MBIT); fread (buffer, 1, MSG_HEADER_LEN, file); emu_mode_select = buffer[1]; // this byte is needed later ffe_send_command0 (0xe008, 0); printf ("Press q to abort\n\n"); starttime = time (NULL); while ((bytesread = fread (buffer, 1, BUFFERSIZE, file)) != 0) { ffe_send_command (5, blocksdone, 0); ffe_send_block (0x8000, buffer, (unsigned short) bytesread); blocksdone++; bytessent += bytesread; ucon64_gauge (starttime, bytessent, size); ffe_checkabort (2); } if (emu_mode_select & 1) ffe_send_command (4, 0xff00, 0); else ffe_send_command (4, 0xff03, 0); free (buffer); fclose (file); return 0; }
int mccl_read (const char *filename, unsigned int parport) { unsigned char buffer[0x1760], inbyte; char dest_name[FILENAME_MAX]; int count = 0; time_t starttime; parport_print_info (); puts ("Resetting device"); do { outportb (CONTROL, 0x24); while ((inportb (STATUS) & 0x20) == 0) ; } while ((inportw (DATA) & 0xf) != 4); outportb (CONTROL, 0x22); while ((inportb (STATUS) & 0x20) != 0) ; outportb (CONTROL, 0x26); printf ("Receive: %d Bytes (%.4f Mb)\n\n", 0x1760, (float) 0x1760 / MBIT); starttime = time (NULL); do { outportb (CONTROL, 0x26); while ((inportb (STATUS) & 0x20) == 0) ; inbyte = (unsigned char) (inportw (DATA) & 0xf); outportb (CONTROL, 0x22); while ((inportb (STATUS) & 0x20) != 0) ; outportb (CONTROL, 0x26); while ((inportb (STATUS) & 0x20) == 0) ; inbyte |= (unsigned char) ((inportw (DATA) & 0xf) << 4); outportb (CONTROL, 0x22); while ((inportb (STATUS) & 0x20) != 0) ; buffer[count++] = inbyte; if ((count & 0x1f) == 0) ucon64_gauge (starttime, count, 0x1760); } while (count < 0x1760); strcpy (dest_name, filename); ucon64_file_handler (dest_name, NULL, 0); ucon64_fwrite (buffer, 0, count, dest_name, "wb"); printf (ucon64_msg[WROTE], dest_name); return 0; }
int md_write_sram (const char *filename, unsigned short parport, int start_bank) { FILE *file; unsigned char buffer[0x4000]; int size, bytesread, bytessent = 0, address; time_t starttime; void (*write_block) (int *, unsigned char *) = write_ram_by_byte; // write_ram_by_page (void) write_ram_by_page; size = ucon64.file_size; if (start_bank == -1) address = 0; else { if (start_bank < 1 || start_bank > 4) { fputs ("ERROR: Bank must be a value 1 - 4\n", stderr); exit (1); } address = (start_bank - 1) * 32 * 1024; } if ((file = fopen (filename, "rb")) == NULL) { fprintf (stderr, ucon64_msg[OPEN_READ_ERROR], filename); exit (1); } ttt_init_io (parport); printf ("Send: %d Bytes (%.4f Mb)\n\n", size, (float) size / MBIT); if (check_card () == 0) { fclose (file); exit (1); } starttime = time (NULL); while ((bytesread = fread (buffer, 1, 0x4000, file)) != 0) { write_block (&address, buffer); bytessent += bytesread; ucon64_gauge (starttime, bytessent, size); } fclose (file); return 0; }
int pce_read_rom (const char *filename, unsigned short parport, int size) { FILE *file; unsigned char buffer[0x100]; int blocksleft, address = 0; time_t starttime; void (*read_block) (int, unsigned char *) = ttt_read_rom_w; // ttt_read_rom_b if ((file = fopen (filename, "wb")) == NULL) { fprintf (stderr, ucon64_msg[OPEN_WRITE_ERROR], filename); exit (1); } ttt_init_io (parport); printf ("Receive: %d Bytes (%.4f Mb)\n\n", size, (float) size / MBIT); if (check_card () == 0) { fclose (file); remove (filename); exit (1); } blocksleft = size >> 8; eep_reset (); ttt_rom_enable (); if (read_block == ttt_read_rom_w) ttt_set_ai_data (6, 0x94); // rst=1, wei=0(dis.), rdi=0(dis.), inc mode, rom_CS starttime = time (NULL); while (blocksleft-- > 0) { read_block (address, buffer); // 0x100 bytes read fwrite (buffer, 1, 0x100, file); address += 0x100; if ((address & 0x3fff) == 0) ucon64_gauge (starttime, address, size); } // original code doesn't call ttt_rom_disable() when byte-size function is // used (ttt_read_rom_b() calls it) if (read_block == ttt_read_rom_w) ttt_rom_disable (); fclose (file); return 0; }
int smd_write_sram (const char *filename, unsigned int parport) { FILE *file; unsigned char *buffer; int bytesread, bytessend = 0, size; unsigned short address; time_t starttime; ffe_init_io (parport); if ((file = fopen (filename, "rb")) == NULL) { fprintf (stderr, ucon64_msg[OPEN_READ_ERROR], filename); exit (1); } if ((buffer = (unsigned char *) malloc (BUFFERSIZE)) == NULL) { fprintf (stderr, ucon64_msg[FILE_BUFFER_ERROR], BUFFERSIZE); exit (1); } size = fsizeof (filename) - SMD_HEADER_LEN; printf ("Send: %d Bytes\n", size); fseek (file, SMD_HEADER_LEN, SEEK_SET); // skip the header ffe_send_command0 (0x2001, 4); printf ("Press q to abort\n\n"); address = 0x4000; starttime = time (NULL); while ((bytesread = fread (buffer, 1, BUFFERSIZE, file))) { ffe_send_block (address, buffer, bytesread); address += 0x4000; bytessend += bytesread; ucon64_gauge (starttime, bytessend, size); ffe_checkabort (2); } free (buffer); fclose (file); ffe_deinit_io (); return 0; }
int smsgg_write_rom (const char *filename, unsigned int parport) { FILE *file; unsigned char buffer[0x4000]; int size, address = 0, bytesread, bytessend = 0; time_t starttime; void (*write_block) (int *, unsigned char *) = write_rom_by_page; // write_rom_by_byte (void) write_rom_by_byte; if ((file = fopen (filename, "rb")) == NULL) { fprintf (stderr, ucon64_msg[OPEN_READ_ERROR], filename); exit (1); } ttt_init_io (parport); size = fsizeof (filename); printf ("Send: %d Bytes (%.4f Mb)\n\n", size, (float) size / MBIT); eep_reset (); if (ttt_get_id () != 0xb0d0) { fputs ("ERROR: SMS-PRO/GG-PRO flash card (programmer) not detected\n", stderr); fclose (file); ttt_deinit_io (); exit (1); } starttime = time (NULL); eep_reset (); while ((bytesread = fread (buffer, 1, 0x4000, file))) { if ((address & 0xffff) == 0) ttt_erase_block (address); write_block (&address, buffer); bytessend += bytesread; ucon64_gauge (starttime, bytessend, size); } fclose (file); ttt_deinit_io (); return 0; }
int mcd_read_rom (const char *filename, unsigned short parport) { FILE *file; unsigned char buffer[BUFFERSIZE]; int n_bytes = 0, size; time_t starttime; #if (defined __unix__ || defined __BEOS__) && !defined __MSDOS__ init_conio (); if (register_func (deinit_conio) == -1) { fputs ("ERROR: Could not register function with register_func()\n", stderr); exit (1); } #endif parport_print_info (); if ((file = fopen (filename, "wb")) == NULL) { fprintf (stderr, ucon64_msg[OPEN_WRITE_ERROR], filename); exit (1); } read_block (buffer, 1, parport); size = (buffer[0] + 1) * 64 * 1024; printf ("Receive: %d Bytes (%.4f Mb)\n\n", size, (float) size / MBIT); puts ("Press q to abort\n"); starttime = time (NULL); while (n_bytes < size) { read_block (buffer, BUFFERSIZE, parport); fwrite (buffer, 1, BUFFERSIZE, file); n_bytes += BUFFERSIZE; ucon64_gauge (starttime, n_bytes, size); checkabort (2); } fclose (file); return 0; }
int md_read_sram (const char *filename, unsigned short parport, int start_bank) /* The MD-PRO has 256 kB of SRAM. However, the SRAM dumps of all games that have been tested had each byte doubled. In order to make it possible to easily obtain the SRAM data for use in an emulator, or to send an emulator SRAM file to the MD-PRO, we remove the redundant data when receiving/dumping and double the data when sending. It could be that this approach causes trouble for some games. However, when looking at ToToTEK's own code in ttt_write_page_ram2() this seems unlikely (data is doubled in that function). Note that write_sram_by_byte() is a function written by us, and so does the doubling of data, but it doesn't mean it should work for all games. */ { FILE *file; unsigned char buffer[0x100]; int blocksleft, address, bytesreceived = 0, size, i; time_t starttime; void (*read_block) (int, unsigned char *) = ttt_read_ram_b; // ttt_read_ram_w // This function does not seem to work if ttt_read_ram_w() is used, but see // note below if (start_bank == -1) { address = 0; size = 128 * 1024; } else { if (start_bank < 1 || start_bank > 4) { fputs ("ERROR: Bank must be a value 1 - 4\n", stderr); exit (1); } address = (start_bank - 1) * 32 * 1024; size = 32 * 1024; } if ((file = fopen (filename, "wb")) == NULL) { fprintf (stderr, ucon64_msg[OPEN_WRITE_ERROR], filename); exit (1); } ttt_init_io (parport); printf ("Receive: %d Bytes (%.4f Mb)\n\n", size, (float) size / MBIT); if (check_card () == 0) { fclose (file); remove (filename); exit (1); } if (read_block == ttt_read_ram_w) { // address *= 2; ttt_ram_enable (); #if 0 // According to JohnDie, disabling this statement should make it possible // to use ttt_read_ram_w(). ttt_set_ai_data (6, 0x98); // rst=1, wei=0(dis.), rdi=0(dis.), inc mode, rom_CS #endif } // else // ttt_set_ai_data (6, 0x94); // rst=1, wei=0(dis.), rdi=0(dis.), inc mode, rom_CS blocksleft = size >> 7; starttime = time (NULL); while (blocksleft-- > 0) { read_block (address, buffer); // 0x100 bytes read for (i = 0; i < 0x80; i++) buffer[i] = buffer[2 * i]; // data is doubled => no problems with endianess fwrite (buffer, 1, 0x80, file); address += 0x100; bytesreceived += 0x80; if ((address & 0x3fff) == 0) ucon64_gauge (starttime, bytesreceived, size); } if (read_block == ttt_read_ram_w) ttt_ram_disable (); fclose (file); return 0; }
int md_write_rom (const char *filename, unsigned short parport) { FILE *file; unsigned char buffer[0x4000], game_table[32 * 0x20]; int game_no, size, address = 0, bytesread, bytessent = 0, bytesleft = 0, multi_game; time_t starttime; void (*write_block) (int *, unsigned char *) = write_rom_by_page; // write_rom_by_byte (void) write_rom_by_byte; if ((file = fopen (filename, "rb")) == NULL) { fprintf (stderr, ucon64_msg[OPEN_READ_ERROR], filename); exit (1); } ttt_init_io (parport); fseek (file, 0x83f4, SEEK_SET); buffer[0] = 0; fread (buffer, 1, 12, file); // it's OK to not verify if we can read // currently we ignore the version string (full string is "uCON64 2.0.2") multi_game = strncmp ((char *) buffer, "uCON64", 6) ? 0 : 1; if (multi_game) { fseek (file, 0x8000, SEEK_SET); bytesread = fread (game_table, 1, 32 * 0x20, file); if (bytesread != 32 * 0x20) { fputs ("ERROR: Could not read game table from file\n", stderr); fclose (file); return -1; } } size = ucon64.file_size; printf ("Send: %d Bytes (%.4f Mb)\n\n", size, (float) size / MBIT); md_id = check_card (); if (md_id == 0) { fclose (file); exit (1); } fseek (file, 0, SEEK_SET); starttime = time (NULL); if (!multi_game) bytesleft = size; // one file (no multi-game) eep_reset (); game_no = -1; do { if (game_no >= 0) // a game of a multi-game file bytesleft = game_table[game_no * 0x20 + 0x1d] * MBIT; else if (multi_game) bytesleft = MD_PRO_LOADER_SIZE; // the loader while (bytesleft > 0 && (bytesread = fread (buffer, 1, 0x4000, file)) != 0) { ucon64_bswap16_n (buffer, 0x4000); if ((((address & 0xffff) == 0) && (md_id == 0xb0d0)) || (((address & 0x1ffff) == 0) && (md_id == 0x8916 || md_id == 0x8917))) ttt_erase_block (address); write_block (&address, buffer); bytessent += bytesread; ucon64_gauge (starttime, bytessent, size); bytesleft -= bytesread; } // Games have to be aligned to (start at) a 2 Mbit boundary. address = (address + 2 * MBIT - 1) & ~(2 * MBIT - 1); game_no++; } while (multi_game ? (game_table[game_no * 0x20] && game_no < 31) : 0); fclose (file); return 0; }
u32 EraseNonTurboFABlocks (u32 StartAddr, u32 BlockCount) { u16 k; u16 Ready = 1; u32 i = 0; u32 Timeout; time_t starttime = time (NULL); for (k = 0; k < BlockCount; k++) { i = StartAddr + (k * 65536 * _MEM_INC); Ready = 0; Timeout = FP_TIMEOUT2; while ((Ready == 0) && (Timeout != 0)) { READ_NTURBO_SR (_CART_START, Ready); Ready &= 0x80; Timeout--; } if (Ready) { WriteFlash (i, INTEL28F_BLOCKERASE); // Erase a 128k byte block Ready = 0; Timeout = FP_TIMEOUT3; while ((!Ready) && (Timeout != 0)) { READ_NTURBO_S (Ready); Ready = (Ready == 0x80); Timeout--; } if (Ready) { WriteFlash (i, INTEL28F_CONFIRM); // Comfirm block erase Ready = 0; Timeout = FP_TIMEOUT3; while ((!Ready) && (Timeout != 0)) { READ_NTURBO_S (Ready); Ready = (Ready == 0x80); Timeout--; } if (Ready) { READ_NTURBO_SR (_CART_START, Ready); Ready = (Ready == 0x80); if (!Ready) break; } else break; } else break; } else break; ucon64_gauge (starttime, (k + 1) * 128 * 1024, BlockCount * 128 * 1024); } if (!Ready) { WriteFlash (i, INTEL28F_CLEARSR); // Clear flash status register } WriteFlash (i, INTEL28F_READARRAY); // Set flash to normal read mode WriteFlash (i, INTEL28F_READARRAY); // Set flash to normal read mode return Ready != 0; }
static void cd64_progress (uint32_t current, uint32_t total) { ucon64_gauge (cd64_starttime, current, total); }
int pce_write_rom (const char *filename, unsigned short parport) { FILE *file; unsigned char buffer[0x4000], game_table[32 * 0x20]; int game_no, size, romsize = 0, startaddress, address = 0, bytesread, bytessent = 0, bytesleft, multi_game; time_t starttime; void (*write_block) (int *, unsigned char *) = write_rom_by_page; // write_rom_by_byte (void) write_rom_by_byte; if ((file = fopen (filename, "rb")) == NULL) { fprintf (stderr, ucon64_msg[OPEN_READ_ERROR], filename); exit (1); } ttt_init_io (parport); fseek (file, 0xb3f4, SEEK_SET); buffer[0] = 0; fread (buffer, 1, 12, file); // it's OK to not verify if we can read // currently we ignore the version string (full string is "uCON64 2.0.1") multi_game = strncmp ((char *) buffer, "uCON64", 6) ? 0 : 1; if (multi_game) { fseek (file, 0xb000, SEEK_SET); bytesread = fread (game_table, 1, 32 * 0x20, file); if (bytesread != 32 * 0x20) { fputs ("ERROR: Could not read game table from file\n", stderr); fclose (file); return -1; } } size = ucon64.file_size; // 4 Mbit games need the last 2 Mbit to be mirrored (so, they need 6 Mbit) if (multi_game) { game_no = 0; while (game_table[game_no * 0x20] && game_no < 31) { if (game_table[game_no * 0x20 + 0x1e] == 4) size += 2 * MBIT; game_no++; } } else { romsize = size; // one file (no multi-game) if (size == 4 * MBIT) size += 2 * MBIT; } printf ("Send: %d Bytes (%.4f Mb)\n\n", size, (float) size / MBIT); if (check_card () == 0) { fclose (file); exit (1); } fseek (file, 0, SEEK_SET); starttime = time (NULL); eep_reset (); game_no = -1; do { if (game_no >= 0) // a game of a multi-game file romsize = game_table[game_no * 0x20 + 0x1e] * MBIT; else if (multi_game) romsize = PCE_PRO_LOADER_SIZE; // the loader bytesleft = romsize; if (bytesleft == 4 * MBIT) bytesleft += 2 * MBIT; startaddress = address; while (bytesleft > 0 && (bytesread = fread (buffer, 1, 0x4000, file)) != 0) { if ((address & 0xffff) == 0) ttt_erase_block (address); write_block (&address, buffer); if ((romsize == 3 * MBIT) && (address - startaddress == 2 * MBIT)) address += 2 * MBIT; else if ((romsize == 4 * MBIT) && (address - startaddress == 4 * MBIT)) fseek (file, -2 * MBIT, SEEK_CUR); bytessent += bytesread; ucon64_gauge (starttime, bytessent, size); bytesleft -= bytesread; } // Games have to be aligned to a Mbit boundary. address = (address + MBIT - 1) & ~(MBIT - 1); game_no++; } while (multi_game ? (game_table[game_no * 0x20] && game_no < 31) : 0); fclose (file); return 0; }
int smsgg_read_sram (const char *filename, unsigned int parport, int start_bank) { FILE *file; unsigned char buffer[0x100]; int blocksleft, address, size, bytesreceived = 0; time_t starttime; void (*read_block) (int, unsigned char *) = ttt_read_ram_b; // ttt_read_ram_w if (start_bank == -1) { address = 0; size = 128 * 1024; } else { if (start_bank < 1 || start_bank > 4) { fputs ("ERROR: Bank must be a value 1 - 4\n", stderr); exit (1); } address = (start_bank - 1) * 32 * 1024; size = 32 * 1024; } if ((file = fopen (filename, "wb")) == NULL) { fprintf (stderr, ucon64_msg[OPEN_WRITE_ERROR], filename); exit (1); } ttt_init_io (parport); printf ("Receive: %d Bytes (%.4f Mb)\n\n", size, (float) size / MBIT); if (read_block == ttt_read_ram_w) { ttt_ram_enable (); ttt_set_ai_data (6, 0x98); // rst=1, wei=0(dis.), rdi=0(dis.), inc mode, rom_CS } // else // ttt_set_ai_data (6, 0x94); // rst=1, wei=0(dis.), rdi=0(dis.), inc mode, rom_CS blocksleft = size >> 8; starttime = time (NULL); while (blocksleft-- > 0) { read_block (address, buffer); // 0x100 bytes read fwrite (buffer, 1, 0x100, file); address += 0x100; bytesreceived += 0x100; if ((address & 0x3fff) == 0) ucon64_gauge (starttime, bytesreceived, size); } if (read_block == ttt_read_ram_w) ttt_ram_disable (); fclose (file); ttt_deinit_io (); return 0; }
u32 EraseTurboFABlocks (u32 StartAddr, u32 BlockCount) { u16 j, k; u16 done1, done2; u16 Ready = 1; u32 i = 0; u32 Timeout; time_t starttime = time (NULL); for (k = 0; k < BlockCount; k++) { i = StartAddr + (k * 131072 * _MEM_INC); Ready = 0; Timeout = FP_TIMEOUT2; while ((!Ready) && (Timeout != 0)) { READ_TURBO_SR (j); Ready = (j == 0x8080); Timeout--; } if (Ready) { done1 = 0; done2 = 0; Ready = 0; Timeout = FP_TIMEOUT3; while ((!Ready) && (Timeout != 0)) { if (done1 == 0) WriteFlash (i, INTEL28F_BLOCKERASE); // Erase a 128k byte block in flash #1 if (done2 == 0) WriteFlash (i + _MEM_INC, INTEL28F_BLOCKERASE); // Erase a 128k byte block in flash #2 READ_TURBO_S2 (_CART_START, done1, done2); Ready = ((done1 + done2) == 0x100); Timeout--; } if (Ready) { WriteFlash (i, INTEL28F_CONFIRM); // Comfirm block erase in flash #1 WriteFlash (i + _MEM_INC, INTEL28F_CONFIRM); // Comfirm block erase in flash #2 Ready = 0; Timeout = FP_TIMEOUT3; j = 0; while (((j & 0x8080) != 0x8080) && (Timeout != 0)) { READ_TURBO_S (j); Ready = (j == 0x8080); Timeout--; } if (!Ready) break; } else break; } else break; ucon64_gauge (starttime, (k + 1) * 256 * 1024, BlockCount * 256 * 1024); } if (!Ready) { WriteFlash (i, INTEL28F_CLEARSR); WriteFlash (i + _MEM_INC, INTEL28F_CLEARSR); } WriteFlash (_CART_START, INTEL28F_READARRAY); WriteFlash (_CART_START + _MEM_INC, INTEL28F_READARRAY); WriteFlash (_CART_START, INTEL28F_READARRAY); WriteFlash (_CART_START + _MEM_INC, INTEL28F_READARRAY); return Ready != 0; }
int msg_read_rom (const char *filename, unsigned short parport) { FILE *file; unsigned char *buffer, blocksleft, emu_mode_select; int size, bytesreceived = 0; time_t starttime; unsigned short blocksdone = 0; ffe_init_io (parport); if ((file = fopen (filename, "wb")) == NULL) { fprintf (stderr, ucon64_msg[OPEN_WRITE_ERROR], filename); exit (1); } if ((buffer = (unsigned char *) malloc (BUFFERSIZE)) == NULL) { fprintf (stderr, ucon64_msg[FILE_BUFFER_ERROR], BUFFERSIZE); exit (1); } set_header (buffer); if (buffer[0] == 0) { fprintf (stderr, "ERROR: There is no cartridge present in the Magic Super Griffin\n"); fclose (file); remove (filename); exit (1); } blocksleft = buffer[0]; size = buffer[0] * 8192; printf ("Receive: %d Bytes (%.4f Mb)\n", size, (float) size / MBIT); fwrite (buffer, 1, MSG_HEADER_LEN, file); // write header emu_mode_select = buffer[1]; ffe_send_command (5, 0, 0); ffe_send_command0 (0xbff0, 0); printf ("Press q to abort\n\n"); starttime = time (NULL); while (blocksleft > 0) { ffe_send_command (5, blocksdone, 0); if (emu_mode_select && blocksdone >= 32) ffe_send_command (5, blocksdone + 32, 0); ffe_receive_block (0xa000, buffer, BUFFERSIZE); // vgs aborts if the checksum doesn't match the data, we let the user decide blocksleft--; blocksdone++; fwrite (buffer, 1, BUFFERSIZE, file); bytesreceived += BUFFERSIZE; ucon64_gauge (starttime, bytesreceived, size); ffe_checkabort (2); } free (buffer); fclose (file); return 0; }
int smd_read_rom (const char *filename, unsigned int parport) { FILE *file; unsigned char *buffer, byte; int size, blocksdone = 0, blocksleft, bytesreceived = 0; time_t starttime; ffe_init_io (parport); if ((file = fopen (filename, "wb")) == NULL) { fprintf (stderr, ucon64_msg[OPEN_WRITE_ERROR], filename); exit (1); } if ((buffer = (unsigned char *) malloc (BUFFERSIZE)) == NULL) { fprintf (stderr, ucon64_msg[FILE_BUFFER_ERROR], BUFFERSIZE); exit (1); } ffe_send_command (1, 0xdff1, 1); byte = ffe_receiveb (); if ((0x81 ^ byte) != ffe_receiveb ()) printf ("received data is corrupt\n"); blocksleft = 8 * byte; if (blocksleft == 0) { fprintf (stderr, "ERROR: There is no cartridge present in the Super Magic Drive\n"); fclose (file); remove (filename); exit (1); } memset (buffer, 0, SMD_HEADER_LEN); buffer[0] = blocksleft; buffer[1] = 3; buffer[8] = 0xaa; buffer[9] = 0xbb; buffer[10] = 6; fwrite (buffer, 1, SMD_HEADER_LEN, file); // write header size = blocksleft * 16384; // size in bytes for ucon64_gauge() below printf ("Receive: %d Bytes (%.4f Mb)\n", size, (float) size / MBIT); wait2 (32); ffe_send_command0 (0x2001, 0); printf ("Press q to abort\n\n"); starttime = time (NULL); while (blocksleft > 0) { ffe_send_command (5, (unsigned short) blocksdone, 0); ffe_receive_block (0x4000, buffer, BUFFERSIZE); blocksdone++; blocksleft--; fwrite (buffer, 1, BUFFERSIZE, file); bytesreceived += BUFFERSIZE; ucon64_gauge (starttime, bytesreceived, size); ffe_checkabort (2); } free (buffer); fclose (file); ffe_deinit_io (); return 0; }