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_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; }
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; }