OpenCBM
detect.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 Spiro Trikaliotis
9  * Copyright 2011 Wolfgang Moser (http://d81.de)
10  * Copyright 2011 Thomas Winkler
11  *
12 */
13 
23 #define DBG_USERMODE
24 
26 #define DBG_PROGNAME "OPENCBM.DLL"
27 
28 #include "debug.h"
29 
30 #include <stdlib.h>
31 
33 #define DLL
34 #include "opencbm.h"
35 #include "archlib.h"
36 
37 
65 int CBMAPIDECL
66 cbm_identify(CBM_FILE HandleDevice, unsigned char DeviceAddress,
67  enum cbm_device_type_e *CbmDeviceType,
68  const char **CbmDeviceString)
69 {
70  enum cbm_device_type_e deviceType = cbm_dt_unknown;
71  unsigned short magic;
72  unsigned char buf[3];
73  char command[] = { 'M', '-', 'R', (char) 0x40, (char) 0xff, (char) 0x02 };
74  static char unknownDevice[] = "*unknown*, footprint=<....>";
75  char *deviceString = unknownDevice;
76  int rv = -1;
77 
78  FUNC_ENTER();
79 
80  /* get footprint from 0xFF40 */
81  if (cbm_exec_command(HandleDevice, DeviceAddress, command, sizeof(command)) == 0
82  && cbm_talk(HandleDevice, DeviceAddress, 15) == 0)
83  {
84  if (cbm_raw_read(HandleDevice, buf, 3) == 3)
85  {
86  magic = buf[0] | (buf[1] << 8);
87 
88  if(magic == 0xaaaa)
89  {
90  cbm_untalk(HandleDevice);
91  command[3] = (char) 0xFE; /* get footprint from 0xFFFE, IRQ vector */
92  if (cbm_exec_command(HandleDevice, DeviceAddress, command, sizeof(command)) == 0
93  && cbm_talk(HandleDevice, DeviceAddress, 15) == 0)
94  {
95  if (cbm_raw_read(HandleDevice, buf, 3) == 3
96  && ( buf[0] != 0x67 || buf[1] != 0xFE ) )
97  {
98  magic = buf[0] | (buf[1] << 8);
99  }
100  }
101  }
102 
103  switch(magic)
104  {
105  default:
106  unknownDevice[22] = ((magic >> 12 & 0x0F) | 0x40);
107  unknownDevice[24] = ((magic >> 4 & 0x0F) | 0x40);
108  magic &= 0x0F0F;
109  magic |= 0x4040;
110  unknownDevice[23] = magic >> 8;
111  unknownDevice[25] = (char)magic;
112  break;
113 
114  case 0xaaaa:
115  deviceType = cbm_dt_cbm1541;
116  deviceString = "1540 or 1541";
117  break;
118 
119  case 0xf00f:
120  deviceType = cbm_dt_cbm1541;
121  deviceString = "1541-II";
122  break;
123 
124  case 0xcd18:
125  deviceType = cbm_dt_cbm1541;
126  deviceString = "1541C";
127  break;
128 
129  case 0x10ca:
130  deviceType = cbm_dt_cbm1541;
131  deviceString = "DolphinDOS 1541";
132  break;
133 
134  case 0x6f10:
135  deviceType = cbm_dt_cbm1541;
136  deviceString = "SpeedDOS 1541";
137  break;
138 
139  case 0x2710:
140  deviceType = cbm_dt_cbm1541;
141  deviceString = "ProfessionalDOS 1541";
142  break;
143 
144  case 0x8085:
145  deviceType = cbm_dt_cbm1541;
146  deviceString = "JiffyDOS 1541";
147  break;
148 
149  case 0xaeea:
150  deviceType = cbm_dt_cbm1541;
151  deviceString = "64'er DOS 1541";
152  break;
153 
154  case 0xfed7:
155  deviceType = cbm_dt_cbm1570;
156  deviceString = "1570";
157  break;
158 
159  case 0x02ac:
160  deviceType = cbm_dt_cbm1571;
161  deviceString = "1571";
162  break;
163 
164  case 0x01ba:
165  deviceType = cbm_dt_cbm1581;
166  deviceString = "1581";
167  break;
168 
169  case 0x32f0:
170  deviceType = cbm_dt_cbm3040;
171  deviceString = "3040";
172  break;
173 
174  case 0xc320:
175  case 0x20f8:
176  deviceType = cbm_dt_cbm4040;
177  deviceString = "4040";
178  break;
179 
180  case 0xf2e9:
181  deviceType = cbm_dt_cbm8050;
182  deviceString = "8050 dos2.5";
183  break;
184 
185  case 0xc866: /* special dos2.7 ?? Speed-DOS 8250 ?? */
186  case 0xc611:
187  deviceType = cbm_dt_cbm8250;
188  deviceString = "8250 dos2.7";
189  break;
190  }
191  rv = 0;
192  }
193  cbm_untalk(HandleDevice);
194  }
195 
196  if(CbmDeviceType)
197  {
198  *CbmDeviceType = deviceType;
199  }
200 
201  if(CbmDeviceString)
202  {
203  *CbmDeviceString = deviceString;
204  }
205 
206  FUNC_LEAVE_INT(rv);
207 }
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
#define FUNC_LEAVE_INT(_xxx)
Definition: debug.h:358
Define makros for debugging purposes.
#define CBMAPIDECL
Definition: opencbm.h:85
#define CBM_FILE
Definition: opencbm.h:87
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
#define FUNC_ENTER()
Definition: debug.h:347
cbm_device_type_e
Definition: opencbm.h:114
int CBMAPIDECL cbm_identify(CBM_FILE HandleDevice, unsigned char DeviceAddress, enum cbm_device_type_e *CbmDeviceType, const char **CbmDeviceString)
Identify the connected floppy drive.
Definition: detect.c:66
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