3 #include <stdlib.h> //atoi()
4 #include "memory_manage.h"
6 #include "flash_device.h"
8 #include "reader_master.h"
9 #include "reader_kazzo.h"
10 //#include "reader_dummy.h"
11 //#include "script_program.h"
12 #include "script_dump.h"
15 static bool transtype_flash_set(char mode, struct memory *t)
19 t->transtype = TRANSTYPE_TOP;
22 t->transtype = TRANSTYPE_EMPTY;
25 t->transtype = TRANSTYPE_BOTTOM;
28 t->transtype = TRANSTYPE_FULL;
35 static bool transtype_set(const char *mode, struct romimage *t)
38 case 'a': case 'f': case 'F':
40 t->cpu_rom.transtype = TRANSTYPE_FULL;
41 t->ppu_rom.transtype = TRANSTYPE_FULL;
44 if(transtype_flash_set(mode[1], &t->cpu_rom) == false){
48 t->ppu_rom.transtype = TRANSTYPE_FULL;
51 if(transtype_flash_set(mode[2], &t->ppu_rom) == false){
58 static bool config_parse(const char *romimage, const char *device_cpu, const char *device_ppu, struct config_flash *c)
61 if(nesfile_load(__FUNCTION__, romimage, &c->rom) == false){
64 c->rom.cpu_rom.offset = 0;
65 c->rom.ppu_rom.offset = 0;
66 if(flash_device_get(device_cpu, &c->flash_cpu) == false){
67 printf("unkown flash memory device %s\n", device_cpu);
70 if(flash_device_get(device_ppu, &c->flash_ppu) == false){
71 printf("unkown flash memory device %s\n", device_ppu);
74 if(c->flash_cpu.id_device == FLASH_ID_DEVICE_DUMMY){
75 c->rom.cpu_rom.transtype = TRANSTYPE_EMPTY;
76 }else if(c->flash_cpu.capacity < c->rom.cpu_rom.size){
77 puts("cpu area ROM image size is larger than target device");
81 (c->flash_ppu.id_device == FLASH_ID_DEVICE_DUMMY) ||
82 (c->rom.ppu_rom.size == 0)
84 c->rom.ppu_rom.transtype = TRANSTYPE_EMPTY;
85 }else if(c->flash_ppu.capacity < c->rom.ppu_rom.size){
86 puts("ppu area ROM image size is larger than target device");
91 static void program(int c, char **v)
93 struct config_flash config;
94 config.rom.cpu_rom.data = NULL;
95 config.rom.ppu_rom.data = NULL;
97 config.reader = &DRIVER_KAZZO;
98 config.compare = false;
99 config.testrun = false;
102 config.reader = &DRIVER_DUMMY;
103 config.testrun = true;
106 config.compare = true;
109 if(transtype_set(v[1], &config.rom) == false){
110 puts("mode argument error");
114 case 5: //mode script target cpu_flash_device
115 if(config_parse(v[3], v[4], "dummy", &config) == false){
116 nesbuffer_free(&config.rom, 0);
120 case 6: //mode script target cpu_flash_device ppu_flash_device
121 if(config_parse(v[3], v[4], v[5], &config) == false){
122 nesbuffer_free(&config.rom, 0);
127 puts("mode script target cpu_flash_device ppu_flash_device");
130 if(config.reader->open_or_close(READER_OPEN) == NG){
131 puts("reader open error");
132 nesbuffer_free(&config.rom, 0);
135 config.reader->init();
136 script_flash_execute(&config);
137 nesbuffer_free(&config.rom, 0);
138 config.reader->open_or_close(READER_CLOSE);
142 static void dump(int c, char **v)
144 struct dump_config config;
146 puts("argument error");
149 config.increase.cpu = 1;
150 config.increase.ppu = 1;
151 config.progress = true;
154 config.progress = false;
159 config.increase.cpu = 2;
162 config.increase.cpu = 4;
168 config.increase.ppu = 2;
171 config.increase.ppu = 4;
175 config.script = v[2];
176 config.target = v[3];
177 config.reader = &DRIVER_KAZZO;
178 config.mappernum = -1;
180 config.mappernum = atoi(v[4]);
182 if(config.reader->open_or_close(READER_OPEN) == NG){
183 puts("reader open error");
186 config.reader->init();
187 script_dump_execute(&config);
188 config.reader->open_or_close(READER_CLOSE);
190 static void usage(const char *v)
192 puts("famicom bus simluator 'anago'");
193 printf("%s [mode] [script] [target] ....\n", v);
195 int main(int c, char **v)
200 case 'a': case 'f': case 'F':
208 puts("mode are a, d, D, f, g");