OSDN Git Service

support exception
authornaruko <naruko@24ea1065-a21e-4ca1-99c9-f5125deb0858>
Fri, 29 Oct 2010 00:29:47 +0000 (00:29 +0000)
committernaruko <naruko@24ea1065-a21e-4ca1-99c9-f5125deb0858>
Fri, 29 Oct 2010 00:29:47 +0000 (00:29 +0000)
git-svn-id: svn+ssh://svn.osdn.net/svnroot/unagi@381 24ea1065-a21e-4ca1-99c9-f5125deb0858

13 files changed:
client/trunk/anago/Makefile.windows
client/trunk/anago/anago.mk
client/trunk/anago/anago_cui.c
client/trunk/anago/anago_frame.cpp
client/trunk/anago/script_common.c
client/trunk/anago/script_common.h
client/trunk/anago/script_dump.c
client/trunk/anago/script_dump.h
client/trunk/anago/script_program.c
client/trunk/anago/script_program.h
client/trunk/reader_kazzo.c
client/trunk/reader_kazzo.h
client/trunk/reader_master.h

index efa1e8f..87d86b9 100644 (file)
@@ -4,5 +4,5 @@ LIBUSB = d:/dev/LibUSB-Win32
 SQUIRREL = ../SQUIRREL2\r
 KAZZO = ../../kazzo/firmware\r
 WX_CONFIG = /d/dev/wxWidgets/build_release/wx-config\r
-\r
+CXXFLAGS = -finput-charset=utf-8 -fexec-charset=cp932\r
 include anago.mk\r
index 9b07e79..cf98dc4 100644 (file)
@@ -10,7 +10,7 @@ CFLAGS = -I.. -I$(SQUIRREL)/include -I$(KAZZO)
 ifneq ($(strip $(LIBUSB)),)
   CFLAGS += -I$(LIBUSB)/include
 endif
-CXXFLAGS = -I.. `$(WX_CONFIG) --cppflags`
+CXXFLAGS += -I.. `$(WX_CONFIG) --cppflags`
 
 LDFLAG = -L$(SQUIRREL)/lib
 ifneq ($(strip $(LIBUSB)),)
@@ -40,5 +40,8 @@ $(APP_CUI): $(OBJ_CUI)
 clean:
        rm -f $(OBJ_CUI) $(OBJ_GUI) $(OBJ_CORE)
 
-script_flash.o: squirrel_wrap.h
-script_dump.o: squirrel_wrap.h
+anago.d:
+       gcc -MM $(CFLAGS) $(CPPFLAGS) *.c > $@
+       g++ -MM $(CFLAGS) $(CXXFLAGS) *.cpp >> $@
+
+-include anago.d
index 2b710aa..51389e0 100644 (file)
@@ -1,6 +1,7 @@
 #include <assert.h>
 #include <stdio.h>
 #include <stdarg.h>
+#include <stdlib.h>
 #include "memory_manage.h"
 #include "type.h"
 #include "widget.h"
@@ -32,6 +33,12 @@ static void log_set(struct textcontrol *log)
        log->append_va = text_append_va;
 }
 
+static void except(const char *str)
+{
+       puts(str);
+       exit(0);
+}
+
 static bool program_rom_set(const char *device, char trans, struct memory *m, struct flash_device *f)
 {
        m->offset = 0;
@@ -116,6 +123,7 @@ static void program(int c, char **v)
        log_set(&config.log);
        cui_gauge_new(&config.cpu.gauge, "Program  Flash", 2, -2);
        cui_gauge_new(&config.ppu.gauge, "Charcter Flash", 1, -1);
+       config.except = except;
        script_program_execute(&config);
        cui_gauge_destory(&config.cpu.gauge);
        cui_gauge_destory(&config.ppu.gauge);
@@ -161,6 +169,7 @@ static void dump(int c, char **v)
        config.ppu.access = &DRIVER_KAZZO.ppu;
        cui_gauge_new(&config.cpu.gauge, "Program  ROM", 2, -2);
        cui_gauge_new(&config.ppu.gauge, "Charcter ROM", 1, -1);
+       config.except = except;
        config.mappernum = -1;
        if(c == 5){
                config.mappernum = atoi(v[4]);
index a1b99a7..490deaa 100644 (file)
@@ -1,24 +1,27 @@
 #include <wx/wx.h>
-#include <wx/log.h>
-#include <wx/dir.h>
-#include <wx/thread.h>
 #include <wx/app.h>
-#include <cstring>
+#include <wx/thread.h>
+#include <wx/dir.h>
+#include <wx/sound.h>
 #include <cstdarg>
 #include "anago_gui.h"
 #include "widget.h"
 #include "reader_master.h"
-//#include "reader_kazzo.h"
-extern const struct reader_driver DRIVER_KAZZO;
+#include "reader_kazzo.h"
 extern "C"{
-#include "header.h"
-#include "flash_device.h"
-#include "script_dump.h"
-#include "script_program.h"
-void qr_version_print(const struct textcontrol *l);
+  #include "header.h"
+  #include "flash_device.h"
+  #include "script_dump.h"
+  #include "script_program.h"
+  void qr_version_print(const struct textcontrol *l);
 }
 
 //---- C++ -> C -> C++ wrapping functions ----
+static void throw_error(const char *t)
+{
+       throw t;
+}
+
 static void value_set(void *gauge, void *label, int value)
 {
        wxGauge *g = static_cast<wxGauge *>(gauge);
@@ -124,7 +127,7 @@ public:
        anago_dumper(anago_frame *f, const struct dump_config *d) : wxThread()
        {
                m_frame = f;
-               memcpy(&m_config, d, sizeof(struct dump_config));
+               m_config = *d; //struct data copy
        }
 };
 
@@ -144,7 +147,7 @@ public:
        anago_programmer(anago_frame *f, const struct program_config *d) : wxThread()
        {
                m_frame = f;
-               memcpy(&m_config, d, sizeof(struct program_config));
+               m_config = *d;
        }
 };
 
@@ -215,6 +218,7 @@ private:
                config.log.object = m_log;
                config.log.append = text_append;
                config.log.append_va = text_append_va;
+               config.except = throw_error;
                config.cpu.increase = dump_increase_get(m_dump_cpu_increase);
                config.ppu.increase = dump_increase_get(m_dump_ppu_increase);
                config.progress = true;
@@ -326,6 +330,7 @@ private:
                f.log.object = m_log;
                f.log.append = text_append;
                f.log.append_va = text_append_va;
+               f.except = throw_error;
                
                {
                        wxString str_script = m_program_script_choice->GetStringSelection();
@@ -494,6 +499,11 @@ public:
 
        void DumpThreadFinish(void)
        {
+/*             wxSound sound(wxT("tinkalink2.wav"), false);
+               if(sound.IsOk() == true){
+                       sound.Play();
+               }*/
+               
                m_dump_script_choice->Enable();
                m_dump_romimage_picker->Enable();
                m_dump_check_battery->Enable();
@@ -519,26 +529,38 @@ public:
                m_program_ppu_device->Enable();
                m_status = STATUS_IDLE;
        }
+       void LogAppend(const char *t)
+       {
+               *m_log << t;
+       }
 };
 
 
 void *anago_dumper::Entry(void)
 {
-       script_dump_execute(&m_config);
+       try{
+               script_dump_execute(&m_config);
+       }catch(const char *t){
+               m_frame->LogAppend(t);
+       }
        m_frame->DumpThreadFinish();
        return NULL;
 }
 
 void *anago_programmer::Entry(void)
 {
-       script_program_execute(&m_config);
+       try{
+               script_program_execute(&m_config);
+       }catch(const char *t){
+               m_frame->LogAppend(t);
+       }
        m_frame->ProgramThreadFinish();
        return NULL;
 }
 
 #ifndef WIN32
 extern "C"{
-       int anago_cui(int c, char **v);
+  int anago_cui(int c, char **v);
 }
 int main(int c, char **v)
 {
@@ -562,5 +584,8 @@ public:
                return true;
        }
 };
+#ifdef WIN32
 IMPLEMENT_APP(MyApp)
-
+#else
+IMPLEMENT_APP_NO_MAIN(MyApp)
+#endif
index b598516..0f381ae 100644 (file)
@@ -58,7 +58,7 @@ SQInteger script_require(HSQUIRRELVM v)
        return 0;
 }
 
-static bool connection_check_main(const int *h, const struct textcontrol *text, const struct reader_memory_access *m, long address)
+static bool connection_check_main(const struct reader_handle *h, const struct textcontrol *text, const struct reader_memory_access *m, long address)
 {
        const int size = 0x10;
        uint8_t test1[size], test_m[size];
@@ -74,7 +74,7 @@ static bool connection_check_main(const int *h, const struct textcontrol *text,
        }
        return true;
 }
-bool connection_check(const int *h, const struct textcontrol *text, const struct reader_memory_access *cpu, const struct reader_memory_access *ppu)
+bool connection_check(const struct reader_handle *h, const struct textcontrol *text, const struct reader_memory_access *cpu, const struct reader_memory_access *ppu)
 {
        if(connection_check_main(h, text, cpu, 0xf000) == false){
                return false;
index e1c6960..3190c67 100644 (file)
@@ -10,5 +10,5 @@ SQInteger script_require(HSQUIRRELVM v);
 
 struct reader_handle;
 struct reader_memory_access;
-bool connection_check(const int *h, const struct textcontrol *text, const struct reader_memory_access *cpu, const struct reader_memory_access *ppu);
+bool connection_check(const struct reader_handle *h, const struct textcontrol *text, const struct reader_memory_access *cpu, const struct reader_memory_access *ppu);
 #endif
index 970eac4..e1a2dca 100644 (file)
@@ -14,7 +14,7 @@
 #include "script_common.h"
 #include "script_dump.h"
 
-static SQInteger write_memory(HSQUIRRELVM v, const int *h, struct dump_memory_driver *t)
+static SQInteger write_memory(HSQUIRRELVM v, const struct reader_handle *h, struct dump_memory_driver *t)
 {
        long address, data;
        SQRESULT r = qr_argument_get(v, 2, &address, &data);
@@ -68,7 +68,7 @@ static void buffer_show(struct memory *t, long length)
        fflush(stdout);
 }
 
-static SQInteger read_memory(HSQUIRRELVM v, const int *h, struct dump_memory_driver *t, bool progress)
+static SQInteger read_memory(HSQUIRRELVM v, const struct reader_handle *h, struct dump_memory_driver *t, bool progress)
 {
        long address, length;
        SQRESULT r = qr_argument_get(v, 2, &address, &length);
@@ -346,7 +346,7 @@ void script_dump_execute(struct dump_config *d)
 /*     if(d->progress == true){
                progress_init();
        }*/
-       d->handle = d->control->open();
+       d->handle = d->control->open(d->except);
        if(d->handle == NULL){
                d->log.append(d->log.object, "reader open error\n");
                return;
index 761089a..545718f 100644 (file)
@@ -3,7 +3,7 @@
 struct dump_config{
        const char *script;
        const char *target;
-       const int *handle;
+       const struct reader_handle *handle;
        const struct reader_control *control;
        struct dump_memory_driver{
                const struct reader_memory_access *access;
@@ -15,6 +15,7 @@ struct dump_config{
        bool progress;
        bool battery;
        struct textcontrol log;
+       void (*except)(const char *str);
 };
 void script_dump_execute(struct dump_config *c);
 #endif
index 9631f0d..40f6d16 100644 (file)
@@ -67,7 +67,7 @@ static SQInteger ppu_command(HSQUIRRELVM v)
        }
        return command_set(v, &d->ppu);
 }
-static SQInteger write_memory(HSQUIRRELVM v, const int *h, struct flash_memory_driver *t)
+static SQInteger write_memory(HSQUIRRELVM v, const struct reader_handle *h, struct flash_memory_driver *t)
 {
        long address, data;
        SQRESULT r = qr_argument_get(v, 2, &address, &data);
@@ -87,7 +87,7 @@ static SQInteger cpu_write(HSQUIRRELVM v)
        }
        return write_memory(v, d->handle, &d->cpu);
 }
-static SQInteger erase_set(HSQUIRRELVM v, const int *h, struct flash_memory_driver *t, struct textcontrol *log)
+static SQInteger erase_set(HSQUIRRELVM v, const struct reader_handle *h, struct flash_memory_driver *t, struct textcontrol *log)
 {
        t->access->flash_config(h, t->c000x, t->c2aaa, t->c5555, t->flash.pagesize, t->flash.retry);
        t->command_change = false;
@@ -115,7 +115,7 @@ static SQInteger ppu_erase(HSQUIRRELVM v)
        }
        return erase_set(v, d->handle, &d->ppu, &d->log);
 }
-static SQInteger program_regist(HSQUIRRELVM v, const int *h, struct flash_memory_driver *t)
+static SQInteger program_regist(HSQUIRRELVM v, const struct reader_handle *h, struct flash_memory_driver *t)
 {
        SQRESULT r = qr_argument_get(v, 2, &t->programming.address, &t->programming.length);
        if(SQ_FAILED(r)){
@@ -135,7 +135,7 @@ static SQInteger program_regist(HSQUIRRELVM v, const int *h, struct flash_memory
        fflush(stdout);*/
        return sq_suspendvm(v);
 }
-static void program_execute(const int *h, struct flash_memory_driver *t)
+static void program_execute(const struct reader_handle *h, struct flash_memory_driver *t)
 {
        const long w = t->access->flash_program(
                h, &t->gauge, 
@@ -150,7 +150,7 @@ static void program_execute(const int *h, struct flash_memory_driver *t)
        t->programming.offset += w;
 }
 
-static bool program_compare(const int *h, struct flash_memory_driver *t)
+static bool program_compare(const struct reader_handle *h, struct flash_memory_driver *t)
 {
        uint8_t *comparea = Malloc(t->compare.length);
        bool ret = false;
@@ -193,7 +193,7 @@ static SQInteger ppu_program_memory(HSQUIRRELVM v)
        return program_regist(v, d->handle, &d->ppu);
 }
 
-static long erase_timer_get(const int *h, struct flash_memory_driver *t)
+static long erase_timer_get(const struct reader_handle *h, struct flash_memory_driver *t)
 {
        if(
                (t->memory.transtype != TRANSTYPE_EMPTY) && 
@@ -238,7 +238,7 @@ static void gauge_init(struct flash_memory_driver *t)
        }
 }
 
-static bool program_memoryarea(HSQUIRRELVM co, const int *h, struct flash_memory_driver *t, bool compare, SQInteger *state, struct textcontrol *log)
+static bool program_memoryarea(HSQUIRRELVM co, const struct reader_handle *h, struct flash_memory_driver *t, bool compare, SQInteger *state, struct textcontrol *log)
 {
        if(t->programming.length == 0){
                if(t->programming.offset != 0 && compare == true){
@@ -462,7 +462,7 @@ void script_program_execute(struct program_config *c)
                return;
        }
 //reader initalize
-       c->handle = c->control->open();
+       c->handle = c->control->open(c->except);
        if(c->handle == NULL){
                c->log.append(c->log.object, "reader open error\n");
                nesbuffer_free(&rom, 0);
index 1103191..d1c3197 100644 (file)
@@ -3,7 +3,7 @@
 struct program_config{
        const char *script;
        const char *target;
-       const int *handle;
+       const struct reader_handle *handle;
        const struct reader_control *control;
        struct flash_memory_driver{
                const struct reader_memory_access *access;
@@ -19,6 +19,7 @@ struct program_config{
        long mappernum;
        bool compare, testrun;
        struct textcontrol log;
+       void (*except)(const char *str);
 };
 void script_program_execute(struct program_config *c);
 #endif
index a136ea0..247d6b7 100644 (file)
@@ -29,40 +29,54 @@ static inline usb_dev_handle *device_open(void)
        return NULL;
 }
 
-static const int *kazzo_open(void)
+struct reader_handle{
+       usb_dev_handle *handle;
+       void (*except)(const char *str);
+};
+
+static const struct reader_handle *kazzo_open(void (*except)(const char *str))
 {
-       return (const int *) device_open();
+       struct reader_handle *h;
+       usb_dev_handle *usb = device_open();
+       if(usb == NULL){
+               return NULL;
+       }
+       h = Malloc(sizeof(struct reader_handle));
+       h->handle = usb;
+       h->except = except;
+       return h;
 }
 
-static void kazzo_close(const int *h)
+static void kazzo_close(const struct reader_handle *h)
 {
-       usb_close((usb_dev_handle *) h);
+       usb_close(h->handle);
+       Free((void *) h);
 }
 enum{
        TIMEOUT = 4000
 };
 //-------- read sequence --------
-static void device_read(usb_dev_handle *handle, enum request r, enum index index, long address, long length, uint8_t *data)
+static void device_read(const struct reader_handle *h, enum request r, enum index index, long address, long length, uint8_t *data)
 {
        int cnt = usb_control_msg(
-               handle, 
+               h->handle, 
                USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, 
                r, address, 
                index, (char *) data, length, TIMEOUT
        );
        if(cnt != length){
-               puts(__FUNCTION__);
-               puts(usb_strerror());
-               exit(1);
+               h->except(usb_strerror());
+//             puts(__FUNCTION__);
+//             puts(usb_strerror());
+//             exit(1);
        }
 }
-static void read_main(const int *d, const struct gauge *g, const enum request r, enum index index, long address, long length, uint8_t *data)
+static void read_main(const struct reader_handle *h, const struct gauge *g, const enum request r, enum index index, long address, long length, uint8_t *data)
 {
        const int packet = READ_PACKET_SIZE;
        while(length >= packet){
                device_read(
-                       (usb_dev_handle *) d,
-                       r, index, address, packet, data
+                       h, r, index, address, packet, data
                );
                data += packet;
                address += packet;
@@ -71,27 +85,26 @@ static void read_main(const int *d, const struct gauge *g, const enum request r,
        }
        if(length != 0){
                device_read(
-                       (usb_dev_handle *) d, 
-                       r, index, address, length, data
+                       h, r, index, address, length, data
                );
                g->value_add(g->bar, g->label, packet);
        }
 }
-static void kazzo_cpu_read(const int *d, const struct gauge *g, long address, long length, uint8_t *data)
+static void kazzo_cpu_read(const struct reader_handle *h, const struct gauge *g, long address, long length, uint8_t *data)
 {
-       read_main(d, g, REQUEST_CPU_READ, INDEX_IMPLIED, address, length, data);
+       read_main(h, g, REQUEST_CPU_READ, INDEX_IMPLIED, address, length, data);
 //     read_main(REQUEST_CPU_READ_6502, address, length, data);
 }
-static void kazzo_ppu_read(const int *d, const struct gauge *g, long address, long length, uint8_t *data)
+static void kazzo_ppu_read(const struct reader_handle *h, const struct gauge *g, long address, long length, uint8_t *data)
 {
-       read_main(d, g, REQUEST_PPU_READ, INDEX_IMPLIED, address, length, data);
+       read_main(h, g, REQUEST_PPU_READ, INDEX_IMPLIED, address, length, data);
 }
 //-------- write sequence --------
 /*
 When host send data that contains 0xff many times, v-usb losts some 
 bits. To prevent losting bits, mask data xor 0xa5;
 */
-static void device_write(usb_dev_handle *handle, enum request w, enum index index, long address, long length, const uint8_t *data)
+static void device_write(const struct reader_handle *h, enum request w, enum index index, long address, long length, const uint8_t *data)
 {
        uint8_t *d = Malloc(length);
        int i;
@@ -100,42 +113,43 @@ static void device_write(usb_dev_handle *handle, enum request w, enum index inde
                d[i] ^= 0xa5;
        }
        int cnt = usb_control_msg(
-               handle, 
+               h->handle, 
                USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT,
                w, address, 
                index, (char *) d, length, TIMEOUT
        );
        if(cnt != length){
-               puts(__FUNCTION__);
-               puts(usb_strerror());
-               exit(1);
+//             puts(__FUNCTION__);
+//             puts(usb_strerror());
+//             exit(1);
+               h->except(usb_strerror());
        }
        Free(d);
 }
 
-static void kazzo_init(const int *d)
+static void kazzo_init(const struct reader_handle *h)
 {
-       device_write((usb_dev_handle *) d, REQUEST_PHI2_INIT, INDEX_IMPLIED, 0, 0, NULL);
+       device_write(h, REQUEST_PHI2_INIT, INDEX_IMPLIED, 0, 0, NULL);
 }
 
-static void write_memory(const int *d, enum request r, long address, long length, const uint8_t *data)
+static void write_memory(const struct reader_handle *h, enum request r, long address, long length, const uint8_t *data)
 {
        while(length != 0){
                long l = length >= FLASH_PACKET_SIZE ? FLASH_PACKET_SIZE : length;
-               device_write((usb_dev_handle *) d, r, INDEX_IMPLIED, address, l, data);
+               device_write(h, r, INDEX_IMPLIED, address, l, data);
                address += l;
                data += l;
                length -= l;
        }
 }
-static void kazzo_cpu_write_6502(const int *d, long address, long length, const uint8_t *data)
+static void kazzo_cpu_write_6502(const struct reader_handle *h, long address, long length, const uint8_t *data)
 {
-       write_memory(d, REQUEST_CPU_WRITE_6502, address, length, data);
+       write_memory(h, REQUEST_CPU_WRITE_6502, address, length, data);
 }
 
-static void kazzo_ppu_write(const int *d, long address, long length, const uint8_t *data)
+static void kazzo_ppu_write(const struct reader_handle *h, long address, long length, const uint8_t *data)
 {
-       write_memory(d, REQUEST_PPU_WRITE, address, length, data);
+       write_memory(h, REQUEST_PPU_WRITE, address, length, data);
 }
 
 static inline void pack_short_le(long l, uint8_t *t)
@@ -143,7 +157,7 @@ static inline void pack_short_le(long l, uint8_t *t)
        t[0] = l & 0xff;
        t[1] = (l >> 8) & 0xff;
 }
-static void flash_config(const int *d, enum request r, enum index index, long c000x, long c2aaa, long c5555, long unit, bool retry)
+static void flash_config(const struct reader_handle *h, enum request r, enum index index, long c000x, long c2aaa, long c5555, long unit, bool retry)
 {
        const int size = 2 * 4 + 1;
        uint8_t buf[size];
@@ -158,18 +172,18 @@ static void flash_config(const int *d, enum request r, enum index index, long c0
        pack_short_le(unit, t);
        t += sizeof(uint16_t);
        *t = retry == true ? 1 : 0;
-       device_write((usb_dev_handle *) d, r, index, 0, size, buf);
+       device_write(h, r, index, 0, size, buf);
 }
-static void kazzo_cpu_flash_config(const int *d, long c000x, long c2aaa, long c5555, long unit, bool retry)
+static void kazzo_cpu_flash_config(const struct reader_handle *h, long c000x, long c2aaa, long c5555, long unit, bool retry)
 {
-       flash_config(d, REQUEST_FLASH_CONFIG_SET, INDEX_CPU, c000x, c2aaa, c5555, unit, retry);
+       flash_config(h, REQUEST_FLASH_CONFIG_SET, INDEX_CPU, c000x, c2aaa, c5555, unit, retry);
 }
-static void kazzo_ppu_flash_config(const int *d, long c000x, long c2aaa, long c5555, long unit, bool retry)
+static void kazzo_ppu_flash_config(const struct reader_handle *h, long c000x, long c2aaa, long c5555, long unit, bool retry)
 {
-       flash_config(d, REQUEST_FLASH_CONFIG_SET, INDEX_PPU, c000x, c2aaa, c5555, unit, retry);
+       flash_config(h, REQUEST_FLASH_CONFIG_SET, INDEX_PPU, c000x, c2aaa, c5555, unit, retry);
 }
 
-static inline void flash_execute(const int *d, enum request p, enum request s, enum index index, long address, const uint8_t *data, int size, bool dowait, bool skip)
+static inline void flash_execute(const struct reader_handle *h, enum request p, enum request s, enum index index, long address, const uint8_t *data, int size, bool dowait, bool skip)
 {
        uint8_t status;
        int filled = 1;
@@ -184,22 +198,22 @@ static inline void flash_execute(const int *d, enum request p, enum request s, e
                Free(filldata);
        }
        if(filled != 0){
-               device_write((usb_dev_handle *) d, p, index, address, size, data);
+               device_write(h, p, index, address, size, data);
        }
        if(dowait == true){
                do{
                        wait(10);
-                       device_read((usb_dev_handle *) d, s, index, 0, 1, &status);
+                       device_read(h, s, index, 0, 1, &status);
                }while(status != KAZZO_TASK_FLASH_IDLE);
        }
 }
-static void kazzo_cpu_flash_erase(const int *d, long address, bool dowait)
+static void kazzo_cpu_flash_erase(const struct reader_handle *h, long address, bool dowait)
 {
-       flash_execute(d, REQUEST_FLASH_ERASE, REQUEST_FLASH_STATUS, INDEX_CPU, address, NULL, 0, dowait, false);
+       flash_execute(h, REQUEST_FLASH_ERASE, REQUEST_FLASH_STATUS, INDEX_CPU, address, NULL, 0, dowait, false);
 }
-static void kazzo_ppu_flash_erase(const int *d, long address, bool dowait)
+static void kazzo_ppu_flash_erase(const struct reader_handle *h, long address, bool dowait)
 {
-       flash_execute(d, REQUEST_FLASH_ERASE, REQUEST_FLASH_STATUS, INDEX_PPU, address, NULL, 0, dowait, false);
+       flash_execute(h, REQUEST_FLASH_ERASE, REQUEST_FLASH_STATUS, INDEX_PPU, address, NULL, 0, dowait, false);
 }
 
 static void dump(const uint8_t *w, const uint8_t *r, long length)
@@ -223,7 +237,7 @@ static void dump(const uint8_t *w, const uint8_t *r, long length)
                length -= 0x10;
        }
 }
-static long flash_program(const int *h, const struct gauge *g, enum index index, long address, long length, const uint8_t *data, bool dowait, bool skip)
+static long flash_program(const struct reader_handle *h, const struct gauge *g, enum index index, long address, long length, const uint8_t *data, bool dowait, bool skip)
 {
        enum request p = REQUEST_FLASH_PROGRAM;
        enum request s = REQUEST_FLASH_STATUS;
@@ -252,31 +266,31 @@ static long flash_program(const int *h, const struct gauge *g, enum index index,
        Free(d);
        return count;
 }
-static long kazzo_cpu_flash_program(const int *d, const struct gauge *g, long address, long length, const uint8_t *data, bool dowait, bool skip)
+static long kazzo_cpu_flash_program(const struct reader_handle *h, const struct gauge *g, long address, long length, const uint8_t *data, bool dowait, bool skip)
 {
-       return flash_program(d, g, INDEX_CPU, address, length, data, dowait, skip);
+       return flash_program(h, g, INDEX_CPU, address, length, data, dowait, skip);
 }
-static long kazzo_ppu_flash_program(const int *d, const struct gauge *g, long address, long length, const uint8_t *data, bool dowait, bool skip)
+static long kazzo_ppu_flash_program(const struct reader_handle *h, const struct gauge *g, long address, long length, const uint8_t *data, bool dowait, bool skip)
 {
-       return flash_program(d, g, INDEX_PPU, address, length, data, dowait, skip);
+       return flash_program(h, g, INDEX_PPU, address, length, data, dowait, skip);
 }
 
-static void kazzo_flash_status(const int *d, uint8_t s[2])
+static void kazzo_flash_status(const struct reader_handle *h, uint8_t s[2])
 {
-       read_main(d, &GAUGE_DUMMY, REQUEST_FLASH_STATUS, INDEX_BOTH, 0, 2, s);
+       read_main(h, &GAUGE_DUMMY, REQUEST_FLASH_STATUS, INDEX_BOTH, 0, 2, s);
 }
-static void kazzo_cpu_flash_device_get(const int *d, uint8_t s[2])
+static void kazzo_cpu_flash_device_get(const struct reader_handle *h, uint8_t s[2])
 {
-       read_main(d, &GAUGE_DUMMY, REQUEST_FLASH_DEVICE, INDEX_CPU, 0, 2, s);
+       read_main(h, &GAUGE_DUMMY, REQUEST_FLASH_DEVICE, INDEX_CPU, 0, 2, s);
 }
-static void kazzo_ppu_flash_device_get(const int *d, uint8_t s[2])
+static void kazzo_ppu_flash_device_get(const struct reader_handle *h, uint8_t s[2])
 {
-       read_main(d, &GAUGE_DUMMY, REQUEST_FLASH_DEVICE, INDEX_PPU, 0, 2, s);
+       read_main(h, &GAUGE_DUMMY, REQUEST_FLASH_DEVICE, INDEX_PPU, 0, 2, s);
 }
-static uint8_t kazzo_vram_connection(const int *d)
+static uint8_t kazzo_vram_connection(const struct reader_handle *h)
 {
        uint8_t s;
-       read_main(d, &GAUGE_DUMMY, REQUEST_VRAM_CONNECTION, INDEX_IMPLIED, 0, 1, &s);
+       read_main(h, &GAUGE_DUMMY, REQUEST_VRAM_CONNECTION, INDEX_IMPLIED, 0, 1, &s);
        return s;
 }
 const struct reader_driver DRIVER_KAZZO = {
index 1b9a07a..3a831ae 100644 (file)
@@ -1,4 +1,4 @@
 #ifndef _READER_KAZZO_H_
 #define _READER_KAZZO_H_
-const struct reader_driver DRIVER_KAZZO;
+extern const struct reader_driver DRIVER_KAZZO;
 #endif
index 199ac33..2e97ce6 100644 (file)
@@ -9,22 +9,23 @@
 
 struct textcontrol;
 struct gauge;
+struct reader_handle;
 
 struct reader_memory_access{
-       void (*memory_read)(const int *d, const struct gauge *g, long address, long length, uint8_t *data);
-       void (*memory_write)(const int *d, long address, long length, const uint8_t *data);
-       void (*flash_config)(const int *d, long c000x, long c2aaa, long c5555, long unit, bool retry);
-       void (*flash_erase)(const int *d, long address, bool wait);
-       long (*flash_program)(const int *d, const struct gauge *g, long address, long length, const uint8_t *data, bool wait, bool skip);
-       void (*flash_device_get)(const int *d, uint8_t s[2]);
+       void (*memory_read)(const struct reader_handle *h, const struct gauge *g, long address, long length, uint8_t *data);
+       void (*memory_write)(const struct reader_handle *h, long address, long length, const uint8_t *data);
+       void (*flash_config)(const struct reader_handle *h, long c000x, long c2aaa, long c5555, long unit, bool retry);
+       void (*flash_erase)(const struct reader_handle *h, long address, bool wait);
+       long (*flash_program)(const struct reader_handle *h, const struct gauge *g, long address, long length, const uint8_t *data, bool wait, bool skip);
+       void (*flash_device_get)(const struct reader_handle *h, uint8_t s[2]);
 };
 struct reader_control{
        const char *name;
-       const int *(*open)(void);
-       void (*close)(const int *h);
-       void (*init)(const int *d);
-       void (*flash_status)(const int *d, uint8_t s[2]);
-       uint8_t (*vram_connection)(const int *d);
+       const struct reader_handle *(*open)(void (*except)(const char *str));
+       void (*close)(const struct reader_handle *h);
+       void (*init)(const struct reader_handle *h);
+       void (*flash_status)(const struct reader_handle *h, uint8_t s[2]);
+       uint8_t (*vram_connection)(const struct reader_handle *h);
 };
 struct reader_driver{
        const struct reader_control control;