unagi.o header.o crc32.o \
script_engine.o script_syntax.o \
reader_master.o \
- reader_onajimi.o reader_hongkongfc.o reader_dozeu.o \
- waveform_dozeu.o cusb.o \
+ reader_onajimi.o reader_hongkongfc.o reader_kazzo.o \
flashmemory.o \
- file.o textutil.o giveio.o unagi.res.o
+ file.o textutil.o giveio.o usb_device.o unagi.res.o
TARGET = unagi.exe
CC = gcc
-CFLAGS = -Wall -Werror -Wmissing-declarations -I.. -I$(EZUSBDRV)
+CFLAGS += -Wall -Werror -Wmissing-declarations -I..
+#CFLAGS += -I$(EZUSBDRV)
#include "type.h"
#include "header.h"
#include "flashmemory.h"
-/*
-JEDEC flash memory command
-http://www.sst.com/downloads/software_driver/SST49LF002A.txt
-*/
-struct flash_task{
- long address, data;
-};
-enum{
- ADDRESS_0000 = 0,
- ADDRESS_2AAA = 0x2aaa,
- ADDRESS_5555 = 0x5555,
- FLASH_COMMAND_END
-};
-static const struct flash_task PRODUCTID_ENTRY[] = {
- {ADDRESS_5555, 0xaa},
- {ADDRESS_2AAA, 0x55},
- {ADDRESS_5555, 0x90},
- {FLASH_COMMAND_END, 0}
-};
-static const struct flash_task PRODUCTID_EXIT[] = {
- {ADDRESS_5555, 0xaa},
- {ADDRESS_2AAA, 0x55},
- {ADDRESS_5555, 0xf0},
- {FLASH_COMMAND_END, 0}
-};
-static const struct flash_task PROTECT_DISABLE[] = {
- {ADDRESS_5555, 0xaa},
- {ADDRESS_2AAA, 0x55},
- {ADDRESS_5555, 0xa0},
- {FLASH_COMMAND_END, 0}
-};
-static const struct flash_task PROTECT_ENABLE[] = {
- {ADDRESS_5555, 0xaa},
- {ADDRESS_2AAA, 0x55},
- {ADDRESS_5555, 0x80},
- {ADDRESS_5555, 0xaa},
- {ADDRESS_2AAA, 0x55},
- {ADDRESS_5555, 0x20},
- {FLASH_COMMAND_END, 0}
-};
-static const struct flash_task ERASE_CHIP[] = {
- {ADDRESS_5555, 0xaa},
- {ADDRESS_2AAA, 0x55},
- {ADDRESS_5555, 0x80},
- {ADDRESS_5555, 0xaa},
- {ADDRESS_2AAA, 0x55},
- {ADDRESS_5555, 0x10},
- {FLASH_COMMAND_END, 0}
-};
-
-static const struct flash_task ERASE_SECTOR[] = {
- {ADDRESS_5555, 0xaa},
- {ADDRESS_2AAA, 0x55},
- {ADDRESS_5555, 0x80},
- {ADDRESS_5555, 0xaa},
- {ADDRESS_2AAA, 0x55},
- //¤³¤Î¤¢¤È sectoraddress ¤Ë 0x30 ¤ò write
- {FLASH_COMMAND_END, 0}
-};
-
-static const struct flash_task PP[] = {
- {ADDRESS_5555, 0xaa},
- {ADDRESS_2AAA, 0x55},
- {ADDRESS_5555, 0x80},
- {ADDRESS_5555, 0xaa},
- {ADDRESS_2AAA, 0x55},
- {ADDRESS_5555, 0x60},
- {FLASH_COMMAND_END, 0}
-};
-
-static void command_set(const struct flash_order *d, const struct flash_task *t)
-{
- while(t->address != FLASH_COMMAND_END){
- long logical_address = 0;
- switch(t->address){
- case ADDRESS_0000: //bank ¤Ë¤è¤Ã¤Æ¤ÏÀßÄê¤Ç¤¤Ê¤¤¤«¤â?
- logical_address = d->command_0000;
- break;
- case ADDRESS_2AAA:
- logical_address = d->command_2aaa;
- break;
- case ADDRESS_5555:
- logical_address = d->command_5555;
- break;
- default:
- assert(0); //unknown task address
- }
- d->flash_write(logical_address, t->data);
- t++;
- }
-}
/*
----- product ID check ----
-*/
-#define dprintf if(DEBUG==1) printf
-static int productid_check(const struct flash_order *d, const struct flash_driver *f)
-{
- u8 data[3];
- command_set(d, PRODUCTID_ENTRY);
- d->read(d->command_0000, 3, data);
- command_set(d, PRODUCTID_EXIT);
- if(f->id_manufacurer != data[0]){
- return NG;
- }
- if(f->id_device != data[1]){
- return NG;
- }
- return OK;
-}
-
-static int productid_sram(const struct flash_order *d, const struct flash_driver *f)
-{
- return OK;
-}
-/*
----- toggle check ----
-databit6
-*/
-const int CHECK_RETRY_MAX = 0x10000;
-static int toggle_check_d6(const struct flash_order *d, long address)
-{
- u8 predata;
- int retry = 0;
- d->read(address, 1, &predata); //read DQ6
- predata &= 0x40;
- while(retry < CHECK_RETRY_MAX){
- u8 data;
- d->read(address, 1, &data); //read DQ6 again
- data &= 0x40;
- if(predata == data){
- return OK;
- }
- predata = data;
- retry++;
- }
- return NG;
-}
-
-static int toggle_check_d2d5d6(const struct flash_order *d, long address)
-{
- u8 predata;
- int retry = 0;
- d->read(address, 1, &predata);
- predata &= 0x40;
- do{
- u8 data;
- d->read(address, 1, &data);
- //DQ6 toggle check
- if(predata == (data & 0x40)){
- return OK;
- }
- //DQ5 == 0 ¤Ê¤é¤ä¤ê¤Ê¤ª¤·
- if(data & 0x20){
- //recheck toggle bit, read twice
- u8 t[2];
- d->read(address, 1, &t[0]);
- d->read(address, 1, &t[1]);
- if((t[0] & 0x40) == (t[1] & 0x40)){
- return OK;
- }
- //Program/Erase operation not complete, write reset command.
- return NG;
- }
- if((retry & 0x0f) == 0){
- dprintf("toggle out %06x \n", (int) address);
- }
- retry++;
- }while(retry < CHECK_RETRY_MAX);
- return NG;
-}
-
-/*
----- polling check ----
-databit7
-*/
-static int polling_check_d7(const struct flash_order *d, long address, u8 truedata)
-{
- int retry = 0;
-
- truedata &= 0x80;
- while(retry < CHECK_RETRY_MAX){
- u8 data;
- d->read(address, 1, &data);
- data &= 0x80;
- if(truedata == data){
- return OK;
- }
- retry++;
- }
- return NG;
-}
-
-static int polling_check_d5d7(const struct flash_order *d, long address, u8 truedata)
-{
- int retry = 0;
-
- truedata &= 0x80;
- do{
- u8 data;
- d->read(address, 1, &data);
- if(truedata == (data & 0x80)){
- return OK;
- }
- if(data & 0x20){
- d->read(address, 1, &data);
- if(truedata == (data & 0x80)){
- return OK;
- }
- dprintf("%s error", __FUNCTION__);
- return NG;
- }
- retry++;
- }while(retry < CHECK_RETRY_MAX);
- return NG;
-}
-/*
---- erase ----
*/
-static void flash_erase_chip_2aaa(const struct flash_order *d)
-{
- command_set(d, ERASE_CHIP);
- toggle_check_d6(d, d->command_2aaa);
- Sleep(d->erase_wait);
-}
-
-static void flash_erase_chip_02aa(const struct flash_order *d)
-{
- u8 data;
- d->read(d->command_2aaa, 1, &data);
- command_set(d, ERASE_CHIP);
- if(0){
- toggle_check_d2d5d6(d, d->command_2aaa);
-
- }else{
- polling_check_d5d7(d, d->command_2aaa, data);
- }
- Sleep(d->erase_wait);
-}
-
#if DEBUG==1
static void sram_erase(const struct flash_order *d)
{
}
#endif
-/*
----- program ----
-*/
-static int program_byte(const struct flash_order *d, long address, const u8 *data, long length)
-{
- while(length != 0){
- if(*data != 0xff){
- fflush(stdout);
- command_set(d, PROTECT_DISABLE);
- d->flash_write(address, *data);
- if(toggle_check_d6(d, address) == NG){
- dprintf("%s NG\n", __FUNCTION__);
- return NG;
- }
- /*if(polling_check_d7(d, address, *data) == NG){
- dprintf("%s NG\n", __FUNCTION__);
- return NG;
- }*/
- }
- address++;
- data++;
- length--;
- }
- return OK;
-}
-
-static int program_pagewrite(const struct flash_order *d, long address, const u8 *data, long length)
+static void init_nop(const struct flash_order *d)
{
- const long toggle_address = address ;
- command_set(d, PROTECT_DISABLE);
- while(length != 0){
- d->flash_write(address, *data);
- address++;
- data++;
- length--;
- }
- int ret = toggle_check_d6(d, toggle_address);
- if(0){
- data--;
- polling_check_d7(d, address - 1, *data);
- }
-
- return ret;
}
-/*
-¸ÇͥǥХ¤¥¹¥É¥é¥¤¥Ð
-*/
-static void w49f002_init(const struct flash_order *d)
+static void init_erase(const struct flash_order *d)
{
-/*
-byte program mode ¤Ç¤Ï 1->0 ¤Ë¤¹¤ë¤À¤±¡£ 0->1 ¤Ï erase ¤Î¤ß¡£
-¤è¤Ã¤Æ½é´ü²½»þ¤Ë¤Ï erase ¤ò¼Â¹Ô¤¹¤ë
-*/
- flash_erase_chip_2aaa(d);
+ assert(d->pagesize > 0);
+ d->erase(d->command_2aaa);
}
-static void w49f002_write(const struct flash_order *d, long address, long length, const struct memory *m)
+static void program_dummy(const struct flash_order *d, long address, long length, const struct memory *m)
{
- program_byte(d, address, m->data, length);
-// dprintf("write %s 0x%06x done\n", m->name, (int) m->offset);
}
-
-static void am29f040_init(const struct flash_order *d)
+static void program_sram(const struct flash_order *d, long address, long length, const struct memory *m)
{
- flash_erase_chip_02aa(d);
+ d->write(address, length, m->data);
}
-
-static void am29f040_write(const struct flash_order *d, long address, long length, const struct memory *m)
+static void program_flash(const struct flash_order *d, long address, long length, const struct memory *m)
{
- const u8 *data;
- data = m->data;
- while(length != 0){
- if(*data != 0xff){
- command_set(d, PROTECT_DISABLE);
- d->flash_write(address, *data);
- if(toggle_check_d2d5d6(d, address) == NG){
- dprintf("%s NG\n", __FUNCTION__);
- return;
- }
- }
- address++;
- data++;
- length--;
- }
+ d->program(address, length, m->data);
}
-
-static void init_nop(const struct flash_order *d)
-{
-/*
-page write mode ¤Ç¤Ï¤È¤¯¤Ë¤Ê¤·
-*/
-}
-
-static void w29c040_write(const struct flash_order *d, long address, long length, const struct memory *m)
-{
- u8 *cmp;
- int ngblock = 0;
- int retry = 0;
- assert(d->pagesize != 0);
- cmp = malloc(d->pagesize);
- do{
- long a = address;
- long i = length;
- long offset = m->offset;
- const u8 *dd;
-
- dd = m->data;
- ngblock = 0;
- while(i != 0){
- d->read(a, d->pagesize, cmp);
- if(memcmp(cmp, dd, d->pagesize) != 0){
- ngblock++;
- //dprintf("write %s 0x%06x\n", m->name, (int) offset);
- int result = program_pagewrite(d, a, dd, d->pagesize);
- if(result == NG){
- printf("%s: write error\n", __FUNCTION__);
- free(cmp);
- return;
- }
- }
- a += d->pagesize;
- dd += d->pagesize;
- offset += d->pagesize;
- i -= d->pagesize;
- }
- dprintf("%s 0x%06x, ngblock %d\n", m->name, (int) m->offset, ngblock);
- /* mmc5 test
- if(retry >= 3 && ngblock >= 16){
- dprintf("skip\n");
- break;
- }*/
- if(retry > 80){
- dprintf("skip\n");
- break;
- }
- retry++;
- fflush(stdout);
- }while(ngblock != 0);
-
- free(cmp);
-}
-
-static void sram_write(const struct flash_order *d, long address, long length, const struct memory *m)
-{
- const u8 *data;
- data = m->data;
- while(length != 0){
- d->flash_write(address, *data);
- address++;
- data++;
- length--;
- }
-}
-
-static void dummy_write(const struct flash_order *d, long address, long length, const struct memory *m)
-{
-}
-
/*
¥Ç¥Ð¥¤¥¹¥ê¥¹¥È
*/
enum{MEGA = 0x20000};
+const struct flash_driver FLASH_DRIVER_UNDEF = {
+ .name = "undefined",
+ .capacity = 0,
+ .pagesize = 1,
+ .erase_wait = 0,
+ .command_mask = 0,
+ .id_manufacurer = 0,
+ .id_device = 0,
+ .productid_check = NULL,
+ .init = NULL,
+ .program = NULL
+};
static const struct flash_driver DRIVER_SRAM = {
.name = "SRAM",
.capacity = 4 * MEGA,
- .pagesize = 0,
+ .pagesize = 1,
.erase_wait = 0,
.command_mask = 0,
.id_manufacurer = FLASH_ID_DEVICE_SRAM,
.id_device = FLASH_ID_DEVICE_SRAM,
- .productid_check = productid_sram,
-#if DEBUG==1
- .erase = sram_erase,
-#endif
+// .productid_check = productid_sram,
.init = init_nop,
- .write = sram_write
+ .program = program_sram
};
static const struct flash_driver DRIVER_DUMMY = {
.name = "dummy",
.capacity = 16 * MEGA,
- .pagesize = 0,
+ .pagesize = 1,
.erase_wait = 0,
.command_mask = 0,
.id_manufacurer = FLASH_ID_DEVICE_DUMMY,
.id_device = FLASH_ID_DEVICE_DUMMY,
- .productid_check = productid_sram,
-#if DEBUG==1
- .erase = init_nop,
-#endif
+// .productid_check = productid_sram,
.init = init_nop,
- .write = dummy_write
+ .program = program_dummy
};
static const struct flash_driver DRIVER_W29C020 = {
.command_mask = 0x7fff,
.id_manufacurer = 0xda,
.id_device = 0x45,
- .productid_check = productid_check,
-#if DEBUG==1
- .erase = flash_erase_chip_2aaa,
-#endif
+// .productid_check = productid_check,
.init = init_nop,
- .write = w29c040_write
+ .program = program_flash
};
static const struct flash_driver DRIVER_W29C040 = {
.command_mask = 0x7fff,
.id_manufacurer = 0xda,
.id_device = 0x46,
- .productid_check = productid_check,
-#if DEBUG==1
- .erase = flash_erase_chip_2aaa,
-#endif
+// .productid_check = productid_check,
.init = init_nop,
- .write = w29c040_write
+ .program = program_flash
};
static const struct flash_driver DRIVER_W49F002 = {
.name = "W49F002",
.capacity = 2 * MEGA,
- .pagesize = 0,
- .erase_wait = 1000, //typ 0.1, max 0.2 sec
+ .pagesize = 1,
+ .erase_wait = 100, //typ 0.1, max 0.2 sec
.command_mask = 0x7fff,
.id_manufacurer = 0xda,
.id_device = 0xae,
- .productid_check = productid_check,
-#if DEBUG==1
- .erase = flash_erase_chip_2aaa,
-#endif
- .init = w49f002_init,
- .write = w49f002_write
+// .productid_check = productid_check,
+ .init = init_erase,
+ .program = program_flash
};
/*
static const struct flash_driver DRIVER_EN29F002T = {
.name = "EN29F002T",
.capacity = 2 * MEGA,
- .pagesize = 0,
- .erase_wait = 3000, //typ 2, max 5 sec
+ .pagesize = 1,
+ .erase_wait = 2000, //typ 2, max 5 sec
.command_mask = 0x07ff,
.id_manufacurer = 0x1c,
.id_device = 0x92,
- .productid_check = productid_check,
-#if DEBUG==1
- .erase = flash_erase_chip_02aa,
-#endif
- .init = am29f040_init,
- .write = am29f040_write
+// .productid_check = productid_check,
+ .init = init_erase,
+ .program = program_flash
};
static const struct flash_driver DRIVER_AM29F040B = {
.name = "AM29F040B",
.capacity = 4 * MEGA,
- .pagesize = 0,
+ .pagesize = 1,
.erase_wait = 8000, //typ 8, max 64 sec
.command_mask = 0x07ff,
.id_manufacurer = 0x01,
.id_device = 0xa4,
- .productid_check = productid_check,
-#if DEBUG==1
- .erase = flash_erase_chip_02aa,
-#endif
- .init = am29f040_init,
- .write = am29f040_write
+// .productid_check = productid_check,
+ .init = init_erase,
+ .program = program_flash
+};
+
+static const struct flash_driver DRIVER_MBM29F080A = {
+ .name = "MBM29F080A",
+ .capacity = 8 * MEGA,
+ .pagesize = 1,
+ .erase_wait = 8000, //chip erase time is not written in datasheet!!
+ .command_mask = 0x07ff,
+ .id_manufacurer = 0x04,
+ .id_device = 0xd5,
+// .productid_check = productid_check,
+ .init = init_erase,
+ .program = program_flash
};
static const struct flash_driver *DRIVER_LIST[] = {
&DRIVER_W29C020, &DRIVER_W29C040,
- &DRIVER_W49F002, &DRIVER_EN29F002T, &DRIVER_AM29F040B,
+ &DRIVER_W49F002, &DRIVER_EN29F002T, &DRIVER_AM29F040B, &DRIVER_MBM29F080A,
&DRIVER_SRAM,
&DRIVER_DUMMY,
NULL
long command_0000, command_2aaa, command_5555;
long command_mask;
long pagesize;
- long erase_wait;
//struct reader_driver ¤Î´Ø¿ô¥Ý¥¤¥ó¥¿¤òÅϤ¹¾ì½ê
- void (*flash_write)(long address, long data);
- void (*read)(long address, long length, u8 *data);
+ void (*config)(long c2aaa, long c5555, long unit);
+ void (*erase)(long address);
+ void (*write)(long address, long length, u8 *data);
+ void (*program)(long address, long length, u8 *data);
};
struct memory;
const char *name;
long capacity, pagesize;
long command_mask;
- long erase_wait; //ñ°Ì msec
+ long erase_wait; //unit is msec
u8 id_manufacurer, id_device;
int (*productid_check)(const struct flash_order *d, const struct flash_driver *f);
-#if DEBUG==1
- void (*erase)(const struct flash_order *d);
-#endif
void (*init)(const struct flash_order *d);
- void (*write)(const struct flash_order *d, long address, long length, const struct memory *m);
+ void (*program)(const struct flash_order *d, long address, long length, const struct memory *m);
};
-
+const struct flash_driver FLASH_DRIVER_UNDEF;
const struct flash_driver *flash_driver_get(const char *name);
//0x80 °Ê¹ß¤ÏËÜÅö¤Î¥Ç¥Ð¥¤¥¹½ÅÊ£¤·¤Ê¤¤¤È»×¤¦. 狼 JEDEC ¤Î¤È¤³¤ò¤·¤é¤Ù¤Æ.
data_port_latch(DATA_SELECT_A15toA8, address >> 8);
}
-static void hk_cpu_6502_write(long address, long data, long wait_msec)
+static void hk_cpu_write_6502(long address, long data, long wait_msec)
{
int c = BUS_CONTROL_BUS_STANDBY;
//Á´¤Æ¤Î¥Ð¥¹¤ò»ß¤á¤ë
data_port_latch(DATA_SELECT_CONTROL, BUS_CONTROL_BUS_STANDBY);
}
+#if 0
static const int FLASH_CPU_WRITE = (
(1 << BITNUM_PPU_OUTPUT) |
(1 << BITNUM_PPU_RW) |
//CS up
cpu_romcs_set(address | ADDRESS_MASK_A15);
}
+#endif
const struct reader_driver DRIVER_HONGKONGFC = {
.name = "hongkongfc",
.init = hk_init,
.cpu_read = hk_cpu_read,
.ppu_read = hk_ppu_read,
- .cpu_6502_write = hk_cpu_6502_write,
+ .cpu_write_6502 = hk_cpu_write_6502,
.ppu_write = hk_ppu_write,
- .cpu_flash_write = hk_cpu_flash_write
+ .flash_support = NG,
+ .cpu_flash_config = NULL, .cpu_flash_erase = NULL, .cpu_flash_program = NULL,
+ .ppu_flash_config = NULL, .ppu_flash_erase = NULL, .ppu_flash_program = NULL
};
#ifdef TEST
--- /dev/null
+#include <assert.h>
+#include <usb.h>
+#include "reader_master.h"
+#include "usb_device.h"
+#include "../kazzo/request.h"
+#include "../kazzo/usbconfig.h"
+#include "reader_kazzo.h"
+
+static usb_dev_handle *device_open(void)
+{
+ usb_dev_handle *handle = NULL;
+ const unsigned char rawVid[2] = {USB_CFG_VENDOR_ID};
+ const unsigned char rawPid[2] = {USB_CFG_DEVICE_ID};
+ char vendor[] = {USB_CFG_VENDOR_NAME, 0};
+ char product[] = {USB_CFG_DEVICE_NAME, 0};
+ int vid, pid;
+
+ /* compute VID/PID from usbconfig.h so that there is a central source of information */
+ vid = (rawVid[1] << 8) | rawVid[0];
+ pid = (rawPid[1] << 8) | rawPid[0];
+
+ if(usbOpenDevice(&handle, vid, vendor, pid, product, NULL, NULL, NULL) == 0){
+ return handle;
+ }
+ fprintf(stderr, "Could not find USB device \"%s\" with vid=0x%x pid=0x%x\n", product, vid, pid);
+ return NULL;
+}
+static usb_dev_handle *handle = NULL;
+static int kazzo_open_close(enum reader_control oc)
+{
+ switch(oc){
+ case READER_OPEN:
+ handle = device_open();
+ return handle == NULL ? NG : OK;
+ case READER_CLOSE:
+ usb_close(handle);
+ handle = NULL;
+ return OK;
+ }
+ return NG;
+}
+static void kazzo_init(void)
+{
+ //no operation
+}
+enum{
+ TIMEOUT = 4000
+};
+//-------- read sequence --------
+static void device_read(usb_dev_handle *handle, enum request r, long address, long length, u8 *data)
+{
+ int cnt = usb_control_msg(
+ handle,
+ USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN,
+ r, address,
+ 0, data, length, TIMEOUT
+ );
+ assert(cnt == length);
+}
+static void read_main(const enum request r, long address, long length, u8 *data)
+{
+ while(length >= READ_PACKET_SIZE){
+ device_read(handle, r, address, READ_PACKET_SIZE, data);
+ data += READ_PACKET_SIZE;
+ address += READ_PACKET_SIZE;
+ length -= READ_PACKET_SIZE;
+ }
+ if(length != 0){
+ device_read(handle, r, address, length, data);
+ }
+}
+static void kazzo_cpu_read(long address, long length, u8 *data)
+{
+ read_main(REQUEST_CPU_READ, address, length, data);
+}
+static void kazzo_ppu_read(long address, long length, u8 *data)
+{
+ read_main(REQUEST_PPU_READ, address, length, data);
+}
+//-------- write sequence --------
+static void device_write(usb_dev_handle *handle, enum request w, long address, long length, u8 *data)
+{
+ int cnt = usb_control_msg(
+ handle,
+ USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT,
+ w, address,
+ 0, data, length, TIMEOUT
+ );
+ assert(cnt == length);
+}
+
+static void kazzo_cpu_write_6502(long address, long data, long wait_msec)
+{
+ u8 d = (u8) (data & 0xff);
+ device_write(handle, REQUEST_CPU_WRITE_6502, address, 1, &d);
+}
+static void kazzo_cpu_write_flash(long address, long data)
+{
+ u8 d = (u8) (data & 0xff);
+ device_write(handle, REQUEST_CPU_WRITE_FLASH, address, 1, &d);
+}
+static void kazzo_ppu_write(long address, long data)
+{
+ u8 d = (u8) (data & 0xff);
+ device_write(handle, REQUEST_PPU_WRITE, address, 1, &d);
+}
+
+static inline void pack_short_le(long l, u8 *t)
+{
+ t[0] = l & 0xff;
+ t[1] = (l >> 8) & 0xff;
+}
+static flash_config(enum request r, long c2aaa, long c5555, long unit)
+{
+ const int size = 2 * 3;
+ u8 t[size];
+ assert(unit >= 1 && unit < 0x400);
+ pack_short_le(c2aaa, t);
+ pack_short_le(c5555, t + 2);
+ pack_short_le(unit, t + 4);
+ device_write(handle, r, 0, size, t);
+}
+static void kazzo_cpu_flash_config(long c2aaa, long c5555, long unit)
+{
+ flash_config(REQUEST_CPU_FLASH_CONFIG_SET, c2aaa, c5555, unit);
+}
+static void kazzo_ppu_flash_config(long c2aaa, long c5555, long unit)
+{
+ flash_config(REQUEST_PPU_FLASH_CONFIG_SET, c2aaa, c5555, unit);
+}
+
+static inline void flash_execute(enum request p, enum request s, long address, u8 *data, int size)
+{
+ u8 status;
+ device_write(handle, p, address, size, data);
+ do{
+ wait(1);
+ device_read(handle, s, 0, 1, &status);
+ }while(status != 0);
+}
+static void kazzo_cpu_flash_erase(long address)
+{
+ flash_execute(REQUEST_CPU_FLASH_ERASE, REQUEST_CPU_FLASH_STATUS, address, NULL, 0);
+}
+static void kazzo_ppu_flash_erase(long address)
+{
+ flash_execute(REQUEST_PPU_FLASH_ERASE, REQUEST_PPU_FLASH_STATUS, address, NULL, 0);
+}
+
+static void flash_program(enum request p, enum request s, long address, long length, u8 *data)
+{
+ while(length >= READ_PACKET_SIZE){
+ flash_execute(p, s, address, data, READ_PACKET_SIZE);
+ address += READ_PACKET_SIZE;
+ data += READ_PACKET_SIZE;
+ length -= READ_PACKET_SIZE;
+ }
+}
+static void kazzo_cpu_flash_program(long address, long length, u8 *data)
+{
+ enum request p = REQUEST_CPU_FLASH_PROGRAM;
+ enum request s = REQUEST_CPU_FLASH_STATUS;
+ flash_program(p, s, address, length, data);
+}
+static void kazzo_ppu_flash_program(long address, long length, u8 *data)
+{
+ flash_program(REQUEST_PPU_FLASH_PROGRAM, REQUEST_PPU_FLASH_STATUS, address, length, data);
+}
+
+const struct reader_driver DRIVER_KAZZO = {
+ .name = "kazzo",
+ .open_or_close = kazzo_open_close,
+ .init = kazzo_init,
+ .cpu_read = kazzo_cpu_read, .ppu_read = kazzo_ppu_read,
+ .cpu_write_6502 = kazzo_cpu_write_6502,
+ .flash_support = OK,
+ .ppu_write = kazzo_ppu_write,
+ .cpu_flash_config = kazzo_cpu_flash_config,
+ .cpu_flash_erase = kazzo_cpu_flash_erase,
+ .cpu_flash_program = kazzo_cpu_flash_program,
+ .ppu_flash_config = kazzo_ppu_flash_config,
+ .ppu_flash_erase = kazzo_ppu_flash_erase,
+ .ppu_flash_program = kazzo_ppu_flash_program
+};
--- /dev/null
+#ifndef _READER_KAZZO_H_
+#define _READER_KAZZO_H_
+const struct reader_driver DRIVER_KAZZO;
+#endif
#include "reader_master.h"
#include "reader_onajimi.h"
#include "reader_hongkongfc.h"
-#include "reader_dozeu.h"
+//#include "reader_dozeu.h"
+#include "reader_kazzo.h"
-//¤³¤ì¤ò rodata ¤Ë¤·¤¿¤¤¤±¤É const ¤ÎÉÕ¤±Êý¤¬Ê¬¤«¤é¤ó
-static const struct reader_driver *DRIVER_LIST[] = {
- &DRIVER_ONAJIMI, &DRIVER_HONGKONGFC, &DRIVER_DOZEU,
- NULL
-};
-
-int paralellport_open_or_close(int oc)
+int paralellport_open_or_close(enum reader_control oc)
{
static int giveio_status;
- if(oc == READER_OPEN){
+ switch(oc){
+ case READER_OPEN:
giveio_status = giveio_start();
switch(giveio_status){
case GIVEIO_OPEN:
//printf("%s Can't Access Direct IO %d\n", __FILE__, giveio_status);
return NG;
}
- }else if(oc == READER_CLOSE){
+ break;
+ case READER_CLOSE:
if(giveio_status != GIVEIO_WIN95){
giveio_stop(GIVEIO_STOP);
}
- }else{
+ break;
+ default:
assert(0);
+ break;
}
return OK;
}
const struct reader_driver *reader_driver_get(const char *name)
{
+ static const struct reader_driver *DRIVER_LIST[] = {
+ &DRIVER_ONAJIMI, &DRIVER_HONGKONGFC, //&DRIVER_DOZEU,
+ &DRIVER_KAZZO,
+ NULL
+ };
const struct reader_driver **d;
d = DRIVER_LIST;
while(*d != NULL){
#include "type.h"
#include <windows.h>
//C++ ¤Î Class ¤â¤É¤¤ò C ¤Ç¼ÂÁõ¤·¤Æ¤¤¤ë´¶¤¬Áý¤·¤Æ¤¤¿...
+enum reader_control{
+ READER_OPEN, READER_CLOSE
+};
struct reader_driver{
- int (*open_or_close)(int oc);
+ const char *name;
+ int (*open_or_close)(enum reader_control oc);
void (*init)(void);
void (*cpu_read)(long address, long length, u8 *data);
+ void (*cpu_write_6502)(long address, long data, long wait_msec);
void (*ppu_read)(long address, long length, u8 *data);
- void (*cpu_6502_write)(long address, long data, long wait_msec);
- void (*cpu_flash_write)(long address, long data);
void (*ppu_write)(long address, long data);
- const char *name;
+ int flash_support;
+ void (*cpu_flash_config)(long c2aaa, long c5555, long unit);
+ void (*cpu_flash_erase)(long address);
+ void (*cpu_flash_program)(long address, long length, u8 *data);
+ void (*ppu_flash_config)(long c2aaa, long c5555, long unit);
+ void (*ppu_flash_erase)(long address);
+ void (*ppu_flash_program)(long address, long length, u8 *data);
};
-int paralellport_open_or_close(int oc);
+int paralellport_open_or_close(enum reader_control oc);
const struct reader_driver *reader_driver_get(const char *name);
enum{
- READER_OPEN, READER_CLOSE
-};
-enum{
ADDRESS_MASK_A0toA12 = 0x1fff,
ADDRESS_MASK_A0toA14 = 0x7fff,
ADDRESS_MASK_A15 = 0x8000
if(msec == 0){
return;
}
- //const long waittime = 100000;
Sleep(msec);
}
#endif
H:1, L:0, x:ROMareaaccess»þ0, ¤½¤ì°Ê³°1
*/
-static void cpu_6502_write(long address, long data, long wait_msec)
+static void cpu_write_6502(long address, long data, long wait_msec)
{
int control = BUS_CONTROL_BUS_WRITE;
//addressÀßÄê + Á´¤Æ¤Î¥Ð¥¹¤ò»ß¤á¤ë
bus_control(BUS_CONTROL_BUS_WRITE);
}
+/*
static const int BUS_CONTROL_CPU_FLASH_WRITE = (
ADDRESS_NOP | DATA_SHIFT_NOP |
(DATA_DIRECTION_READ << BITNUM_DATA_DIRECTION) |
//WE up
control = bit_set(control, BITNUM_CPU_RW);
bus_control(control);
-}
+}*/
const struct reader_driver DRIVER_ONAJIMI = {
.name = "onajimi",
.open_or_close = paralellport_open_or_close,
.init = reader_init,
.cpu_read = cpu_read,
+ .cpu_write_6502 = cpu_write_6502,
.ppu_read = ppu_read,
- .cpu_6502_write = cpu_6502_write,
- .cpu_flash_write = cpu_flash_write,
- .ppu_write = ppu_write
+ .ppu_write = ppu_write,
+ .flash_support = NG,
+ .cpu_flash_config = NULL, .cpu_flash_erase = NULL, .cpu_flash_program = NULL,
+ .ppu_flash_config = NULL, .ppu_flash_erase = NULL, .ppu_flash_program = NULL
};
}
break;
case MODE_ROM_PROGRAM: //MAPPER check
- assert(c->cpu_flash_driver->write != NULL);
+ assert(c->cpu_flash_driver->program != NULL);
assert(r->cpu_rom.attribute == MEMORY_ATTR_READ);
assert(r->ppu_rom.attribute == MEMORY_ATTR_READ);
if(nesfile_load(LOGICAL_ERROR_PREFIX, c->romimage, r)== NG){
while(i != 0){
switch(region){
case MEMORY_AREA_CPU_RAM:
- d->cpu_6502_write(a, filldata, 0);
+ d->cpu_write_6502(a, filldata, 0);
break;
case MEMORY_AREA_PPU:
d->ppu_write(a, filldata);
long l = length;
writedata = ram->data;
while(l != 0){
- d->cpu_6502_write(a++, *writedata, wait);
+ d->cpu_write_6502(a++, *writedata, wait);
writedata += 1;
l--;
}
int status = DUMP;
int programcount_cpu = 0, programcount_ppu = 0;
+ int flashcommand_change_cpu = 0, flashcommand_change_ppu = 0;
variable_init_all();
while(s->opcode != SCRIPT_OPCODE_DUMP_END){
//printf("%s\n", SCRIPT_SYNTAX[s->opcode].name);
switch(s->opcode){
case SCRIPT_OPCODE_CPU_COMMAND:
command_mask(MEMORY_AREA_CPU_ROM, s->value[0], s->value[1], s->value[2], &(r->cpu_flash));
+ flashcommand_change_cpu = 1;
break;
case SCRIPT_OPCODE_CPU_READ:{
struct memory *m;
case SCRIPT_OPCODE_CPU_WRITE:{
long data;
expression_calc(&s->expression, &data);
- d->cpu_6502_write(s->value[0], data, c->write_wait);
+ d->cpu_write_6502(s->value[0], data, c->write_wait);
}
break;
case SCRIPT_OPCODE_CPU_RAMRW:{
if(c->cpu_flash_driver->id_device == FLASH_ID_DEVICE_DUMMY){
break;
}
+ if(flashcommand_change_cpu != 0){
+ r->cpu_flash.config(
+ r->cpu_flash.command_2aaa,
+ r->cpu_flash.command_5555,
+ r->cpu_flash.pagesize
+ );
+ flashcommand_change_cpu = 0;
+ }
if(programcount_cpu++ == 0){
printf(EXECUTE_PROGRAM_PREPARE, cpu_rom.name);
fflush(stdout);
const long address = s->value[0];
const long length = s->value[1];
execute_program_begin(&cpu_rom, length);
- c->cpu_flash_driver->write(
+ c->cpu_flash_driver->program(
&(r->cpu_flash),
address, length,
&cpu_rom
);
- d->cpu_read(address, length, program_compare);
- const int result = memcmp(program_compare, cpu_rom.data, length);
- execute_program_finish(result);
+ int result;
+ if(1){
+ d->cpu_read(address, length, program_compare);
+ result = memcmp(program_compare, cpu_rom.data, length);
+ execute_program_finish(result);
+ }else{
+ puts("skip");
+ result = 1;
+ }
cpu_rom.data += length;
cpu_rom.offset += length;
break;
case SCRIPT_OPCODE_PPU_COMMAND:
command_mask(MEMORY_AREA_PPU, s->value[0], s->value[1], s->value[2], &(r->ppu_flash));
+ flashcommand_change_ppu = 1;
break;
case SCRIPT_OPCODE_PPU_RAMFIND:
if(ppu_ramfind(d) == PPU_TEST_RAM){
if(c->ppu_flash_driver->id_device == FLASH_ID_DEVICE_DUMMY){
break;
}
+ if(flashcommand_change_ppu != 0){
+ r->ppu_flash.config(
+ r->ppu_flash.command_2aaa,
+ r->ppu_flash.command_5555,
+ r->ppu_flash.pagesize
+ );
+ flashcommand_change_ppu = 0;
+ }
if(programcount_ppu++ == 0){
printf(EXECUTE_PROGRAM_PREPARE, ppu_rom.name);
fflush(stdout);
const long address = s->value[0];
const long length = s->value[1];
execute_program_begin(&ppu_rom, length);
- c->ppu_flash_driver->write(
+ c->ppu_flash_driver->program(
&(r->ppu_flash),
address, length,
&ppu_rom
.command_2aaa = 0,
.command_5555 = 0,
.pagesize = c->cpu_flash_driver->pagesize,
- .erase_wait = c->cpu_flash_driver->erase_wait,
.command_mask = c->cpu_flash_driver->command_mask,
- .flash_write = c->reader->cpu_flash_write,
- .read = c->reader->cpu_read
+ .config = c->reader->cpu_flash_config,
+ .erase = c->reader->cpu_flash_erase,
+ .program = c->reader->cpu_flash_program,
+ .write = NULL //c->reader->cpu_write_6502
},
.ppu_flash = {
.command_0000 = 0,
.command_2aaa = 0,
.command_5555 = 0,
.pagesize = c->ppu_flash_driver->pagesize,
- .erase_wait = c->ppu_flash_driver->erase_wait,
.command_mask = c->ppu_flash_driver->command_mask,
- .flash_write = c->reader->ppu_write,
- .read = c->reader->ppu_read
+ .config = c->reader->ppu_flash_config,
+ .erase = c->reader->ppu_flash_erase,
+ .program = c->reader->ppu_flash_program,
+ .write = NULL //c->reader->ppu_write
},
.mappernum = 0,
.mirror = MIRROR_PROGRAMABLE
#include "textutil.h"
#include "config.h"
#include "flashmemory.h"
-#include "client_test.h"
static int flag_get(const char *flag, struct st_config *c)
{
return OK;
}
-static const struct flash_driver FLASH_UNDEF = {
- .name = "undefined",
- .capacity = 0,
- .pagesize = 1,
- .erase_wait = 0,
- .command_mask = 0,
- .id_manufacurer = 0,
- .id_device = 0,
- .productid_check = NULL,
-#if DEBUG==1
- .erase = NULL,
-#endif
- .init = NULL,
- .write = NULL
-};
static int flash_pointer_init(const char *device, const struct flash_driver **f)
{
*f = flash_driver_get(device);
c->backupram = CONFIG_OVERRIDE_UNDEF;
c->mapper = CONFIG_OVERRIDE_UNDEF;
c->syntaxtest = 0;
- c->cpu_flash_driver = &FLASH_UNDEF;
- c->ppu_flash_driver = &FLASH_UNDEF;
+ c->cpu_flash_driver = &FLASH_DRIVER_UNDEF;
+ c->ppu_flash_driver = &FLASH_DRIVER_UNDEF;
c->write_wait = 0;
//mode ÊÌ target file ½é´ü²½
switch(argv[ARGC_MODE][0]){
break;
}
break;
-
- case MODE_TEST:
- if(DEBUG == 0){
- break;
- }
- switch(argc){
- case 3:
- client_test(c->reader, argv[ARGC_TEST_OPTION], NULL, c->flash_test_device, c->flash_test_mapper);
- break;
- case 4:
- client_test(c->reader, argv[ARGC_TEST_OPTION], argv[ARGC_TEST_FILE], c->flash_test_device, c->flash_test_mapper);
- break;
- default:
- printf("%s test argc error\n", PREFIX_CONFIG_ERROR);
- }
- break;
}
return OK;
--- /dev/null
+/* Name: opendevice.c -> renamed as usb_device.[ch]
+ * Project: V-USB host-side library
+ * Author: Christian Starkjohann
+ * Creation Date: 2008-04-10
+ * Tabsize: 4
+ * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
+ * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
+ * This Revision: $Id: opendevice.c 740 2009-04-13 18:23:31Z cs $
+ */
+#include <stdio.h>
+#include "usb_device.h"
+
+enum{
+ MATCH_SUCCESS = 1,
+ MATCH_FAILED = 0,
+ MATCH_ABORT = -1
+};
+/* private interface: match text and p, return MATCH_SUCCESS, MATCH_FAILED, or MATCH_ABORT. */
+static int _shellStyleMatch(char *text, char *p)
+{
+ int last, matched, reverse;
+
+ for(; *p; text++, p++){
+ if(*text == 0 && *p != '*')
+ return MATCH_ABORT;
+ switch(*p){
+ case '\\':
+ /* Literal match with following character. */
+ p++;
+ /* FALLTHROUGH */
+ default:
+ if(*text != *p)
+ return MATCH_FAILED;
+ continue;
+ case '?':
+ /* Match anything. */
+ continue;
+ case '*':
+ while(*++p == '*')
+ /* Consecutive stars act just like one. */
+ continue;
+ if(*p == 0)
+ /* Trailing star matches everything. */
+ return MATCH_SUCCESS;
+ while(*text)
+ if((matched = _shellStyleMatch(text++, p)) != MATCH_FAILED)
+ return matched;
+ return MATCH_ABORT;
+ case '[':
+ reverse = p[1] == '^';
+ if(reverse) /* Inverted character class. */
+ p++;
+ matched = MATCH_FAILED;
+ if(p[1] == ']' || p[1] == '-')
+ if(*++p == *text)
+ matched = MATCH_SUCCESS;
+ for(last = *p; *++p && *p != ']'; last = *p)
+ if (*p == '-' && p[1] != ']' ? *text <= *++p && *text >= last : *text == *p)
+ matched = MATCH_SUCCESS;
+ if(matched == reverse)
+ return MATCH_FAILED;
+ continue;
+ }
+ }
+ return *text == 0;
+}
+
+/* public interface for shell style matching: returns 0 if fails, 1 if matches */
+static int shellStyleMatch(char *text, char *pattern)
+{
+ if(pattern == NULL) /* NULL pattern is synonymous to "*" */
+ return 1;
+ return _shellStyleMatch(text, pattern) == MATCH_SUCCESS;
+}
+
+/* ------------------------------------------------------------------------- */
+
+int usbGetStringAscii(usb_dev_handle *dev, int index, char *buf, int buflen)
+{
+char buffer[256];
+int rval, i;
+
+ if((rval = usb_get_string_simple(dev, index, buf, buflen)) >= 0) /* use libusb version if it works */
+ return rval;
+ if((rval = usb_control_msg(dev, USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR, (USB_DT_STRING << 8) + index, 0x0409, buffer, sizeof(buffer), 5000)) < 0)
+ return rval;
+ if(buffer[1] != USB_DT_STRING){
+ *buf = 0;
+ return 0;
+ }
+ if((unsigned char)buffer[0] < rval)
+ rval = (unsigned char)buffer[0];
+ rval /= 2;
+ /* lossy conversion to ISO Latin1: */
+ for(i=1;i<rval;i++){
+ if(i > buflen) /* destination buffer overflow */
+ break;
+ buf[i-1] = buffer[2 * i];
+ if(buffer[2 * i + 1] != 0) /* outside of ISO Latin1 range */
+ buf[i-1] = '?';
+ }
+ buf[i-1] = 0;
+ return i-1;
+}
+
+/* ------------------------------------------------------------------------- */
+
+int usbOpenDevice(
+ usb_dev_handle **device, int vendorID, char *vendorNamePattern,
+ int productID, char *productNamePattern,
+ char *serialNamePattern, FILE *printMatchingDevicesFp,
+ FILE *warningsFp
+)
+{
+ struct usb_bus *bus;
+ struct usb_device *dev;
+ usb_dev_handle *handle = NULL;
+ int errorCode = USBOPEN_ERR_NOTFOUND;
+
+ usb_find_busses();
+ usb_find_devices();
+ for(bus = usb_get_busses(); bus; bus = bus->next){
+ for(dev = bus->devices; dev; dev = dev->next){ /* iterate over all devices on all busses */
+ if((vendorID == 0 || dev->descriptor.idVendor == vendorID)
+ && (productID == 0 || dev->descriptor.idProduct == productID)){
+ char vendor[256], product[256], serial[256];
+ int len;
+ handle = usb_open(dev); /* we need to open the device in order to query strings */
+ if(!handle){
+ errorCode = USBOPEN_ERR_ACCESS;
+ if(warningsFp != NULL)
+ fprintf(warningsFp, "Warning: cannot open VID=0x%04x PID=0x%04x: %s\n", dev->descriptor.idVendor, dev->descriptor.idProduct, usb_strerror());
+ continue;
+ }
+ /* now check whether the names match: */
+ len = vendor[0] = 0;
+ if(dev->descriptor.iManufacturer > 0){
+ len = usbGetStringAscii(handle, dev->descriptor.iManufacturer, vendor, sizeof(vendor));
+ }
+ if(len < 0){
+ errorCode = USBOPEN_ERR_ACCESS;
+ if(warningsFp != NULL)
+ fprintf(warningsFp, "Warning: cannot query manufacturer for VID=0x%04x PID=0x%04x: %s\n", dev->descriptor.idVendor, dev->descriptor.idProduct, usb_strerror());
+ }else{
+ errorCode = USBOPEN_ERR_NOTFOUND;
+ /* printf("seen device from vendor ->%s<-\n", vendor); */
+ if(shellStyleMatch(vendor, vendorNamePattern)){
+ len = product[0] = 0;
+ if(dev->descriptor.iProduct > 0){
+ len = usbGetStringAscii(handle, dev->descriptor.iProduct, product, sizeof(product));
+ }
+ if(len < 0){
+ errorCode = USBOPEN_ERR_ACCESS;
+ if(warningsFp != NULL)
+ fprintf(warningsFp, "Warning: cannot query product for VID=0x%04x PID=0x%04x: %s\n", dev->descriptor.idVendor, dev->descriptor.idProduct, usb_strerror());
+ }else{
+ errorCode = USBOPEN_ERR_NOTFOUND;
+ /* printf("seen product ->%s<-\n", product); */
+ if(shellStyleMatch(product, productNamePattern)){
+ len = serial[0] = 0;
+ if(dev->descriptor.iSerialNumber > 0){
+ len = usbGetStringAscii(handle, dev->descriptor.iSerialNumber, serial, sizeof(serial));
+ }
+ if(len < 0){
+ errorCode = USBOPEN_ERR_ACCESS;
+ if(warningsFp != NULL)
+ fprintf(warningsFp, "Warning: cannot query serial for VID=0x%04x PID=0x%04x: %s\n", dev->descriptor.idVendor, dev->descriptor.idProduct, usb_strerror());
+ }
+ if(shellStyleMatch(serial, serialNamePattern)){
+ if(printMatchingDevicesFp != NULL){
+ if(serial[0] == 0){
+ fprintf(printMatchingDevicesFp, "VID=0x%04x PID=0x%04x vendor=\"%s\" product=\"%s\"\n", dev->descriptor.idVendor, dev->descriptor.idProduct, vendor, product);
+ }else{
+ fprintf(printMatchingDevicesFp, "VID=0x%04x PID=0x%04x vendor=\"%s\" product=\"%s\" serial=\"%s\"\n", dev->descriptor.idVendor, dev->descriptor.idProduct, vendor, product, serial);
+ }
+ }else{
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+ usb_close(handle);
+ handle = NULL;
+ }
+ }
+ if(handle) /* we have found a deice */
+ break;
+ }
+ if(handle != NULL){
+ errorCode = 0;
+ *device = handle;
+ }
+ if(printMatchingDevicesFp != NULL) /* never return an error for listing only */
+ errorCode = 0;
+ return errorCode;
+}
+
--- /dev/null
+/* Name: opendevice.h
+ * Project: V-USB host-side library
+ * Author: Christian Starkjohann
+ * Creation Date: 2008-04-10
+ * Tabsize: 4
+ * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
+ * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
+ * This Revision: $Id: opendevice.h 755 2009-08-03 17:01:21Z cs $
+ */
+
+/*
+General Description:
+This module offers additional functionality for host side drivers based on
+libusb or libusb-win32. It includes a function to find and open a device
+based on numeric IDs and textual description. It also includes a function to
+obtain textual descriptions from a device.
+
+To use this functionality, simply copy opendevice.c and opendevice.h into your
+project and add them to your Makefile. You may modify and redistribute these
+files according to the GNU General Public License (GPL) version 2 or 3.
+*/
+
+#ifndef __OPENDEVICE_H_INCLUDED__
+#define __OPENDEVICE_H_INCLUDED__
+
+#include <usb.h> /* this is libusb, see http://libusb.sourceforge.net/ */
+#include <stdio.h>
+
+int usbGetStringAscii(usb_dev_handle *dev, int index, char *buf, int buflen);
+/* This function gets a string descriptor from the device. 'index' is the
+ * string descriptor index. The string is returned in ISO Latin 1 encoding in
+ * 'buf' and it is terminated with a 0-character. The buffer size must be
+ * passed in 'buflen' to prevent buffer overflows. A libusb device handle
+ * must be given in 'dev'.
+ * Returns: The length of the string (excluding the terminating 0) or
+ * a negative number in case of an error. If there was an error, use
+ * usb_strerror() to obtain the error message.
+ */
+
+int usbOpenDevice(usb_dev_handle **device, int vendorID, char *vendorNamePattern, int productID, char *productNamePattern, char *serialNamePattern, FILE *printMatchingDevicesFp, FILE *warningsFp);
+/* This function iterates over all devices on all USB busses and searches for
+ * a device. Matching is done first by means of Vendor- and Product-ID (passed
+ * in 'vendorID' and 'productID'. An ID of 0 matches any numeric ID (wildcard).
+ * When a device matches by its IDs, matching by names is performed. Name
+ * matching can be done on textual vendor name ('vendorNamePattern'), product
+ * name ('productNamePattern') and serial number ('serialNamePattern'). A
+ * device matches only if all non-null pattern match. If you don't care about
+ * a string, pass NULL for the pattern. Patterns are Unix shell style pattern:
+ * '*' stands for 0 or more characters, '?' for one single character, a list
+ * of characters in square brackets for a single character from the list
+ * (dashes are allowed to specify a range) and if the lis of characters begins
+ * with a caret ('^'), it matches one character which is NOT in the list.
+ * Other parameters to the function: If 'warningsFp' is not NULL, warning
+ * messages are printed to this file descriptor with fprintf(). If
+ * 'printMatchingDevicesFp' is not NULL, no device is opened but matching
+ * devices are printed to the given file descriptor with fprintf().
+ * If a device is opened, the resulting USB handle is stored in '*device'. A
+ * pointer to a "usb_dev_handle *" type variable must be passed here.
+ * Returns: 0 on success, an error code (see defines below) on failure.
+ */
+
+/* usbOpenDevice() error codes: */
+#define USBOPEN_SUCCESS 0 /* no error */
+#define USBOPEN_ERR_ACCESS 1 /* not enough permissions to open device */
+#define USBOPEN_ERR_IO 2 /* I/O error */
+#define USBOPEN_ERR_NOTFOUND 3 /* device not found */
+
+
+/* Obdev's free USB IDs, see USB-IDs-for-free.txt for details */
+
+#define USB_VID_OBDEV_SHARED 5824 /* obdev's shared vendor ID */
+#define USB_PID_OBDEV_SHARED_CUSTOM 1500 /* shared PID for custom class devices */
+#define USB_PID_OBDEV_SHARED_HID 1503 /* shared PID for HIDs except mice & keyboards */
+#define USB_PID_OBDEV_SHARED_CDCACM 1505 /* shared PID for CDC Modem devices */
+#define USB_PID_OBDEV_SHARED_MIDI 1508 /* shared PID for MIDI class devices */
+
+#endif /* __OPENDEVICE_H_INCLUDED__ */
//include from unagi.c only
-static const char STR_VERSION[] = "0.5.4 "
+static const char STR_VERSION[] = "1.0.0 "
#if DEBUG==1
"debug "
#else