2002-03-30 16:43:27 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* main.c */
|
|
|
|
/* */
|
|
|
|
/* sim65 main program */
|
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* (C) 2002 Ullrich von Bassewitz */
|
|
|
|
/* Wacholderweg 14 */
|
|
|
|
/* D-70597 Stuttgart */
|
|
|
|
/* EMail: uz@cc65.org */
|
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* This software is provided 'as-is', without any expressed or implied */
|
|
|
|
/* warranty. In no event will the authors be held liable for any damages */
|
|
|
|
/* arising from the use of this software. */
|
|
|
|
/* */
|
|
|
|
/* Permission is granted to anyone to use this software for any purpose, */
|
|
|
|
/* including commercial applications, and to alter it and redistribute it */
|
|
|
|
/* freely, subject to the following restrictions: */
|
|
|
|
/* */
|
|
|
|
/* 1. The origin of this software must not be misrepresented; you must not */
|
|
|
|
/* claim that you wrote the original software. If you use this software */
|
|
|
|
/* in a product, an acknowledgment in the product documentation would be */
|
|
|
|
/* appreciated but is not required. */
|
|
|
|
/* 2. Altered source versions must be plainly marked as such, and must not */
|
|
|
|
/* be misrepresented as being the original software. */
|
|
|
|
/* 3. This notice may not be removed or altered from any source */
|
|
|
|
/* distribution. */
|
|
|
|
/* */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
/* common */
|
|
|
|
#include "abend.h"
|
|
|
|
#include "cmdline.h"
|
|
|
|
#include "print.h"
|
|
|
|
#include "version.h"
|
|
|
|
|
2002-04-07 20:00:39 +00:00
|
|
|
/* sim65 */
|
2002-04-07 13:42:45 +00:00
|
|
|
#include "chip.h"
|
2002-04-07 20:00:39 +00:00
|
|
|
#include "chiplib.h"
|
2002-04-07 13:42:45 +00:00
|
|
|
#include "chippath.h"
|
2002-04-08 20:05:05 +00:00
|
|
|
#include "config.h"
|
2002-04-01 17:55:22 +00:00
|
|
|
#include "cpucore.h"
|
2002-03-30 16:43:27 +00:00
|
|
|
#include "cputype.h"
|
2002-04-08 18:52:47 +00:00
|
|
|
#include "error.h"
|
2002-03-30 16:43:27 +00:00
|
|
|
#include "global.h"
|
2002-04-01 17:42:24 +00:00
|
|
|
#include "memory.h"
|
2002-04-08 18:52:47 +00:00
|
|
|
#include "scanner.h"
|
|
|
|
|
2002-03-30 16:43:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* Code */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void Usage (void)
|
|
|
|
{
|
|
|
|
fprintf (stderr,
|
|
|
|
"Usage: %s [options] file\n"
|
|
|
|
"Short options:\n"
|
2002-04-08 18:52:47 +00:00
|
|
|
" -C name\t\tUse simulator config file\n"
|
|
|
|
" -L dir\t\tSet a chip directory search path\n"
|
2002-03-30 16:43:27 +00:00
|
|
|
" -V\t\t\tPrint the simulator version number\n"
|
|
|
|
" -d\t\t\tDebug mode\n"
|
|
|
|
" -h\t\t\tHelp (this text)\n"
|
|
|
|
" -v\t\t\tIncrease verbosity\n"
|
2002-04-08 18:52:47 +00:00
|
|
|
"\n"
|
|
|
|
"Long options:\n"
|
|
|
|
" --chipdir dir\t\tSet a chip directory search path\n"
|
|
|
|
" --config name\t\tUse simulator config file\n"
|
2002-03-30 16:43:27 +00:00
|
|
|
" --cpu type\t\tSet cpu type\n"
|
|
|
|
" --debug\t\tDebug mode\n"
|
|
|
|
" --help\t\tHelp (this text)\n"
|
|
|
|
" --verbose\t\tIncrease verbosity\n"
|
|
|
|
" --version\t\tPrint the simulator version number\n",
|
|
|
|
ProgName);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-04-08 18:52:47 +00:00
|
|
|
static void OptChipDir (const char* Opt attribute ((unused)), const char* Arg)
|
|
|
|
/* Handle the --chipdir option */
|
|
|
|
{
|
|
|
|
AddChipPath (Arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-03-30 16:43:27 +00:00
|
|
|
static void OptCPU (const char* Opt, const char* Arg)
|
|
|
|
/* Handle the --cpu option */
|
|
|
|
{
|
|
|
|
if (strcmp (Arg, "6502") == 0) {
|
|
|
|
CPU = CPU_6502;
|
|
|
|
} else if (strcmp (Arg, "65C02") == 0) {
|
|
|
|
CPU = CPU_65C02;
|
|
|
|
} else {
|
|
|
|
AbEnd ("Invalid argument for %s: `%s'", Opt, Arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-04-08 18:52:47 +00:00
|
|
|
static void OptConfig (const char* Opt attribute ((unused)), const char* Arg)
|
|
|
|
/* Define the config file */
|
|
|
|
{
|
|
|
|
if (CfgAvail ()) {
|
|
|
|
Error ("Cannot use -C twice");
|
|
|
|
}
|
|
|
|
CfgSetName (Arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-03-30 16:43:27 +00:00
|
|
|
static void OptDebug (const char* Opt attribute ((unused)),
|
2002-04-08 18:52:47 +00:00
|
|
|
const char* Arg attribute ((unused)))
|
2002-03-30 16:43:27 +00:00
|
|
|
/* Simulator debug mode */
|
|
|
|
{
|
|
|
|
Debug = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void OptHelp (const char* Opt attribute ((unused)),
|
|
|
|
const char* Arg attribute ((unused)))
|
|
|
|
/* Print usage information and exit */
|
|
|
|
{
|
|
|
|
Usage ();
|
|
|
|
exit (EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void OptVerbose (const char* Opt attribute ((unused)),
|
|
|
|
const char* Arg attribute ((unused)))
|
|
|
|
/* Increase verbosity */
|
|
|
|
{
|
|
|
|
++Verbosity;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void OptVersion (const char* Opt attribute ((unused)),
|
|
|
|
const char* Arg attribute ((unused)))
|
|
|
|
/* Print the assembler version */
|
|
|
|
{
|
|
|
|
fprintf (stderr,
|
2002-04-08 20:05:05 +00:00
|
|
|
"sim65 V%u.%u.%u\n",
|
2002-03-30 16:43:27 +00:00
|
|
|
VER_MAJOR, VER_MINOR, VER_PATCH);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main (int argc, char* argv[])
|
|
|
|
{
|
|
|
|
/* Program long options */
|
|
|
|
static const LongOpt OptTab[] = {
|
2002-04-08 18:52:47 +00:00
|
|
|
{ "--chipdir", 1, OptChipDir },
|
|
|
|
{ "--config", 1, OptConfig },
|
2002-03-30 16:43:27 +00:00
|
|
|
{ "--cpu", 1, OptCPU },
|
|
|
|
{ "--debug", 0, OptDebug },
|
2002-04-08 18:52:47 +00:00
|
|
|
{ "--help", 0, OptHelp },
|
2002-03-30 16:43:27 +00:00
|
|
|
{ "--verbose", 0, OptVerbose },
|
|
|
|
{ "--version", 0, OptVersion },
|
|
|
|
};
|
|
|
|
|
|
|
|
unsigned I;
|
|
|
|
|
|
|
|
/* Initialize the output file name */
|
|
|
|
const char* InputFile = 0;
|
|
|
|
|
|
|
|
/* Initialize the cmdline module */
|
|
|
|
InitCmdLine (&argc, &argv, "sim65");
|
|
|
|
|
|
|
|
/* Parse the command line */
|
|
|
|
I = 1;
|
|
|
|
while (I < ArgCount) {
|
|
|
|
|
|
|
|
/* Get the argument */
|
|
|
|
const char* Arg = ArgVec[I];
|
|
|
|
|
|
|
|
/* Check for an option */
|
|
|
|
if (Arg [0] == '-') {
|
|
|
|
|
|
|
|
switch (Arg [1]) {
|
|
|
|
|
|
|
|
case '-':
|
|
|
|
LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0]));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'd':
|
|
|
|
OptDebug (Arg, 0);
|
|
|
|
break;
|
|
|
|
|
2002-04-08 18:52:47 +00:00
|
|
|
case 'h':
|
2002-03-30 16:43:27 +00:00
|
|
|
case '?':
|
|
|
|
OptHelp (Arg, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'v':
|
|
|
|
OptVerbose (Arg, 0);
|
|
|
|
break;
|
|
|
|
|
2002-04-08 18:52:47 +00:00
|
|
|
case 'C':
|
|
|
|
OptConfig (Arg, GetArg (&I, 2));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'L':
|
|
|
|
OptChipDir (Arg, GetArg (&I, 2));
|
|
|
|
break;
|
|
|
|
|
2002-03-30 16:43:27 +00:00
|
|
|
case 'V':
|
|
|
|
OptVersion (Arg, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
UnknownOption (Arg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (InputFile) {
|
|
|
|
fprintf (stderr, "additional file specs ignored\n");
|
|
|
|
} else {
|
|
|
|
InputFile = Arg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Next argument */
|
|
|
|
++I;
|
|
|
|
}
|
|
|
|
|
2002-04-08 18:52:47 +00:00
|
|
|
/* Check if we have a valid configuration */
|
|
|
|
if (!CfgAvail ()) {
|
|
|
|
Error ("Simulator configuration missing");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the config file */
|
2002-04-08 20:05:05 +00:00
|
|
|
CfgRead ();
|
2002-04-08 18:52:47 +00:00
|
|
|
|
2002-04-01 17:42:24 +00:00
|
|
|
/* Initialize modules */
|
2002-04-07 13:42:45 +00:00
|
|
|
AddChipPath ("chips");
|
2002-04-07 20:00:39 +00:00
|
|
|
LoadChipLibrary ("ram.so");
|
|
|
|
LoadChips ();
|
2002-04-01 17:42:24 +00:00
|
|
|
MemInit ();
|
2002-04-06 22:11:09 +00:00
|
|
|
MemLoad ("uz.bin", 0x200, 0);
|
2002-04-01 17:55:22 +00:00
|
|
|
CPUInit ();
|
2002-04-06 22:11:09 +00:00
|
|
|
CPURun ();
|
2002-04-01 17:42:24 +00:00
|
|
|
|
2002-03-30 16:43:27 +00:00
|
|
|
/* Return an apropriate exit code */
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|