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; }
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; }
unsigned short int check_card (void) { unsigned short int id; eep_reset (); id = ttt_get_id (); if ((id != 0xb0d0) && (id != 0x8916) && (id != 0x8917)) // Sharp 32M, Intel 64J3 { fprintf (stderr, "ERROR: MD-PRO flash card (programmer) not detected (ID: 0x%02hx)\n", id); return 0; } else return id; }
static unsigned short int check_card (void) { unsigned short int id; eep_reset (); id = ttt_get_id (); if (id != 0xb0d0) { fprintf (stderr, "ERROR: PCE-PRO flash card (programmer) not detected (ID: 0x%02hx)\n", id); return 0; } else return id; }
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 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; }
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; }