OpenCBM
libd64copy/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 */
9 
10 #include "opencbm.h"
11 #include "d64copy_int.h"
12 
13 #include <stdio.h>
14 #include <stdlib.h>
15 
16 static unsigned char drive = 0;
17 static CBM_FILE fd_cbm = (CBM_FILE) -1;
18 
19 static int read_block(unsigned char tr, unsigned char se, unsigned char *block)
20 {
21  char cmd[48];
22  int rv = 1;
23 
24  sprintf(cmd, "U1:2 0 %d %d", tr, se);
25  if(cbm_exec_command(fd_cbm, drive, cmd, 0) == 0) {
26  rv = cbm_device_status(fd_cbm, drive, cmd, sizeof(cmd));
27  if(rv == 0) {
28  if(cbm_exec_command(fd_cbm, drive, "B-P2 0", 0) == 0) {
29  if(cbm_talk(fd_cbm, drive, 2) == 0) {
30  SETSTATEDEBUG(DebugByteCount=0);
31  rv = cbm_raw_read(fd_cbm, block, BLOCKSIZE) != BLOCKSIZE;
32  SETSTATEDEBUG(DebugByteCount=-1);
33  cbm_untalk(fd_cbm);
34  }
35  }
36  }
37  }
38  return rv;
39 }
40 
41 static int write_block(unsigned char tr, unsigned char se, const unsigned char *blk, int size, int read_status)
42 {
43  char cmd[48];
44  int rv = 1;
45 
46  if(cbm_exec_command(fd_cbm, drive, "B-P2 0", 0) == 0)
47  {
48  if(cbm_listen(fd_cbm, drive, 2) == 0)
49  {
50  SETSTATEDEBUG(DebugByteCount=0);
51  rv = cbm_raw_write(fd_cbm, blk, size) != size;
52  SETSTATEDEBUG(DebugByteCount=-1);
53  cbm_unlisten(fd_cbm);
54  if(rv == 0)
55  {
56  sprintf(cmd ,"U2:2 0 %d %d", tr, se);
57  cbm_exec_command(fd_cbm, drive, cmd, 0);
58  rv = cbm_device_status(fd_cbm, drive, cmd, sizeof(cmd));
59  }
60  }
61  }
62  return rv;
63 }
64 
65 static int open_disk(CBM_FILE fd, d64copy_settings *settings,
66  const void *arg, int for_writing,
67  turbo_start start, d64copy_message_cb message_cb)
68 {
69  char buf[48];
70  int rv;
71 
72  if(settings->end_track > STD_TRACKS && !settings->two_sided)
73  {
74  message_cb(0,
75  "standard transfer doesn't handle extended track images");
76  return 99;
77  }
78 
79  drive = (unsigned char)(ULONG_PTR)arg;
80 
81  fd_cbm = fd;
82 
83  cbm_open(fd_cbm, drive, 2, "#", 1);
84 
85  rv = cbm_device_status(fd_cbm, drive, buf, sizeof(buf));
86  if(rv)
87  {
88  message_cb(0, "drive %02d: %s", drive, buf);
89  }
90  return rv;
91 }
92 
93 static void close_disk(void)
94 {
95  cbm_close(fd_cbm, drive, 2);
96 }
97 
98 DECLARE_TRANSFER_FUNCS(std_transfer, 1, 0);
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_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_close(CBM_FILE HandleDevice, unsigned char DeviceAddress, unsigned char SecondaryAddress)
Close a file on the IEC serial bus.
Definition: cbm.c:1072
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_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
int CBMAPIDECL cbm_raw_read(CBM_FILE HandleDevice, void *Buffer, size_t Count)
Read data from the IEC serial bus.
Definition: cbm.c:906
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
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