ucon64_quickdev16.patch 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  1. diff -Naur ucon64-2.0.0-src/src/backup/backup.h ucon64/src/backup/backup.h
  2. --- ucon64-2.0.0-src/src/backup/backup.h 2009-09-16 09:43:42.000000000 +0000
  3. +++ ucon64/src/backup/backup.h 2009-08-28 10:00:36.000000000 +0000
  4. @@ -59,4 +59,9 @@
  5. #include "f2a.h"
  6. #endif
  7. +#ifdef USE_USB
  8. +#include "quickdev16.h"
  9. +#endif // USE_PARALLEL
  10. +
  11. +
  12. #endif // BACKUP_H
  13. diff -Naur ucon64-2.0.0-src/src/backup/quickdev16.c ucon64/src/backup/quickdev16.c
  14. --- ucon64-2.0.0-src/src/backup/quickdev16.c 1970-01-01 00:00:00.000000000 +0000
  15. +++ ucon64/src/backup/quickdev16.c 2009-09-01 13:01:12.000000000 +0000
  16. @@ -0,0 +1,228 @@
  17. +/*
  18. +quickdev16.c - Quickdev16 support for uCON64
  19. +
  20. +Copyright (c) 2009 david@optixx.org
  21. +
  22. +
  23. +This program is free software; you can redistribute it and/or modify
  24. +it under the terms of the GNU General Public License as published by
  25. +the Free Software Foundation; either version 2 of the License, or
  26. +(at your option) any later version.
  27. +
  28. +This program is distributed in the hope that it will be useful,
  29. +but WITHOUT ANY WARRANTY; without even the implied warranty of
  30. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  31. +GNU General Public License for more details.
  32. +
  33. +You should have received a copy of the GNU General Public License
  34. +along with this program; if not, write to the Free Software
  35. +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  36. +*/
  37. +#ifdef HAVE_CONFIG_H
  38. +#include "config.h"
  39. +#endif
  40. +#include <stdio.h>
  41. +#include <stdlib.h>
  42. +#include <time.h>
  43. +#include <string.h>
  44. +#include <usb.h>
  45. +#include "misc/misc.h"
  46. +#include "misc/itypes.h"
  47. +#ifdef USE_ZLIB
  48. +#include "misc/archive.h"
  49. +#endif
  50. +#include "misc/getopt2.h" // st_getopt2_t
  51. +#include "misc/file.h"
  52. +#include "misc/opendevice.h"
  53. +
  54. +
  55. +#include "ucon64.h"
  56. +#include "ucon64_misc.h"
  57. +#include "ffe.h"
  58. +#include "smc.h"
  59. +#include "quickdev16.h"
  60. +
  61. +#include "console/snes.h"
  62. +
  63. +#define SNES_HEADER_LEN (sizeof (st_snes_header_t))
  64. +
  65. +const st_getopt2_t quickdev16_usage[] =
  66. + {
  67. + {
  68. + NULL, 0, 0, 0,
  69. + NULL, "Quickdev16"/* http://www.optixx.org */,
  70. + NULL
  71. + },
  72. +#ifdef USE_USB
  73. + {
  74. + "xquickdev16", 0, 0, UCON64_XSNESRAM, // send only
  75. + NULL, "send ROM (in FFE format) to Quickdev16",
  76. + &ucon64_wf[WF_OBJ_NES_DEFAULT_STOP_NO_SPLIT]
  77. + },
  78. +#endif
  79. + {NULL, 0, 0, 0, NULL, NULL, NULL}
  80. + };
  81. +
  82. +
  83. +#ifdef USE_USB
  84. +
  85. +#define READ_BUFFER_SIZE 8192
  86. +#define SEND_BUFFER_SIZE 128
  87. +#define SNES_HIROM_SHIFT 16
  88. +#define SNES_LOROM_SHIFT 15
  89. +
  90. +int
  91. +quickdev16_write_rom (const char *filename)
  92. +{
  93. + FILE *file;
  94. + int bytesread, bytessend, size;
  95. + time_t starttime;
  96. + usb_dev_handle *handle = NULL;
  97. + const unsigned char rawVid[2] = { USB_CFG_VENDOR_ID }, rawPid[2] = { USB_CFG_DEVICE_ID};
  98. + char vendor[] = { USB_CFG_VENDOR_NAME, 0 }, product[] = { USB_CFG_DEVICE_NAME, 0};
  99. + int cnt, vid, pid;
  100. + uint8_t *read_buffer;
  101. + uint32_t addr = 0;
  102. + uint16_t addr_lo = 0;
  103. + uint16_t addr_hi = 0;
  104. + uint16_t step = 0;
  105. + uint8_t bank = 0;
  106. + uint8_t bank_cnt = 0;
  107. + uint16_t bank_shift;
  108. + uint32_t bank_size;
  109. + uint32_t hirom = 0;
  110. + uint8_t byte = 0;
  111. + st_rominfo_t rominfo;
  112. +
  113. +
  114. + usb_init();
  115. + vid = rawVid[1] * 256 + rawVid[0];
  116. + pid = rawPid[1] * 256 + rawPid[0];
  117. + if (usbOpenDevice(&handle, vid, vendor, pid, product, NULL, NULL, NULL) != 0) {
  118. + fprintf(stderr,
  119. + "Could not find USB device \"%s\" with vid=0x%x pid=0x%x\n",
  120. + product, vid, pid);
  121. + exit(1);
  122. + }
  123. + printf("Open USB device \"%s\" with vid=0x%x pid=0x%x\n", product, vid,pid);
  124. +
  125. + if ((file = fopen (filename, "rb")) == NULL)
  126. + {
  127. + fprintf (stderr, ucon64_msg[OPEN_READ_ERROR], filename);
  128. + exit (1);
  129. + }
  130. +
  131. + if ((read_buffer = (unsigned char *) malloc (READ_BUFFER_SIZE)) == NULL)
  132. + {
  133. + fprintf (stderr, ucon64_msg[FILE_BUFFER_ERROR], READ_BUFFER_SIZE);
  134. + exit (1);
  135. + }
  136. +
  137. + snes_init (&rominfo);
  138. + printf(rominfo.misc);
  139. + printf("\n");
  140. +
  141. + if (UCON64_ISSET (ucon64.snes_hirom))
  142. + hirom = ucon64.snes_hirom ? 1 : 0;
  143. + else {
  144. + hirom = snes_get_snes_hirom ();
  145. + }
  146. +
  147. +
  148. +
  149. + if (hirom) {
  150. + bank_shift = SNES_HIROM_SHIFT;
  151. + bank_size = 1 << SNES_HIROM_SHIFT;
  152. + } else {
  153. + bank_shift = SNES_LOROM_SHIFT;
  154. + bank_size = 1 << SNES_LOROM_SHIFT;
  155. + }
  156. +
  157. +
  158. +
  159. + fseek (file, 0, SEEK_END);
  160. + size = ftell (file);
  161. + fseek (file, SMC_HEADER_LEN, SEEK_SET);
  162. + size -= SMC_HEADER_LEN;
  163. + bank_cnt = size / bank_size;
  164. +
  165. + printf ("Send: %d Bytes (%.4f Mb) Hirom: %s, Banks: %i\n", size, (float) size / MBIT, hirom ? "Yes" : "No", bank_cnt);
  166. + bytessend = 0;
  167. + printf ("Press q to abort\n\n");
  168. + starttime = time (NULL);
  169. +
  170. + cnt = usb_control_msg(handle,
  171. + USB_TYPE_VENDOR | USB_RECIP_DEVICE |
  172. + USB_ENDPOINT_OUT, USB_MODE_AVR, 0, 0, NULL,
  173. + 0, 5000);
  174. +
  175. + /* wait for the loader to depack */
  176. + usleep(500000);
  177. +
  178. +
  179. + cnt = usb_control_msg(handle,
  180. + USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT,
  181. + USB_BULK_UPLOAD_INIT, bank_shift , bank_cnt, NULL, 0, 5000);
  182. +
  183. +
  184. + while ((bytesread = fread(read_buffer, READ_BUFFER_SIZE, 1, file)) > 0) {
  185. + for (step = 0; step < READ_BUFFER_SIZE; step += SEND_BUFFER_SIZE) {
  186. +
  187. + addr_lo = addr & 0xffff;
  188. + addr_hi = (addr >> 16) & 0x00ff;
  189. +
  190. + if (addr == 0){
  191. + cnt = usb_control_msg(handle,
  192. + USB_TYPE_VENDOR | USB_RECIP_DEVICE |
  193. + USB_ENDPOINT_OUT, USB_BULK_UPLOAD_ADDR, addr_hi,
  194. + addr_lo, (char *) read_buffer + step,
  195. + SEND_BUFFER_SIZE, 5000);
  196. + } else {
  197. + cnt = usb_control_msg(handle,
  198. + USB_TYPE_VENDOR | USB_RECIP_DEVICE |
  199. + USB_ENDPOINT_OUT, USB_BULK_UPLOAD_NEXT, addr_hi,
  200. + addr_lo, (char *) read_buffer + step,
  201. + SEND_BUFFER_SIZE, 5000);
  202. + }
  203. + if (cnt < 0) {
  204. + fprintf(stderr, "USB error: %s\n", usb_strerror());
  205. + usb_close(handle);
  206. + exit(-1);
  207. + }
  208. +
  209. + bytessend += SEND_BUFFER_SIZE;
  210. + ucon64_gauge (starttime, bytessend, size);
  211. +
  212. + addr += SEND_BUFFER_SIZE;
  213. + if ( addr % bank_size == 0) {
  214. + bank++;
  215. + }
  216. + }
  217. + }
  218. + cnt = usb_control_msg(handle,
  219. + USB_TYPE_VENDOR | USB_RECIP_DEVICE |
  220. + USB_ENDPOINT_OUT, USB_BULK_UPLOAD_END, 0, 0, NULL,
  221. + 0, 5000);
  222. +
  223. +#if 0
  224. + bank = 0;
  225. + fseek(fp, 0, SEEK_SET);
  226. + while ((cnt = fread(read_buffer, READ_BUFFER_SIZE, 1, fp)) > 0) {
  227. + printf ("bank=0x%02x crc=0x%04x\n", bank++,
  228. + do_crc(read_buffer, READ_BUFFER_SIZE));
  229. + }
  230. + fclose(fp);
  231. +#endif
  232. + cnt = usb_control_msg(handle,
  233. + USB_TYPE_VENDOR | USB_RECIP_DEVICE |
  234. + USB_ENDPOINT_OUT, USB_MODE_SNES, 0, 0, NULL,
  235. + 0, 5000);
  236. +
  237. +
  238. + free (read_buffer);
  239. + fclose (file);
  240. + return 0;
  241. +}
  242. +
  243. +
  244. +#endif // USE_USB
  245. diff -Naur ucon64-2.0.0-src/src/backup/quickdev16.h ucon64/src/backup/quickdev16.h
  246. --- ucon64-2.0.0-src/src/backup/quickdev16.h 1970-01-01 00:00:00.000000000 +0000
  247. +++ ucon64/src/backup/quickdev16.h 2009-08-28 10:00:36.000000000 +0000
  248. @@ -0,0 +1,81 @@
  249. +/*
  250. +quickdev16.h - Quickdev16 support for uCON64
  251. +
  252. +Copyright (c) 2009 david@optixx.org
  253. +
  254. +
  255. +This program is free software; you can redistribute it and/or modify
  256. +it under the terms of the GNU General Public License as published by
  257. +the Free Software Foundation; either version 2 of the License, or
  258. +(at your option) any later version.
  259. +
  260. +This program is distributed in the hope that it will be useful,
  261. +but WITHOUT ANY WARRANTY; without even the implied warranty of
  262. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  263. +GNU General Public License for more details.
  264. +
  265. +You should have received a copy of the GNU General Public License
  266. +along with this program; if not, write to the Free Software
  267. +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  268. +*/
  269. +#ifndef SNESRAM_H
  270. +#define SNESRAM_H
  271. +
  272. +#define USB_UPLOAD_INIT 0
  273. +#define USB_UPLOAD_ADDR 1
  274. +
  275. +#define USB_DOWNLOAD_INIT 2
  276. +#define USB_DOWNLOAD_ADDR 3
  277. +
  278. +#define USB_CRC 4
  279. +#define USB_CRC_ADDR 5
  280. +
  281. +#define USB_BULK_UPLOAD_INIT 6
  282. +#define USB_BULK_UPLOAD_ADDR 7
  283. +#define USB_BULK_UPLOAD_NEXT 8
  284. +#define USB_BULK_UPLOAD_END 9
  285. +#define USB_MODE_SNES 10
  286. +#define USB_MODE_AVR 11
  287. +#define USB_AVR_RESET 12
  288. +
  289. +/* -------------------------- Device Description --------------------------- */
  290. +
  291. +#define USB_CFG_VENDOR_ID 0xc0, 0x16
  292. +/* USB vendor ID for the device, low byte first. If you have registered your
  293. + * own Vendor ID, define it here. Otherwise you use one of obdev's free shared
  294. + * VID/PID pairs. Be sure to read USBID-License.txt for rules!
  295. + */
  296. +#define USB_CFG_DEVICE_ID 0xdd, 0x05
  297. +/* This is the ID of the product, low byte first. It is interpreted in the
  298. + * scope of the vendor ID. If you have registered your own VID with usb.org
  299. + * or if you have licensed a PID from somebody else, define it here. Otherwise
  300. + * you use obdev's free shared VID/PID pair. Be sure to read the rules in
  301. + * USBID-License.txt!
  302. + */
  303. +#define USB_CFG_DEVICE_VERSION 0x00, 0x01
  304. +/* Version number of the device: Minor number first, then major number.
  305. + */
  306. +#define USB_CFG_VENDOR_NAME 'o', 'p', 't', 'i', 'x', 'x', '.', 'o', 'r', 'g'
  307. +#define USB_CFG_VENDOR_NAME_LEN 10
  308. +/* These two values define the vendor name returned by the USB device. The name
  309. + * must be given as a list of characters under single quotes. The characters
  310. + * are interpreted as Unicode (UTF-16) entities.
  311. + * If you don't want a vendor name string, undefine these macros.
  312. + * ALWAYS define a vendor name containing your Internet domain name if you use
  313. + * obdev's free shared VID/PID pair. See the file USBID-License.txt for
  314. + * details.
  315. + */
  316. +#define USB_CFG_DEVICE_NAME 'Q', 'U', 'I', 'C', 'K', 'D', 'E', 'V', '1', '6'
  317. +#define USB_CFG_DEVICE_NAME_LEN 10
  318. +/* Same as above for the device name. If you don't want a device name, undefine
  319. + * the macros. See the file USBID-License.txt before you assign a name if you
  320. + * use a shared VID/PID.
  321. + */
  322. +
  323. +extern const st_getopt2_t quickdev16_usage[];
  324. +
  325. +#ifdef USE_USB
  326. +extern int quickdev16_write_rom (const char *filename);
  327. +#endif
  328. +
  329. +#endif // SNESRAM_H
  330. diff -Naur ucon64-2.0.0-src/src/console/snes.c ucon64/src/console/snes.c
  331. --- ucon64-2.0.0-src/src/console/snes.c 2009-09-16 09:43:42.000000000 +0000
  332. +++ ucon64/src/console/snes.c 2009-08-28 10:00:36.000000000 +0000
  333. @@ -3261,6 +3261,7 @@
  334. snes_hirom = 0;
  335. if (UCON64_ISSET (ucon64.snes_hirom)) // see snes_set_hirom()
  336. snes_hirom = ucon64.snes_hirom;
  337. + //ucon64.snes_hirom = snes_hirom;
  338. snes_hirom_ok = 1;
  339. rominfo->interleaved = 0;
  340. diff -Naur ucon64-2.0.0-src/src/Makefile.in ucon64/src/Makefile.in
  341. --- ucon64-2.0.0-src/src/Makefile.in 2009-09-16 09:43:42.000000000 +0000
  342. +++ ucon64/src/Makefile.in 2009-08-28 10:00:36.000000000 +0000
  343. @@ -7,8 +7,8 @@
  344. @DEFINE_LIBCD64_MAKE@
  345. CC=@CC@
  346. -CFLAGS=-I. -Wall -W -O3 @DEFS@
  347. -LDFLAGS=-s
  348. +CFLAGS=-I. -Wall -W -O3 @DEFS@ -I/opt/local/include
  349. +LDFLAGS=-s -L/opt/local/lib
  350. TARGETS=
  351. ifdef USE_DISCMAGE
  352. @@ -96,7 +96,8 @@
  353. OBJECTS=ucon64.o ucon64_dat.o ucon64_misc.o ucon64_opts.o \
  354. misc/chksum.o misc/file.o misc/getopt.o misc/getopt2.o \
  355. misc/misc.o misc/parallel.o misc/property.o misc/string.o \
  356. - patch/aps.o patch/bsl.o patch/gg.o patch/ips.o patch/pal4u.o \
  357. + misc/opendevice.o \
  358. + patch/aps.o patch/bsl.o patch/gg.o patch/ips.o patch/pal4u.o \
  359. patch/ppf.o patch/xps.o \
  360. console/dc.o console/gb.o console/gba.o console/genesis.o \
  361. console/jaguar.o console/lynx.o console/n64.o console/neogeo.o \
  362. @@ -107,7 +108,7 @@
  363. backup/fig.o backup/gbx.o backup/gd.o backup/interceptor.o \
  364. backup/lynxit.o backup/mccl.o backup/mcd.o backup/md-pro.o \
  365. backup/mgd.o backup/msg.o backup/pce-pro.o backup/pl.o \
  366. - backup/psxpblib.o backup/sflash.o backup/smc.o backup/smd.o \
  367. + backup/psxpblib.o backup/sflash.o backup/quickdev16.o backup/smc.o backup/smd.o \
  368. backup/smsgg-pro.o backup/ssc.o backup/swc.o backup/tototek.o \
  369. backup/ufo.o backup/yoko.o backup/z64.o
  370. ifdef USE_ZLIB
  371. diff -Naur ucon64-2.0.0-src/src/misc/opendevice.c ucon64/src/misc/opendevice.c
  372. --- ucon64-2.0.0-src/src/misc/opendevice.c 1970-01-01 00:00:00.000000000 +0000
  373. +++ ucon64/src/misc/opendevice.c 2009-08-28 10:00:36.000000000 +0000
  374. @@ -0,0 +1,286 @@
  375. +/*
  376. + * Name: opendevice.c Project: V-USB host-side library Author: Christian
  377. + * Starkjohann Creation Date: 2008-04-10 Tabsize: 4 Copyright: (c) 2008 by
  378. + * OBJECTIVE DEVELOPMENT Software GmbH License: GNU GPL v2 (see License.txt),
  379. + * GNU GPL v3 or proprietary (CommercialLicense.txt) This Revision: $Id:
  380. + * opendevice.c 740 2009-04-13 18:23:31Z cs $
  381. + */
  382. +
  383. +/*
  384. + * General Description: The functions in this module can be used to find and
  385. + * open a device based on libusb or libusb-win32.
  386. + */
  387. +
  388. +
  389. +#include <stdio.h>
  390. +#include "opendevice.h"
  391. +
  392. +/*
  393. + * -------------------------------------------------------------------------
  394. + */
  395. +
  396. +#define MATCH_SUCCESS 1
  397. +#define MATCH_FAILED 0
  398. +#define MATCH_ABORT -1
  399. +
  400. +/*
  401. + * private interface: match text and p, return MATCH_SUCCESS, MATCH_FAILED, or
  402. + * MATCH_ABORT.
  403. + */
  404. +static int _shellStyleMatch(char *text, char *p)
  405. +{
  406. + int last,
  407. + matched,
  408. + reverse;
  409. +
  410. + for (; *p; text++, p++) {
  411. + if (*text == 0 && *p != '*')
  412. + return MATCH_ABORT;
  413. + switch (*p) {
  414. + case '\\':
  415. + /*
  416. + * Literal match with following character.
  417. + */
  418. + p++;
  419. + /*
  420. + * FALLTHROUGH
  421. + */
  422. + default:
  423. + if (*text != *p)
  424. + return MATCH_FAILED;
  425. + continue;
  426. + case '?':
  427. + /*
  428. + * Match anything.
  429. + */
  430. + continue;
  431. + case '*':
  432. + while (*++p == '*')
  433. + /*
  434. + * Consecutive stars act just like one.
  435. + */
  436. + continue;
  437. + if (*p == 0)
  438. + /*
  439. + * Trailing star matches everything.
  440. + */
  441. + return MATCH_SUCCESS;
  442. + while (*text)
  443. + if ((matched = _shellStyleMatch(text++, p)) != MATCH_FAILED)
  444. + return matched;
  445. + return MATCH_ABORT;
  446. + case '[':
  447. + reverse = p[1] == '^';
  448. + if (reverse) /* Inverted character class. */
  449. + p++;
  450. + matched = MATCH_FAILED;
  451. + if (p[1] == ']' || p[1] == '-')
  452. + if (*++p == *text)
  453. + matched = MATCH_SUCCESS;
  454. + for (last = *p; *++p && *p != ']'; last = *p)
  455. + if (*p == '-' && p[1] != ']' ? *text <= *++p
  456. + && *text >= last : *text == *p)
  457. + matched = MATCH_SUCCESS;
  458. + if (matched == reverse)
  459. + return MATCH_FAILED;
  460. + continue;
  461. + }
  462. + }
  463. + return *text == 0;
  464. +}
  465. +
  466. +/*
  467. + * public interface for shell style matching: returns 0 if fails, 1 if matches
  468. + */
  469. +static int shellStyleMatch(char *text, char *pattern)
  470. +{
  471. + if (pattern == NULL) /* NULL pattern is synonymous to "*" */
  472. + return 1;
  473. + return _shellStyleMatch(text, pattern) == MATCH_SUCCESS;
  474. +}
  475. +
  476. +/*
  477. + * -------------------------------------------------------------------------
  478. + */
  479. +
  480. +int usbGetStringAscii(usb_dev_handle * dev, int index, char *buf, int buflen)
  481. +{
  482. + char buffer[256];
  483. + int rval,
  484. + i;
  485. +
  486. + if ((rval = usb_get_string_simple(dev, index, buf, buflen)) >= 0) /* use
  487. + * libusb
  488. + * version
  489. + * if
  490. + * it
  491. + * works
  492. + */
  493. + return rval;
  494. + if ((rval =
  495. + usb_control_msg(dev, USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR,
  496. + (USB_DT_STRING << 8) + index, 0x0409, buffer,
  497. + sizeof(buffer), 5000)) < 0)
  498. + return rval;
  499. + if (buffer[1] != USB_DT_STRING) {
  500. + *buf = 0;
  501. + return 0;
  502. + }
  503. + if ((unsigned char) buffer[0] < rval)
  504. + rval = (unsigned char) buffer[0];
  505. + rval /= 2;
  506. + /*
  507. + * lossy conversion to ISO Latin1:
  508. + */
  509. + for (i = 1; i < rval; i++) {
  510. + if (i > buflen) /* destination buffer overflow */
  511. + break;
  512. + buf[i - 1] = buffer[2 * i];
  513. + if (buffer[2 * i + 1] != 0) /* outside of ISO Latin1 range */
  514. + buf[i - 1] = '?';
  515. + }
  516. + buf[i - 1] = 0;
  517. + return i - 1;
  518. +}
  519. +
  520. +/*
  521. + * -------------------------------------------------------------------------
  522. + */
  523. +
  524. +int usbOpenDevice(usb_dev_handle ** device, int vendorID,
  525. + char *vendorNamePattern, int productID,
  526. + char *productNamePattern, char *serialNamePattern,
  527. + FILE * printMatchingDevicesFp, FILE * warningsFp)
  528. +{
  529. + struct usb_bus *bus;
  530. + struct usb_device *dev;
  531. + usb_dev_handle *handle = NULL;
  532. + int errorCode = USBOPEN_ERR_NOTFOUND;
  533. +
  534. + usb_find_busses();
  535. + usb_find_devices();
  536. + for (bus = usb_get_busses(); bus; bus = bus->next) {
  537. + for (dev = bus->devices; dev; dev = dev->next) { /* iterate over
  538. + * all devices
  539. + * on all
  540. + * busses */
  541. + if ((vendorID == 0 || dev->descriptor.idVendor == vendorID)
  542. + && (productID == 0 || dev->descriptor.idProduct == productID)) {
  543. + char vendor[256],
  544. + product[256],
  545. + serial[256];
  546. + int len;
  547. + handle = usb_open(dev); /* we need to open the device in order
  548. + * to query strings */
  549. + if (!handle) {
  550. + errorCode = USBOPEN_ERR_ACCESS;
  551. + if (warningsFp != NULL)
  552. + fprintf(warningsFp,
  553. + "Warning: cannot open VID=0x%04x PID=0x%04x: %s\n",
  554. + dev->descriptor.idVendor,
  555. + dev->descriptor.idProduct, usb_strerror());
  556. + continue;
  557. + }
  558. + /*
  559. + * now check whether the names match:
  560. + */
  561. + len = vendor[0] = 0;
  562. + if (dev->descriptor.iManufacturer > 0) {
  563. + len =
  564. + usbGetStringAscii(handle, dev->descriptor.iManufacturer,
  565. + vendor, sizeof(vendor));
  566. + }
  567. + if (len < 0) {
  568. + errorCode = USBOPEN_ERR_ACCESS;
  569. + if (warningsFp != NULL)
  570. + fprintf(warningsFp,
  571. + "Warning: cannot query manufacturer for VID=0x%04x PID=0x%04x: %s\n",
  572. + dev->descriptor.idVendor,
  573. + dev->descriptor.idProduct, usb_strerror());
  574. + } else {
  575. + errorCode = USBOPEN_ERR_NOTFOUND;
  576. + /*
  577. + * printf("seen device from vendor ->%s<-\n", vendor);
  578. + */
  579. + if (shellStyleMatch(vendor, vendorNamePattern)) {
  580. + len = product[0] = 0;
  581. + if (dev->descriptor.iProduct > 0) {
  582. + len =
  583. + usbGetStringAscii(handle,
  584. + dev->descriptor.iProduct,
  585. + product, sizeof(product));
  586. + }
  587. + if (len < 0) {
  588. + errorCode = USBOPEN_ERR_ACCESS;
  589. + if (warningsFp != NULL)
  590. + fprintf(warningsFp,
  591. + "Warning: cannot query product for VID=0x%04x PID=0x%04x: %s\n",
  592. + dev->descriptor.idVendor,
  593. + dev->descriptor.idProduct,
  594. + usb_strerror());
  595. + } else {
  596. + errorCode = USBOPEN_ERR_NOTFOUND;
  597. + /*
  598. + * printf("seen product ->%s<-\n", product);
  599. + */
  600. + if (shellStyleMatch(product, productNamePattern)) {
  601. + len = serial[0] = 0;
  602. + if (dev->descriptor.iSerialNumber > 0) {
  603. + len =
  604. + usbGetStringAscii(handle,
  605. + dev->descriptor.
  606. + iSerialNumber, serial,
  607. + sizeof(serial));
  608. + }
  609. + if (len < 0) {
  610. + errorCode = USBOPEN_ERR_ACCESS;
  611. + if (warningsFp != NULL)
  612. + fprintf(warningsFp,
  613. + "Warning: cannot query serial for VID=0x%04x PID=0x%04x: %s\n",
  614. + dev->descriptor.idVendor,
  615. + dev->descriptor.idProduct,
  616. + usb_strerror());
  617. + }
  618. + if (shellStyleMatch(serial, serialNamePattern)) {
  619. + if (printMatchingDevicesFp != NULL) {
  620. + if (serial[0] == 0) {
  621. + fprintf(printMatchingDevicesFp,
  622. + "VID=0x%04x PID=0x%04x vendor=\"%s\" product=\"%s\"\n",
  623. + dev->descriptor.idVendor,
  624. + dev->descriptor.idProduct,
  625. + vendor, product);
  626. + } else {
  627. + fprintf(printMatchingDevicesFp,
  628. + "VID=0x%04x PID=0x%04x vendor=\"%s\" product=\"%s\" serial=\"%s\"\n",
  629. + dev->descriptor.idVendor,
  630. + dev->descriptor.idProduct,
  631. + vendor, product, serial);
  632. + }
  633. + } else {
  634. + break;
  635. + }
  636. + }
  637. + }
  638. + }
  639. + }
  640. + }
  641. + usb_close(handle);
  642. + handle = NULL;
  643. + }
  644. + }
  645. + if (handle) /* we have found a deice */
  646. + break;
  647. + }
  648. + if (handle != NULL) {
  649. + errorCode = 0;
  650. + *device = handle;
  651. + }
  652. + if (printMatchingDevicesFp != NULL) /* never return an error for listing
  653. + * only */
  654. + errorCode = 0;
  655. + return errorCode;
  656. +}
  657. +
  658. +/*
  659. + * -------------------------------------------------------------------------
  660. + */
  661. diff -Naur ucon64-2.0.0-src/src/misc/opendevice.h ucon64/src/misc/opendevice.h
  662. --- ucon64-2.0.0-src/src/misc/opendevice.h 1970-01-01 00:00:00.000000000 +0000
  663. +++ ucon64/src/misc/opendevice.h 2009-08-28 10:00:36.000000000 +0000
  664. @@ -0,0 +1,77 @@
  665. +/* Name: opendevice.h
  666. + * Project: V-USB host-side library
  667. + * Author: Christian Starkjohann
  668. + * Creation Date: 2008-04-10
  669. + * Tabsize: 4
  670. + * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
  671. + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
  672. + * This Revision: $Id: opendevice.h 740 2009-04-13 18:23:31Z cs $
  673. + */
  674. +
  675. +/*
  676. +General Description:
  677. +This module offers additional functionality for host side drivers based on
  678. +libusb or libusb-win32. It includes a function to find and open a device
  679. +based on numeric IDs and textual description. It also includes a function to
  680. +obtain textual descriptions from a device.
  681. +
  682. +To use this functionality, simply copy opendevice.c and opendevice.h into your
  683. +project and add them to your Makefile. You may modify and redistribute these
  684. +files according to the GNU General Public License (GPL) version 2 or 3.
  685. +*/
  686. +
  687. +#ifndef __OPENDEVICE_H_INCLUDED__
  688. +#define __OPENDEVICE_H_INCLUDED__
  689. +
  690. +#include <usb.h> /* this is libusb, see http://libusb.sourceforge.net/ */
  691. +#include <stdio.h>
  692. +
  693. +int usbGetStringAscii(usb_dev_handle *dev, int index, char *buf, int buflen);
  694. +/* This function gets a string descriptor from the device. 'index' is the
  695. + * string descriptor index. The string is returned in ISO Latin 1 encoding in
  696. + * 'buf' and it is terminated with a 0-character. The buffer size must be
  697. + * passed in 'buflen' to prevent buffer overflows. A libusb device handle
  698. + * must be given in 'dev'.
  699. + * Returns: The length of the string (excluding the terminating 0) or
  700. + * a negative number in case of an error. If there was an error, use
  701. + * usb_strerror() to obtain the error message.
  702. + */
  703. +
  704. +int usbOpenDevice(usb_dev_handle **device, int vendorID, char *vendorNamePattern, int productID, char *productNamePattern, char *serialNamePattern, FILE *printMatchingDevicesFp, FILE *warningsFp);
  705. +/* This function iterates over all devices on all USB busses and searches for
  706. + * a device. Matching is done first by means of Vendor- and Product-ID (passed
  707. + * in 'vendorID' and 'productID'. An ID of 0 matches any numeric ID (wildcard).
  708. + * When a device matches by its IDs, matching by names is performed. Name
  709. + * matching can be done on textual vendor name ('vendorNamePattern'), product
  710. + * name ('productNamePattern') and serial number ('serialNamePattern'). A
  711. + * device matches only if all non-null pattern match. If you don't care about
  712. + * a string, pass NULL for the pattern. Patterns are Unix shell style pattern:
  713. + * '*' stands for 0 or more characters, '?' for one single character, a list
  714. + * of characters in square brackets for a single character from the list
  715. + * (dashes are allowed to specify a range) and if the lis of characters begins
  716. + * with a caret ('^'), it matches one character which is NOT in the list.
  717. + * Other parameters to the function: If 'warningsFp' is not NULL, warning
  718. + * messages are printed to this file descriptor with fprintf(). If
  719. + * 'printMatchingDevicesFp' is not NULL, no device is opened but matching
  720. + * devices are printed to the given file descriptor with fprintf().
  721. + * If a device is opened, the resulting USB handle is stored in '*device'. A
  722. + * pointer to a "usb_dev_handle *" type variable must be passed here.
  723. + * Returns: 0 on success, an error code (see defines below) on failure.
  724. + */
  725. +
  726. +/* usbOpenDevice() error codes: */
  727. +#define USBOPEN_SUCCESS 0 /* no error */
  728. +#define USBOPEN_ERR_ACCESS 1 /* not enough permissions to open device */
  729. +#define USBOPEN_ERR_IO 2 /* I/O error */
  730. +#define USBOPEN_ERR_NOTFOUND 3 /* device not found */
  731. +
  732. +
  733. +/* Obdev's free USB IDs, see USBID-License.txt for details */
  734. +
  735. +#define USB_VID_OBDEV_SHARED 5824 /* obdev's shared vendor ID */
  736. +#define USB_PID_OBDEV_SHARED_CUSTOM 1500 /* shared PID for custom class devices */
  737. +#define USB_PID_OBDEV_SHARED_HID 1503 /* shared PID for HIDs except mice & keyboards */
  738. +#define USB_PID_OBDEV_SHARED_CDCACM 1505 /* shared PID for CDC Modem devices */
  739. +#define USB_PID_OBDEV_SHARED_MIDI 1508 /* shared PID for MIDI class devices */
  740. +
  741. +#endif /* __OPENDEVICE_H_INCLUDED__ */
  742. diff -Naur ucon64-2.0.0-src/src/ucon64.c ucon64/src/ucon64.c
  743. --- ucon64-2.0.0-src/src/ucon64.c 2009-09-16 09:43:42.000000000 +0000
  744. +++ ucon64/src/ucon64.c 2009-08-28 10:00:36.000000000 +0000
  745. @@ -171,6 +171,9 @@
  746. sflash_usage,
  747. // mgd_usage,
  748. #endif
  749. +#ifdef USE_USB
  750. + quickdev16_usage,
  751. +#endif
  752. lf,
  753. neogeo_usage,
  754. lf,
  755. diff -Naur ucon64-2.0.0-src/src/ucon64_defines.h ucon64/src/ucon64_defines.h
  756. --- ucon64-2.0.0-src/src/ucon64_defines.h 2009-09-16 09:43:42.000000000 +0000
  757. +++ ucon64/src/ucon64_defines.h 2009-08-28 10:00:36.000000000 +0000
  758. @@ -326,6 +326,7 @@
  759. UCON64_XSMCR,
  760. UCON64_XSMD,
  761. UCON64_XSMDS,
  762. + UCON64_XSNESRAM,
  763. UCON64_XSWC,
  764. UCON64_XSWC2,
  765. UCON64_XSWC_IO,
  766. diff -Naur ucon64-2.0.0-src/src/ucon64_opts.c ucon64/src/ucon64_opts.c
  767. --- ucon64-2.0.0-src/src/ucon64_opts.c 2009-09-16 09:43:42.000000000 +0000
  768. +++ ucon64/src/ucon64_opts.c 2009-08-28 10:00:36.000000000 +0000
  769. @@ -310,6 +310,7 @@
  770. case UCON64_XSMCR:
  771. case UCON64_XSMD:
  772. case UCON64_XSMDS:
  773. + case UCON64_XSNESRAM:
  774. case UCON64_XSWC:
  775. case UCON64_XSWC2:
  776. case UCON64_XSWCR:
  777. @@ -558,7 +559,7 @@
  778. break;
  779. case UCON64_Q:
  780. - case UCON64_QQ: // for now -qq is equivalent to -q
  781. + case UCON64_QQ: //UCON64_XSMC for now -qq is equivalent to -q
  782. ucon64.quiet = 1;
  783. break;
  784. @@ -2050,6 +2051,7 @@
  785. smc_write_rts (ucon64.rom, ucon64.parport);
  786. fputc ('\n', stdout);
  787. break;
  788. +
  789. case UCON64_XSMD:
  790. if (access (ucon64.rom, F_OK) != 0) // file does not exist -> dump cartridge
  791. @@ -2077,6 +2079,15 @@
  792. fputc ('\n', stdout);
  793. break;
  794. + case UCON64_XSNESRAM:
  795. + if (!ucon64.rominfo->buheader_len)
  796. + fputs ("ERROR: This ROM has no header. Convert to an SMC compatible format with -ffe\n",
  797. + stderr);
  798. + else
  799. + quickdev16_write_rom (ucon64.rom);
  800. + fputc ('\n', stdout);
  801. + break;
  802. +
  803. case UCON64_XSWC:
  804. enableRTS = 0; // falling through
  805. case UCON64_XSWC2: