OSDN Git Service

ram mode, database に対応,
[unagi/old-svn-converted.git] / client / trunk / anago / script_program.c
index ee4ce9b..a6c680b 100644 (file)
@@ -6,12 +6,11 @@
 #include <kazzo_task.h>
 #include "type.h"
 #include "widget.h"
-#include "header.h"
+#include "romimage.h"
 #include "memory_manage.h"
 #include "reader_master.h"
 #include "squirrel_wrap.h"
 #include "flash_device.h"
-#include "progress.h"
 #include "script_common.h"
 #include "script_program.h"
 
@@ -131,10 +130,9 @@ static SQInteger program_regist(HSQUIRRELVM v, const struct reader_handle *h, st
                t->command_change = false;
        }
        
-/*     printf("programming %s ROM area 0x%06x...\n", name, t->memory->offset);
-       fflush(stdout);*/
        return sq_suspendvm(v);
 }
+
 static void program_execute(const struct reader_handle *h, struct flash_memory_driver *t)
 {
        const long w = t->access->flash_program(
@@ -232,10 +230,8 @@ static SQInteger erase_wait(HSQUIRRELVM v)
 static void gauge_init(struct flash_memory_driver *t)
 {
        t->gauge.range_set(t->gauge.bar, t->programming.count);
-       t->gauge.value_set(t->gauge.bar, t->gauge.label, t->programming.offset);
-       if(t->programming.count == 0){
-               t->gauge.label_set(t->gauge.label, wgT("skip"));
-       }
+
+       t->gauge.value_set(t->gauge.bar, t->gauge.label, 0);
 }
 
 static bool program_memoryarea(HSQUIRRELVM co, const struct reader_handle *h, struct flash_memory_driver *t, bool compare, SQInteger *state, struct textcontrol *log)
@@ -243,12 +239,12 @@ static bool program_memoryarea(HSQUIRRELVM co, const struct reader_handle *h, st
        if(t->programming.length == 0){
                if(t->programming.offset != 0 && compare == true){
                        if(program_compare(h, t) == false){
-                               log->append(log->object, wgT("%s memory compare error\n"), t->memory.name);
+                               log->append(log->object, wgT("%s memory compare error, offset 0x%06x\n"), t->memory.name, t->programming.offset);
                                return false;
                        }
                }
 
-               sq_wakeupvm(co, SQFalse, SQFalse, SQTrue/*, SQTrue*/);
+               sq_wakeupvm(co, SQFalse, SQFalse, SQTrue, SQFalse);
                *state = sq_getvmstate(co);
        }else{
                program_execute(h, t);
@@ -340,15 +336,12 @@ static SQInteger ppu_program_count(HSQUIRRELVM v)
 static bool script_execute(HSQUIRRELVM v, const wgChar *function, struct program_config *c)
 {
        bool ret = true;
-       if(SQ_FAILED(sqstd_dofile(v, _SC("flashcore.nut"), SQFalse, SQTrue))){
+       if(SQ_FAILED(sqstd_dofile(v, _SC("programcore.nut"), SQFalse, SQTrue))){
                c->log.append(c->log.object, wgT("flash core script error\n"));
                ret = false;
-       }else if(SQ_FAILED(sqstd_dofile(v, c->script, SQFalse, SQTrue))){
-               c->log.append(c->log.object, wgT("%s open error\n"), c->script);
-               ret = false;
        }else{
                SQRESULT r = qr_call(
-                       v, function, (SQUserPointer) c, true, 
+                       v, function, (SQUserPointer) c, c->script,
                        1 + 3 * 2, c->mappernum, 
                        c->cpu.memory.transtype, c->cpu.memory.size, c->cpu.flash.capacity,
                        c->ppu.memory.transtype, c->ppu.memory.size, c->cpu.flash.capacity
@@ -360,7 +353,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 +376,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 +412,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 +435,42 @@ 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);
+       c->handle = c->control->open(c->except, &c->log);
        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;
+               c->control->close(c->handle);
+               return false;
        }
-       zendan(c);
+       bool ret = zendan(c);
        c->control->close(c->handle);
        c->handle = NULL;
        nesbuffer_free(&rom, 0);
+       return ret;
 }