#include <assert.h>
#include <stdio.h>
+#include <string.h>
#include <squirrel.h>
#include <sqstdio.h>
#include <sqstdaux.h>
#include "type.h"
+#include "widget.h"
#include "header.h"
#include "progress.h"
#include "memory_manage.h"
#include "reader_master.h"
#include "squirrel_wrap.h"
+#include "script_common.h"
#include "script_dump.h"
-struct dump_driver{
- const char *target;
- struct memory_driver{
- struct memory memory;
- long read_count;
- void (*const write)(long address, long length, const uint8_t *data);
- void (*const read)(long address, long length, u8 *data);
- }cpu, ppu;
- bool progress;
-};
-static SQInteger write(HSQUIRRELVM v, struct 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);
return r;
}
uint8_t d8 = (uint8_t) data;
- t->write(address, 1, &d8);
+ t->access->memory_write(h, address, 1, &d8);
return 0;
}
static SQInteger cpu_write(HSQUIRRELVM v)
{
- struct dump_driver *d;
- SQRESULT r = qr_userpointer_get(v, (SQUserPointer *) &d);
+ struct dump_config *d;
+ SQRESULT r = qr_userpointer_get(v, (SQUserPointer) &d);
if(SQ_FAILED(r)){
return r;
}
- return write(v, &d->cpu);
+ return write_memory(v, d->handle, &d->cpu);
}
+//¤³¤³¤Î printf ¤Ï debug ÍѤ˻Ĥ·¤Æ¤ª¤¯
static void buffer_show(struct memory *t, long length)
{
int i;
fflush(stdout);
}
-static void progress_show(struct dump_driver *d)
-{
- if(d->progress == true){
- progress_draw(d->cpu.memory.offset, d->cpu.memory.size, d->ppu.memory.offset, d->ppu.memory.size);
- }
-}
-static SQInteger read(HSQUIRRELVM v, struct 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);
if(SQ_FAILED(r)){
return r;
}
- t->read(address, length == 0 ? 1: length, t->memory.data + t->memory.offset);
+ t->access->memory_read(h, &t->gauge, address, length == 0 ? 1: length, t->memory.data + t->memory.offset);
if((length != 0) && (progress == false)){
buffer_show(&t->memory, length);
}
t->memory.offset += length;
+
return 0;
}
+
static SQInteger cpu_read(HSQUIRRELVM v)
{
- struct dump_driver *d;
- SQRESULT r = qr_userpointer_get(v, (SQUserPointer *) &d);
+ struct dump_config *d;
+ SQRESULT r = qr_userpointer_get(v, (SQUserPointer) &d);
if(SQ_FAILED(r)){
return r;
}
- r = read(v, &d->cpu, d->progress);
- progress_show(d);
+ r = read_memory(v, d->handle, &d->cpu, d->progress);
return r;
}
static SQInteger ppu_read(HSQUIRRELVM v)
{
- struct dump_driver *d;
- SQRESULT r = qr_userpointer_get(v, (SQUserPointer *) &d);
+ struct dump_config *d;
+ SQRESULT r = qr_userpointer_get(v, (SQUserPointer) &d);
if(SQ_FAILED(r)){
return r;
}
- r = read(v, &d->ppu, d->progress);
- progress_show(d);
+ r = read_memory(v, d->handle, &d->ppu, d->progress);
return r;
}
static SQInteger ppu_ramfind(HSQUIRRELVM v)
{
- struct dump_driver *d;
+ struct dump_config *d;
enum{
testsize = 8,
testaddress = 1234
static const uint8_t test_val[testsize] = {0xaa, 0x55, 0, 0xff, 0x46, 0x49, 0x07, 0x21};
static const uint8_t test_str[testsize] = "pputest";
uint8_t test_result[testsize];
+ SQRESULT r = qr_userpointer_get(v, (SQUserPointer) &d);
+ struct dump_memory_driver *p = &d->ppu;
- SQRESULT r = qr_userpointer_get(v, (SQUserPointer *) &d);
if(SQ_FAILED(r)){
return r;
}
- d->ppu.write(testaddress, testsize, test_val);
- d->ppu.read(testaddress, testsize, test_result);
+ p->access->memory_write(d->handle, testaddress, testsize, test_val);
+ p->access->memory_read(d->handle, &GAUGE_DUMMY, testaddress, testsize, test_result);
if(memcmp(test_val, test_result, testsize) != 0){
sq_pushbool(v, SQFalse);
return 1;
}
- d->ppu.write(testaddress, testsize, test_str);
- d->ppu.read(testaddress, testsize, test_result);
+ p->access->memory_write(d->handle, testaddress, testsize, test_str);
+ p->access->memory_read(d->handle, &GAUGE_DUMMY, testaddress, testsize, test_result);
if(memcmp(test_str, test_result, testsize) != 0){
sq_pushbool(v, SQFalse);
return 1;
}
- d->ppu.memory.offset = 0;
- d->ppu.memory.size = 0;
+ p->memory.offset = 0;
+ p->memory.size = 0;
sq_pushbool(v, SQTrue);
return 1;
}
+static void memory_new_init(struct dump_memory_driver *d)
+{
+ d->memory.offset = 0;
+ d->memory.data = Malloc(d->memory.size);
+ d->gauge.range_set(d->gauge.bar, d->memory.size);
+ d->gauge.value_set(d->gauge.bar, d->gauge.label, 0);
+}
+
//test »þ/1ÅÙÌܤΠcall ¤Ç»ÈÍÑ
static SQInteger memory_new(HSQUIRRELVM v)
{
- struct dump_driver *d;
- SQRESULT r = qr_userpointer_get(v, (SQUserPointer *) &d);
+ struct dump_config *d;
+ SQRESULT r = qr_userpointer_get(v, (SQUserPointer) &d);
if(SQ_FAILED(r)){
return r;
}
if(SQ_FAILED(r)){
return r;
}
- d->cpu.memory.offset = 0;
- d->cpu.memory.data = Malloc(d->cpu.memory.size);
- d->ppu.memory.offset = 0;
- d->ppu.memory.data = Malloc(d->ppu.memory.size);
+
+ memory_new_init(&d->cpu);
+ memory_new_init(&d->ppu);
return 0;
}
//dump »þ/2ÅÙÌܤΠcall ¤Ç nesfile_save ¤È¤·¤Æ»ÈÍÑ
static SQInteger nesfile_save(HSQUIRRELVM v)
{
- struct dump_driver *d;
- SQRESULT r = qr_userpointer_get(v, (SQUserPointer *) &d);
+ struct dump_config *d;
+ SQRESULT r = qr_userpointer_get(v, (SQUserPointer) &d);
if(SQ_FAILED(r)){
return r;
}
struct romimage image;
- r = qr_argument_get(v, 1, &image.mappernum);
+ long mirrorfind;
+ r = qr_argument_get(v, 2, &image.mappernum, &mirrorfind);
if(SQ_FAILED(r)){
return r;
}
image.cpu_ram.data = NULL;
image.ppu_rom = d->ppu.memory;
image.mirror = MIRROR_PROGRAMABLE;
+ if(mirrorfind == 1){
+ if(d->control->vram_connection(d->handle) == 0x05){
+ image.mirror = MIRROR_VERTICAL;
+ }else{
+ image.mirror = MIRROR_HORIZONAL;
+ }
+ }
image.backupram = 0;
- nesfile_create(&image, d->target);
+ if(d->battery == true){
+ image.backupram = 1;
+ }
+ nesfile_create(&d->log, &image, d->target);
nesbuffer_free(&image, 0); //0 is MODE_xxx_xxxx
d->cpu.memory.data = NULL;
//dump »þ/1ÅÙÌܤΠcall ¤Ç nesfile_save ¤È¤·¤Æ»ÈÍÑ
static SQInteger length_check(HSQUIRRELVM v)
{
- struct dump_driver *d;
- SQRESULT r = qr_userpointer_get(v, (SQUserPointer *) &d);
+ struct dump_config *d;
+ SQRESULT r = qr_userpointer_get(v, (SQUserPointer) &d);
if(SQ_FAILED(r)){
return r;
}
cpu = false;
}
if(cpu == false){
- printf("cpu_romsize is not connected 0x%06x/0x%06x\n", (int) d->cpu.read_count, (int) d->cpu.memory.size);
+ d->log.append(d->log.object, "cpu_romsize is not connected 0x%06x/0x%06x\n", (int) d->cpu.read_count, (int) d->cpu.memory.size);
}
if(d->ppu.memory.size != d->ppu.read_count){
ppu = false;
}
if(ppu == false){
- printf("ppu_romsize is not connected 0x%06x/0x%06x\n", (int) d->ppu.read_count, (int) d->ppu.memory.size);
+ d->log.append(d->log.object, "ppu_romsize is not connected 0x%06x/0x%06x\n", (int) d->ppu.read_count, (int) d->ppu.memory.size);
}
if(cpu == false || ppu == false){
r = sq_throwerror(v, "script logical error");
}
return r;
}
-static SQInteger script_nop(HSQUIRRELVM v)
-{
- return 0;
-}
-struct range{
- long start, end;
-};
-static SQInteger range_check(HSQUIRRELVM v, const char *name, long target, const struct range *range)
-{
- if((target < range->start) || (target > range->end)){
- printf("%s range must be 0x%06x to 0x%06x", name, (int) range->start, (int) range->end);
- return sq_throwerror(v, "script logical error");
- }
- return 0;
-}
-static SQInteger read_count(HSQUIRRELVM v, struct memory_driver *t, const struct range *range_address, const struct range *range_length)
+static SQInteger read_count(HSQUIRRELVM v, const struct textcontrol *l, struct dump_memory_driver *t, const struct range *range_address, const struct range *range_length)
{
long address, length;
SQRESULT r = qr_argument_get(v, 2, &address, &length);
return r;
}
if((address < range_address->start) || ((address + length) > range_address->end)){
- printf("address range must be 0x%06x to 0x%06x", (int) range_address->start, (int) range_address->end);
+ l->append(l->object, "address range must be 0x%06x to 0x%06x", (int) range_address->start, (int) range_address->end);
return sq_throwerror(v, "script logical error");;
}
t->read_count += length;
static const struct range range_address = {0x8000, 0x10000};
//length == 0 ¤Ï Âоݥ¢¥É¥ì¥¹¤ò¸Æ¤ó¤Ç¡¢¥Ð¥Ã¥Õ¥¡¤Ë¤¤¤ì¤Ê¤¤¡£mmc2, mmc4 ¤Ç»ÈÍѤ¹¤ë¡£
static const struct range range_length = {0x0000, 0x4000};
- struct dump_driver *d;
- SQRESULT r = qr_userpointer_get(v, (SQUserPointer *) &d);
+ struct dump_config *d;
+ SQRESULT r = qr_userpointer_get(v, (SQUserPointer) &d);
if(SQ_FAILED(r)){
return r;
}
- return read_count(v, &d->cpu, &range_address, &range_length);
+ return read_count(v, &d->log, &d->cpu, &range_address, &range_length);
}
static SQInteger ppu_read_count(HSQUIRRELVM v)
{
static const struct range range_address = {0x0000, 0x2000};
static const struct range range_length = {0x0001, 0x2000};
- struct dump_driver *d;
- SQRESULT r = qr_userpointer_get(v, (SQUserPointer *) &d);
+ struct dump_config *d;
+ SQRESULT r = qr_userpointer_get(v, (SQUserPointer) &d);
if(SQ_FAILED(r)){
return r;
}
- return read_count(v, &d->ppu, &range_address, &range_length);
+ return read_count(v, &d->log, &d->ppu, &range_address, &range_length);
}
-static SQInteger cpu_write_check(HSQUIRRELVM v)
+static SQInteger memory_size_set(HSQUIRRELVM v)
{
- static const struct range range_address = {0x4000, 0x10000};
- static const struct range range_data = {0x0, 0xff};
- long address, data;
- SQRESULT r = qr_argument_get(v, 2, &address, &data);
- if(SQ_FAILED(r)){
- return r;
- }
- r = range_check(v, "address", address, &range_address);
+ struct dump_config *d;
+ SQRESULT r = qr_userpointer_get(v, (SQUserPointer) &d);
if(SQ_FAILED(r)){
return r;
}
- return range_check(v, "data", data, &range_data);
+ r = qr_argument_get(v, 2, &d->cpu.memory.size, &d->ppu.memory.size);
+ return r;
}
-static bool script_execute(HSQUIRRELVM v, struct config_dump *c, struct dump_driver *d)
+
+static bool script_execute(HSQUIRRELVM v, struct dump_config *d)
{
bool ret = true;
if(SQ_FAILED(sqstd_dofile(v, _SC("dumpcore.nut"), SQFalse, SQTrue))){
- printf("dump core script error\n");
+ d->log.append(d->log.object, "dump core script error\n");
ret = false;
- }else if(SQ_FAILED(sqstd_dofile(v, _SC(c->script), SQFalse, SQTrue))){
- printf("%s open error\n", c->script);
+ }else if(SQ_FAILED(sqstd_dofile(v, _SC(d->script), SQFalse, SQTrue))){
+ d->log.append(d->log.object, "%s open error\n", d->script);
ret = false;
}else{
SQRESULT r = qr_call(
v, "dump", (SQUserPointer) d, true,
- 3, c->mappernum, c->increase.cpu, c->increase.ppu
+ 3, d->mappernum, d->cpu.increase, d->ppu.increase
);
if(SQ_FAILED(r)){
ret = false;
}
return ret;
}
-void script_dump_execute(struct config_dump *c)
+
+static void dump_memory_driver_init(struct dump_memory_driver *dd)
+{
+ dd->memory.size = 0;
+ dd->memory.offset = 0;
+ dd->memory.attribute = MEMORY_ATTR_WRITE;
+ dd->memory.transtype = TRANSTYPE_FULL;
+ dd->memory.data = NULL;
+ dd->read_count = 0;
+}
+
+void script_dump_execute(struct dump_config *d)
{
- struct dump_driver d = {
- .cpu = {
- .memory = {
- .name = "program",
- .size = 0, .offset = 0,
- .attribute = MEMORY_ATTR_WRITE,
- .transtype = TRANSTYPE_FULL,
- .data = NULL
- },
- .read_count = 0,
- .write = c->reader->cpu_write_6502,
- .read = c->reader->cpu_read
- },
- .ppu = {
- .memory = {
- .name = "charcter",
- .size = 0, .offset = 0,
- .attribute = MEMORY_ATTR_WRITE,
- .transtype = TRANSTYPE_FULL,
- .data = NULL
- },
- .read_count = 0,
- .write = c->reader->ppu_write,
- .read = c->reader->ppu_read
- },
- .target = c->target,
- .progress = c->progress
- };
+ dump_memory_driver_init(&d->cpu);
+ d->cpu.memory.name = "Program";
+
+ dump_memory_driver_init(&d->ppu);
+ d->ppu.memory.name = "Charcter";
+
{
- HSQUIRRELVM v = qr_open();
+ HSQUIRRELVM v = qr_open(&d->log);
qr_function_register_global(v, "ppu_ramfind", script_nop);
qr_function_register_global(v, "cpu_write", cpu_write_check);
- qr_function_register_global(v, "memory_new", memory_new);
+ qr_function_register_global(v, "memory_new", memory_size_set);
qr_function_register_global(v, "nesfile_save", length_check);
qr_function_register_global(v, "cpu_read", cpu_read_count);
qr_function_register_global(v, "ppu_read", ppu_read_count);
- if(script_execute(v, c, &d) == false){
+ qr_function_register_global(v, "require", script_require);
+ if(script_execute(v, d) == false){
qr_close(v);
return;
}
qr_close(v);
}
- if(c->progress == true){
+/* if(d->progress == true){
progress_init();
+ }*/
+ d->handle = d->control->open(d->except);
+ if(d->handle == NULL){
+ d->log.append(d->log.object, "reader open error\n");
+ return;
+ }
+ d->control->init(d->handle);
+ if(connection_check(d->handle, &d->log, d->cpu.access, d->ppu.access) == false){
+ return;
}
{
- HSQUIRRELVM v = qr_open();
- qr_function_register_global(v, "memory_new", script_nop);
+ HSQUIRRELVM v = qr_open(&d->log);
+ qr_function_register_global(v, "memory_new", memory_new);
qr_function_register_global(v, "nesfile_save", nesfile_save);
qr_function_register_global(v, "cpu_write", cpu_write);
qr_function_register_global(v, "cpu_read", cpu_read);
qr_function_register_global(v, "ppu_read", ppu_read);
qr_function_register_global(v, "ppu_ramfind", ppu_ramfind);
- script_execute(v, c, &d);
+ qr_function_register_global(v, "require", script_require);
+ script_execute(v, d);
qr_close(v);
}
+ d->control->close(d->handle);
+ d->handle = NULL;
}