OSDN Git Service

script 実行結果をみて音を出すようにした
authornaruko <naruko@24ea1065-a21e-4ca1-99c9-f5125deb0858>
Sat, 30 Oct 2010 03:35:09 +0000 (03:35 +0000)
committernaruko <naruko@24ea1065-a21e-4ca1-99c9-f5125deb0858>
Sat, 30 Oct 2010 03:35:09 +0000 (03:35 +0000)
git-svn-id: svn+ssh://svn.osdn.net/svnroot/unagi@383 24ea1065-a21e-4ca1-99c9-f5125deb0858

client/trunk/anago/anago_cui.c
client/trunk/anago/anago_frame.cpp
client/trunk/anago/anago_gui.cpp
client/trunk/anago/anago_gui.fbp
client/trunk/anago/script_dump.c
client/trunk/anago/script_dump.h
client/trunk/anago/script_program.c
client/trunk/anago/script_program.h

index 4ab7842..9b4732f 100644 (file)
 #include "flash_device.h"
 #include "script_program.h"
 
+#ifdef _UNICODE
+  #define PUTS _putws
+  #define PRINTF wprintf
+#else
+  #define PUTS puts
+  #define PRINTF printf
+#endif
+
 static void text_append_va(void *obj, const wgChar *format, va_list list)
 {
+#ifdef _UNICODE
        vwprintf(format, list);
+#else
+       vprintf(format, list);
+#endif
 }
 
 static void text_append(void *obj, const wgChar *format, ...)
@@ -33,12 +45,6 @@ static void log_set(struct textcontrol *log)
        log->append_va = text_append_va;
 }
 
-#ifdef _UNICODE
-  #define PUTS _putws
-#else
-  #define PUTS puts
-#endif
-
 static void except(const wgChar *str)
 {
        PUTS(str);
@@ -49,11 +55,7 @@ static bool program_rom_set(const wgChar *device, wgChar trans, struct memory *m
 {
        m->offset = 0;
        if(flash_device_get(device, f) == false){
-#ifdef _UNICODE
-               wprintf(L"unknown flash memory device %s\n", device);
-#else
-               printf("unknown flash memory device %s\n", device);
-#endif
+               PRINTF(wgT("unknown flash memory device %s\n"), device);
                return false;
        }
        switch(trans){
@@ -198,11 +200,7 @@ static void dump(int c, wgChar **v)
 static void usage(const wgChar *v)
 {
        PUTS(wgT("famicom bus simluator 'anago'"));
-#ifdef _UNICODE
-       wprintf(L"%s [mode] [script] [target] ....\n", v);
-#else
-       printf("%s [mode] [script] [target] ....\n", v);
-#endif
+       PRINTF(wgT("%s [mode] [script] [target] ....\n"), v);
 }
 
 #ifdef WIN32
@@ -218,9 +216,9 @@ int anago_cui(int c, wgChar **v)
                wchar_t **v;
                v = Malloc(sizeof(wchar_t *) * c);
                for(i = 0; i < c; i++){
-                       size_t len = strlen(vv[i]);
-                       v[i] = Malloc(sizeof(wchar_t) * (len + 1));
-                       mbstowcs(v[i], vv[i], len + 1);
+                       size_t len = strlen(vv[i]) + 1;
+                       v[i] = Malloc(sizeof(wchar_t) * len);
+                       mbstowcs(v[i], vv[i], len);
                }
 #endif
                switch(v[1][0]){
@@ -241,8 +239,12 @@ int anago_cui(int c, wgChar **v)
                }
                Free(v);
 #endif
-       }else{
-               //usage(v[0]);
+       }else{ //usage
+               size_t len = strlen(vv[0]) + 1;
+               wchar_t *t = Malloc(sizeof(wchar_t) * len);
+               mbstowcs(t, vv[0], len);
+               usage(t);
+               Free(t);
        }
        mm_end();
        return 0;
index 255f03e..18d9fea 100644 (file)
@@ -3,6 +3,7 @@
 #include <wx/thread.h>
 #include <wx/dir.h>
 #include <wx/sound.h>
+#include <wx/fileconf.h>
 #include <cstdarg>
 #include "type.h"
 #include "anago_gui.h"
@@ -116,11 +117,13 @@ void choice_append(void *choice, const wxChar *str)
 
 //---- script execute thread ----
 class anago_frame;
+
 class anago_dumper : public wxThread
 {
 private:
        anago_frame *m_frame;
        struct dump_config m_config;
+       const wxSound m_sound_success, m_sound_fail;
 protected:
        void *Entry(void);
        void OnExit()
@@ -129,7 +132,8 @@ protected:
                delete [] m_config.target;
        }
 public:
-       anago_dumper(anago_frame *f, const struct dump_config *d) : wxThread()
+       anago_dumper(anago_frame *f, const struct dump_config *d, wxString sound_success, wxString sound_fail) 
+         : wxThread(), m_sound_success(sound_success), m_sound_fail(sound_fail)
        {
                m_frame = f;
                m_config = *d; //struct data copy
@@ -141,6 +145,7 @@ class anago_programmer : public wxThread
 private:
        anago_frame *m_frame;
        struct program_config m_config;
+       const wxSound m_sound_success, m_sound_fail;
 protected:
        void *Entry(void);
        void OnExit()
@@ -149,7 +154,8 @@ protected:
                delete [] m_config.target;
        }
 public:
-       anago_programmer(anago_frame *f, const struct program_config *d) : wxThread()
+       anago_programmer(anago_frame *f, const struct program_config *d, wxString sound_success, wxString sound_fail) 
+         : wxThread(), m_sound_success(sound_success), m_sound_fail(sound_fail)
        {
                m_frame = f;
                m_config = *d;
@@ -161,6 +167,9 @@ class anago_frame : public frame_main
 {
 private:
        wxThread *m_anago_thread;
+       const wxString m_config_file;
+       wxString m_dump_sound_success, m_dump_sound_fail;
+       wxString m_program_sound_success, m_program_sound_fail;
        enum{
                STATUS_IDLE, STATUS_DUMPPING, STATUS_PROGRAMMING
        }m_status;
@@ -275,7 +284,7 @@ private:
 /*             if(m_anago_thread != NULL){ //???
                        delete m_anago_thread;
                }*/
-               m_anago_thread = new anago_dumper(this, &config);
+               m_anago_thread = new anago_dumper(this, &config, m_dump_sound_success, m_dump_sound_fail);
                if(m_anago_thread->Create() != wxTHREAD_NO_ERROR){
                        *m_log << wxT("thread creating error");
                }else if(m_anago_thread->Run() != wxTHREAD_NO_ERROR){
@@ -387,7 +396,7 @@ private:
                m_program_ppu_device->Disable();
                m_program_compare->Disable();
 
-               m_anago_thread = new anago_programmer(this, &f);
+               m_anago_thread = new anago_programmer(this, &f, m_program_sound_success, m_program_sound_fail);
                if(m_anago_thread->Create() != wxTHREAD_NO_ERROR){
                        *m_log << wxT("thread creating error");
                }else if(m_anago_thread->Run() != wxTHREAD_NO_ERROR){
@@ -442,18 +451,48 @@ protected:
        }
 public:
        /** Constructor */
-       anago_frame( wxWindow* parent ) : frame_main(parent)
+       anago_frame( wxWindow* parent )
+         : frame_main(parent), 
+#ifdef WIN32
+         m_config_file(wxGetCwd() + wxT("/anago.cfg"))
+#else
+         m_config_file(wxT(".anago"))
+#endif
        {
+//form config load
+               {
+                       wxFileConfig config(wxEmptyString, wxEmptyString, m_config_file);
+                       wxPoint position;
+                       
+                       config.Read(wxT("position.x"), &position.x, 32);
+                       config.Read(wxT("position.y"), &position.y, 32);
+                       this->SetPosition(position);
+                       
+                       wxSize size;
+                       config.Read(wxT("size.x"), &size.x, 340);
+                       config.Read(wxT("size.y"), &size.y, 460);
+                       this->SetSize(size);
+                       
+                       config.Read(wxT("program.sound.success"), &m_program_sound_success, wxT("cuckoo.wav"));
+                       config.Read(wxT("program.sound.fail"), &m_program_sound_fail, wxT("doggrowl.wav"));
+
+                       config.Read(wxT("dump.sound.success"), &m_dump_sound_success, wxT("tinkalink2.wav"));
+                       config.Read(wxT("dump.sound.fail"), &m_dump_sound_fail, wxT("doggrowl.wav"));
+               }
+
+//form item init
                this->script_choice_init(m_dump_script_choice, wxT("*.ad"));
                this->script_choice_init(m_program_script_choice, wxT("*.af"));
                this->dump_increase_init(m_dump_cpu_increase);
                this->dump_increase_init(m_dump_ppu_increase);
 
-               struct flash_listup list;
-               list.obj_cpu = m_program_cpu_device;
-               list.obj_ppu = m_program_ppu_device;
-               list.append = choice_append;
-               flash_device_listup(&list);
+               {
+                       struct flash_listup list;
+                       list.obj_cpu = m_program_cpu_device;
+                       list.obj_ppu = m_program_ppu_device;
+                       list.append = choice_append;
+                       flash_device_listup(&list);
+               }
                if(m_program_cpu_device->GetCount() == 0){
                        *m_log << wxT("warning: flash device parameter not found\n");
                }else{
@@ -467,14 +506,15 @@ public:
                m_status = STATUS_IDLE;
 
 //version infomation
-               struct textcontrol detail;
-               *m_version_detail << wxT("anago build at ") << wxT(__DATE__) << wxT("\n\n");
-               detail.object = m_version_detail;
-               detail.append = version_append;
-               detail.append_va = version_append_va;
-               qr_version_print(&detail);
-               *m_version_detail << wxVERSION_STRING << wxT(" (c) Julian Smar");
-               
+               {
+                       struct textcontrol detail;
+                       *m_version_detail << wxT("anago build at ") << wxT(__DATE__) << wxT("\n\n");
+                       detail.object = m_version_detail;
+                       detail.append = version_append;
+                       detail.append_va = version_append_va;
+                       qr_version_print(&detail);
+                       *m_version_detail << wxVERSION_STRING << wxT(" (c) Julian Smar");
+               }
 #ifdef WIN32
                #include "okada.xpm"
                wxBitmap bitmap_okada(okada);
@@ -533,22 +573,32 @@ public:
        {
                *m_log << t;
        }
+       virtual ~anago_frame(void)
+       {
+               wxFileConfig config(wxEmptyString, wxEmptyString, m_config_file);
+               wxPoint position = this->GetPosition();
+               
+               config.Write(wxT("position.x"), position.x);
+               config.Write(wxT("position.y"), position.y);
+
+               wxSize size = this->GetSize();
+               config.Write(wxT("size.x"), size.x);
+               config.Write(wxT("size.y"), size.y);
+       }
 };
 
 
 void *anago_dumper::Entry(void)
 {
        try{
-               script_dump_execute(&m_config);
-
-               wxSound sound(wxT("tinkalink2.wav"), false);
-               if(sound.IsOk() == true){
-                       sound.Play();
+               if(script_dump_execute(&m_config) == true){
+                       if(m_sound_success.IsOk() == true){
+                               m_sound_success.Play();
+                       }
                }
        }catch(const wxChar *t){
-               wxSound sound(wxT("doggrowl.wav"), false);
-               if(sound.IsOk() == true){
-                       sound.Play();
+               if(m_sound_fail.IsOk() == true){
+                       m_sound_fail.Play();
                }
                m_frame->LogAppend(t);
        }
@@ -559,16 +609,14 @@ void *anago_dumper::Entry(void)
 void *anago_programmer::Entry(void)
 {
        try{
-               script_program_execute(&m_config);
-
-               wxSound sound(wxT("cuckoo.wav"), false);
-               if(sound.IsOk() == true){
-                       sound.Play();
+               if(script_program_execute(&m_config) == true){
+                       if(m_sound_success.IsOk() == true){
+                               m_sound_success.Play();
+                       }
                }
        }catch(const wxChar *t){
-               wxSound sound(wxT("doggrowl.wav"), false);
-               if(sound.IsOk() == true){
-                       sound.Play();
+               if(m_sound_fail.IsOk() == true){
+                       m_sound_fail.Play();
                }
                m_frame->LogAppend(t);
        }
index 0fcd21c..fcbdd12 100644 (file)
@@ -41,7 +41,7 @@ frame_main::frame_main( wxWindow* parent, wxWindowID id, const wxString& title,
        m_dump_romimage_label->Wrap( -1 );
        fgSizer1->Add( m_dump_romimage_label, 0, wxALL, 5 );
        
-       m_dump_romimage_picker = new wxFilePickerCtrl( m_panel_dump, wxID_ANY, wxEmptyString, wxT("Select a file"), wxT("*.*"), wxDefaultPosition, wxDefaultSize, wxFLP_DEFAULT_STYLE|wxFLP_OVERWRITE_PROMPT|wxFLP_SAVE|wxFLP_USE_TEXTCTRL );
+       m_dump_romimage_picker = new wxFilePickerCtrl( m_panel_dump, wxID_ANY, wxEmptyString, wxT("Select a file"), wxT("*.nes"), wxDefaultPosition, wxDefaultSize, wxFLP_DEFAULT_STYLE|wxFLP_OVERWRITE_PROMPT|wxFLP_SAVE|wxFLP_USE_TEXTCTRL );
        fgSizer1->Add( m_dump_romimage_picker, 0, wxALL|wxEXPAND, 5 );
        
        bSizer9->Add( fgSizer1, 0, wxEXPAND, 5 );
index d8698a4..fb6a0af 100644 (file)
                                                     <property name="validator_type">wxDefaultValidator</property>\r
                                                     <property name="validator_variable"></property>\r
                                                     <property name="value"></property>\r
-                                                    <property name="wildcard">*.*</property>\r
+                                                    <property name="wildcard">*.nes</property>\r
                                                     <property name="window_extra_style"></property>\r
                                                     <property name="window_name"></property>\r
                                                     <property name="window_style"></property>\r
index aab1ae5..574b6f8 100644 (file)
@@ -336,7 +336,7 @@ static void dump_memory_driver_init(struct dump_memory_driver *dd)
        dd->read_count = 0;
 }
 
-void script_dump_execute(struct dump_config *d)
+bool script_dump_execute(struct dump_config *d)
 {
        dump_memory_driver_init(&d->cpu);
        d->cpu.memory.name = wgT("Program");
@@ -355,7 +355,7 @@ void script_dump_execute(struct dump_config *d)
                qr_function_register_global(v, wgT("require"), script_require);
                if(script_execute(v, d) == false){
                        qr_close(v);
-                       return;
+                       return false;
                }
                qr_close(v);
        }
@@ -365,11 +365,11 @@ void script_dump_execute(struct dump_config *d)
        d->handle = d->control->open(d->except);
        if(d->handle == NULL){
                d->log.append(d->log.object, wgT("reader open error\n"));
-               return;
+               return false;
        }
        d->control->init(d->handle);
        if(connection_check(d->handle, &d->log, d->cpu.access, d->ppu.access) == false){
-               return;
+               return false;
        }
        {
                HSQUIRRELVM v = qr_open(&d->log); 
@@ -385,4 +385,5 @@ void script_dump_execute(struct dump_config *d)
        }
        d->control->close(d->handle);
        d->handle = NULL;
+       return true;
 }
index 8cdaad9..b1be3af 100644 (file)
@@ -17,5 +17,5 @@ struct dump_config{
        struct textcontrol log;
        void (*except)(const wgChar *str);
 };
-void script_dump_execute(struct dump_config *c);
+bool script_dump_execute(struct dump_config *c);
 #endif
index ee4ce9b..e6730ab 100644 (file)
@@ -360,7 +360,7 @@ static bool script_execute(HSQUIRRELVM v, const wgChar *function, struct program
        return ret;
 }
 
-static void zendan(struct program_config *c)
+static bool zendan(struct program_config *c)
 {
 //script test run
        {
@@ -383,19 +383,19 @@ static void zendan(struct program_config *c)
                
                if(script_execute(v, wgT("testrun"), c) == false){
                        qr_close(v);
-                       return;
+                       return false;
                }
                qr_close(v);
                assert(c->cpu.memory.size != 0);
 
                if(c->cpu.programming.count % c->cpu.memory.size  != 0){
                        c->log.append(c->log.object, wgT("logical error: cpu_programsize is not connected 0x%06x/0x%06x\n"), (int) c->cpu.programming.count, (int) c->cpu.memory.size);
-                       return;
+                       return false;
                }
                if(c->ppu.memory.size != 0){
                        if(c->ppu.programming.count % c->ppu.memory.size != 0){
                                c->log.append(c->log.object, wgT("logical error: ppu_programsize is not connected 0x%06x/0x%06x\n"), (int) c->ppu.programming.count, (int) c->ppu.memory.size);
-                               return;
+                               return false;
                        }
                }
        }
@@ -419,6 +419,7 @@ static void zendan(struct program_config *c)
                script_execute(v, wgT("program"), c);
                qr_close(v);
        }
+       return true;
 }
 
 static bool memory_image_init(const struct memory *from, struct flash_memory_driver *t, struct textcontrol *log)
@@ -441,40 +442,41 @@ static bool memory_image_init(const struct memory *from, struct flash_memory_dri
        return true;
 }
 
-void script_program_execute(struct program_config *c)
+bool script_program_execute(struct program_config *c)
 {
 //rom image load
        struct romimage rom;
        if(nesfile_load(&c->log, c->target, &rom) == false){
                c->log.append(c->log.object, wgT("ROM image open error"));
-               return;
+               return false;
        }
 //variable init
        c->mappernum = rom.mappernum;
        c->cpu.memory.name = wgT("Program Flash");
        if(memory_image_init(&rom.cpu_rom, &c->cpu, &c->log) == false){
                nesbuffer_free(&rom, 0);
-               return;
+               return false;
        }
        c->ppu.memory.name = wgT("Charcter Flash");
        if(memory_image_init(&rom.ppu_rom, &c->ppu, &c->log) == false){
                nesbuffer_free(&rom, 0);
-               return;
+               return false;
        }
 //reader initalize
        c->handle = c->control->open(c->except);
        if(c->handle == NULL){
                c->log.append(c->log.object, wgT("reader open error\n"));
                nesbuffer_free(&rom, 0);
-               return;
+               return false;
        }
 //program start, reader finalize
        if(connection_check(c->handle, &c->log, c->cpu.access, c->ppu.access) == false){
                nesbuffer_free(&rom, 0);
-               return;
+               return false;
        }
-       zendan(c);
+       bool ret = zendan(c);
        c->control->close(c->handle);
        c->handle = NULL;
        nesbuffer_free(&rom, 0);
+       return ret;
 }
index cc5ccdb..b59dbb5 100644 (file)
@@ -21,5 +21,5 @@ struct program_config{
        struct textcontrol log;
        void (*except)(const wgChar *str);
 };
-void script_program_execute(struct program_config *c);
+bool script_program_execute(struct program_config *c);
 #endif