[Coco] CMOC file-I/O examples?
Brendan Donahe
brendan at polylith.com
Fri Jan 18 09:58:29 EST 2019
Evan,
Assuming you are talking about Pierre's decb_* functions, I have examples
of CMOC file I/O (directory listing, file read, file write) in my CoCoVGA
character set editor, CCVEDIT. I can share my Git repository source with
you if you want everything, otherwise, I've pasted a few code snippets
below.
Hope this helps,
Brendan
unsigned char save_repo(const char *filename,
unsigned char which_drive,
unsigned short load_addr,
unsigned char *charset_with_preamble) {
DECBFile file;
unsigned char err;
// Open binary file for output
err = decb_createSectorFile(&file, which_drive, filename,
DECB_TYPE_MACHINE_CODE, DECB_FORMAT_BINARY);
if(err != DECB_OK) return err;
// All 8x12x256 character sets are 12 sectors of data plus another
// with header/trailer (preamble/postamble) info
#define NUM_SECTORS 13
// Header/preamble
charset_with_preamble[0] = 0x00; //
preamble flag 00
charset_with_preamble[1] = 0x0c; //
length of data block (MSbyte?)
charset_with_preamble[2] = 0x00; //
length of data block (LSbyte?)
charset_with_preamble[3] = (unsigned char)(load_addr >> 8); // load
address (MSbyte?)
charset_with_preamble[4] = (unsigned char)(load_addr & 0x00ff); // load
address (LSbyte?)
// Trailer/postamble
charset_with_preamble[SIZE_OF_EDIT_CHARSET + 5 + 0] = 0xff; //
postamble flag
charset_with_preamble[SIZE_OF_EDIT_CHARSET + 5 + 1] = 0x00; // zero
byte
charset_with_preamble[SIZE_OF_EDIT_CHARSET + 5 + 2] = 0x00; // zero
byte
charset_with_preamble[SIZE_OF_EDIT_CHARSET + 5 + 3] = 0x00; // exec
addr
charset_with_preamble[SIZE_OF_EDIT_CHARSET + 5 + 4] = 0x00; // exec
addr
// Write sectors
for(unsigned char file_sector_idx = 0; (file_sector_idx < NUM_SECTORS) &&
(err == DECB_OK); ++file_sector_idx) {
err = decb_writeSector(&file, &(charset_with_preamble[256*(unsigned
short)file_sector_idx]), file_sector_idx);
}
// Close file
if(err == DECB_OK) {
decb_setNumBytesUsedInLastSector(&file, 10);
err = decb_closeSectorFile(&file);
}
return err;
}
unsigned char load_repo(const char *filename,
unsigned char which_drive,
unsigned char *charset_with_preamble) {
DECBFile file;
unsigned char err;
// Open binary file for input
err = decb_openSectorFile(&file, which_drive, filename);
if(err != DECB_OK) return err;
// Read sectors
for(unsigned char file_sector_idx = 0; (file_sector_idx < NUM_SECTORS) &&
(err == DECB_OK); ++file_sector_idx) {
err = decb_readSector(&file, &(charset_with_preamble[256*(unsigned
short)file_sector_idx]), file_sector_idx);
}
// Close file
if(err == DECB_OK) {
err = decb_closeSectorFile(&file);
}
return err;
}
On Fri, Jan 18, 2019 at 8:48 AM Evan Wright via Coco <coco at maltedmedia.com>
wrote:
> Does anyone have an examples of file IO using CMOC? I just need to read /
> write a binary file whose size will never change.
> Evan
>
> --
> Coco mailing list
> Coco at maltedmedia.com
> https://pairlist5.pair.net/mailman/listinfo/coco
>
More information about the Coco
mailing list