/**************************************************************************************/ /* Header for Library Libcyc.a(.lib) */ /* Copyright(C)1999 Peter Armstrong */ /* Release 2.0 */ /**************************************************************************************/ /**************************************************************************************/ /* miscellaneous info */ /**************************************************************************************/ /* return values for cyc_ping() */ #define PNG_PC 1 /* connected to PC */ #define PNG_PSX 0 /* connected to psx */ #define PNG_NG -1 /* no response, not connected (at time of calling) */ /* return values for block_read/write() */ #define B_OK 1 /* read/write successful */ #define B_CNT_ERROR 0 /* not connected to other psx */ #define B_TIMEOUT -1 /* communications error (serial port time-out) */ #define B_CMD_MISMATCH -2 /* write not matched by read & vice versa */ #define B_ID_MISMATCH -3 /* different data identifiers */ #define B_SIZE_MISMATCH -4 /* invalid block size */ #define B_MEM_FAIL -5 /* malloc() failure on block_read()ing psx */ /**************************************************************************************/ /**************************************************************************************/ /* file server info */ /**************************************************************************************/ /* structure for PC file & directory information, values returned by cyc_findfirst/next() */ struct c_find { int attrib; /* attribute bits, see CA_ macros below */ u_int wr_time; /* time file was last written to */ u_int wr_date; /* date file was last written to */ int size; /* size in bytes */ char name[13]; /* name in dos 8.3 format */ }; /* macros for attr parameter in cyc_findfirst(), and c_find .attrib return value */ #define CA_NORMAL 0x0000 /* ordinary file, no attributes */ #define CA_RDONLY 0x0001 /* read only */ #define CA_HIDDEN 0x0002 /* hidden file */ #define CA_SYSTEM 0x0004 /* system file */ #define CA_VOLID 0x0008 /* volume label */ #define CA_SUBDIR 0x0010 /* sub-directory */ #define CA_ARCH 0x0020 /* archive bit set */ /* cyc_creat() file creation flags */ #define C_IREAD 0x0100 /* read only */ #define C_IWRITE 0x0080 /* write only */ #define C_IRDWR C_IREAD|C_IWRITE /* read/write mode */ /* cyc_open() file opening flags */ #define C_RDONLY 0x0001 /* read-only */ #define C_WRONLY 0x0002 /* write-only */ #define C_RDWR 0x0004 /* read/write */ #define C_CREAT 0x0100 /* create and open file (always read-only) */ #define C_TRUNC 0x0200 /* open with truncation */ #define C_EXCL 0x0400 /* open only if non-existant */ #define C_APPEND 0x0800 /* append data to end of file */ #define C_BINARY 0x8000 /* open with this for all non-text files */ #define C_TEXT 0x4000 /* CR-LF translation */ /* macros for cyc_lseek() origin */ #define C_SEEK_SET 0 /* start of file */ #define C_SEEK_CUR 1 /* current file position */ #define C_SEEK_END 2 /* end of file */ /**************************************************************************************/ /**************************************************************************************/ /* packet transfer info */ /**************************************************************************************/ /* PC's packet transfer mode type */ #define P_TFR_REAL 0 /* transfer packets with remote psx */ #define P_TFR_TEST 1 /* test transfer to PC and back */ /* commands/messages read/written within callback function */ struct cmds { int exit; /* remote exit notification */ int command; /* stored command to be sent */ int loc_reply; /* stored reply to be sent */ int rem_reply; /* command reply received */ int reply_await; /* local waiting for a reply from remote */ int connect; /* connect command received */ int cnt_type; /* remote connect command value */ int start; /* start command received */ int st_size; /* remote start command, packet data size value */ int st_diff; /* remote start command, frame difference value */ int acknowledge; /* acknowledge command received */ int ack_val; /* remote acknowledge command value */ int block; /* rd/wr/canx block command received */ int blk_id; /* block identifier */ u_char *cmd; /* command to send */ char loc_rpy; /* local reply value */ char rem_rpy; /* remote reply value */ }; #define INFO_SIZE 12 /* main link structure */ struct link_info { volatile struct cmds cmd_info; /* psx command structure */ int ping; /* connect type */ int connected; /* connect status */ int lk_type; /* link connection type */ int m_state; /* master/slave status */ int max_diff; /* max local/remote frame difference */ u_char *loc_data; /* ptr to local data */ u_char *rem_data; /* ptr to remote data */ int end_tfr; /* end packet session */ int loc_status; /* local psx status */ int rem_status; /* remote psx status */ u_char info[INFO_SIZE]; /* array keeping track of packet transfers */ }; /* defines for above struct */ /* lk_type */ #define LK_PSX 0 #define LK_PC 1 #define LK_MODEM 2 /* m_state */ #define SLAVE 2 #define MASTER 3 /* frame difference */ #define MAXD_PSX 2 #define MAXD_PC 2 #define MAXD_MODEM 5 /* loc_status values on return from link_connect() */ #define I_CONNECTED 1 /* connection made */ #define I_USER_INT 0 /* connection interrupted by user */ #define I_CNT_FAIL -1 /* unable to connect */ /* defines for loc/rem_status in tfr mode */ #define TFR_OK 0 /* no problems */ #define TFR_END -1 /* local or remote has ended transfer */ #define TFR_TIMEOUT -2 /* loss of connection to remote psx */ /* return values for pkt_start() */ #define S_READY 1 /* transfer session has begun */ #define S_NOT_CONNECTED 0 /* not connected */ #define S_START_FAIL -1 /* transfer could not be started */ #define S_BAD_SIZE -2 /* data size out of range */ #define S_MEM_FAIL -3 /* malloc() failure */ /* return values for pkt_transfer() */ #define T_DATA_AVAIL 1 /* local/remote data available for next frame */ #define T_NO_DATA 0 /* no data available */ #define T_TFR_ENDED -1 /* remote has ended transfer session */ #define T_TIMEOUT -2 /* remote psx no longer sending packets */ /**************************************************************************************/ /**************************************************************************************/ /* function prototypes */ /**************************************************************************************/ int sio_open(void); void sio_close(void); void chain_callback(void (*f)()); int cyc_ping(void); int cyc_exit(void); int cyc_printf(char *format_str, ...); int cyc_findfirst(char *fname,int attr,struct c_find *ptr); int cyc_findnext(struct c_find *ptr); int cyc_getfileattr(char *fname, u_int *attrib); int cyc_setfileattr(char *fname, u_int attrib); int cyc_creat(char *fname,int pmode); int cyc_open(char *fname,int mode); int cyc_close(int fd); long cyc_lseek(int fd,int offset,int origin); int cyc_unlink(char *fname); int cyc_system(char *cmd); long cyc_tell(int fd); int cyc_eof(int fd); int cyc_read(int fd,char *buf,u_int num); int cyc_write(int fd,char *buf,u_int num); int block_read(int id, char **buf, int size); int block_write(int id, char *buf, int size); struct link_info *link_connect(volatile char *padbuf); void link_disconnect(void); int pkt_start(u_int size,int mode); int pkt_transfer(u_char *data_p); void pkt_end(void); /**************************************************************************************/