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)
#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"
}
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;
{
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;
}
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;
}
--- /dev/null
+#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;
+}
--- /dev/null
+#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
#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);
}
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)
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;
}
}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)
{
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,
},
.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,
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,
#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;
};
#ifndef _HEADER_H_
#define _HEADER_H_
+#if ANAGO==0
#include "flashmemory.h"
+#endif
enum trastype{
TRANSTYPE_EMPTY,
TRANSTYPE_TOP,
};
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;
+++ /dev/null
-#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