Has anyone been able to get binary byte-oriented file I/O working in cc65 C applications? If so, could you please point me to an example of some working code?
I've only been able to get the cbm_load() and cbm_save() functions working which loads or saves an entire file.
I noticed C3c posted assembly source code below which loads an entire file into memory. As I said above I've been able to accomplish this with the cbm_load function defined in the cbm.h file in the cc65 include directory.
To clarify I'd like to load and save a file a byte at a time which is what I meant by byte-oriented file I/O. This provides the ability to save and load files where different portions go to or come from different portions of memory. This also provides the ability to extract the relevant portion of very large files while discarding the remainder. My primary interest is a working example of cc65 C source code, but a working example of cc65 assembly source code might provide some insight.
I've tried various level of APIs including the following.
c - fopen() seems to work but fgetc() seems to hang
cbm - cbm_load() and cbm_save() seem to work as mentioned above, but cbm_open() returns error code 6.
cbm_k: cbm_k_open() returns error code 6 after first executing cbm_k_setnam() and cbm_k_setlfs()
I believe the cbm_k level API above is the direct interface to the kernel API which is claimed to work by desertfish below, but perhaps there's an error in cc65 (or my code).
I've also implemented my own C interface to the kernel API which works for everything I've tested except file I/O.
cbm_load(INFILE_STR, device, inputBuffer) works but cbm_open(lfn, device, sec_addr, INFILE_STR) returns error code 6 and
cbm_k_open() also returns error code 6 after first executing cbm_k_setnam(INFILE_STR) and cbm_k_setlfs(lfn, device, sec_addr).
I also tried using
#define lfn 1
which just seems to lead to error code 5 instead of 6 returned by cbm_open() and cbm_k_open().
I also tried various BASIC OPEN statements and they all returned a DEVICE NOT PRESENT error.
I noticed the Commander X16 Emulator User Guide indicates the following: "Note that this feature is very limited! Manually reading and writing files (e.g. OPEN in BASIC) is not supported by the host filesystem interface. Use SD card images for this."
So perhaps I need to create an SD card image for my data file instead of using the host computer's local filesystem.
Edited by CX16UserSteveC Clarified may need to use SD card image instead of using host computer's local filesystem.
Question
CX16UserSteveC
Has anyone been able to get binary byte-oriented file I/O working in cc65 C applications? If so, could you please point me to an example of some working code?
I've only been able to get the cbm_load() and cbm_save() functions working which loads or saves an entire file.
I noticed C3c posted assembly source code below which loads an entire file into memory. As I said above I've been able to accomplish this with the cbm_load function defined in the cbm.h file in the cc65 include directory.
To clarify I'd like to load and save a file a byte at a time which is what I meant by byte-oriented file I/O. This provides the ability to save and load files where different portions go to or come from different portions of memory. This also provides the ability to extract the relevant portion of very large files while discarding the remainder. My primary interest is a working example of cc65 C source code, but a working example of cc65 assembly source code might provide some insight.
I've tried various level of APIs including the following.
I believe the cbm_k level API above is the direct interface to the kernel API which is claimed to work by desertfish below, but perhaps there's an error in cc65 (or my code).
I've also implemented my own C interface to the kernel API which works for everything I've tested except file I/O.
Assuming the following definitions
#define INFILE_STR "celestemap.dat"
#define lfn 0
#define device 8
#define sec_addr 0
cbm_load(INFILE_STR, device, inputBuffer) works but cbm_open(lfn, device, sec_addr, INFILE_STR) returns error code 6 and
cbm_k_open() also returns error code 6 after first executing cbm_k_setnam(INFILE_STR) and cbm_k_setlfs(lfn, device, sec_addr).
I also tried using
#define lfn 1
which just seems to lead to error code 5 instead of 6 returned by cbm_open() and cbm_k_open().
I also tried various BASIC OPEN statements and they all returned a DEVICE NOT PRESENT error.
I noticed the Commander X16 Emulator User Guide indicates the following: "Note that this feature is very limited! Manually reading and writing files (e.g.
OPEN
in BASIC) is not supported by the host filesystem interface. Use SD card images for this."So perhaps I need to create an SD card image for my data file instead of using the host computer's local filesystem.
Edited by CX16UserSteveCClarified may need to use SD card image instead of using host computer's local filesystem.
Link to comment
Share on other sites
4 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.