OSDN Git Service

anago: flash device をスクリプト化
[unagi/old-svn-converted.git] / client / trunk / anago / flashcore.nut
1 mega <- 0x20000;
2 trans_empty <- 0;
3 function cpu_banksize_get(capacity)
4 {
5         return capacity * mega / cpu_banksize;
6 }
7 function ppu_banksize_get(capacity)
8 {
9         return capacity * mega / ppu_banksize;
10 }
11 function loopsize_get(flashsize, trans, size)
12 {
13         local trans_full = 3, trans_top = 1, trans_bottom = 2; //header.h enum transtype
14         local loop;
15         switch(trans){
16         case trans_full:
17                 loop = flashsize.full;
18                 break;
19         case trans_top:
20                 loop = flashsize.top[size];
21                 break;
22         case trans_bottom:
23                 loop = flashsize.bottom[size];
24                 break;
25         default:
26                 loop = {start = 0, end = 0};
27                 break;
28         }
29         return loop;
30 }
31 function program(d, mapper, cpu_trans, cpu_size, ppu_trans, ppu_size)
32 {
33         if(board.mapper != mapper){
34                 print("mapper number not connected");
35                 return;
36         }
37         local cpu_loop = loopsize_get(board.cpu_flashsize, cpu_trans, cpu_size);
38         local ppu_loop = loopsize_get(board.ppu_flashsize, ppu_trans, ppu_size);
39         local co_cpu = newthread(program_cpu);
40         local co_ppu = newthread(program_ppu);
41         initalize(d);
42         if(cpu_trans != trans_empty){
43                 cpu_erase(d);
44         }
45         if(ppu_trans != trans_empty){
46                 ppu_erase(d);
47         }
48         erase_wait(d);
49         if(cpu_trans != 0){
50                 co_cpu.call(d, cpu_loop);
51         }
52         if(ppu_trans != trans_empty){
53                 co_ppu.call(d, ppu_loop);
54         }
55         program_main(d, co_cpu, co_ppu)
56 }
57