3 #include "memory_manage.h"
5 //#include "flashmemory.h"
6 #include "flash_device.h"
8 #include "reader_master.h"
9 #include "reader_kazzo.h"
10 #include "reader_dummy.h"
13 static bool transtype_flash_set(char mode, struct memory *t)
17 t->transtype = TRANSTYPE_TOP;
20 t->transtype = TRANSTYPE_EMPTY;
23 t->transtype = TRANSTYPE_BOTTOM;
26 t->transtype = TRANSTYPE_FULL;
33 static bool transtype_set(const char *mode, struct romimage *t)
38 t->cpu_rom.transtype = TRANSTYPE_FULL;
39 t->ppu_rom.transtype = TRANSTYPE_FULL;
42 if(transtype_flash_set(mode[1], &t->cpu_rom) == false){
46 t->ppu_rom.transtype = TRANSTYPE_FULL;
49 if(transtype_flash_set(mode[2], &t->ppu_rom) == false){
56 static bool config_parse(const char *romimage, const char *device_cpu, const char *device_ppu, struct config *c)
59 if(nesfile_load(__FUNCTION__, romimage, &c->rom) == false){
62 c->rom.cpu_rom.offset = 0;
63 c->rom.ppu_rom.offset = 0;
64 if(flash_device_get(device_cpu, &c->flash_cpu) == false){
65 printf("unkown flash memory device %s\n", device_cpu);
68 if(flash_device_get(device_ppu, &c->flash_ppu) == false){
69 printf("unkown flash memory device %s\n", device_ppu);
72 if(c->flash_cpu.id_device == FLASH_ID_DEVICE_DUMMY){
73 c->rom.cpu_rom.transtype = TRANSTYPE_EMPTY;
76 (c->flash_ppu.id_device == FLASH_ID_DEVICE_DUMMY) ||
77 (c->rom.ppu_rom.size == 0)
79 c->rom.ppu_rom.transtype = TRANSTYPE_EMPTY;
83 static void anago(int c, char **v)
87 config.reader = &DRIVER_KAZZO;
89 config.reader = &DRIVER_DUMMY;
91 if(transtype_set(v[1], &config.rom) == false){
92 puts("mode argument error");
96 case 5: //mode script target cpu_flash_device
97 if(config_parse(v[3], v[4], "dummy", &config) == false){
98 nesbuffer_free(&config.rom, 0);
102 case 6: //mode script target cpu_flash_device ppu_flash_device
103 if(config_parse(v[3], v[4], v[5], &config) == false){
104 nesbuffer_free(&config.rom, 0);
109 puts("mode script target cpu_flash_device ppu_flash_device");
112 if(config.reader->open_or_close(READER_OPEN) == NG){
113 puts("reader open error");
114 nesbuffer_free(&config.rom, 0);
117 script_execute(&config);
118 nesbuffer_free(&config.rom, 0);
119 config.reader->open_or_close(READER_CLOSE);
121 int main(int c, char **v)