5 #include "memory_manage.h"
10 #include "reader_master.h"
11 #include "reader_kazzo.h"
12 #include "script_dump.h"
13 #include "flash_device.h"
14 #include "script_program.h"
18 #define PRINTF wprintf
24 static void text_append_va(void *obj, const wgChar *format, va_list list)
27 vwprintf(format, list);
29 vprintf(format, list);
33 static void text_append(void *obj, const wgChar *format, ...)
36 va_start(list, format);
37 text_append_va(obj, format, list);
41 static void log_set(struct textcontrol *log)
44 log->append = text_append;
45 log->append_va = text_append_va;
48 static void except(const wgChar *str)
54 static bool program_rom_set(const wgChar *device, wgChar trans, struct memory *m, struct flash_device *f)
57 if(flash_device_get(device, f) == false){
58 PRINTF(wgT("unknown flash memory device %s\n"), device);
63 m->transtype = TRANSTYPE_FULL;
66 m->transtype = TRANSTYPE_TOP;
69 m->transtype = TRANSTYPE_BOTTOM;
73 m->transtype = TRANSTYPE_EMPTY;
79 static void program(int c, wgChar **v)
81 struct program_config config;
82 config.cpu.memory.data = NULL;
83 config.ppu.memory.data = NULL;
86 config.control = &DRIVER_KAZZO.control;
87 config.cpu.access = &DRIVER_KAZZO.cpu;
88 config.ppu.access = &DRIVER_KAZZO.ppu;
89 config.compare = false;
90 config.testrun = false;
93 // config.reader = &DRIVER_DUMMY;
94 config.testrun = true;
97 config.compare = true;
102 case 5: {//mode script target cpu_flash_device
103 wgChar trans = wgT('f');
104 if(v[1][1] != wgT('\0')){
107 if(program_rom_set(v[4], trans, &config.cpu.memory, &config.cpu.flash) == false){
110 if(program_rom_set(wgT("dummy"), wgT('e'), &config.ppu.memory, &config.ppu.flash) == false){
115 case 6: { //mode script target cpu_flash_device ppu_flash_device
116 wgChar trans = wgT('f');
117 if(v[1][1] != wgT('\0')){
120 if(program_rom_set(v[4], trans, &config.cpu.memory, &config.cpu.flash) == false){
124 if(v[1][1] != wgT('\0') && v[1][2] != wgT('\0')){
127 if(program_rom_set(v[5], trans, &config.ppu.memory, &config.ppu.flash) == false){
132 PUTS(wgT("mode script target cpu_flash_device ppu_flash_device"));
135 log_set(&config.log);
136 cui_gauge_new(&config.cpu.gauge, wgT("Program Flash"), 2, -2);
137 cui_gauge_new(&config.ppu.gauge, wgT("Charcter Flash"), 1, -1);
138 config.except = except;
139 script_program_execute(&config);
140 cui_gauge_destory(&config.cpu.gauge);
141 cui_gauge_destory(&config.ppu.gauge);
144 static void dump(int c, wgChar **v)
146 struct dump_config config;
148 PUTS(wgT("argument error"));
151 config.cpu.increase = 1;
152 config.ppu.increase = 1;
153 config.progress = true;
156 config.progress = false;
161 config.cpu.increase = 2;
164 config.cpu.increase = 4;
167 if(v[1][1] != wgT('\0')){
170 config.ppu.increase = 2;
173 config.ppu.increase = 4;
177 config.script = v[2];
178 config.target = v[3];
179 config.control = &DRIVER_KAZZO.control;
180 config.cpu.access = &DRIVER_KAZZO.cpu;
181 config.ppu.access = &DRIVER_KAZZO.ppu;
182 cui_gauge_new(&config.cpu.gauge, wgT("Program ROM"), 2, -2);
183 cui_gauge_new(&config.ppu.gauge, wgT("Charcter ROM"), 1, -1);
184 config.except = except;
185 config.mappernum = -1;
188 config.mappernum = _wtoi(v[4]);
190 config.mappernum = atoi(v[4]);
193 config.battery = false;
194 log_set(&config.log);
195 script_dump_execute(&config);
196 cui_gauge_destory(&config.cpu.gauge);
197 cui_gauge_destory(&config.ppu.gauge);
200 static void usage(const wgChar *v)
202 PUTS(wgT("famicom bus simluator 'anago'"));
203 PRINTF(wgT("%s [mode] [script] [target] ....\n"), v);
207 int main(int c, char **vv)
209 int anago_cui(int c, wgChar **v)
217 v = Malloc(sizeof(wchar_t *) * c);
218 for(i = 0; i < c; i++){
219 size_t len = strlen(vv[i]) + 1;
220 v[i] = Malloc(sizeof(wchar_t) * len);
221 mbstowcs(v[i], vv[i], len);
225 case wgT('a'): case wgT('f'): case wgT('F'):
228 case wgT('d'): case wgT('D'):
233 PUTS(wgT("mode are d, D, f, g"));
237 for(i = 0; i < c; i++){
243 size_t len = strlen(vv[0]) + 1;
244 wchar_t *t = Malloc(sizeof(wchar_t) * len);
245 mbstowcs(t, vv[0], len);