OpenCBM
xum1541/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 2009-2010 Nate Lawson
8  */
9 
18 #include <stdio.h>
19 #include <stdlib.h>
20 
21 #define DBG_USERMODE
22 #define DBG_PROGNAME "OPENCBM-XUM1541.DLL"
23 #include "debug.h"
24 
25 #define OPENCBM_PLUGIN
26 #include "archlib.h"
27 
28 #include "xum1541.h"
29 
30 
46 unsigned char CBMAPIDECL
48 {
49  unsigned char result;
50 
51  result = (unsigned char)xum1541_ioctl((usb_dev_handle *)HandleDevice, XUM1541_PARBURST_READ, 0, 0);
52  //printf("parburst read: %x\n", result);
53  return result;
54 }
55 
71 void CBMAPIDECL
72 opencbm_plugin_parallel_burst_write(CBM_FILE HandleDevice, unsigned char Value)
73 {
74  int result;
75 
76  result = xum1541_ioctl((usb_dev_handle *)HandleDevice, XUM1541_PARBURST_WRITE, Value, 0);
77  //printf("parburst write: %x, res %x\n", Value, result);
78 }
79 
80 int CBMAPIDECL
81 opencbm_plugin_parallel_burst_read_n(CBM_FILE HandleDevice, unsigned char *Buffer,
82  unsigned int Length)
83 {
84  int result;
85 
86  result = xum1541_read((usb_dev_handle *)HandleDevice, XUM1541_NIB_COMMAND, Buffer, Length);
87  if (result != Length) {
88  DBG_WARN((DBG_PREFIX "parallel_burst_read_n: returned with error %d", result));
89  }
90 
91  return result;
92 }
93 
94 int CBMAPIDECL
95 opencbm_plugin_parallel_burst_write_n(CBM_FILE HandleDevice, unsigned char *Buffer,
96  unsigned int Length)
97 {
98  int result;
99 
100  result = xum1541_write((usb_dev_handle *)HandleDevice, XUM1541_NIB_COMMAND, Buffer, Length);
101  if (result != Length) {
102  DBG_WARN((DBG_PREFIX "parallel_burst_write_n: returned with error %d", result));
103  }
104 
105  return result;
106 }
107 
129 int CBMAPIDECL
130 opencbm_plugin_parallel_burst_read_track(CBM_FILE HandleDevice, unsigned char *Buffer, unsigned int Length)
131 {
132  int result;
133 
134  result = xum1541_read((usb_dev_handle *)HandleDevice, XUM1541_NIB, Buffer, Length);
135  if (result != Length) {
136  DBG_WARN((DBG_PREFIX "parallel_burst_read_track: returned with error %d", result));
137  }
138 
139  return result;
140 }
141 
163 int CBMAPIDECL
164 opencbm_plugin_parallel_burst_read_track_var(CBM_FILE HandleDevice, unsigned char *Buffer, unsigned int Length)
165 {
166  int result;
167 
168  // Add a flag to indicate this read terminates early after seeing
169  // an 0x55 byte.
170  result = xum1541_read((usb_dev_handle *)HandleDevice, XUM1541_NIB, Buffer, Length | XUM1541_NIB_READ_VAR);
171  if (result <= 0) {
172  DBG_WARN((DBG_PREFIX "parallel_burst_read_track_var: returned with error %d", result));
173  }
174 
175  return result;
176 }
177 
199 int CBMAPIDECL
200 opencbm_plugin_parallel_burst_write_track(CBM_FILE HandleDevice, unsigned char *Buffer, unsigned int Length)
201 {
202  int result;
203 
204  result = xum1541_write((usb_dev_handle *)HandleDevice, XUM1541_NIB, Buffer, Length);
205  if (result != Length) {
206  DBG_WARN((DBG_PREFIX "parallel_burst_write_track: returned with error %d", result));
207  }
208 
209  return result;
210 }
211 
212 /********* Fast serial nibbler routines below ********/
213 
229 unsigned char CBMAPIDECL
230 opencbm_plugin_srq_burst_read(CBM_FILE HandleDevice)
231 {
232  unsigned char result;
233 
234  result = (unsigned char)xum1541_ioctl((usb_dev_handle *)HandleDevice, XUM1541_SRQBURST_READ, 0, 0);
235  return result;
236 }
237 
253 void CBMAPIDECL
254 opencbm_plugin_srq_burst_write(CBM_FILE HandleDevice, unsigned char Value)
255 {
256  int result;
257 
258  result = xum1541_ioctl((usb_dev_handle *)HandleDevice, XUM1541_SRQBURST_WRITE, Value, 0);
259 }
260 
261 int CBMAPIDECL
262 opencbm_plugin_srq_burst_read_n(CBM_FILE HandleDevice, unsigned char *Buffer,
263  unsigned int Length)
264 {
265  int result;
266 
267  result = xum1541_read((usb_dev_handle *)HandleDevice, XUM1541_NIB_SRQ_COMMAND, Buffer, Length);
268  if (result != Length) {
269  DBG_WARN((DBG_PREFIX "srq_burst_read_n: returned with error %d", result));
270  }
271 
272  return result;
273 }
274 
275 int CBMAPIDECL
276 opencbm_plugin_srq_burst_write_n(CBM_FILE HandleDevice, unsigned char *Buffer,
277  unsigned int Length)
278 {
279  int result;
280 
281  result = xum1541_write((usb_dev_handle *)HandleDevice, XUM1541_NIB_SRQ_COMMAND, Buffer, Length);
282  if (result != Length) {
283  DBG_WARN((DBG_PREFIX "srq_burst_write_n: returned with error %d", result));
284  }
285 
286  return result;
287 }
288 
310 int CBMAPIDECL
311 opencbm_plugin_srq_burst_read_track(CBM_FILE HandleDevice, unsigned char *Buffer, unsigned int Length)
312 {
313  int result;
314 
315  result = xum1541_read((usb_dev_handle *)HandleDevice, XUM1541_NIB_SRQ, Buffer, Length);
316  if (result != Length) {
317  DBG_WARN((DBG_PREFIX "srq_read_track: returned with error %d", result));
318  }
319 
320  return result;
321 }
322 
344 int CBMAPIDECL
345 opencbm_plugin_srq_burst_write_track(CBM_FILE HandleDevice, unsigned char *Buffer, unsigned int Length)
346 {
347  int result;
348 
349  result = xum1541_write((usb_dev_handle *)HandleDevice, XUM1541_NIB_SRQ, Buffer, Length);
350  if (result != Length) {
351  DBG_WARN((DBG_PREFIX "srq_write_track: returned with error %d", result));
352  }
353 
354  return result;
355 }
356 
357 /**************** Tape routines below ****************/
358 
376 int CBMAPIDECL
377 opencbm_plugin_tap_prepare_capture(CBM_FILE HandleDevice, int *Status)
378 {
379  *Status = xum1541_ioctl((usb_dev_handle *)HandleDevice, XUM1541_TAP_PREPARE_CAPTURE, 0, 0);
380  //printf("opencbm_plugin_tap_prepare_capture: %x\n", result);
381  return 1;
382 }
383 
401 int CBMAPIDECL
402 opencbm_plugin_tap_prepare_write(CBM_FILE HandleDevice, int *Status)
403 {
404  *Status = xum1541_ioctl((usb_dev_handle *)HandleDevice, XUM1541_TAP_PREPARE_WRITE, 0, 0);
405  //printf("opencbm_plugin_tap_prepare_write: %x\n", result);
406  return 1;
407 }
408 
426 int CBMAPIDECL
427 opencbm_plugin_tap_get_sense(CBM_FILE HandleDevice, int *Status)
428 {
429  *Status = xum1541_ioctl((usb_dev_handle *)HandleDevice, XUM1541_TAP_GET_SENSE, 0, 0);
430  //printf("opencbm_plugin_tap_get_sense: %x\n", result);
431  return 1;
432 }
433 
451 int CBMAPIDECL
452 opencbm_plugin_tap_wait_for_stop_sense(CBM_FILE HandleDevice, int *Status)
453 {
454  *Status = xum1541_ioctl((usb_dev_handle *)HandleDevice, XUM1541_TAP_WAIT_FOR_STOP_SENSE, 0, 0);
455  //printf("opencbm_plugin_tap_wait_for_stop_sense: %x\n", result);
456  return 1;
457 }
458 
476 int CBMAPIDECL
477 opencbm_plugin_tap_wait_for_play_sense(CBM_FILE HandleDevice, int *Status)
478 {
479  *Status = xum1541_ioctl((usb_dev_handle *)HandleDevice, XUM1541_TAP_WAIT_FOR_PLAY_SENSE, 0, 0);
480  //printf("opencbm_plugin_tap_wait_for_play_sense: %x\n", result);
481  return 1;
482 }
483 
501 int CBMAPIDECL
502 opencbm_plugin_tap_motor_on(CBM_FILE HandleDevice, int *Status)
503 {
504  *Status = xum1541_ioctl((usb_dev_handle *)HandleDevice, XUM1541_TAP_MOTOR_ON, 0, 0);
505  //printf("opencbm_plugin_tap_motor_on: %x\n", result);
506  return 1;
507 }
508 
526 int CBMAPIDECL
527 opencbm_plugin_tap_motor_off(CBM_FILE HandleDevice, int *Status)
528 {
529  *Status = xum1541_ioctl((usb_dev_handle *)HandleDevice, XUM1541_TAP_MOTOR_OFF, 0, 0);
530  //printf("opencbm_plugin_tap_motor_off: %x\n", result);
531  return 1;
532 }
533 
563 int CBMAPIDECL
564 opencbm_plugin_tap_start_capture(CBM_FILE HandleDevice, unsigned char *Buffer, unsigned int Buffer_Length, int *Status, int *BytesRead)
565 {
566  int result = xum1541_read_ext((usb_dev_handle *)HandleDevice, XUM1541_TAP, Buffer, Buffer_Length, Status, BytesRead);
567  if (result <= 0) {
568  DBG_WARN((DBG_PREFIX "opencbm_plugin_tap_start_capture: returned with error %d", result));
569  }
570  return result;
571 }
572 
602 int CBMAPIDECL
603 opencbm_plugin_tap_start_write(CBM_FILE HandleDevice, unsigned char *Buffer, unsigned int Length, int *Status, int *BytesWritten)
604 {
605  int result = xum1541_write_ext((usb_dev_handle *)HandleDevice, XUM1541_TAP, Buffer, Length, Status, BytesWritten);
606  if (result <= 0) {
607  DBG_WARN((DBG_PREFIX "opencbm_plugin_tap_start_write: returned with error %d", result));
608  }
609  return result;
610 }
611 
629 int CBMAPIDECL
630 opencbm_plugin_tap_get_ver(CBM_FILE HandleDevice, int *Status)
631 {
632  *Status = xum1541_ioctl((usb_dev_handle *)HandleDevice, XUM1541_TAP_GET_VER, 0, 0);
633  //printf("opencbm_plugin_tap_get_ver: %x\n", result);
634  return 1;
635 }
636 
637 int CBMAPIDECL
638 opencbm_plugin_tap_break(CBM_FILE HandleDevice)
639 {
640  return xum1541_tap_break((usb_dev_handle *)HandleDevice);
641  //printf("opencbm_plugin_tap_break: %x\n", result);
642 }
643 
673 int CBMAPIDECL
674 opencbm_plugin_tap_download_config(CBM_FILE HandleDevice, unsigned char *Buffer, unsigned int Buffer_Length, int *Status, int *BytesRead)
675 {
676  int result = xum1541_read_ext((usb_dev_handle *)HandleDevice, XUM1541_TAP_CONFIG, Buffer, Buffer_Length, Status, BytesRead);
677  if (result <= 0) {
678  DBG_WARN((DBG_PREFIX "opencbm_plugin_tap_download_config: returned with error %d", result));
679  }
680  return result;
681 }
682 
712 int CBMAPIDECL
713 opencbm_plugin_tap_upload_config(CBM_FILE HandleDevice, unsigned char *Buffer, unsigned int Length, int *Status, int *BytesWritten)
714 {
715  int result = xum1541_write_ext((usb_dev_handle *)HandleDevice, XUM1541_TAP_CONFIG, Buffer, Length, Status, BytesWritten);
716  if (result <= 0) {
717  DBG_WARN((DBG_PREFIX "opencbm_plugin_tap_upload_config: returned with error %d", result));
718  }
719  return result;
720 }
#define DBG_WARN(_xxx)
Definition: debug.h:395
void CBMAPIDECL opencbm_plugin_parallel_burst_write(CBM_FILE HandleDevice, unsigned char Value)
PARBURST: Write to the parallel port.
Define makros for debugging purposes.
#define CBMAPIDECL
Definition: opencbm.h:85
int xum1541_tap_break(usb_dev_handle *HandleXum1541)
Send tape operations abort command to the xum1541 device.
Definition: xum1541.c:656
unsigned char CBMAPIDECL opencbm_plugin_parallel_burst_read(CBM_FILE HandleDevice)
PARBURST: Read from the parallel port.
#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.
int xum1541_write(usb_dev_handle *HandleXum1541, unsigned char modeFlags, const unsigned char *data, size_t size)
Write data to the xum1541 device.
Definition: xum1541.c:686
int CBMAPIDECL opencbm_plugin_parallel_burst_read_track_var(CBM_FILE HandleDevice, unsigned char *Buffer, unsigned int Length)
PARBURST: Read a variable length track.
int xum1541_read_ext(usb_dev_handle *HandleXum1541, unsigned char mode, unsigned char *data, size_t size, int *Status, int *BytesRead)
Wrapper for xum1541_read() forcing xum1541_wait_status(), with additional parameters: ...
Definition: xum1541.c:801
#define DBG_PREFIX
Definition: debug.h:320
int CBMAPIDECL opencbm_plugin_parallel_burst_write_track(CBM_FILE HandleDevice, unsigned char *Buffer, unsigned int Length)
PARBURST: Write a complete track.
int xum1541_write_ext(usb_dev_handle *HandleXum1541, unsigned char modeFlags, const unsigned char *data, size_t size, int *Status, int *BytesWritten)
Wrapper for xum1541_write() forcing xum1541_wait_status(), with additional parameters: ...
Definition: xum1541.c:775
int xum1541_ioctl(usb_dev_handle *HandleXum1541, unsigned int cmd, unsigned int addr, unsigned int secaddr)
Perform an ioctl on the xum1541, which is any command other than read/write or special device managem...
Definition: xum1541.c:616
int xum1541_read(usb_dev_handle *HandleXum1541, unsigned char mode, unsigned char *data, size_t size)
Read data from the xum1541 device.
Definition: xum1541.c:833