OpenCBM
xa1541/LINUX/parburst.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 2005 Tim Schürmann
8  * Copyright 2007,2009 Spiro Trikaliotis
9  * Copyright 2009 Arnd <arnd(at)jonnz(dot)de>
10 */
11 
12 #include <fcntl.h>
13 #include <stdlib.h>
14 #include <stdio.h>
15 #include <string.h>
16 #include <sys/ioctl.h>
17 #include <unistd.h>
18 
19 #include "opencbm.h"
20 #include "cbm_module.h"
21 
22 #if defined(__linux__)
23 #include <linux/errno.h> /* error codes */
24 #else
25 #include <errno.h> /* error codes */
26 #endif
27 
28 
29 /*linux functions needed by parallel burst */
30 
32 {
33  return ioctl(f, CBMCTRL_PARBURST_READ);
34 }
35 
36 void opencbm_plugin_parallel_burst_write(CBM_FILE f, unsigned char c)
37 {
38  ioctl(f, CBMCTRL_PARBURST_WRITE, c);
39 }
40 
41 int opencbm_plugin_parallel_burst_read_track(CBM_FILE f, unsigned char *buffer, unsigned int length)
42 {
43  int retval;
44 
46  mv.buffer=buffer;
47  mv.length=length; /* only needed in write_track */
48  retval=ioctl(f, CBMCTRL_PARBURST_READ_TRACK, &mv); /* we have to catch retval to check on EFAULT */
49  if(retval==(-EFAULT)) {printf("cbm4linux: cbm.c: cbm_parallel_burst_read_track: ioctl returned -EFAULT"); return 0;}
50  return retval;
51 }
52 
53 int opencbm_plugin_parallel_burst_read_track_var(CBM_FILE f, unsigned char *buffer, unsigned int length)
54 {
55  int retval;
56 
58  mv.buffer=buffer;
59  mv.length=length; /* only needed in write_track */
60  retval=ioctl(f, CBMCTRL_PARBURST_READ_TRACK_VAR, &mv); /* we have to catch retval to check on EFAULT */
61  if(retval==(-EFAULT)) {printf("cbm4linux: cbm.c: cbm_parallel_burst_read_track_var: ioctl returned -EFAULT"); return 0;}
62  return retval;
63 }
64 
65 int opencbm_plugin_parallel_burst_write_track(CBM_FILE f, unsigned char *buffer, unsigned int length)
66 {
67  int retval;
68 
70  mv.buffer=buffer;
71  mv.length=length;
72  retval=ioctl(f, CBMCTRL_PARBURST_WRITE_TRACK, &mv);
73  if(retval==(-EFAULT)) {printf("cbm4linux: cbm.c: cbm_parallel_burst_write_track: ioctl returned -EFAULT"); return 0;}
74  return retval;
75 }
#define CBMCTRL_PARBURST_READ_TRACK
IOCTL for reading a complete track (for parallel burst)
Definition: cbmioctl.h:315
void CBMAPIDECL opencbm_plugin_parallel_burst_write(CBM_FILE HandleDevice, unsigned char Value)
PARBURST: Write to the parallel port.
unsigned char CBMAPIDECL opencbm_plugin_parallel_burst_read(CBM_FILE HandleDevice)
PARBURST: Read from the parallel port.
#define CBMCTRL_PARBURST_WRITE
IOCTL for writing to the parallel port (for controlling parallel burst)
Definition: cbmioctl.h:311
#define CBM_FILE
Definition: opencbm.h:87
int CBMAPIDECL opencbm_plugin_parallel_burst_read_track(CBM_FILE HandleDevice, unsigned char *Buffer, unsigned int Length)
PARBURST: Read a complete track.
#define CBMCTRL_PARBURST_READ
IOCTL for reading from the parallel port (for controlling parallel burst)
Definition: cbmioctl.h:307
int CBMAPIDECL opencbm_plugin_parallel_burst_read_track_var(CBM_FILE HandleDevice, unsigned char *Buffer, unsigned int Length)
PARBURST: Read a variable length track.
#define CBMCTRL_PARBURST_WRITE_TRACK
IOCTL for writing a complete track (for parallel burst)
Definition: cbmioctl.h:319
#define CBMCTRL_PARBURST_READ_TRACK_VAR
IOCTL for reading a variable length track (for parallel burst)
Definition: cbmioctl.h:346
DLL interface for accessing the driver.
int CBMAPIDECL opencbm_plugin_parallel_burst_write_track(CBM_FILE HandleDevice, unsigned char *Buffer, unsigned int Length)
PARBURST: Write a complete track.