OSDN Git Service

anago: flash device をスクリプト化
authornaruko <naruko@24ea1065-a21e-4ca1-99c9-f5125deb0858>
Fri, 6 Nov 2009 14:27:28 +0000 (14:27 +0000)
committernaruko <naruko@24ea1065-a21e-4ca1-99c9-f5125deb0858>
Fri, 6 Nov 2009 14:27:28 +0000 (14:27 +0000)
git-svn-id: svn+ssh://svn.osdn.net/svnroot/unagi@302 24ea1065-a21e-4ca1-99c9-f5125deb0858

client/trunk/anago/Makefile
client/trunk/anago/anago.c
client/trunk/anago/flash_device.c [new file with mode: 0644]
client/trunk/anago/flash_device.h [new file with mode: 0644]
client/trunk/anago/flashcore.nut [moved from client/trunk/anago/flashmode.nut with 100% similarity]
client/trunk/anago/script.c
client/trunk/anago/script.h
client/trunk/header.h
client/trunk/waveform_dozeu.h [deleted file]

index dcc5240..3a4df82 100644 (file)
@@ -5,7 +5,8 @@ VPATH = ..
 CFLAGS = -g -O0 -Wall -Werror -I.. -I$(LIBUSB)/include -I$(SQUIRREL)/include -DDEBUG=1 -DANAGO=1
 LDFLAG = -L. -L$(LIBUSB)/lib/gcc -L$(SQUIRREL)/lib
 CC = gcc
-OBJ = anago.o flashmemory.o header.o crc32.o file.o script.o \
+OBJ = anago.o header.o crc32.o file.o script.o \
+       flash_device.o \
        reader_dummy.o reader_kazzo.o usb_device.o squirrel_wrap.o memory_manage.o
 clean:
        rm -f $(OBJ)
index 32a4549..68b9ea9 100644 (file)
@@ -2,7 +2,8 @@
 #include <stdbool.h>
 #include "memory_manage.h"
 #include "type.h"
-#include "flashmemory.h"
+//#include "flashmemory.h"
+#include "flash_device.h"
 #include "header.h"
 #include "reader_master.h"
 #include "reader_kazzo.h"
@@ -60,20 +61,19 @@ static bool config_parse(const char *romimage, const char *device_cpu, const cha
        }
        c->rom.cpu_rom.offset = 0;
        c->rom.ppu_rom.offset = 0;
-       c->flash_cpu = flash_driver_get(device_cpu);
-       if(device_ppu != NULL){
-               c->flash_ppu = flash_driver_get(device_ppu);
-       }else{
-               c->flash_ppu = flash_driver_get("dummy");
+       if(flash_device_get(device_cpu, &c->flash_cpu) == false){
+               printf("unkown flash memory device %s\n", device_cpu);
+               return false;
        }
-       if(c->flash_cpu == NULL || c->flash_ppu == NULL){
+       if(flash_device_get(device_ppu, &c->flash_ppu) == false){
+               printf("unkown flash memory device %s\n", device_ppu);
                return false;
        }
-       if(c->flash_cpu->id_device == FLASH_ID_DEVICE_DUMMY){
+       if(c->flash_cpu.id_device == FLASH_ID_DEVICE_DUMMY){
                c->rom.cpu_rom.transtype = TRANSTYPE_EMPTY;
        }
        if(
-               (c->flash_ppu->id_device == FLASH_ID_DEVICE_DUMMY) ||
+               (c->flash_ppu.id_device == FLASH_ID_DEVICE_DUMMY) ||
                (c->rom.ppu_rom.size == 0)
        ){
                c->rom.ppu_rom.transtype = TRANSTYPE_EMPTY;
@@ -84,7 +84,6 @@ static void anago(int c, char **v)
 {
        struct config config;
        config.script = v[2];
-       config.flash_ppu = &FLASH_DRIVER_UNDEF;
        config.reader = &DRIVER_KAZZO;
        if(v[1][0] == 'd'){
                config.reader = &DRIVER_DUMMY;
@@ -95,7 +94,7 @@ static void anago(int c, char **v)
        }
        switch(c){
        case 5: //mode script target cpu_flash_device
-               if(config_parse(v[3], v[4], NULL, &config) == false){
+               if(config_parse(v[3], v[4], "dummy", &config) == false){
                        nesbuffer_free(&config.rom, 0);
                        return;
                }
diff --git a/client/trunk/anago/flash_device.c b/client/trunk/anago/flash_device.c
new file mode 100644 (file)
index 0000000..3388b2e
--- /dev/null
@@ -0,0 +1,107 @@
+#include <assert.h>
+#include <stdio.h>
+#include <squirrel.h>
+#include <sqstdio.h>
+#include <sqstdaux.h>
+#include "type.h"
+#include "memory_manage.h"
+#include "squirrel_wrap.h"
+#include "flash_device.h"
+
+static void call(HSQUIRRELVM v, const char *devicename)
+{
+       sq_pushroottable(v);
+       sq_pushstring(v, _SC("flash_device_get"), -1);
+       if(SQ_SUCCEEDED(sq_get(v,-2))){
+               sq_pushroottable(v);
+               sq_pushstring(v, _SC(devicename), -1);
+               SQRESULT r = sq_call(v, 2, SQTrue, SQTrue);
+               assert(r == SQ_OK);
+       }
+}
+static bool long_get(HSQUIRRELVM v, const char *field, long *ret)
+{
+       sq_pushstring(v, _SC(field), -1);
+       SQRESULT r = sq_get(v, -2);
+       if(r != SQ_OK){
+               return false;
+       }
+       if(sq_gettype(v, -1) != OT_INTEGER){
+               return false;
+       }
+       SQInteger i;
+       r = sq_getinteger(v, -1, &i);
+       if(r != SQ_OK){
+               return false;
+       }
+       *ret = (long) i;
+       sq_pop(v, 1);
+       return true;
+}
+static bool bool_get(HSQUIRRELVM v, const char *field, bool *ret)
+{
+       sq_pushstring(v, _SC(field), -1);
+       SQRESULT r = sq_get(v, -2);
+       if(r != SQ_OK){
+               return false;
+       }
+       if(sq_gettype(v, -1) != OT_BOOL){
+               return false;
+       }
+       SQBool i;
+       r = sq_getbool(v, -1, &i);
+       if(r != SQ_OK){
+               return false;
+       }
+       if(i == SQTrue){
+               *ret = true;
+       }else{
+               *ret = false;
+       }
+       sq_pop(v, 1);
+       return true;
+}
+bool flash_device_get(const char *name, struct flash_device *t)
+{
+       HSQUIRRELVM v = qr_open(); 
+       if(SQ_FAILED(sqstd_dofile(v, _SC("flashdevice.nut"), SQFalse, SQTrue))){
+               puts("flash device script error");
+               qr_close(v);
+               return false;
+       }
+       SQInteger top = sq_gettop(v);
+       call(v, name);
+       if(sq_gettype(v, -1) != OT_TABLE){
+               goto field_error;
+       }
+       t->name = name;
+       if(long_get(v, "capacity", &t->capacity) == false){
+               goto field_error;
+       }
+       if(long_get(v, "pagesize", &t->pagesize) == false){
+               goto field_error;
+       }
+       if(long_get(v, "erase_wait", &t->erase_wait) == false){
+               goto field_error;
+       }
+       if(bool_get(v, "erase_require", &t->erase_require) == false){
+               goto field_error;
+       }
+       long dd;
+       if(long_get(v, "id_manufacurer", &dd) == false){
+               goto field_error;
+       }
+       t->id_manufacurer = dd;
+       if(long_get(v, "id_device", &dd) == false){
+               goto field_error;
+       }
+       t->id_device = dd;
+       sq_settop(v, top);
+       qr_close(v);
+       return true;
+
+field_error:
+       puts("script field error");
+       qr_close(v);
+       return false;
+}
diff --git a/client/trunk/anago/flash_device.h b/client/trunk/anago/flash_device.h
new file mode 100644 (file)
index 0000000..b95922f
--- /dev/null
@@ -0,0 +1,17 @@
+#ifndef _FLASH_DEVICE_H_
+#define _FLASH_DEVICE_H_
+struct flash_device{
+       const char *name;
+       long capacity, pagesize;
+       long erase_wait; //unit is msec
+       bool erase_require;
+       uint8_t id_manufacurer, id_device;
+};
+
+bool flash_device_get(const char *name, struct flash_device *t);
+//0x80 °Ê¹ß¤ÏËÜÅö¤Î¥Ç¥Ð¥¤¥¹½ÅÊ£¤·¤Ê¤¤¤È»×¤¦. Ã¯¤« JEDEC ¤Î¤È¤³¤ò¤·¤é¤Ù¤Æ.
+enum{
+       FLASH_ID_DEVICE_SRAM = 0xf0, 
+       FLASH_ID_DEVICE_DUMMY
+};
+#endif
index c966c35..7fbe1b7 100644 (file)
@@ -6,14 +6,16 @@
 #include "header.h"
 #include "reader_master.h"
 #include "squirrel_wrap.h"
+#include "flash_device.h"
 #include "script.h"
 
 struct anago_driver{
        struct anago_flash_order{
                bool command_change;
                long address, length;
-               long c000x, c2aaa, c5555, unit;
-               struct memory *memory;
+               long c000x, c2aaa, c5555;
+               struct memory *const memory;
+               struct flash_device *const device;
                void (*const config)(long c000x, long c2aaa, long c5555, long unit);
                void (*const device_get)(uint8_t s[2]);
                void (*const write)(long address, long length, const uint8_t *data);
@@ -89,11 +91,13 @@ static SQInteger cpu_write(HSQUIRRELVM v)
 }
 static SQInteger erase_set(HSQUIRRELVM v, struct anago_flash_order *t, const char *region)
 {
-       t->config(t->c000x, t->c2aaa, t->c5555, t->unit);
+       t->config(t->c000x, t->c2aaa, t->c5555, t->device->pagesize);
        t->command_change = false;
-       t->erase(t->c2aaa, false);
-       printf("erasing %s memory...\n", region);
-       fflush(stdout);
+       if(t->device->erase_require == true){
+               t->erase(t->c2aaa, false);
+               printf("erasing %s memory...\n", region);
+               fflush(stdout);
+       }
        return 0; //sq_suspendvm(v);
 }
 static SQInteger cpu_erase(HSQUIRRELVM v)
@@ -121,7 +125,7 @@ static SQInteger program_regist(HSQUIRRELVM v, const char *name, struct anago_fl
                return r;
        }
        if(t->command_change == true){
-               t->config(t->c000x, t->c2aaa, t->c5555, t->unit);
+               t->config(t->c000x, t->c2aaa, t->c5555, t->device->pagesize);
                t->command_change = false;
        }
        
@@ -172,24 +176,6 @@ static SQInteger erase_wait(HSQUIRRELVM v)
        }while((s[0] != 0) && (s[1] != 0));
        return 0;
 }
-/*static void execute_main(HSQUIRRELVM v, struct config *c)
-{
-       if(SQ_FAILED(sqstd_dofile(v, _SC("flashmode.nut"), SQFalse, SQTrue)))
-       {
-               return;
-       }
-       if(SQ_FAILED(sqstd_dofile(v, _SC(c->script), SQFalse, SQTrue)))
-       {
-               printf("%s open error\n", c->script);
-               return;
-       }
-       qr_call(
-               v, "program", NULL, true, 
-               5, c->rom.mappernum, 
-               order_cpu.memory->transtype, order_cpu.memory->size, 
-               order_ppu.memory->transtype, order_ppu.memory->size
-       );
-}*/
 
 static SQInteger program_main(HSQUIRRELVM v)
 {
@@ -238,7 +224,7 @@ void script_execute(struct config *c)
        struct anago_driver d = {
                .order_cpu = {
                        .command_change = true,
-                       .unit = c->flash_cpu->pagesize,
+                       .device = &c->flash_cpu,
                        .memory = &c->rom.cpu_rom,
                        .config = c->reader->cpu_flash_config,
                        .device_get = c->reader->cpu_flash_device_get,
@@ -249,11 +235,11 @@ void script_execute(struct config *c)
                },
                .order_ppu = {
                        .command_change = true,
-                       .unit = c->flash_ppu->pagesize,
+                       .device = &c->flash_ppu,
                        .memory = &c->rom.ppu_rom,
                        .config = c->reader->ppu_flash_config,
                        .device_get = c->reader->ppu_flash_device_get,
-                       .write = c->reader->ppu_write, //warning ¤Ï̵»ë
+                       .write = c->reader->ppu_write,
                        .read = c->reader->ppu_read,
                        .erase = c->reader->ppu_flash_erase,
                        .program = c->reader->ppu_flash_program,
@@ -272,11 +258,10 @@ void script_execute(struct config *c)
        qr_function_register_global(v, "program_main", program_main);
        qr_function_register_global(v, "erase_wait", erase_wait);
        
-       if(SQ_FAILED(sqstd_dofile(v, _SC("flashmode.nut"), SQFalse, SQTrue))){
-               return;
+       if(SQ_FAILED(sqstd_dofile(v, _SC("flashcore.nut"), SQFalse, SQTrue))){
+               printf("flash core script error\n");
        }else if(SQ_FAILED(sqstd_dofile(v, _SC(c->script), SQFalse, SQTrue))){
                printf("%s open error\n", c->script);
-               return;
        }else{
                qr_call(
                        v, "program", (SQUserPointer) &d, true, 
index 39330d4..dd850ec 100644 (file)
@@ -2,7 +2,7 @@
 #define _SCRIPT_H_
 struct config{
        const char *script, *target;
-       const struct flash_driver *flash_cpu, *flash_ppu;
+       struct flash_device flash_cpu, flash_ppu;
        const struct reader_driver *reader;
        struct romimage rom;
 };
index b5d0e4e..4e4ab48 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef _HEADER_H_
 #define _HEADER_H_
+#if ANAGO==0
 #include "flashmemory.h"
+#endif
 enum trastype{
        TRANSTYPE_EMPTY,
        TRANSTYPE_TOP,
@@ -43,7 +45,9 @@ enum vram_mirroring{
 };
 struct romimage{
        struct memory cpu_rom, ppu_rom, cpu_ram;
+#if ANAGO==0
        struct flash_order cpu_flash, ppu_flash;
+#endif
        long mappernum;
        enum vram_mirroring mirror;
        int backupram;
diff --git a/client/trunk/waveform_dozeu.h b/client/trunk/waveform_dozeu.h
deleted file mode 100644 (file)
index cbb1841..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-#ifndef _WAVEFORM_DOZEU_H_
-#define _WAVEFORM_DOZEU_H_
-enum{
-       WAVE_NUM = 4,
-       INIT_SIZE = 8,
-       WAVE_SIZE = 32,
-       FLOW_SIZE = 9
-};
-struct gpif_data{
-       u8 wave[WAVE_NUM][WAVE_SIZE];
-       u8 flow[WAVE_NUM][FLOW_SIZE];
-};
-extern const u8 WAVEFORM_INIT[INIT_SIZE];
-extern const struct gpif_data *const WAVEFORM_DATA;
-#endif