예제 #1
0
static void SetOptions (void)
/* Set the option for the translator */
{
    StrBuf Buf = STATIC_STRBUF_INITIALIZER;

    /* Set the translator */
    SB_Printf (&Buf, "ca65 V%s", GetVersionAsString ());
    OptTranslator (&Buf);

    /* Set date and time */
    OptDateTime ((unsigned long) time(0));

    /* Release memory for the string */
    SB_Done (&Buf);
}
예제 #2
0
파일: listing.c 프로젝트: cc65/cc65
static void PrintPageHeader (FILE* F, const ListLine* L)
/* Print the header for a new page. It is assumed that the given line is the
** last line of the previous page.
*/
{
    /* Gte a pointer to the current input file */
    const StrBuf* CurFile = GetFileName (L->File);

    /* Print the header on the new page */
    fprintf (F,
             "ca65 V%s\n"
             "Main file   : %s\n"
             "Current file: %.*s\n"
             "\n",
             GetVersionAsString (),
             InFile,
             (int) SB_GetLen (CurFile), SB_GetConstBuf (CurFile));

    /* Count pages, reset lines */
    ++PageNumber;
    PageLines = 4;
}
예제 #3
0
파일: main.c 프로젝트: Aliandrana/snesdev
int main (int argc, char* argv [])
/* Assembler main program */
{
    unsigned I;

    /* Initialize the cmdline module */
    InitCmdLine (&argc, &argv, "ar65");

    /* We must have a file name */
    if (ArgCount < 2) {
	Usage ();
    }

    /* Check the parameters */
    I = 1;
    while (I < ArgCount) {

	/* Get the argument */
	const char* Arg = ArgVec [I];

	/* Check for an option */
	if (strlen (Arg) != 1) {
	    Usage ();
	}
	switch (Arg [0]) {

	    case 'a':
		AddObjFiles (ArgCount - I - 1, &ArgVec[I+1]);
		break;

	    case 'd':
		DelObjFiles (ArgCount - I - 1, &ArgVec [I+1]);
		break;

	    case 'l':
		ListObjFiles (ArgCount - I - 1, &ArgVec [I+1]);
		break;

	    case 'v':
		++Verbosity;
		break;

	    case 'x':
		ExtractObjFiles (ArgCount - I - 1, &ArgVec [I+1]);
		break;

	    case 'V':
		fprintf (stderr,
       	       	       	 "ar65 V%s - (C) Copyright 1998-2009 Ullrich von Bassewitz\n",
			 GetVersionAsString ());
		break;

	    default:
		fprintf (stderr, "Unknown option: %s\n", Arg);
		Usage ();

	}

	/* Next argument */
	++I;
    }

    /* Return an apropriate exit code */
    return EXIT_SUCCESS;
}
예제 #4
0
파일: main.c 프로젝트: MonteCarlos/cc65
int main (int argc, char* argv [])
/* Assembler main program */
{
    unsigned I;

    /* Initialize the cmdline module */
    InitCmdLine (&argc, &argv, "ar65");

    /* We must have a file name */
    if (ArgCount < 2) {
        Usage ();
    }

    /* Check the parameters */
    I = 1;
    while (I < ArgCount) {

        /* Get the argument */
        const char* Arg = ArgVec [I];

        switch (Arg [0]) {

            case 'r': /* POSIX.2 */
            case 'a': /* staying compatible */
                AddObjFiles (ArgCount - I - 1, &ArgVec[I+1]);
                break;

            case 'd':
                DelObjFiles (ArgCount - I - 1, &ArgVec [I+1]);
                break;

            case 't': /* POSIX.2 */
            case 'l': /* staying compatible */
                if (Arg [1] == 'v') {
                    ++Verbosity;
                }
                ListObjFiles (ArgCount - I - 1, &ArgVec [I+1]);
                break;

            case 'v':
                ++Verbosity;
                break;

            case 'x':
                ExtractObjFiles (ArgCount - I - 1, &ArgVec [I+1]);
                break;

            case 'V':
                fprintf (stderr, "%s V%s\n", ProgName, GetVersionAsString ());
                break;

            default:
                fprintf (stderr, "Unknown option: %s\n", Arg);
                Usage ();

        }

        /* Next argument */
        ++I;
    }

    /* Return an apropriate exit code */
    return EXIT_SUCCESS;
}
예제 #5
0
파일: c.c 프로젝트: Aliandrana/cc65
void WriteCFile (const StrBuf* Data, const Collection* A, const Bitmap* B)
/* Write the contents of Data to a file in C format */
{
    FILE*       F;
    const char* D;
    unsigned    Size;


    /* Get the name of the image */
    const StrBuf* S = GetBitmapName (B);

    /* Get the file name */
    const char* Name = NeedAttrVal (A, "name", "write");

    /* Check the number of bytes per line */
    unsigned BytesPerLine = GetBytesPerLine (A);

    /* Get the number base */
    unsigned Base = GetBase (A);

    /* Get the identifier */
    const char* Ident = GetIdentifier (A);

    /* Open the output file */
    F = fopen (Name, "w");
    if (F == 0) {
        Error ("Cannot open output file `%s': %s", Name, strerror (errno));
    }

    /* Write a readable header */
    fprintf (F,
             "/*\n"
             "** This file was generated by %s %s from\n"
             "** %.*s (%ux%u, %u colors%s)\n"
             "*/\n"
             "\n",
             ProgName,
             GetVersionAsString (),
             SB_GetLen (S), SB_GetConstBuf (S),
             GetBitmapWidth (B), GetBitmapHeight (B),
             GetBitmapColors (B),
             BitmapIsIndexed (B)? ", indexed" : "");

    /* If an identifier was given, output #defines for width, height, the
    ** number of colors and declare a variable for the data.
    */
    if (Ident) {
        fprintf (F,
                 "#define %s_COLORS       %u\n"
                 "#define %s_WIDTH        %u\n"
                 "#define %s_HEIGHT       %u\n"
                 "const unsigned char %s[] = {\n",
                 Ident, GetBitmapColors (B),
                 Ident, GetBitmapWidth (B),
                 Ident, GetBitmapHeight (B),
                 Ident);
    }

    /* Write the data */
    D    = SB_GetConstBuf (Data);
    Size = SB_GetLen (Data);
    while (Size) {

        unsigned I;

        /* Output one line */
        unsigned Chunk = Size;
        if (Chunk > BytesPerLine) {
            Chunk = BytesPerLine;
        }
        fputs ("    ", F);
        for (I = 0; I < Chunk; ++I) {
            switch (Base) {
                case 10:
                    fprintf (F, "%u,", *D++ & 0xFF);
                    break;
                case 16:
                    fprintf (F, "0x%02X,", *D++ & 0xFF);
                    break;

            }
        }
        fputc ('\n', F);

        /* Bump the counters */
        Size -= Chunk;
    }

    /* Terminate the array if we had an identifier */
    if (Ident) {
        fputs ("};\n", F);
    }

    /* Close the file */
    if (fclose (F) != 0) {
        Error ("Error closing output file `%s': %s", Name, strerror (errno));
    }
}
예제 #6
0
파일: convert.c 프로젝트: eakmeister/cc65
void Convert (const O65Data* D)
/* Convert the o65 file in D using the given output file. */
{
    FILE*       F;
    unsigned    I;
    char*       Author = 0;

    /* For now, we do only accept o65 files generated by the ld65 linker which
     * have a specific format.
     */
    if (!Debug && D->Header.mode != O65_MODE_CC65) {
        Error ("Cannot convert o65 files of this type");
    }

    /* Output statistics */
    PrintO65Stats (D);

    /* Walk through the options and print them if verbose mode is enabled.
     * Check for a os=cc65 option and bail out if we didn't find one (for
     * now - later we switch to special handling).
     */
    for (I = 0; I < CollCount (&D->Options); ++I) {

        /* Get the next option */
        const O65Option* O = CollConstAt (&D->Options, I);

        /* Check the type of the option */
        switch (O->Type) {

            case O65_OPT_FILENAME:
                Print (stdout, 1, "O65 filename option:         `%s'\n",
                       GetO65OptionText (O));
                break;

            case O65_OPT_OS:
                if (O->Len == 2) {
                    Warning ("Operating system option without data found");
                } else {
                    Print (stdout, 1, "O65 operating system option: `%s'\n",
                           GetO65OSName (O->Data[0]));
                    switch (O->Data[0]) {
                        case O65_OS_CC65_MODULE:
                            if (Model != O65_MODEL_NONE &&
                                Model != O65_MODEL_CC65_MODULE) {
                                Warning ("Wrong o65 model for input file specified");
                            } else {
                                Model = O65_MODEL_CC65_MODULE;
                            }
                            break;
                    }
                }
                break;

            case O65_OPT_ASM:
                Print (stdout, 1, "O65 assembler option:        `%s'\n",
                       GetO65OptionText (O));
                break;

            case O65_OPT_AUTHOR:
                if (Author) {
                    xfree (Author);
                }
                Author = xstrdup (GetO65OptionText (O));
                Print (stdout, 1, "O65 author option:           `%s'\n", Author);
                break;

            case O65_OPT_TIMESTAMP:
                Print (stdout, 1, "O65 timestamp option:        `%s'\n",
                       GetO65OptionText (O));
                break;

            default:
                Warning ("Found unknown option, type %d, length %d",
                         O->Type, O->Len);
                break;
        }
    }

    /* If we shouldn't generate output, we're done here */
    if (NoOutput) {
        return;
    }

    /* Open the output file */
    F = fopen (OutputName, "w");
    if (F == 0) {
        Error ("Cannot open `%s': %s", OutputName, strerror (errno));
    }

    /* Create a header */
    fprintf (F, ";\n; File generated by co65 v %s using model `%s'\n;\n",
             GetVersionAsString (), GetModelName (Model));

    /* Select the CPU */
    if ((D->Header.mode & O65_CPU_MASK) == O65_CPU_65816) {
    	fprintf (F, ".p816\n");
    }

    /* Object file options */
    fprintf (F, ".fopt\t\tcompiler,\"co65 v %s\"\n", GetVersionAsString ());
    if (Author) {
        fprintf (F, ".fopt\t\tauthor, \"%s\"\n", Author);
        xfree (Author);
        Author = 0;
    }

    /* Several other assembler options */
    fprintf (F, ".case\t\ton\n");
    fprintf (F, ".debuginfo\t%s\n", (DebugInfo != 0)? "on" : "off");

    /* Setup/export the segment labels */
    SetupSegLabels (F);

    /* End of header */
    fprintf (F, "\n");

    /* Imported identifiers */
    ConvertImports (F, D);

    /* Exported identifiers */
    ConvertExports (F, D);

    /* Code segment */
    ConvertCodeSeg (F, D);

    /* Data segment */
    ConvertDataSeg (F, D);

    /* BSS segment */
    ConvertBssSeg (F, D);

    /* Zero page segment */
    ConvertZeropageSeg (F, D);

    /* End of data */
    fprintf (F, ".end\n");
    fclose (F);
}