Next Previous Contents

8.4 Functions

(All functions except cbm_driver_open(): f must be a valid file descriptor)

Basic I/O

int cbm_driver_open(CBM_FILE *f, int port);

Opens the driver. port isn't used by now and should be 0. After successful completion, 0 is returned along with a valid CBM_FILE descriptor in f.

void cbm_driver_close(CBM_FILE f);

Closes the driver.

void cbm_lock(CBM_FILE f);

The equivalent to cbmctrl lock. Make sure the parallel port is kept locked even if the driver is closed with cbm_driver_close().

void cbm_unlock(CBM_FILE f);

The equivalent to cbmctrl unlock. Unlock the parallel port as soon is the driver is closed with cbm_driver_close().

int cbm_raw_read(CBM_FILE f, void *buf, size_t size);

Retrieve data after cbm_talk();. At most size bytes are read. Return value is the actual number of bytes read. < indicates an error.

int cbm_raw_write(CBM_FILE f, const void *buf, size_t size);

Send data after cbm_listen();. At most size bytes are written, Return value is the actual number of bytes written. < indicates an error.

int cbm_listen(CBM_FILE f, __u_char dev, __u_char secadr);

Tell device dev to listen on secondary channel secadr. Return value is 0 on success, < 0 means error.

int cbm_talk(CBM_FILE f, __u_char dev, __u_char secadr);

Tell device dev to talk on secondary channel secadr. Return value is 0 on success, < 0 means error.

int cbm_open(CBM_FILE f, __u_char dev, __u_char secadr);

Prepare device dev for opening a file. This device listens for the file name after this call which is normally sent by a call to the write()-function followed by an unlisten() call. Return value 0 on success, < 0 means error.

int cbm_close(CBM_FILE f, __u_char dev, __u_char secadr);

Close file associated with secondary address secadr on device dev. Return value 0 on success, < 0 means error.

int cbm_unlisten(CBM_FILE f);

Send unlisten on bus. Return value 0 on success, < 0 means error.

int cbm_untalk(CBM_FILE f);

Send untalk on bus. Return value 0 on success, < 0 means error.

int cbm_get_eoi(CBM_FILE f);

Get EOI flag after bus read, return value is 0 with no EOI, otherwise 1. When EOI is set to 1, the active talker has nothing more to send.

int cbm_clear_eoi(CBM_FILE f);

Reset EOI flag. Return value 0 on success, < 0 means error.

int cbm_reset(CBM_FILE f);

Do a hardware reset on all connected devices. Control is returned after a 5 second delay.

Low-level port access

__u_char cbm_pp_read(CBM_FILE f);

Read byte from XP1541/XP1571 bus. No handshaking or such involved.

void cbm_pp_write(CBM_FILE f, __u_char c);

Write byte to XP1541/XP1571 bus. No handshaking or such involved.

int cbm_iec_poll(CBM_FILE f);

Read status of all bus lines. Return value is a combination of IEC_ATN, IEC_CLOCK and IEC_DATA.

int cbm_iec_get(CBM_FILE f, int line);

Get (logical) status of line line.

void cbm_iec_set(CBM_FILE f, int line);

Activate lines line (set to 0V). line can be one of or a combination with OR of any of IEC_DATA, IEC_CLOCK, IEC_ATN.

void cbm_iec_release(CBM_FILE f, int line);

Release lines line (set to 5V). line can be one of or a combination with OR of any of IEC_DATA, IEC_CLOCK, IEC_ATN.

void cbm_iec_setrelease(CBM_FILE f, int setline, int resetline);

Set lines setline (set to 0V) and release line releaseline (set to 5V) setline and resetline can each be one of or a combination with OR of any of IEC_DATA, IEC_CLOCK, IEC_ATN. If a line is part of both setline and resetline, the outcome is undefined.

int cbm_iec_wait(CBM_FILE f, int line, int state);

Experimental, do not use.

Helper functions

int cbm_upload(CBM_FILE f, __u_char dev, int adr, void *prog, int size);

Write prog into device dev's memory space via a series of "M-W" commands.

int cbm_device_status(CBM_FILE f, __u_char drv, void *buf, int bufsize);

Read device status info buf, at most bufsize bytes are read. Returns atoi(buf).

int cbm_exec_command(CBM_FILE f, __u_char drv, void *cmd, int len);

Execute command cmd. Returns number of bytes actually written. if len is 0, cmd is considered a 0-terminated string.

int cbm_identify(CBM_FILE f, __u_char drv, enum cbm_device_type_e *t, const char **type_str);

Tries to identify the device drv. The hardware type is returned in t, type_str contains a descriptive string which also includes the drives' operating system. Both t and type_str may be NULL in case the caller is not interrested in any of both values.

The return value is 0 if the device responded to the "M-R" command, even if it could not be identified, < 0 indicates error.

int cbm_identify_xp1541(CBM_FILE f, __u_char drv, enum cbm_device_type_e *t1, enum cbm_cable_type_e *t2);

Tries to identify the device drv. The hardware type is returned in t1, t2 contains whether the drive has an parallel (XP1541) cable attached. Both t1 and t2 may be NULL in case the caller is not interrested in any of both values.

The return value is 0 if the device responded to the "M-R" command, even if it could not be identified, < 0 indicates error.

PetSCII functions

char cbm_petscii2ascii_c(char character);

Converts one character character from PetSCII to ASCII.

char cbm_ascii2petscii_c(char character);

Converts one character character from ASCII to PetSCII.

char * cbm_petscii2ascii(char *str);

Convert a null-terminated string str from PetSCII to ASCII.

char * cbm_ascii2petscii(char *str);

Convert a null-terminated string str from ASCII to PetSCII.

Parallel Burst functions

__u_char cbm_parallel_burst_read(CBM_FILE f);

Support function for mnib. Do not use.

void cbm_parallel_burst_write(CBM_FILE f, __u_char c);

Support function for mnib. Do not use.

int cbm_parallel_burst_read_track(CBM_FILE f, __u_char *buffer, unsigned int length);

Support function for mnib. Do not use.

int cbm_parallel_burst_write_track(CBM_FILE f, __u_char *buffer, unsigned int length);

Support function for mnib. Do not use.

libd64copy TODO

Not documented yet. See libd64copy and d64copy source.

Types and prototypes are defined in d64copy.h.

libcbmcopy TODO

Not documented yet. See libcbmcopy and cbmcopy source.

Types and prototypes are defined in cbmcopy.h.


Next Previous Contents