OpenCBM
cbm.c
Go to the documentation of this file.
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-2005 Michael Klein <michael(dot)klein(at)puffin(dot)lb(dot)shuttle(dot)de>
8  * Copyright 2001-2005,2007-2009, 2011 Spiro Trikaliotis
9  * Copyright 2009,2011 Arnd Menge <arnd(at)jonnz(dot)de>
10  *
11 */
12 
22 #define DBG_USERMODE
23 
25 #define DBG_PROGNAME "OPENCBM.DLL"
26 
27 #include "debug.h"
28 
29 #include <stdlib.h>
30 #include <string.h>
31 
32 #include "libmisc.h"
33 
35 #define DLL
36 #include "opencbm.h"
37 #include "archlib.h"
38 
39 #include "opencbm-plugin.h"
40 
41 #include "getpluginaddress.h"
42 
43 #include "configuration.h"
44 
45 #include "arch.h"
46 
55 int plugin_is_active(opencbm_configuration_handle Handle, const char PluginName[])
56 {
57  char * active = NULL;
58  unsigned int active_number = 1;
59 
60  FUNC_ENTER();
61 
62  do {
63  char * next;
64 
65  opencbm_configuration_get_data(Handle, PluginName, "Active", &active);
66 
67  if ( ! active ) {
68  break;
69  }
70 
71  active_number = strtoul(active, &next, 10);
72  if (next && (next[0] != 0) ) {
73  DBG_WARN((DBG_PREFIX "Entry 'Active' for plugin '%' "
74  "is set to the non-numerical value '%s'",
75  PluginName, active));
76  active_number = 1;
77  break;
78  }
79 
80  } while (0);
81 
82  cbmlibmisc_strfree(active);
83 
84  FUNC_LEAVE_INT(active_number);
85 }
86 
93 int plugin_set_active(const char PluginName[])
94 {
95  FUNC_ENTER();
96 
97  FUNC_LEAVE_INT(0);
98 }
99 
100 
107 int plugin_set_inactive(const char PluginName[])
108 {
109  FUNC_ENTER();
110 
111  FUNC_LEAVE_INT(0);
112 }
113 
114 
119 };
120 
123 
124 static
125 struct plugin_information_s Plugin_information = { 0 };
126 
128 {
129  UINT_PTR offset;
130  const char * name;
131 };
132 
133 #define OFFSETOF(_type, _element) \
134  ((UINT_PTR) (void *) &((_type *)0)->_element)
135 
136 #define GETELEMENT(_type, _structpointer, _elementoffset) \
137  ((_type *)(((char*)(_structpointer)) + (_elementoffset)))
138 
139 #define PLUGIN_POINTER_DEF(_xxx) \
140  { OFFSETOF(plugin_information_t, Plugin._xxx), #_xxx }
141 
142 #define PLUGIN_POINTER_GET(_what, _element) \
143  GEELEMENT(void, _what, _element)
144 
145 #define PLUGIN_POINTER_END() \
146  { 0, NULL }
147 
148 static struct plugin_read_pointer plugin_pointer_to_read_mandatory[] =
149 {
150  PLUGIN_POINTER_DEF(opencbm_plugin_get_driver_name),
151  PLUGIN_POINTER_DEF(opencbm_plugin_driver_open),
152  PLUGIN_POINTER_DEF(opencbm_plugin_driver_close),
153  PLUGIN_POINTER_DEF(opencbm_plugin_raw_write),
154  PLUGIN_POINTER_DEF(opencbm_plugin_raw_read),
155  PLUGIN_POINTER_DEF(opencbm_plugin_open),
156  PLUGIN_POINTER_DEF(opencbm_plugin_close),
157  PLUGIN_POINTER_DEF(opencbm_plugin_listen),
158  PLUGIN_POINTER_DEF(opencbm_plugin_talk),
159  PLUGIN_POINTER_DEF(opencbm_plugin_unlisten),
160  PLUGIN_POINTER_DEF(opencbm_plugin_untalk),
161  PLUGIN_POINTER_DEF(opencbm_plugin_get_eoi),
162  PLUGIN_POINTER_DEF(opencbm_plugin_clear_eoi),
163  PLUGIN_POINTER_DEF(opencbm_plugin_reset),
164  PLUGIN_POINTER_DEF(opencbm_plugin_iec_poll),
165  PLUGIN_POINTER_DEF(opencbm_plugin_iec_setrelease),
166  PLUGIN_POINTER_DEF(opencbm_plugin_iec_wait),
167  PLUGIN_POINTER_END()
168 };
169 
170 static struct plugin_read_pointer plugin_pointer_to_read_optional[] =
171 {
172  PLUGIN_POINTER_DEF(opencbm_plugin_init),
173  PLUGIN_POINTER_DEF(opencbm_plugin_uninit),
174  PLUGIN_POINTER_DEF(opencbm_plugin_lock),
175  PLUGIN_POINTER_DEF(opencbm_plugin_unlock),
176  PLUGIN_POINTER_DEF(opencbm_plugin_iec_set),
177  PLUGIN_POINTER_DEF(opencbm_plugin_iec_release),
178  PLUGIN_POINTER_DEF(opencbm_plugin_parallel_burst_read),
179  PLUGIN_POINTER_DEF(opencbm_plugin_parallel_burst_write),
180  PLUGIN_POINTER_DEF(opencbm_plugin_parallel_burst_read_track),
181  PLUGIN_POINTER_DEF(opencbm_plugin_parallel_burst_write_track),
182  PLUGIN_POINTER_DEF(opencbm_plugin_pp_read),
183  PLUGIN_POINTER_DEF(opencbm_plugin_pp_write),
184  PLUGIN_POINTER_END()
185 };
186 
187 static struct plugin_read_pointer plugin_pointer_to_read_parallel_burst[] =
188 {
189  PLUGIN_POINTER_DEF(opencbm_plugin_parallel_burst_read),
190  PLUGIN_POINTER_DEF(opencbm_plugin_parallel_burst_write),
191  PLUGIN_POINTER_DEF(opencbm_plugin_parallel_burst_read_track),
192  PLUGIN_POINTER_DEF(opencbm_plugin_parallel_burst_write_track),
193  PLUGIN_POINTER_END()
194 };
195 
196 static struct plugin_read_pointer plugin_pointer_to_read_pp_readwrite[] =
197 {
198  PLUGIN_POINTER_DEF(opencbm_plugin_pp_read),
199  PLUGIN_POINTER_DEF(opencbm_plugin_pp_write),
200  PLUGIN_POINTER_END()
201 };
202 
203 static struct plugin_read_pointer plugin_pointer_to_read_srq_burst[] =
204 {
205  PLUGIN_POINTER_DEF(opencbm_plugin_srq_burst_read ),
206  PLUGIN_POINTER_DEF(opencbm_plugin_srq_burst_write),
207  PLUGIN_POINTER_DEF(opencbm_plugin_srq_burst_read_track),
208  PLUGIN_POINTER_DEF(opencbm_plugin_srq_burst_write_track),
209  PLUGIN_POINTER_END()
210 };
211 
212 static struct plugin_read_pointer plugin_pointer_to_read_tape[] =
213 {
214  PLUGIN_POINTER_DEF(opencbm_plugin_tap_prepare_capture),
215  PLUGIN_POINTER_DEF(opencbm_plugin_tap_prepare_write),
216  PLUGIN_POINTER_DEF(opencbm_plugin_tap_get_sense),
217  PLUGIN_POINTER_DEF(opencbm_plugin_tap_wait_for_stop_sense),
218  PLUGIN_POINTER_DEF(opencbm_plugin_tap_wait_for_play_sense),
219  PLUGIN_POINTER_DEF(opencbm_plugin_tap_motor_on),
220  PLUGIN_POINTER_DEF(opencbm_plugin_tap_motor_off),
221  PLUGIN_POINTER_DEF(opencbm_plugin_tap_start_capture),
222  PLUGIN_POINTER_DEF(opencbm_plugin_tap_start_write),
223  PLUGIN_POINTER_DEF(opencbm_plugin_tap_get_ver),
224  PLUGIN_POINTER_DEF(opencbm_plugin_tap_download_config),
225  PLUGIN_POINTER_DEF(opencbm_plugin_tap_upload_config),
226  PLUGIN_POINTER_DEF(opencbm_plugin_tap_break),
227  PLUGIN_POINTER_END()
228 };
229 
230 
232 {
233  struct plugin_read_pointer * read_pointer;
234  enum {
235  PRP_MANDATORY,
236  PRP_OPTIONAL,
237  PRP_OPTIONAL_ALL_OR_NOTHING
238  } type;
239 };
240 
241 static struct plugin_read_pointer_group read_pointer_group[] =
242 {
243  { plugin_pointer_to_read_mandatory, PRP_MANDATORY },
244  { plugin_pointer_to_read_optional, PRP_OPTIONAL },
245  { plugin_pointer_to_read_parallel_burst, PRP_OPTIONAL_ALL_OR_NOTHING },
246  { plugin_pointer_to_read_pp_readwrite, PRP_OPTIONAL_ALL_OR_NOTHING },
247  { plugin_pointer_to_read_srq_burst, PRP_OPTIONAL_ALL_OR_NOTHING },
248  { plugin_pointer_to_read_tape, PRP_OPTIONAL_ALL_OR_NOTHING },
249  { NULL, PRP_OPTIONAL }
250 };
251 
252 static void
253 read_plugin_pointer(
254  plugin_information_t * Plugin_information,
255  struct plugin_read_pointer pointer_to_read[]
256 )
257 {
258  while (pointer_to_read->name) {
259  void * ptr_read = plugin_get_address(Plugin_information->Library, pointer_to_read->name);
260  void ** ptr_to_save = GETELEMENT(void *, Plugin_information, pointer_to_read->offset);
261  *ptr_to_save = ptr_read;
262  DBGDO(
263  if (ptr_read == NULL) {
264  DBG_PRINT((DBG_PREFIX "Plugin entry point %s not found!", pointer_to_read->name));
265  }
266  )
267  ++pointer_to_read;
268  }
269 }
270 
271 static int check_plugin_pointer(
272  plugin_information_t * Plugin_information,
273  struct plugin_read_pointer pointer_to_check[]
274 )
275 {
276  while (pointer_to_check->name) {
277  void ** ptr_to_check = GETELEMENT(void *, Plugin_information, pointer_to_check->offset);
278  DBGDO(
279  if (ptr_to_check == NULL) {
280  DBG_PRINT((DBG_PREFIX "Plugin entry point %s not found!", pointer_to_check->name));
281  }
282  )
283  if (ptr_to_check == NULL) return 1;
284  ++pointer_to_check;
285  }
286  return 0;
287 }
288 
289 static int check_plugin_pointer_all_or_nothing(
290  plugin_information_t * Plugin_information,
291  struct plugin_read_pointer pointer_to_check[]
292 )
293 {
294  int error;
295 
296  // first, check if all pointers are available
297  error = check_plugin_pointer(Plugin_information, pointer_to_check);
298  if (!error) return 0;
299 
300  // if not, check if all pointers are *not* available
301  while (pointer_to_check->name) {
302  void ** ptr_to_check = GETELEMENT(void *, Plugin_information, pointer_to_check->offset);
303  DBGDO(
304  if (ptr_to_check != NULL) {
305  DBG_PRINT((DBG_PREFIX "Plugin entry point %s found, but it should not be available!", pointer_to_check->name));
306  }
307  )
308  if (ptr_to_check != NULL) return 1;
309  ++pointer_to_check;
310  }
311  return 0;
312 }
313 
314 static int
315 read_plugin_pointer_groups(
316  plugin_information_t * Plugin_information,
317  struct plugin_read_pointer_group pointer_to_read_group[]
318 )
319 {
320  int error = 0;
321 
322  while (pointer_to_read_group->read_pointer) {
323  read_plugin_pointer(Plugin_information, pointer_to_read_group->read_pointer);
324 
325  switch (pointer_to_read_group->type) {
326  case PRP_MANDATORY:
327  error = error || check_plugin_pointer(Plugin_information, pointer_to_read_group->read_pointer);
328  break;
329 
330  case PRP_OPTIONAL:
331  break;
332  case PRP_OPTIONAL_ALL_OR_NOTHING:
333  error = error || check_plugin_pointer_all_or_nothing(Plugin_information, pointer_to_read_group->read_pointer);
334  break;
335  };
336 
337  ++pointer_to_read_group;
338  }
339 
340  return error;
341 }
342 
343 static int
344 initialize_plugin_pointer(plugin_information_t *Plugin_information, const char * const Adapter)
345 {
346  int error = 1;
347 
348  const char * configurationFilename = configuration_get_default_filename();
349 
350  char * plugin_name = NULL;
351  char * plugin_location = NULL;
352 
353  do {
354 
355  opencbm_configuration_handle handle_configuration;
356 
357  if (configurationFilename == NULL) {
358  DBG_ERROR((DBG_PREFIX "Do not know where the plugin information is stored!\n"));
359  break;
360  }
361 
362  handle_configuration = opencbm_configuration_open(configurationFilename);
363 
364  if (handle_configuration)
365  {
366  int error = 0;
367 
368  if (Adapter == NULL)
369  {
370  //
371  // get the name of the default plugin
372  //
373 
374  error = opencbm_configuration_get_data(handle_configuration,
375  "plugins", "default", &plugin_name);
376  }
377  else
378  {
379  //
380  // Use the given plugin name
381  //
382  plugin_name = cbmlibmisc_strdup(Adapter);
383  }
384 
385  //
386  // check if the plugin has been disabled
387  //
388 
389  if ( ! plugin_is_active(handle_configuration, plugin_name) ) {
390  error = 1;
391  break;
392  }
393 
394  //
395  // get the location of the plugin
396  //
397  if (!error)
398  {
399  error = opencbm_configuration_get_data(handle_configuration,
400  plugin_name, "location", &plugin_location);
401  }
402 
403  //
404  // if an error occurred, make sure that no plugin will be loaded!
405  //
406  if (error)
407  {
408  cbmlibmisc_strfree(plugin_location);
409  plugin_location = NULL;
410  }
411 
412  opencbm_configuration_close(handle_configuration);
413  }
414  else
415  {
416  DBG_ERROR((DBG_PREFIX "Cannot open config file '%s'.\n", configurationFilename));
417  break;
418  }
419  DBG_PRINT((DBG_PREFIX "Using plugin at '%s'", plugin_location ? plugin_location : "(none)"));
420 
421  memset(&Plugin_information->Plugin, 0, sizeof(Plugin_information->Plugin));
422 
423  Plugin_information->Library = plugin_load(plugin_location);
424 
425  DBG_PRINT((DBG_PREFIX "plugin_load() returned %p", Plugin_information->Library));
426 
427  if (!Plugin_information->Library) {
428  DBG_ERROR((DBG_PREFIX "Could not open plugin driver at '%s'.\n", plugin_location));
429  break;
430  }
431 
432  error = read_plugin_pointer_groups(Plugin_information, read_pointer_group);
433  if (error) {
434  DBG_ERROR((DBG_PREFIX "The entry points of plugin %s do not validate correctly.\n",
435  plugin_location));
436  break;
437  }
438 
439  if (Plugin_information->Plugin.opencbm_plugin_init) {
440  error = Plugin_information->Plugin.opencbm_plugin_init();
441  if (error) {
442  DBG_ERROR((DBG_PREFIX "Plugin %s fails to initialize itself.\n",
443  plugin_location));
444  if (Plugin_information->Plugin.opencbm_plugin_uninit) {
445  Plugin_information->Plugin.opencbm_plugin_uninit();
446  }
447  break;
448  }
449  }
450 
451  } while (0);
452 
453  cbmlibmisc_strfree(plugin_name);
454  cbmlibmisc_strfree(plugin_location);
455  cbmlibmisc_strfree(configurationFilename);
456 
457  return error;
458 }
459 
460 static void
461 uninitialize_plugin(void)
462 {
463  if (Plugin_information.Library != NULL)
464  {
465  if (Plugin_information.Plugin.opencbm_plugin_uninit) {
466  Plugin_information.Plugin.opencbm_plugin_uninit();
467  }
468 
469  plugin_unload(Plugin_information.Library);
470 
471  Plugin_information.Library = NULL;
472  }
473 }
474 
475 static int
476 initialize_plugin(const char * const Adapter)
477 {
478  /* if library is already opened and initialized correctly then
479  this function returns OK */
480  int error = 0;
481 
482  /* init pointers if library was not yet opened */
483  if (Plugin_information.Library == NULL)
484  {
485  /* if pointer init failed then close library and make Library NULL */
486  error = initialize_plugin_pointer(&Plugin_information, Adapter);
487  if(error != 0)
488  {
489  uninitialize_plugin();
490  }
491  }
492 
493  return error;
494 }
495 
496 // #define DBG_DUMP_RAW_READ
497 // #define DBG_DUMP_RAW_WRITE
498 
528 static char *
529 cbm_split_adapter_in_name_and_port(char * Adapter, char ** Port)
530 {
531  char * adapter_stripped = NULL;
532 
533  *Port = NULL;
534 
535  if (Adapter)
536  {
537  char *p = strchr(Adapter, ':');
538 
539  if (p)
540  {
541  // there was some colon (:), thus, extract portNumber and name
542 
543  adapter_stripped = cbmlibmisc_strndup(Adapter, p - Adapter);
544 
545  if (adapter_stripped != NULL) {
546  if (p[1] != 0)
547  {
548  *Port = cbmlibmisc_strdup(p+1);
549  }
550  }
551  }
552  else
553  {
554  adapter_stripped = cbmlibmisc_strdup(Adapter);
555  }
556  }
557 
558  if (adapter_stripped && adapter_stripped[0] == 0) {
559  cbmlibmisc_strfree(adapter_stripped);
560  adapter_stripped = NULL;
561  }
562 
563  return adapter_stripped;
564 }
565 
566 /*-------------------------------------------------------------------*/
567 /*--------- DRIVER HANDLING -----------------------------------------*/
568 
582 const char * CBMAPIDECL
583 cbm_get_driver_name_ex(char * Adapter)
584 {
585  const char *ret = NULL;
586 
587  static const char * buffer = NULL;
588  char *adapter_stripped = NULL;
589  char *port = NULL;
590 
591  int error;
592 
593  FUNC_ENTER();
594 
595  if ( buffer ) {
596  cbmlibmisc_strfree(buffer);
597  buffer = NULL;
598  }
599 
600  if (Adapter != NULL)
601  {
602  adapter_stripped = cbm_split_adapter_in_name_and_port(Adapter, &port);
603 
605  (adapter_stripped == NULL
606  ? "Using default adapter"
607  : "Using adapter '%s', that is, adapter '%s' with port '%s'"),
608  Adapter, adapter_stripped, port));
609  }
610 
611  error = initialize_plugin(adapter_stripped);
612 
613  if (error == 0) {
614  ret = Plugin_information.Plugin.opencbm_plugin_get_driver_name(port);
615  }
616  else {
617  ret = "NO PLUGIN DRIVER!";
618  }
619 
620  buffer = cbmlibmisc_strdup(ret);
621 
622  cbmlibmisc_strfree(adapter_stripped);
623  cbmlibmisc_strfree(port);
624 
625  FUNC_LEAVE_STRING(buffer);
626 }
627 
649 const char * CBMAPIDECL
650 cbm_get_driver_name(int PortNumber)
651 {
652  char number[] = ":0";
653 
654  FUNC_ENTER();
655 
656  if (PortNumber >= 0 && PortNumber < 10) {
657  number[1] = PortNumber + '0';
658  }
659 
661 }
662 
682 int CBMAPIDECL
683 cbm_driver_open_ex(CBM_FILE *HandleDevice, char * Adapter)
684 {
685  int error;
686  char * port = NULL;
687  char * adapter_stripped = NULL;
688 
689  FUNC_ENTER();
690 
691  DBG_PRINT((DBG_PREFIX "cbm_driver_open_ex() called"));
692 
693  if (Adapter != NULL)
694  {
695  adapter_stripped = cbm_split_adapter_in_name_and_port(Adapter, &port);
696 
697  DBG_PRINT((DBG_PREFIX "Using adapter '%s', that is, adapter '%s' with port '%s'",
698  Adapter, adapter_stripped, port));
699  }
700 
701  error = initialize_plugin(adapter_stripped);
702 
703  cbmlibmisc_strfree(adapter_stripped);
704 
705  if (error == 0) {
706  error = Plugin_information.Plugin.opencbm_plugin_driver_open(HandleDevice, port);
707  }
708 
709  cbmlibmisc_strfree(port);
710 
711  FUNC_LEAVE_INT(error);
712 }
713 
739 int CBMAPIDECL
740 cbm_driver_open(CBM_FILE *HandleDevice, int PortNumber)
741 {
742  char number[] = ":0";
743 
744  FUNC_ENTER();
745 
746  if (PortNumber >= 0 && PortNumber < 10) {
747  number[1] = PortNumber + '0';
748  }
749 
750  FUNC_LEAVE_INT(cbm_driver_open_ex(HandleDevice, number));
751 }
752 
767 void CBMAPIDECL
769 {
770  FUNC_ENTER();
771 
772  Plugin_information.Plugin.opencbm_plugin_driver_close(HandleDevice);
773 
774  uninitialize_plugin();
775 
776  FUNC_LEAVE();
777 }
778 
803 void CBMAPIDECL
804 cbm_lock(CBM_FILE HandleDevice)
805 {
806  FUNC_ENTER();
807 
808  if (Plugin_information.Plugin.opencbm_plugin_lock)
809  Plugin_information.Plugin.opencbm_plugin_lock(HandleDevice);
810 
811  FUNC_LEAVE();
812 }
813 
831 void CBMAPIDECL
832 cbm_unlock(CBM_FILE HandleDevice)
833 {
834  FUNC_ENTER();
835 
836  if (Plugin_information.Plugin.opencbm_plugin_unlock)
837  Plugin_information.Plugin.opencbm_plugin_unlock(HandleDevice);
838 
839  FUNC_LEAVE();
840 }
841 
842 /*-------------------------------------------------------------------*/
843 /*--------- BASIC I/O -----------------------------------------------*/
844 
869 int CBMAPIDECL
870 cbm_raw_write(CBM_FILE HandleDevice, const void *Buffer, size_t Count)
871 {
872  FUNC_ENTER();
873 
874 #ifdef DBG_DUMP_RAW_WRITE
875  DBG_MEMDUMP("cbm_raw_write", Buffer, Count);
876 #endif
877 
878  FUNC_LEAVE_INT(Plugin_information.Plugin.opencbm_plugin_raw_write(HandleDevice,Buffer, Count));
879 }
880 
881 
905 int CBMAPIDECL
906 cbm_raw_read(CBM_FILE HandleDevice, void *Buffer, size_t Count)
907 {
908  int bytesRead = 0;
909 
910  FUNC_ENTER();
911 
912  bytesRead = Plugin_information.Plugin.opencbm_plugin_raw_read(HandleDevice, Buffer, Count);
913 
914 #ifdef DBG_DUMP_RAW_READ
915  DBG_MEMDUMP("cbm_raw_read", Buffer, bytesRead);
916 #endif
917 
918  FUNC_LEAVE_INT(bytesRead);
919 }
920 
944 int CBMAPIDECL
945 cbm_listen(CBM_FILE HandleDevice, unsigned char DeviceAddress, unsigned char SecondaryAddress)
946 {
947  FUNC_ENTER();
948 
949  FUNC_LEAVE_INT(Plugin_information.Plugin.opencbm_plugin_listen(HandleDevice, DeviceAddress, SecondaryAddress));
950 }
951 
975 int CBMAPIDECL
976 cbm_talk(CBM_FILE HandleDevice, unsigned char DeviceAddress, unsigned char SecondaryAddress)
977 {
978  FUNC_ENTER();
979 
980  FUNC_LEAVE_INT(Plugin_information.Plugin.opencbm_plugin_talk(HandleDevice, DeviceAddress, SecondaryAddress));
981 }
982 
1011 int CBMAPIDECL
1012 cbm_open(CBM_FILE HandleDevice, unsigned char DeviceAddress, unsigned char SecondaryAddress,
1013  const void *Filename, size_t FilenameLength)
1014 {
1015  int returnValue;
1016 
1017  FUNC_ENTER();
1018 
1019  returnValue = Plugin_information.Plugin.opencbm_plugin_open(HandleDevice, DeviceAddress, SecondaryAddress);
1020 
1021  if (returnValue == 0)
1022  {
1023  returnValue = 0;
1024 
1025  if(Filename != NULL)
1026  {
1027  if (FilenameLength == 0)
1028  {
1029  DBG_WARN((DBG_PREFIX "*** FilenameLength of 0 encountered!"));
1030  FilenameLength = strlen(Filename);
1031  }
1032 
1033  if (FilenameLength > 0)
1034  {
1035  returnValue =
1036  (size_t) (cbm_raw_write(HandleDevice, Filename, FilenameLength))
1037  != FilenameLength;
1038  }
1039  cbm_unlisten(HandleDevice);
1040  }
1041  }
1042  else
1043  {
1044  returnValue = -1;
1045  }
1046 
1047  FUNC_LEAVE_INT(returnValue);
1048 }
1049 
1071 int CBMAPIDECL
1072 cbm_close(CBM_FILE HandleDevice, unsigned char DeviceAddress, unsigned char SecondaryAddress)
1073 {
1074  FUNC_ENTER();
1075 
1076  FUNC_LEAVE_INT(Plugin_information.Plugin.opencbm_plugin_close(HandleDevice, DeviceAddress, SecondaryAddress));
1077 }
1078 
1099 int CBMAPIDECL
1100 cbm_unlisten(CBM_FILE HandleDevice)
1101 {
1102  FUNC_ENTER();
1103 
1104  FUNC_LEAVE_INT(Plugin_information.Plugin.opencbm_plugin_unlisten(HandleDevice));
1105 }
1106 
1127 int CBMAPIDECL
1128 cbm_untalk(CBM_FILE HandleDevice)
1129 {
1130  FUNC_ENTER();
1131 
1132  FUNC_LEAVE_INT(Plugin_information.Plugin.opencbm_plugin_untalk(HandleDevice));
1133 }
1134 
1135 
1156 int CBMAPIDECL
1157 cbm_get_eoi(CBM_FILE HandleDevice)
1158 {
1159  FUNC_ENTER();
1160 
1161  FUNC_LEAVE_INT(Plugin_information.Plugin.opencbm_plugin_get_eoi(HandleDevice));
1162 }
1163 
1179 int CBMAPIDECL
1181 {
1182  FUNC_ENTER();
1183 
1184  FUNC_LEAVE_INT(Plugin_information.Plugin.opencbm_plugin_clear_eoi(HandleDevice));
1185 }
1186 
1208 int CBMAPIDECL
1209 cbm_reset(CBM_FILE HandleDevice)
1210 {
1211  FUNC_ENTER();
1212 
1213  FUNC_LEAVE_INT(Plugin_information.Plugin.opencbm_plugin_reset(HandleDevice));
1214 }
1215 
1216 
1217 /*-------------------------------------------------------------------*/
1218 /*--------- LOW-LEVEL PORT ACCESS -----------------------------------*/
1219 
1243 unsigned char CBMAPIDECL
1244 cbm_pp_read(CBM_FILE HandleDevice)
1245 {
1246  unsigned char ret = -1;
1247 
1248  FUNC_ENTER();
1249 
1250  if (Plugin_information.Plugin.opencbm_plugin_pp_read)
1251  ret = Plugin_information.Plugin.opencbm_plugin_pp_read(HandleDevice);
1252 
1253  FUNC_LEAVE_UCHAR(ret);
1254 }
1255 
1281 void CBMAPIDECL
1282 cbm_pp_write(CBM_FILE HandleDevice, unsigned char Byte)
1283 {
1284  FUNC_ENTER();
1285 
1286  if (Plugin_information.Plugin.opencbm_plugin_pp_write)
1287  Plugin_information.Plugin.opencbm_plugin_pp_write(HandleDevice, Byte);
1288 
1289  FUNC_LEAVE();
1290 }
1291 
1313 int CBMAPIDECL
1314 cbm_iec_poll(CBM_FILE HandleDevice)
1315 {
1316  FUNC_ENTER();
1317 
1318  FUNC_LEAVE_INT(Plugin_information.Plugin.opencbm_plugin_iec_poll(HandleDevice));
1319 }
1320 
1321 
1340 void CBMAPIDECL
1341 cbm_iec_set(CBM_FILE HandleDevice, int Line)
1342 {
1343  FUNC_ENTER();
1344 
1345  if (Plugin_information.Plugin.opencbm_plugin_iec_set)
1346  Plugin_information.Plugin.opencbm_plugin_iec_set(HandleDevice, Line);
1347  else
1348  Plugin_information.Plugin.opencbm_plugin_iec_setrelease(HandleDevice, Line, 0);
1349 
1350  FUNC_LEAVE();
1351 }
1352 
1371 void CBMAPIDECL
1372 cbm_iec_release(CBM_FILE HandleDevice, int Line)
1373 {
1374  FUNC_ENTER();
1375 
1376  if (Plugin_information.Plugin.opencbm_plugin_iec_release)
1377  Plugin_information.Plugin.opencbm_plugin_iec_release(HandleDevice, Line);
1378  else
1379  Plugin_information.Plugin.opencbm_plugin_iec_setrelease(HandleDevice, 0, Line);
1380 
1381  FUNC_LEAVE();
1382 }
1383 
1411 void CBMAPIDECL
1412 cbm_iec_setrelease(CBM_FILE HandleDevice, int Set, int Release)
1413 {
1414  FUNC_ENTER();
1415 
1416  Plugin_information.Plugin.opencbm_plugin_iec_setrelease(HandleDevice, Set, Release);
1417 
1418  FUNC_LEAVE();
1419 }
1420 
1447 int CBMAPIDECL
1448 cbm_iec_wait(CBM_FILE HandleDevice, int Line, int State)
1449 {
1450  FUNC_ENTER();
1451 
1452  FUNC_LEAVE_INT(Plugin_information.Plugin.opencbm_plugin_iec_wait(HandleDevice, Line, State));
1453 }
1454 
1476 int CBMAPIDECL
1477 cbm_iec_get(CBM_FILE HandleDevice, int Line)
1478 {
1479  FUNC_ENTER();
1480 
1481  FUNC_LEAVE_INT((Plugin_information.Plugin.opencbm_plugin_iec_poll(HandleDevice)&Line) != 0 ? 1 : 0);
1482 }
1483 
1484 
1485 /*-------------------------------------------------------------------*/
1486 /*--------- HELPER FUNCTIONS ----------------------------------------*/
1487 
1488 
1524 int CBMAPIDECL
1525 cbm_device_status(CBM_FILE HandleDevice, unsigned char DeviceAddress,
1526  void *Buffer, size_t BufferLength)
1527 {
1528  int retValue;
1529 
1530  FUNC_ENTER();
1531 
1532  DBG_ASSERT(Buffer && (BufferLength > 0));
1533 
1534  // Pre-occupy return value
1535 
1536  retValue = 99;
1537 
1538  if (Buffer && (BufferLength > 0))
1539  {
1540  char *bufferToWrite = Buffer;
1541 
1542  // make sure we have a trailing zero at the end of the buffer:
1543 
1544  bufferToWrite[--BufferLength] = '\0';
1545 
1546  // pre-occupy buffer with the error value
1547 
1548  strncpy(bufferToWrite, "99, DRIVER ERROR,00,00\r", BufferLength);
1549 
1550  // Now, ask the drive for its error status:
1551 
1552  if (cbm_talk(HandleDevice, DeviceAddress, 15) == 0)
1553  {
1554  unsigned int bytesRead;
1555 
1556  bytesRead = cbm_raw_read(HandleDevice, bufferToWrite, BufferLength - 1);
1557 
1558  DBG_ASSERT(bytesRead <= BufferLength);
1559 
1560  // make sure we have a trailing zero at the end of the status:
1561 
1562  bufferToWrite[bytesRead] = '\0';
1563 
1564  cbm_untalk(HandleDevice);
1565  }
1566 
1567  retValue = atoi(bufferToWrite);
1568  }
1569 
1570  FUNC_LEAVE_INT(retValue);
1571 }
1572 
1598 int CBMAPIDECL
1599 cbm_exec_command(CBM_FILE HandleDevice, unsigned char DeviceAddress,
1600  const void *Command, size_t Size)
1601 {
1602  int rv;
1603 
1604  FUNC_ENTER();
1605  rv = cbm_listen(HandleDevice, DeviceAddress, 15);
1606  if(rv == 0) {
1607  if(Size == 0) {
1608  Size = (size_t) strlen(Command);
1609  }
1610  rv = (size_t) cbm_raw_write(HandleDevice, Command, Size) != Size;
1611  cbm_unlisten(HandleDevice);
1612  }
1613 
1614  FUNC_LEAVE_INT(rv);
1615 }
1616 
1634 unsigned char CBMAPIDECL
1636 {
1637  unsigned char ret = 0;
1638 
1639  FUNC_ENTER();
1640 
1641  if (Plugin_information.Plugin.opencbm_plugin_parallel_burst_read)
1642  ret = Plugin_information.Plugin.opencbm_plugin_parallel_burst_read(HandleDevice);
1643 
1644  FUNC_LEAVE_UCHAR(ret);
1645 }
1646 
1664 void CBMAPIDECL
1665 cbm_parallel_burst_write(CBM_FILE HandleDevice, unsigned char Value)
1666 {
1667  FUNC_ENTER();
1668 
1669  if (Plugin_information.Plugin.opencbm_plugin_parallel_burst_write)
1670  Plugin_information.Plugin.opencbm_plugin_parallel_burst_write(HandleDevice, Value);
1671 
1672  FUNC_LEAVE();
1673 }
1674 
1675 int CBMAPIDECL
1676 cbm_parallel_burst_read_n(CBM_FILE HandleDevice, unsigned char *Buffer,
1677  unsigned int Length)
1678 {
1679  unsigned int i;
1680  int rv;
1681 
1682  FUNC_ENTER();
1683 
1684  if (Plugin_information.Plugin.opencbm_plugin_parallel_burst_read_n) {
1685  rv = Plugin_information.Plugin.opencbm_plugin_parallel_burst_read_n(
1686  HandleDevice, Buffer, Length);
1687  } else {
1688  for (i = 0; i < Length; i++) {
1689  Buffer[i] = Plugin_information.Plugin
1690  .opencbm_plugin_parallel_burst_read(HandleDevice);
1691  }
1692  rv = Length;
1693  }
1694 
1695  FUNC_LEAVE_INT(rv);
1696 }
1697 
1698 int CBMAPIDECL
1699 cbm_parallel_burst_write_n(CBM_FILE HandleDevice, unsigned char *Buffer,
1700  unsigned int Length)
1701 {
1702  unsigned int i;
1703  int rv;
1704 
1705  FUNC_ENTER();
1706 
1707  if (Plugin_information.Plugin.opencbm_plugin_parallel_burst_write_n) {
1708  rv = Plugin_information.Plugin.opencbm_plugin_parallel_burst_write_n(
1709  HandleDevice, Buffer, Length);
1710  } else {
1711  for (i = 0; i < Length; i++) {
1712  Plugin_information.Plugin.opencbm_plugin_parallel_burst_write(
1713  HandleDevice, Buffer[i]);
1714  }
1715  rv = Length;
1716  }
1717 
1718  FUNC_LEAVE_INT(rv);
1719 }
1720 
1745 int CBMAPIDECL
1746 cbm_parallel_burst_read_track(CBM_FILE HandleDevice, unsigned char *Buffer, unsigned int Length)
1747 {
1748  int ret = -1;
1749 
1750  FUNC_ENTER();
1751 
1752  if (Plugin_information.Plugin.opencbm_plugin_parallel_burst_read_track)
1753  ret = Plugin_information.Plugin.opencbm_plugin_parallel_burst_read_track(HandleDevice, Buffer, Length);
1754 
1755  FUNC_LEAVE_INT(ret);
1756 }
1757 
1779 int CBMAPIDECL
1780 cbm_parallel_burst_read_track_var(CBM_FILE HandleDevice, unsigned char *Buffer, unsigned int Length)
1781 {
1782  int ret = -1;
1783 
1784  FUNC_ENTER();
1785 
1786  if (Plugin_information.Plugin.opencbm_plugin_parallel_burst_read_track)
1787  ret = Plugin_information.Plugin.opencbm_plugin_parallel_burst_read_track_var(HandleDevice, Buffer, Length);
1788 
1789  FUNC_LEAVE_INT(ret);
1790 }
1791 
1816 int CBMAPIDECL
1817 cbm_parallel_burst_write_track(CBM_FILE HandleDevice, unsigned char *Buffer, unsigned int Length)
1818 {
1819  int ret = -1;
1820 
1821  FUNC_ENTER();
1822 
1823  if (Plugin_information.Plugin.opencbm_plugin_parallel_burst_write_track)
1824  ret = Plugin_information.Plugin.opencbm_plugin_parallel_burst_write_track(HandleDevice, Buffer, Length);
1825 
1826  FUNC_LEAVE_INT(ret);
1827 }
1828 
1846 unsigned char CBMAPIDECL
1848 {
1849  unsigned char ret = 0;
1850 
1851  FUNC_ENTER();
1852 
1853  if (Plugin_information.Plugin.opencbm_plugin_srq_burst_read)
1854  ret = Plugin_information.Plugin.opencbm_plugin_srq_burst_read(HandleDevice);
1855 
1856  FUNC_LEAVE_UCHAR(ret);
1857 }
1858 
1876 void CBMAPIDECL
1877 cbm_srq_burst_write(CBM_FILE HandleDevice, unsigned char Value)
1878 {
1879  FUNC_ENTER();
1880 
1881  if (Plugin_information.Plugin.opencbm_plugin_srq_burst_write)
1882  Plugin_information.Plugin.opencbm_plugin_srq_burst_write(HandleDevice, Value);
1883 
1884  FUNC_LEAVE();
1885 }
1886 
1887 int CBMAPIDECL
1888 cbm_srq_burst_read_n(CBM_FILE HandleDevice, unsigned char *Buffer,
1889  unsigned int Length)
1890 {
1891  unsigned int i;
1892  int rv;
1893 
1894  FUNC_ENTER();
1895 
1896  if (Plugin_information.Plugin.opencbm_plugin_srq_burst_read_n) {
1897  rv = Plugin_information.Plugin.opencbm_plugin_srq_burst_read_n(
1898  HandleDevice, Buffer, Length);
1899  } else {
1900  for (i = 0; i < Length; i++) {
1901  Buffer[i] = Plugin_information.Plugin
1902  .opencbm_plugin_srq_burst_read(HandleDevice);
1903  }
1904  rv = Length;
1905  }
1906 
1907  FUNC_LEAVE_INT(rv);
1908 }
1909 
1910 int CBMAPIDECL
1911 cbm_srq_burst_write_n(CBM_FILE HandleDevice, unsigned char *Buffer,
1912  unsigned int Length)
1913 {
1914  unsigned int i;
1915  int rv;
1916 
1917  FUNC_ENTER();
1918 
1919  if (Plugin_information.Plugin.opencbm_plugin_srq_burst_write_n) {
1920  rv = Plugin_information.Plugin.opencbm_plugin_srq_burst_write_n(
1921  HandleDevice, Buffer, Length);
1922  } else {
1923  for (i = 0; i < Length; i++) {
1924  Plugin_information.Plugin.opencbm_plugin_srq_burst_write(
1925  HandleDevice, Buffer[i]);
1926  }
1927  rv = Length;
1928  }
1929 
1930  FUNC_LEAVE_INT(rv);
1931 }
1932 
1957 int CBMAPIDECL
1958 cbm_srq_burst_read_track(CBM_FILE HandleDevice, unsigned char *Buffer, unsigned int Length)
1959 {
1960  int ret = -1;
1961 
1962  FUNC_ENTER();
1963 
1964  if (Plugin_information.Plugin.opencbm_plugin_srq_burst_read_track)
1965  ret = Plugin_information.Plugin.opencbm_plugin_srq_burst_read_track(HandleDevice, Buffer, Length);
1966 
1967  FUNC_LEAVE_INT(ret);
1968 }
1969 
1994 int CBMAPIDECL
1995 cbm_srq_burst_write_track(CBM_FILE HandleDevice, unsigned char *Buffer, unsigned int Length)
1996 {
1997  int ret = -1;
1998 
1999  FUNC_ENTER();
2000 
2001  if (Plugin_information.Plugin.opencbm_plugin_srq_burst_write_track)
2002  ret = Plugin_information.Plugin.opencbm_plugin_srq_burst_write_track(HandleDevice, Buffer, Length);
2003 
2004  FUNC_LEAVE_INT(ret);
2005 }
2006 
2024 int CBMAPIDECL
2025 cbm_tap_prepare_capture(CBM_FILE HandleDevice, int *Status)
2026 {
2027  int ret = -1;
2028 
2029  FUNC_ENTER();
2030 
2031  if (Plugin_information.Plugin.opencbm_plugin_tap_prepare_capture)
2032  ret = Plugin_information.Plugin.opencbm_plugin_tap_prepare_capture(HandleDevice, Status);
2033 
2034  FUNC_LEAVE_INT(ret);
2035 }
2036 
2054 int CBMAPIDECL
2055 cbm_tap_prepare_write(CBM_FILE HandleDevice, int *Status)
2056 {
2057  int ret = -1;
2058 
2059  FUNC_ENTER();
2060 
2061  if (Plugin_information.Plugin.opencbm_plugin_tap_prepare_write)
2062  ret = Plugin_information.Plugin.opencbm_plugin_tap_prepare_write(HandleDevice, Status);
2063 
2064  FUNC_LEAVE_INT(ret);
2065 }
2066 
2084 int CBMAPIDECL
2085 cbm_tap_get_sense(CBM_FILE HandleDevice, int *Status)
2086 {
2087  int ret = -1;
2088 
2089  FUNC_ENTER();
2090 
2091  if (Plugin_information.Plugin.opencbm_plugin_tap_get_sense)
2092  ret = Plugin_information.Plugin.opencbm_plugin_tap_get_sense(HandleDevice, Status);
2093 
2094  FUNC_LEAVE_INT(ret);
2095 }
2096 
2114 int CBMAPIDECL
2115 cbm_tap_wait_for_stop_sense(CBM_FILE HandleDevice, int *Status)
2116 {
2117  int ret = -1;
2118 
2119  FUNC_ENTER();
2120 
2121  if (Plugin_information.Plugin.opencbm_plugin_tap_wait_for_stop_sense)
2122  ret = Plugin_information.Plugin.opencbm_plugin_tap_wait_for_stop_sense(HandleDevice, Status);
2123 
2124  FUNC_LEAVE_INT(ret);
2125 }
2126 
2144 int CBMAPIDECL
2145 cbm_tap_wait_for_play_sense(CBM_FILE HandleDevice, int *Status)
2146 {
2147  int ret = -1;
2148 
2149  FUNC_ENTER();
2150 
2151  if (Plugin_information.Plugin.opencbm_plugin_tap_wait_for_play_sense)
2152  ret = Plugin_information.Plugin.opencbm_plugin_tap_wait_for_play_sense(HandleDevice, Status);
2153 
2154  FUNC_LEAVE_INT(ret);
2155 }
2156 
2174 int CBMAPIDECL
2175 cbm_tap_motor_on(CBM_FILE HandleDevice, int *Status)
2176 {
2177  int ret = -1;
2178 
2179  FUNC_ENTER();
2180 
2181  if (Plugin_information.Plugin.opencbm_plugin_tap_motor_on)
2182  ret = Plugin_information.Plugin.opencbm_plugin_tap_motor_on(HandleDevice, Status);
2183 
2184  FUNC_LEAVE_INT(ret);
2185 }
2186 
2204 int CBMAPIDECL
2205 cbm_tap_motor_off(CBM_FILE HandleDevice, int *Status)
2206 {
2207  int ret = -1;
2208 
2209  FUNC_ENTER();
2210 
2211  if (Plugin_information.Plugin.opencbm_plugin_tap_motor_off)
2212  ret = Plugin_information.Plugin.opencbm_plugin_tap_motor_off(HandleDevice, Status);
2213 
2214  FUNC_LEAVE_INT(ret);
2215 }
2216 
2246 int CBMAPIDECL
2247 cbm_tap_start_capture(CBM_FILE HandleDevice, unsigned char *Buffer, unsigned int Buffer_Length, int *Status, int *BytesRead)
2248 {
2249  int ret = -1;
2250 
2251  FUNC_ENTER();
2252 
2253  if (Plugin_information.Plugin.opencbm_plugin_tap_start_capture)
2254  ret = Plugin_information.Plugin.opencbm_plugin_tap_start_capture(HandleDevice, Buffer, Buffer_Length, Status, BytesRead);
2255 
2256  FUNC_LEAVE_INT(ret);
2257 }
2258 
2288 int CBMAPIDECL
2289 cbm_tap_start_write(CBM_FILE HandleDevice, unsigned char *Buffer, unsigned int Length, int *Status, int *BytesWritten)
2290 {
2291  int ret = -1;
2292 
2293  FUNC_ENTER();
2294 
2295  if (Plugin_information.Plugin.opencbm_plugin_tap_start_write)
2296  ret = Plugin_information.Plugin.opencbm_plugin_tap_start_write(HandleDevice, Buffer, Length, Status, BytesWritten);
2297 
2298  FUNC_LEAVE_INT(ret);
2299 }
2300 
2301 
2319 int CBMAPIDECL
2320 cbm_tap_get_ver(CBM_FILE HandleDevice, int *Status)
2321 {
2322  int ret = -1;
2323 
2324  FUNC_ENTER();
2325 
2326  if (Plugin_information.Plugin.opencbm_plugin_tap_get_ver)
2327  ret = Plugin_information.Plugin.opencbm_plugin_tap_get_ver(HandleDevice, Status);
2328 
2329  FUNC_LEAVE_INT(ret);
2330 }
2331 
2332 
2333 int CBMAPIDECL
2334 cbm_tap_break(CBM_FILE HandleDevice)
2335 {
2336  int ret = -1;
2337 
2338  FUNC_ENTER();
2339 
2340  if (Plugin_information.Plugin.opencbm_plugin_tap_break)
2341  ret = Plugin_information.Plugin.opencbm_plugin_tap_break(HandleDevice);
2342 
2343  FUNC_LEAVE_INT(ret);
2344 }
2345 
2346 
2376 int CBMAPIDECL
2377 cbm_tap_download_config(CBM_FILE HandleDevice, unsigned char *Buffer, unsigned int Buffer_Length, int *Status, int *BytesRead)
2378 {
2379  int ret = -1;
2380 
2381  FUNC_ENTER();
2382 
2383  if (Plugin_information.Plugin.opencbm_plugin_tap_download_config)
2384  ret = Plugin_information.Plugin.opencbm_plugin_tap_download_config(HandleDevice, Buffer, Buffer_Length, Status, BytesRead);
2385 
2386  FUNC_LEAVE_INT(ret);
2387 }
2388 
2418 int CBMAPIDECL
2419 cbm_tap_upload_config(CBM_FILE HandleDevice, unsigned char *Buffer, unsigned int Length, int *Status, int *BytesWritten)
2420 {
2421  int ret = -1;
2422 
2423  FUNC_ENTER();
2424 
2425  if (Plugin_information.Plugin.opencbm_plugin_tap_upload_config)
2426  ret = Plugin_information.Plugin.opencbm_plugin_tap_upload_config(HandleDevice, Buffer, Length, Status, BytesWritten);
2427 
2428  FUNC_LEAVE_INT(ret);
2429 }
2430 
2431 
2448 void * CBMAPIDECL
2449 cbm_get_plugin_function_address(const char * Functionname)
2450 {
2451  void * pointer = NULL;
2452 
2453  FUNC_ENTER();
2454 
2455  if (Plugin_information.Library)
2456  pointer = plugin_get_address(Plugin_information.Library, Functionname);
2457 
2458  FUNC_LEAVE_PTR(pointer, void*);
2459 }
2460 
2484 int CBMAPIDECL
2486 {
2487  int returnValue = -1;
2488 
2489  FUNC_ENTER();
2490 
2491  if ( Plugin_information.Plugin.opencbm_plugin_iec_dbg_read ) {
2492  returnValue = Plugin_information.Plugin.opencbm_plugin_iec_dbg_read(HandleDevice);
2493  }
2494 
2495  FUNC_LEAVE_INT(returnValue);
2496 }
2497 
2527 int CBMAPIDECL
2528 cbm_iec_dbg_write(CBM_FILE HandleDevice, unsigned char Value)
2529 {
2530  int returnValue = -1;
2531 
2532  FUNC_ENTER();
2533 
2534  if ( Plugin_information.Plugin.opencbm_plugin_iec_dbg_write ) {
2535  returnValue = Plugin_information.Plugin.opencbm_plugin_iec_dbg_write(HandleDevice, Value);
2536  }
2537 
2538  FUNC_LEAVE_INT(returnValue);
2539 }
#define DBGDO(_xxx)
Definition: debug.h:409
void CBMAPIDECL opencbm_plugin_iec_release(CBM_FILE HandleDevice, int Line)
Deactivate a line on the IEC serial bus.
Definition: WINDOWS/iec.c:881
int CBMAPIDECL cbm_get_eoi(CBM_FILE HandleDevice)
Get EOI flag after bus read.
Definition: cbm.c:1157
int CBMAPIDECL cbm_tap_prepare_write(CBM_FILE HandleDevice, int *Status)
TAPE: Prepare write.
Definition: cbm.c:2055
void CBMAPIDECL opencbm_plugin_driver_close(CBM_FILE HandleDevice)
Closes the driver.
Definition: i_opencbm.c:454
opencbm_plugin_parallel_burst_read_track_t * opencbm_plugin_srq_burst_read_track
#define FUNC_LEAVE_UCHAR(_xxx)
Definition: debug.h:364
opencbm_plugin_tap_break_t * opencbm_plugin_tap_break
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
opencbm_plugin_tap_get_ver_t * opencbm_plugin_tap_get_ver
const char *CBMAPIDECL opencbm_plugin_get_driver_name(const char *const Port)
Get the name of the driver for a specific parallel port.
Definition: i_opencbm.c:347
int CBMAPIDECL opencbm_plugin_driver_open(CBM_FILE *HandleDevice, const char *const Port)
Opens the driver.
Definition: i_opencbm.c:405
int CBMAPIDECL opencbm_plugin_open(CBM_FILE HandleDevice, unsigned char DeviceAddress, unsigned char SecondaryAddress)
Open a file on the IEC serial bus.
Definition: WINDOWS/iec.c:499
opencbm_plugin_parallel_burst_read_n_t * opencbm_plugin_srq_burst_read_n
void * SHARED_OBJECT_HANDLE
@@@
#define DBG_WARN(_xxx)
Definition: debug.h:395
const char *CBMAPIDECL cbm_get_driver_name(int PortNumber)
Get the name of the driver for a specific parallel port.
Definition: cbm.c:650
int CBMAPIDECL cbm_driver_open(CBM_FILE *HandleDevice, int PortNumber)
Opens the driver.
Definition: cbm.c:740
void CBMAPIDECL opencbm_plugin_parallel_burst_write(CBM_FILE HandleDevice, unsigned char Value)
PARBURST: Write to the parallel port.
#define FUNC_LEAVE_INT(_xxx)
Definition: debug.h:358
int CBMAPIDECL cbm_tap_start_capture(CBM_FILE HandleDevice, unsigned char *Buffer, unsigned int Buffer_Length, int *Status, int *BytesRead)
TAPE: Start capture.
Definition: cbm.c:2247
int CBMAPIDECL cbm_tap_get_ver(CBM_FILE HandleDevice, int *Status)
TAPE: Return tape firmware version.
Definition: cbm.c:2320
opencbm_plugin_tap_get_sense_t * opencbm_plugin_tap_get_sense
holds all callbacks of the plugin
char * cbmlibmisc_strdup(const char *const OldString)
Duplicate a given string.
Definition: libstring.c:84
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_tap_wait_for_play_sense(CBM_FILE HandleDevice, int *Status)
TAPE: Wait for sense.
Definition: cbm.c:2145
Define makros for debugging purposes.
int CBMAPIDECL opencbm_plugin_close(CBM_FILE HandleDevice, unsigned char DeviceAddress, unsigned char SecondaryAddress)
Close a file on the IEC serial bus.
Definition: WINDOWS/iec.c:543
opencbm_plugin_parallel_burst_read_track_var_t * opencbm_plugin_parallel_burst_read_track_var
opencbm_plugin_iec_wait_t * opencbm_plugin_iec_wait
#define CBMAPIDECL
Definition: opencbm.h:85
void CBMAPIDECL opencbm_plugin_iec_set(CBM_FILE HandleDevice, int Line)
Activate a line on the IEC serial bus.
Definition: WINDOWS/iec.c:849
void CBMAPIDECL cbm_unlock(CBM_FILE HandleDevice)
Unlock the parallel port for the driver.
Definition: cbm.c:832
opencbm_plugin_iec_dbg_read_t * opencbm_plugin_iec_dbg_read
opencbm_plugin_lock_t * opencbm_plugin_lock
void cbmlibmisc_strfree(const char *String)
Free a string.
Definition: libstring.c:172
opencbm_plugin_iec_dbg_write_t * opencbm_plugin_iec_dbg_write
unsigned char CBMAPIDECL opencbm_plugin_parallel_burst_read(CBM_FILE HandleDevice)
PARBURST: Read from the parallel port.
unsigned char CBMAPIDECL cbm_pp_read(CBM_FILE HandleDevice)
Read a byte from a XP1541/XP1571 cable.
Definition: cbm.c:1244
int CBMAPIDECL cbm_device_status(CBM_FILE HandleDevice, unsigned char DeviceAddress, void *Buffer, size_t BufferLength)
Read the drive status from a floppy.
Definition: cbm.c:1525
int CBMAPIDECL cbm_iec_dbg_read(CBM_FILE HandleDevice)
Read a byte from the parallel port input register.
Definition: cbm.c:2485
opencbm_plugin_iec_release_t * opencbm_plugin_iec_release
opencbm_plugin_parallel_burst_write_t * opencbm_plugin_srq_burst_write
opencbm_plugin_untalk_t * opencbm_plugin_untalk
int CBMAPIDECL cbm_tap_upload_config(CBM_FILE HandleDevice, unsigned char *Buffer, unsigned int Length, int *Status, int *BytesWritten)
TAPE: Upload configuration.
Definition: cbm.c:2419
int CBMAPIDECL opencbm_plugin_iec_poll(CBM_FILE HandleDevice)
Read status of all bus lines.
Definition: WINDOWS/iec.c:818
#define DBG_MEMDUMP(_Where, _Buffer, _Count)
output a memory dump to the debugging system
Definition: debug.h:105
int CBMAPIDECL opencbm_plugin_unlisten(CBM_FILE HandleDevice)
Send an UNLISTEN on the IEC serial bus.
Definition: WINDOWS/iec.c:581
Plugin DLL interface.
unsigned char CBMAPIDECL cbm_parallel_burst_read(CBM_FILE HandleDevice)
PARBURST: Read from the parallel port.
Definition: cbm.c:1635
int CBMAPIDECL cbm_close(CBM_FILE HandleDevice, unsigned char DeviceAddress, unsigned char SecondaryAddress)
Close a file on the IEC serial bus.
Definition: cbm.c:1072
opencbm_plugin_tap_start_write_t * opencbm_plugin_tap_start_write
opencbm_plugin_clear_eoi_t * opencbm_plugin_clear_eoi
int CBMAPIDECL opencbm_plugin_raw_write(CBM_FILE HandleDevice, const void *Buffer, size_t Count)
Write data to the IEC serial bus.
Definition: WINDOWS/iec.c:323
opencbm_plugin_pp_read_t * opencbm_plugin_pp_read
int CBMAPIDECL cbm_tap_start_write(CBM_FILE HandleDevice, unsigned char *Buffer, unsigned int Length, int *Status, int *BytesWritten)
TAPE: Start write.
Definition: cbm.c:2289
opencbm_plugin_iec_set_t * opencbm_plugin_iec_set
opencbm_plugin_uninit_t * opencbm_plugin_uninit
const char *CBMAPIDECL cbm_get_driver_name_ex(char *Adapter)
Get the name of the driver for a specific parallel port, extended version.
Definition: cbm.c:583
opencbm_plugin_parallel_burst_read_track_t * opencbm_plugin_parallel_burst_read_track
int CBMAPIDECL cbm_iec_dbg_write(CBM_FILE HandleDevice, unsigned char Value)
Write a byte to the parallel port output register.
Definition: cbm.c:2528
void * plugin_get_address(SHARED_OBJECT_HANDLE handle, const char *name)
@@@
opencbm_plugin_tap_motor_off_t * opencbm_plugin_tap_motor_off
int CBMAPIDECL cbm_driver_open_ex(CBM_FILE *HandleDevice, char *Adapter)
Opens the driver, extended version.
Definition: cbm.c:683
void CBMAPIDECL cbm_lock(CBM_FILE HandleDevice)
Lock the parallel port for the driver.
Definition: cbm.c:804
opencbm_plugin_iec_setrelease_t * opencbm_plugin_iec_setrelease
int CBMAPIDECL opencbm_plugin_listen(CBM_FILE HandleDevice, unsigned char DeviceAddress, unsigned char SecondaryAddress)
Send a LISTEN on the IEC serial bus.
Definition: WINDOWS/iec.c:421
#define FUNC_LEAVE()
Definition: debug.h:349
opencbm_plugin_parallel_burst_write_track_t * opencbm_plugin_parallel_burst_write_track
int CBMAPIDECL cbm_srq_burst_write_track(CBM_FILE HandleDevice, unsigned char *Buffer, unsigned int Length)
PARBURST: Write a complete track.
Definition: cbm.c:1995
void CBMAPIDECL cbm_iec_set(CBM_FILE HandleDevice, int Line)
Activate a line on the IEC serial bus.
Definition: cbm.c:1341
opencbm_plugin_parallel_burst_read_t * opencbm_plugin_srq_burst_read
void CBMAPIDECL cbm_srq_burst_write(CBM_FILE HandleDevice, unsigned char Value)
PARBURST: Write to the parallel port.
Definition: cbm.c:1877
opencbm_plugin_tap_wait_for_stop_sense_t * opencbm_plugin_tap_wait_for_stop_sense
int opencbm_configuration_get_data(opencbm_configuration_handle Handle, const char Section[], const char Entry[], char **ReturnBuffer)
Read data from the configuration file.
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
opencbm_plugin_talk_t * opencbm_plugin_talk
opencbm_plugin_unlock_t * opencbm_plugin_unlock
unsigned char CBMAPIDECL cbm_srq_burst_read(CBM_FILE HandleDevice)
PARBURST: Read from the parallel port.
Definition: cbm.c:1847
#define FUNC_LEAVE_PTR(_xxx, _TYPE)
Definition: debug.h:376
Shared library / DLL for accessing the driver Functions for obtaining the addresses of plugin functio...
int CBMAPIDECL cbm_iec_get(CBM_FILE HandleDevice, int Line)
Get the (logical) state of a line on the IEC serial bus.
Definition: cbm.c:1477
void CBMAPIDECL cbm_driver_close(CBM_FILE HandleDevice)
Closes the driver.
Definition: cbm.c:768
int CBMAPIDECL cbm_parallel_burst_read_track(CBM_FILE HandleDevice, unsigned char *Buffer, unsigned int Length)
PARBURST: Read a complete track.
Definition: cbm.c:1746
void CBMAPIDECL opencbm_plugin_unlock(CBM_FILE HandleDevice)
Unlock the parallel port for the driver.
Definition: WINDOWS/iec.c:289
#define CBM_FILE
Definition: opencbm.h:87
Shared library / DLL for accessing the driver Read configuration file.
int CBMAPIDECL cbm_unlisten(CBM_FILE HandleDevice)
Send an UNLISTEN on the IEC serial bus.
Definition: cbm.c:1100
opencbm_plugin_init_t * opencbm_plugin_init
#define DBG_ASSERT(_xxx)
Definition: debug.h:401
void CBMAPIDECL cbm_parallel_burst_write(CBM_FILE HandleDevice, unsigned char Value)
PARBURST: Write to the parallel port.
Definition: cbm.c:1665
void CBMAPIDECL cbm_iec_release(CBM_FILE HandleDevice, int Line)
Deactivate a line on the IEC serial bus.
Definition: cbm.c:1372
int CBMAPIDECL opencbm_plugin_parallel_burst_read_track(CBM_FILE HandleDevice, unsigned char *Buffer, unsigned int Length)
PARBURST: Read a complete track.
int CBMAPIDECL cbm_srq_burst_read_track(CBM_FILE HandleDevice, unsigned char *Buffer, unsigned int Length)
PARBURST: Read a complete track.
Definition: cbm.c:1958
#define DBG_ERROR(_xxx)
Definition: debug.h:397
int CBMAPIDECL opencbm_plugin_reset(CBM_FILE HandleDevice)
RESET all devices.
Definition: WINDOWS/iec.c:706
int CBMAPIDECL cbm_tap_download_config(CBM_FILE HandleDevice, unsigned char *Buffer, unsigned int Buffer_Length, int *Status, int *BytesRead)
TAPE: Download configuration.
Definition: cbm.c:2377
int CBMAPIDECL cbm_open(CBM_FILE HandleDevice, unsigned char DeviceAddress, unsigned char SecondaryAddress, const void *Filename, size_t FilenameLength)
Open a file on the IEC serial bus.
Definition: cbm.c:1012
unsigned char CBMAPIDECL opencbm_plugin_pp_read(CBM_FILE HandleDevice)
Read a byte from a XP1541/XP1571 cable.
Definition: WINDOWS/iec.c:748
int CBMAPIDECL cbm_tap_get_sense(CBM_FILE HandleDevice, int *Status)
TAPE: Get tape sense.
Definition: cbm.c:2085
opencbm_plugin_t Plugin
@@@
Definition: cbm.c:118
void CBMAPIDECL opencbm_plugin_iec_setrelease(CBM_FILE HandleDevice, int Set, int Release)
Activate and deactive a line on the IEC serial bus.
Definition: WINDOWS/iec.c:922
int CBMAPIDECL cbm_clear_eoi(CBM_FILE HandleDevice)
Reset the EOI flag.
Definition: cbm.c:1180
opencbm_plugin_parallel_burst_write_t * opencbm_plugin_parallel_burst_write
SHARED_OBJECT_HANDLE Library
@@@
Definition: cbm.c:117
opencbm_plugin_raw_read_t * opencbm_plugin_raw_read
int CBMAPIDECL cbm_raw_read(CBM_FILE HandleDevice, void *Buffer, size_t Count)
Read data from the IEC serial bus.
Definition: cbm.c:906
void plugin_unload(SHARED_OBJECT_HANDLE handle)
@@@
int CBMAPIDECL opencbm_plugin_talk(CBM_FILE HandleDevice, unsigned char DeviceAddress, unsigned char SecondaryAddress)
Send a TALK on the IEC serial bus.
Definition: WINDOWS/iec.c:461
opencbm_plugin_tap_upload_config_t * opencbm_plugin_tap_upload_config
int CBMAPIDECL cbm_reset(CBM_FILE HandleDevice)
RESET all devices.
Definition: cbm.c:1209
opencbm_plugin_get_eoi_t * opencbm_plugin_get_eoi
int CBMAPIDECL cbm_iec_wait(CBM_FILE HandleDevice, int Line, int State)
Wait for a line to have a specific state.
Definition: cbm.c:1448
opencbm_plugin_tap_motor_on_t * opencbm_plugin_tap_motor_on
char * cbmlibmisc_strndup(const char *const OldString, size_t Length)
Duplicate a prefix of a given string.
Definition: libstring.c:136
opencbm_plugin_tap_wait_for_play_sense_t * opencbm_plugin_tap_wait_for_play_sense
SHARED_OBJECT_HANDLE plugin_load(const char *name)
@@@
int CBMAPIDECL opencbm_plugin_untalk(CBM_FILE HandleDevice)
Send an UNTALK on the IEC serial bus.
Definition: WINDOWS/iec.c:613
int CBMAPIDECL cbm_parallel_burst_read_track_var(CBM_FILE HandleDevice, unsigned char *Buffer, unsigned int Length)
PARBURST: Read a variable length track.
Definition: cbm.c:1780
opencbm_plugin_driver_close_t * opencbm_plugin_driver_close
int CBMAPIDECL opencbm_plugin_clear_eoi(CBM_FILE HandleDevice)
Reset the EOI flag.
Definition: WINDOWS/iec.c:673
int CBMAPIDECL cbm_tap_wait_for_stop_sense(CBM_FILE HandleDevice, int *Status)
TAPE: Wait for sense.
Definition: cbm.c:2115
opencbm_plugin_tap_download_config_t * opencbm_plugin_tap_download_config
int CBMAPIDECL cbm_exec_command(CBM_FILE HandleDevice, unsigned char DeviceAddress, const void *Command, size_t Size)
Executes a command in the floppy drive.
Definition: cbm.c:1599
int CBMAPIDECL cbm_tap_motor_off(CBM_FILE HandleDevice, int *Status)
TAPE: Motor off.
Definition: cbm.c:2205
#define FUNC_ENTER()
Definition: debug.h:347
opencbm_plugin_raw_write_t * opencbm_plugin_raw_write
int CBMAPIDECL cbm_parallel_burst_write_track(CBM_FILE HandleDevice, unsigned char *Buffer, unsigned int Length)
PARBURST: Write a complete track.
Definition: cbm.c:1817
#define DBG_PREFIX
Definition: debug.h:320
#define FUNC_LEAVE_STRING(_xxx)
Definition: debug.h:368
DLL interface for accessing the driver.
opencbm_plugin_pp_write_t * opencbm_plugin_pp_write
opencbm_plugin_listen_t * opencbm_plugin_listen
int CBMAPIDECL opencbm_plugin_iec_wait(CBM_FILE HandleDevice, int Line, int State)
Wait for a line to have a specific state.
Definition: WINDOWS/iec.c:963
opencbm_plugin_unlisten_t * opencbm_plugin_unlisten
int CBMAPIDECL opencbm_plugin_parallel_burst_write_track(CBM_FILE HandleDevice, unsigned char *Buffer, unsigned int Length)
PARBURST: Write a complete track.
opencbm_plugin_parallel_burst_read_t * opencbm_plugin_parallel_burst_read
int CBMAPIDECL cbm_iec_poll(CBM_FILE HandleDevice)
Read status of all bus lines.
Definition: cbm.c:1314
opencbm_configuration_handle opencbm_configuration_open(const char *Filename)
Open the configuration file.
opencbm_plugin_parallel_burst_write_track_t * opencbm_plugin_srq_burst_write_track
int CBMAPIDECL cbm_untalk(CBM_FILE HandleDevice)
Send an UNTALK on the IEC serial bus.
Definition: cbm.c:1128
opencbm_plugin_tap_prepare_capture_t * opencbm_plugin_tap_prepare_capture
void CBMAPIDECL opencbm_plugin_lock(CBM_FILE HandleDevice)
Lock the parallel port for the driver.
Definition: WINDOWS/iec.c:262
Define makros and functions which account for differences between the different architectures.
opencbm_plugin_parallel_burst_write_n_t * opencbm_plugin_parallel_burst_write_n
const char * configuration_get_default_filename(void)
Get the default filename for the configuration file.
opencbm_plugin_tap_start_capture_t * opencbm_plugin_tap_start_capture
opencbm_plugin_driver_open_t * opencbm_plugin_driver_open
void CBMAPIDECL cbm_iec_setrelease(CBM_FILE HandleDevice, int Set, int Release)
Activate and deactive a line on the IEC serial bus.
Definition: cbm.c:1412
int plugin_set_inactive(const char PluginName[])
@@@
Definition: cbm.c:107
int CBMAPIDECL opencbm_plugin_get_eoi(CBM_FILE HandleDevice)
Get EOI flag after bus read.
Definition: WINDOWS/iec.c:646
opencbm_plugin_iec_poll_t * opencbm_plugin_iec_poll
int plugin_is_active(opencbm_configuration_handle Handle, const char PluginName[])
@@@
Definition: cbm.c:55
int CBMAPIDECL opencbm_plugin_raw_read(CBM_FILE HandleDevice, void *Buffer, size_t Count)
Read data from the IEC serial bus.
Definition: WINDOWS/iec.c:370
opencbm_plugin_parallel_burst_write_n_t * opencbm_plugin_srq_burst_write_n
void *CBMAPIDECL cbm_get_plugin_function_address(const char *Functionname)
Get the function pointer for a function in a plugin.
Definition: cbm.c:2449
opencbm_plugin_close_t * opencbm_plugin_close
void CBMAPIDECL cbm_pp_write(CBM_FILE HandleDevice, unsigned char Byte)
Write a byte to a XP1541/XP1571 cable.
Definition: cbm.c:1282
opencbm_plugin_parallel_burst_read_n_t * opencbm_plugin_parallel_burst_read_n
opencbm_plugin_open_t * opencbm_plugin_open
int CBMAPIDECL cbm_tap_prepare_capture(CBM_FILE HandleDevice, int *Status)
TAPE: Prepare capture.
Definition: cbm.c:2025
Some functions for string handling.
int CBMAPIDECL cbm_tap_motor_on(CBM_FILE HandleDevice, int *Status)
TAPE: Motor on.
Definition: cbm.c:2175
opencbm_plugin_get_driver_name_t * opencbm_plugin_get_driver_name
opencbm_plugin_reset_t * opencbm_plugin_reset
void CBMAPIDECL opencbm_plugin_pp_write(CBM_FILE HandleDevice, unsigned char Byte)
Write a byte to a XP1541/XP1571 cable.
Definition: WINDOWS/iec.c:783
opencbm_plugin_tap_prepare_write_t * opencbm_plugin_tap_prepare_write
#define DBG_PRINT(_xxx)
Definition: debug.h:403
int plugin_set_active(const char PluginName[])
@@@
Definition: cbm.c:93
int opencbm_configuration_close(opencbm_configuration_handle Handle)
Close the configuration file.