Re: [cc65] Read bytes (program load address) from a file?

From: Ullrich von Bassewitz <uz1musoftware.de>
Date: 2006-09-26 10:01:45
Hi!

On Mon, Sep 25, 2006 at 06:17:31PM -0400, Raj Wurttemberg wrote:
> I'm trying to write a simple program to read the load address of a C64
> program. I tried the cbm_read function but the wrong bytes come up. Is there
> another function I should use?

Try this (untested):


-----------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>

int main (void)
{
    unsigned char Buf[2];
    int Count;

    /* Open the file */
    int Handle = open ("name", O_RDONLY);
    if (Handle < 0) {
        fprintf (stderr, "File open error: %s\n", strerror (errno));
        return EXIT_FAILURE;
    }

    /* Read data */
    Count = read (Handle, Buf, sizeof (Buf));
    if (Count < 0) {
        fprintf (stderr, "File read error: %s\n", strerror (errno));
        return EXIT_FAILURE;
    }
    if (Count != sizeof (Buf)) {
        fprintf (stderr, "Out of file data in read\n");
        return EXIT_FAILURE;
    }

    /* No error checking on close */
    (void) close (Handle);

    /* Output the data read */
    printf ("Bytes read: %02X %02X\n", Buf[0], Buf[1]);

    /* Done */
    return EXIT_SUCCESS;
}
-----------------------------------------------------------------------------


Regards


        Uz


-- 
Ullrich von Bassewitz                                  uz@musoftware.de
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Tue Sep 26 10:01:54 2006

This archive was generated by hypermail 2.1.8 : 2006-09-26 10:01:57 CEST