- /* For now, we do only accept o65 files generated by the ld65 linker which
- * have a specific format.
- */
- if (D->Header.mode != O65_MODE_CC65) {
- Error ("Cannot convert o65 files of this type");
- }
-
- /* Output statistics */
- Print (stdout, 1, "Size of text segment: %5lu\n", D->Header.tlen);
- Print (stdout, 1, "Size of data segment: %5lu\n", D->Header.dlen);
- Print (stdout, 1, "Size of bss segment: %5lu\n", D->Header.blen);
- Print (stdout, 1, "Size of zeropage segment: %5lu\n", D->Header.zlen);
- Print (stdout, 1, "Number of imports: %5u\n", CollCount (&D->Imports));
- Print (stdout, 1, "Number of exports: %5u\n", CollCount (&D->Exports));
- Print (stdout, 1, "Number of text segment relocations: %5u\n", CollCount (&D->TextReloc));
- Print (stdout, 1, "Number of data segment relocations: %5u\n", CollCount (&D->DataReloc));
-
- /* 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).
- */
- cc65 = 0;
- for (I = 0; I < CollCount (&D->Options); ++I) {
-
- /* Get the next option */
- const O65Option* O = CollConstAt (&D->Options, I);
-
- /* Check the type */
- 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 {
- cc65 = (O->Data[0] == O65_OS_CC65_MODULE);
- Print (stdout, 1, "O65 operating system option: `%s'\n",
- GetO65OSName (O->Data[0]));
- }
- 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;
- }
- }
-
- /* Open the output file */
- F = fopen (OutputName, "wb");
- if (F == 0) {
- Error ("Cannot open `%s': %s", OutputName, strerror (errno));
- }
-
- /* Create a header */
- fprintf (F, ";\n; File generated by co65 v %u.%u.%u\n;\n",
- VER_MAJOR, VER_MINOR, VER_PATCH);
-
- /* Select the CPU */
- if ((D->Header.mode & O65_CPU_MASK) == O65_CPU_65816) {
- fprintf (F, "\t.p816\n");
- }
-
- /* Object file options */
- fprintf (F, "\t.fopt\t\tcompiler,\"co65 v %u.%u.%u\"\n",
- VER_MAJOR, VER_MINOR, VER_PATCH);
- if (Author) {
- fprintf (F, "\t.fopt\t\tauthor, \"%s\"\n", Author);
- xfree (Author);
- Author = 0;
- }
-
- /* Several other assembler options */
- fprintf (F, "\t.case\t\ton\n");
- fprintf (F, "\t.debuginfo\t%s\n", (DebugInfo != 0)? "on" : "off");
-
- /* Setup/export the segment labels */
- if (BssLabel) {
- fprintf (F, "\t.export\t\t%s\n", BssLabel);
- } else {
- BssLabel = xstrdup ("__BSS__");
- }
- if (CodeLabel) {
- fprintf (F, "\t.export\t\t%s\n", CodeLabel);
- } else {
- CodeLabel = xstrdup ("__CODE__");
- }
- if (DataLabel) {
- fprintf (F, "\t.export\t\t%s\n", DataLabel);
- } else {
- DataLabel = xstrdup ("__DATA__");
- }
- if (ZeropageLabel) {
- fprintf (F, "\t.export\t\t%s\n", ZeropageLabel);
- } else {
- /* If this is a cc65 module, override the name for the zeropage segment */
- if (cc65) {
- ZeropageLabel = "__ZP_START__";
- fprintf (F, "\t.import\t\t__ZP_START__\t; Linker generated symbol\n");
- } else {
- ZeropageLabel = xstrdup ("__ZEROPAGE__");
- }
- }
-
- /* End of header */
- fprintf (F, "\n");
-
- /* Imported identifiers */
- if (CollCount (&D->Imports) > 0) {
- for (I = 0; I < CollCount (&D->Imports); ++I) {
-
- /* Get the next import */
- O65Import* Import = CollAtUnchecked (&D->Imports, I);
-
- /* Import it by name */
- fprintf (F, "\t.import\t%s\n", Import->Name);
- }
- fprintf (F, "\n");
- }
-
- /* Exported identifiers */
- if (CollCount (&D->Exports) > 0) {
- for (I = 0; I < CollCount (&D->Exports); ++I) {
-
- /* Get the next import */
- O65Export* Export = CollAtUnchecked (&D->Exports, I);
-
- /* First define it */
- fprintf (F, "%s = XXX\n", Export->Name); /* ### */
-
- /* The export it by name */
- fprintf (F, "\t.export\t%s\n", Export->Name);
- }
- fprintf (F, "\n");
- }
-
- /* Code segment */
- fprintf (F, ".segment\t\"%s\"\n", CodeSeg);
- fprintf (F, "%s:\n", CodeLabel);
- ConvertSeg (F, D, &D->TextReloc, D->Text, D->Header.tlen);
-
- /* Data segment */
- fprintf (F, ".segment\t\"%s\"\n", DataSeg);
- fprintf (F, "%s:\n", DataLabel);
- ConvertSeg (F, D, &D->DataReloc, D->Data, D->Header.dlen);