OpenCBM
libcbmcopy/std.c
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version
5  * 2 of the License, or (at your option) any later version.
6  *
7  * Copyright 1999 Michael Klein <michael(dot)klein(at)puffin(dot)lb(dot)shuttle(dot)de>
8  * Copyright 2011 Thomas Winkler
9  * Copyright 2011 Wolfgang Moser
10  */
11 
12 #include "opencbm.h"
13 #include "cbmcopy_int.h"
14 
15 #include <stdlib.h>
16 
17 #include "arch.h"
18 
38 static int write_blk(CBM_FILE HandleDevice, const void *Buffer, unsigned char Count, cbmcopy_message_cb msg_cb)
39 {
40  if( Count == 255 )
41  {
42  /* standard routines don't know how to use the "block is following" flag */
43  Count--;
44  }
45  return cbm_raw_write(HandleDevice, Buffer, Count);
46 }
47 
65 static int read_blk(CBM_FILE HandleDevice, void *Buffer, size_t Count, cbmcopy_message_cb msg_cb)
66 {
67  int rv;
68 
69  /* non-turbo methods don't send a header byte specifying the block length */
70  rv = cbm_raw_read(HandleDevice, Buffer, Count);
71  if( rv == 254 )
72  {
73  /* when a full block was read, return that more blocks are following (255) */
74  /* even if this is wrong. If so, a count of 0 is returned in the next call */
75  rv++;
76  }
77  return rv;
78 }
79 
80 static int check_error(CBM_FILE fd, int write)
81 {
82  /* No explicit error check with cbm_device_status can be done since */
83  /* the device is still listening or talking. The former write_byte */
84  /* and read_byte function return the library's (error) return codes */
85  return 0;
86 }
87 
88 static int upload_turbo(CBM_FILE fd, unsigned char drive,
89  enum cbm_device_type_e drive_type, int write)
90 {
91  if(write)
92  {
93  cbm_listen(fd, drive, SA_WRITE);
94  }
95  else
96  {
97  cbm_talk(fd, drive, SA_READ);
98  }
99  return 0;
100 }
101 
102 
103 static int start_turbo(CBM_FILE fd, int write)
104 {
105  /* no special handshake signalisation needed */
106  return 0;
107 }
108 
109 
110 static void exit_turbo(CBM_FILE fd, int write)
111 {
112  if(write)
113  {
114  cbm_unlisten(fd);
115  }
116  else
117  {
118  cbm_untalk(fd);
119  }
120 }
121 
122 DECLARE_TRANSFER_FUNCS(std_transfer);
int CBMAPIDECL cbm_talk(CBM_FILE HandleDevice, unsigned char DeviceAddress, unsigned char SecondaryAddress)
Send a TALK on the IEC serial bus.
Definition: cbm.c:976
int CBMAPIDECL cbm_listen(CBM_FILE HandleDevice, unsigned char DeviceAddress, unsigned char SecondaryAddress)
Send a LISTEN on the IEC serial bus.
Definition: cbm.c:945
int CBMAPIDECL cbm_raw_write(CBM_FILE HandleDevice, const void *Buffer, size_t Count)
Write data to the IEC serial bus.
Definition: cbm.c:870
#define CBM_FILE
Definition: opencbm.h:87
int CBMAPIDECL cbm_unlisten(CBM_FILE HandleDevice)
Send an UNLISTEN on the IEC serial bus.
Definition: cbm.c:1100
int CBMAPIDECL cbm_raw_read(CBM_FILE HandleDevice, void *Buffer, size_t Count)
Read data from the IEC serial bus.
Definition: cbm.c:906
cbm_device_type_e
Definition: opencbm.h:114
DLL interface for accessing the driver.
int CBMAPIDECL cbm_untalk(CBM_FILE HandleDevice)
Send an UNTALK on the IEC serial bus.
Definition: cbm.c:1128
Define makros and functions which account for differences between the different architectures.