#include "abend.h"
#include "cmdline.h"
#include "fname.h"
+#include "print.h"
#include "version.h"
/* da65 */
/*****************************************************************************/
-/* Code */
+/* Code */
/*****************************************************************************/
" -o name\t\tName the output file\n"
" -v\t\t\tIncrease verbosity\n"
" -F\t\t\tAdd formfeeds to the output\n"
- " -V\t\t\tPrint the assembler version\n"
+ " -S addr\t\tSet the start/load address\n"
+ " -V\t\t\tPrint the disassembler version\n"
"\n"
"Long options:\n"
" --cpu type\t\tSet cpu type\n"
" --formfeeds\t\tAdd formfeeds to the output\n"
" --help\t\tHelp (this text)\n"
" --pagelength n\tSet the page length for the listing\n"
+ " --start-addr addr\tSet the start/load address\n"
" --verbose\t\tIncrease verbosity\n"
- " --version\t\tPrint the assembler version\n",
+ " --version\t\tPrint the disassembler version\n",
ProgName);
}
+static unsigned long CvtNumber (const char* Arg, const char* Number)
+/* Convert a number from a string. Allow '$' and '0x' prefixes for hex
+ * numbers.
+ */
+{
+ unsigned long Val;
+ int Converted;
+
+ /* Convert */
+ if (*Number == '$') {
+ ++Number;
+ Converted = sscanf (Number, "%lx", &Val);
+ } else {
+ Converted = sscanf (Number, "%li", (long*)&Val);
+ }
+
+ /* Check if we do really have a number */
+ if (Converted != 1) {
+ Error ("Invalid number given in argument: %s\n", Arg);
+ }
+
+ /* Return the result */
+ return Val;
+}
+
+
+
static void OptCPU (const char* Opt, const char* Arg)
/* Handle the --cpu option */
{
-static void OptFormFeeds (const char* Opt, const char* Arg)
+static void OptFormFeeds (const char* Opt attribute ((unused)),
+ const char* Arg attribute ((unused)))
/* Add form feeds to the output */
{
FormFeeds = 1;
-static void OptHelp (const char* Opt, const char* Arg)
+static void OptHelp (const char* Opt attribute ((unused)),
+ const char* Arg attribute ((unused)))
/* Print usage information and exit */
{
Usage ();
-static void OptPageLength (const char* Opt, const char* Arg)
+static void OptPageLength (const char* Opt attribute ((unused)), const char* Arg)
/* Handle the --pagelength option */
{
- int Len;
- if (Arg == 0) {
- NeedArg (Opt);
- }
- Len = atoi (Arg);
- if (Len != -1 && (Len < MIN_PAGE_LEN || Len > MAX_PAGE_LEN)) {
+ int Len = atoi (Arg);
+ if (Len != 0 && (Len < MIN_PAGE_LEN || Len > MAX_PAGE_LEN)) {
AbEnd ("Invalid page length: %d", Len);
}
PageLength = Len;
-static void OptVerbose (const char* Opt, const char* Arg)
+static void OptStartAddr (const char* Opt, const char* Arg)
+/* Set the default start address */
+{
+ StartAddr = CvtNumber (Opt, Arg);
+}
+
+
+
+static void OptVerbose (const char* Opt attribute ((unused)),
+ const char* Arg attribute ((unused)))
/* Increase verbosity */
{
++Verbosity;
-static void OptVersion (const char* Opt, const char* Arg)
+static void OptVersion (const char* Opt attribute ((unused)),
+ const char* Arg attribute ((unused)))
/* Print the disassembler version */
{
fprintf (stderr,
const OpcDesc* D = &OpcTable[OPC];
/* If we have a label at this address, output the label */
- const char* Label = GetLabel (PC);
- if (Label) {
- DefLabel (Label);
+ if (MustDefLabel (PC)) {
+ DefLabel (GetLabel (PC));
}
/* Check...
* - ...if there is no label somewhere between the instruction bytes.
* If any of these conditions is true, switch to data mode.
*/
- if (GetStyle (PC) == atDefault) {
+ if (GetStyleAttr (PC) == atDefault) {
if (D->Size > RemainingBytes) {
MarkAddr (PC, atIllegal);
} else if ((D->CPU & CPU) != CPU) {
}
/* Disassemble the line */
- switch (GetStyle (PC)) {
+ switch (GetStyleAttr (PC)) {
case atDefault:
case atCode:
break;
case atByteTab:
- ByteTable (RemainingBytes);
+ ByteTable ();
break;
case atWordTab:
- WordTable (RemainingBytes);
+ WordTable ();
break;
+ case atDWordTab:
+ DWordTable ();
+ break;
+
case atAddrTab:
- AddrTable (RemainingBytes);
+ AddrTable ();
+ break;
+
+ case atRtsTab:
+ RtsTable ();
+ break;
+
+ case atTextTab:
+ TextTable ();
break;
default:
/* Program long options */
static const LongOpt OptTab[] = {
{ "--cpu", 1, OptCPU },
- { "--formfeeds", 0, OptFormFeeds },
- { "--help", 0, OptHelp },
+ { "--formfeeds", 0, OptFormFeeds },
+ { "--help", 0, OptHelp },
{ "--pagelength", 1, OptPageLength },
+ { "--start-addr", 1, OptStartAddr },
{ "--verbose", 0, OptVerbose },
{ "--version", 0, OptVersion },
};
- int I;
+ unsigned I;
/* Initialize the cmdline module */
- InitCmdLine (argc, argv, "da65");
+ InitCmdLine (&argc, &argv, "da65");
/* Check the parameters */
I = 1;
- while (I < argc) {
+ while (I < ArgCount) {
/* Get the argument */
- const char* Arg = argv [I];
+ const char* Arg = ArgVec[I];
/* Check for an option */
if (Arg [0] == '-') {
OptVerbose (Arg, 0);
break;
+ case 'S':
+ OptStartAddr (Arg, GetArg (&I, 2));
+ break;
+
case 'V':
OptVersion (Arg, 0);
break;
}
/* Load the input file */
- LoadCode (InFile, 0xE000); /* ### */
+ LoadCode (InFile, StartAddr);
/* Open the output file */
OpenOutput (OutFile);