void ttt_write_byte_ram (int addr, unsigned char b) // original name: writeRAMDataB { ttt_ram_enable (); ttt_write_mem (addr, b); ttt_ram_disable (); }
void ttt_write_page_ram (int addr, unsigned char *buf) // original name: writeRAMDataPAGE { int i; ttt_ram_enable (); ttt_set_ai_data (6, 0x98); set_addr_write (addr); for (i = 0; i < 0x100; i++) outportb (port_c, buf[(addr + i) & 0x3fff]); ttt_ram_disable (); }
void ttt_read_ram_b (int addr, unsigned char *buf) // original name: read_rambuff { int count; ttt_ram_enable (); for (count = 0; count < 0x100; count++) { set_addr_read (addr + count); buf[count] = inportb (port_c); // read_data () } ttt_ram_disable (); }
void ttt_write_page_ram2 (int addr, unsigned char *buf) // original name: writeRAMDBDataPAGE { // MD-PRO function int i; ttt_ram_enable (); ttt_set_ai_data (6, 0x98); set_addr_write (addr * 2); for (i = 0; i < 0x80; i++) { outportb (port_c, buf[(addr + i) & 0x3fff]); outportb (port_c, buf[(addr + i) & 0x3fff]); } ttt_ram_disable (); }
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 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; }