add snesram prototype

This commit is contained in:
David Voswinkel 2009-07-06 22:54:45 +02:00
parent bcd3d802f0
commit 2e84cf22d1
6 changed files with 225 additions and 2 deletions

View File

@ -107,7 +107,7 @@ OBJECTS=ucon64.o ucon64_dat.o ucon64_misc.o ucon64_opts.o \
backup/fig.o backup/gbx.o backup/gd.o backup/interceptor.o \
backup/lynxit.o backup/mccl.o backup/mcd.o backup/md-pro.o \
backup/mgd.o backup/msg.o backup/pce-pro.o backup/pl.o \
backup/psxpblib.o backup/sflash.o backup/smc.o backup/smd.o \
backup/psxpblib.o backup/sflash.o backup/snesram.o backup/smc.o backup/smd.o \
backup/smsgg-pro.o backup/ssc.o backup/swc.o backup/tototek.o \
backup/ufo.o backup/yoko.o backup/z64.o
ifdef USE_ZLIB

View File

@ -58,5 +58,9 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#if defined USE_PARALLEL || defined USE_USB
#include "f2a.h"
#endif
#ifdef USE_USB
#include "snesram.h"
#endif // USE_PARALLEL
#endif // BACKUP_H

View File

@ -0,0 +1,178 @@
/*
snesram.c - Snesram support for uCON64
Copyright (c) 2009 david@optixx.org
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include "misc/misc.h"
#include "misc/itypes.h"
#ifdef USE_ZLIB
#include "misc/archive.h"
#endif
#include "misc/getopt2.h" // st_getopt2_t
#include "misc/file.h"
#include "ucon64.h"
#include "ucon64_misc.h"
#include "ffe.h"
#include "smc.h"
#include "snesram.h"
const st_getopt2_t snesram_usage[] =
{
{
NULL, 0, 0, 0,
NULL, "Snesram"/* http://www.optixx.org */,
NULL
},
#ifdef USE_USB
{
"xsnesram", 0, 0, UCON64_XSNESRAM, // send only
NULL, "send ROM (in FFE format) to Snesram; " OPTION_LONG_S "port=PORT",
&ucon64_wf[WF_OBJ_NES_DEFAULT_STOP_NO_SPLIT]
},
#endif
{NULL, 0, 0, 0, NULL, NULL, NULL}
};
#ifdef USE_USB
#define BUFFERSIZE 8192
int
snesram_write_rom (const char *filename)
{
FILE *file;
unsigned char *buffer;
int bytesread, bytessend, size, offset, n_blocks1, n_blocks2, n_blocks3, n;
time_t starttime;
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);
}
fread (buffer, 1, SMC_HEADER_LEN, file);
size = (n_blocks1 + n_blocks2 + n_blocks3) * 8 * 1024 + 8 +
(buffer[0] & SMC_TRAINER ? 512 : 0);
printf ("Send: %d Bytes (%.4f Mb)\n", size, (float) size / MBIT);
ffe_send_block (0x5020, buffer, 8); // send "file control block"
bytessend = 8;
if (buffer[1] >> 5 > 4)
offset = 12;
else
offset = 0;
if (buffer[0] & SMC_TRAINER) // send trainer if present
{
fread (buffer, 1, 512, file);
ffe_send_block (0x600, buffer, 512);
bytessend += 512;
}
printf ("Press q to abort\n\n");
starttime = time (NULL);
for (n = 0; n < n_blocks1; n++)
{
ffe_send_command0 (0x4507, (unsigned char) (n + offset));
if ((bytesread = fread (buffer, 1, BUFFERSIZE, file)) == 0)
break;
ffe_send_block (0x6000, buffer, bytesread);
bytessend += bytesread;
ucon64_gauge (starttime, bytessend, size);
ffe_checkabort (2);
}
for (n = 0; n < n_blocks2; n++)
{
ffe_send_command0 (0x4507, (unsigned char) (n + 32));
if ((bytesread = fread (buffer, 1, BUFFERSIZE, file)) == 0)
break;
ffe_send_block (0x6000, buffer, bytesread);
bytessend += bytesread;
ucon64_gauge (starttime, bytessend, size);
ffe_checkabort (2);
}
ffe_send_command0 (0x2001, 0);
for (n = 0; n < n_blocks3; n++)
{
if (n == 0)
{
ffe_send_command0 (0x4500, 0x22);
ffe_send_command0 (0x42ff, 0x30);
if ((bytesread = fread (buffer, 1, BUFFERSIZE, file)) == 0)
break;
ffe_send_block (0x6000, buffer, bytesread);
}
else
{
int m;
ffe_send_command0 (0x4500, 7);
for (m = 0; m < 8; m++)
ffe_send_command0 ((unsigned short) (0x4510 + m), (unsigned char) (n * 8 + m));
if ((bytesread = fread (buffer, 1, BUFFERSIZE, file)) == 0)
break;
ffe_send_block2 (0, buffer, bytesread);
}
bytessend += bytesread;
ucon64_gauge (starttime, bytessend, size);
ffe_checkabort (2);
}
for (n = 0x4504; n < 0x4508; n++)
ffe_send_command0 ((unsigned short) n, 0);
for (n = 0x4510; n < 0x451c; n++)
ffe_send_command0 ((unsigned short) n, 0);
ffe_send_command (5, 1, 0);
free (buffer);
fclose (file);
ffe_deinit_io ();
return 0;
}
#endif // USE_USB

View File

@ -0,0 +1,30 @@
/*
snesram.h - Snesram support for uCON64
Copyright (c) 2009 david@optixx.org
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef SNESRAM_H
#define SNESRAM_H
extern const st_getopt2_t snesram_usage[];
#ifdef USE_USB
extern int snesram_write_rom (const char *filename);
#endif
#endif // SMC_H

View File

@ -324,6 +324,7 @@ enum
UCON64_XSFS,
UCON64_XSMC,
UCON64_XSMCR,
UCON64_XSNESRAM,
UCON64_XSMD,
UCON64_XSMDS,
UCON64_XSWC,

View File

@ -308,6 +308,7 @@ ucon64_switches (st_ucon64_t *p)
case UCON64_XSFS:
case UCON64_XSMC:
case UCON64_XSMCR:
case UCON64_XSNESRAM:
case UCON64_XSMD:
case UCON64_XSMDS:
case UCON64_XSWC:
@ -558,7 +559,7 @@ ucon64_switches (st_ucon64_t *p)
break;
case UCON64_Q:
case UCON64_QQ: // for now -qq is equivalent to -q
case UCON64_QQ: //UCON64_XSMC for now -qq is equivalent to -q
ucon64.quiet = 1;
break;
@ -2051,6 +2052,15 @@ ucon64_options (st_ucon64_t *p)
fputc ('\n', stdout);
break;
case UCON64_XSNESRAM:
if (!ucon64.rominfo->buheader_len)
fputs ("ERROR: This ROM has no header. Convert to an SMC compatible format with -ffe\n",
stderr);
else
snesram_write_rom (ucon64.rom);
fputc ('\n', stdout);
break;
case UCON64_XSMD:
if (access (ucon64.rom, F_OK) != 0) // file does not exist -> dump cartridge
smd_read_rom (ucon64.rom, ucon64.parport);