3 #include "memory_manage.h"
5 #include "flash_device.h"
7 #include "reader_master.h"
8 #include "reader_kazzo.h"
9 #include "reader_dummy.h"
10 #include "script_flash.h"
11 #include "script_dump.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)
36 case 'a': case 'f': case 'F':
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_flash *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;
74 }else if(c->flash_cpu.capacity < c->rom.cpu_rom.size){
75 puts("cpu area ROM image size is larger than target device");
79 (c->flash_ppu.id_device == FLASH_ID_DEVICE_DUMMY) ||
80 (c->rom.ppu_rom.size == 0)
82 c->rom.ppu_rom.transtype = TRANSTYPE_EMPTY;
83 }else if(c->flash_ppu.capacity < c->rom.ppu_rom.size){
84 puts("ppu area ROM image size is larger than target device");
89 static void program(int c, char **v)
91 struct config_flash config;
92 config.rom.cpu_rom.data = NULL;
93 config.rom.ppu_rom.data = NULL;
95 config.reader = &DRIVER_KAZZO;
96 config.compare = false;
97 config.testrun = false;
100 config.reader = &DRIVER_DUMMY;
101 config.testrun = true;
104 config.compare = true;
107 if(transtype_set(v[1], &config.rom) == false){
108 puts("mode argument error");
112 case 5: //mode script target cpu_flash_device
113 if(config_parse(v[3], v[4], "dummy", &config) == false){
114 nesbuffer_free(&config.rom, 0);
118 case 6: //mode script target cpu_flash_device ppu_flash_device
119 if(config_parse(v[3], v[4], v[5], &config) == false){
120 nesbuffer_free(&config.rom, 0);
125 puts("mode script target cpu_flash_device ppu_flash_device");
128 if(config.reader->open_or_close(READER_OPEN) == NG){
129 puts("reader open error");
130 nesbuffer_free(&config.rom, 0);
133 config.reader->init();
134 script_flash_execute(&config);
135 nesbuffer_free(&config.rom, 0);
136 config.reader->open_or_close(READER_CLOSE);
138 static void dump(int c, char **v)
140 struct config_dump config;
142 puts("argument error");
145 config.increase.cpu = 1;
146 config.increase.ppu = 1;
147 config.progress = true;
150 config.progress = false;
155 config.increase.cpu = 2;
158 config.increase.cpu = 4;
164 config.increase.ppu = 2;
167 config.increase.ppu = 4;
171 config.script = v[2];
172 config.target = v[3];
173 config.reader = &DRIVER_KAZZO;
174 config.mappernum = -1;
176 config.mappernum = atoi(v[4]);
178 if(config.reader->open_or_close(READER_OPEN) == NG){
179 puts("reader open error");
182 config.reader->init();
183 script_dump_execute(&config);
184 config.reader->open_or_close(READER_CLOSE);
186 static void usage(const char *v)
188 puts("famicom bus simluator 'anago'");
189 printf("%s [mode] [script] [target] ....\n", v);
191 int main(int c, char **v)
196 case 'a': case 'f': case 'F':
204 puts("mode are a, d, D, f, g");