OSDN Git Service

skip 表示を修正, squirrel の呼び出しバグを修正
[unagi/old-svn-converted.git] / client / trunk / anago / reader_dummy.c
1 #include <string.h>
2 #include "type.h"
3 #include "widget.h"
4 #include "reader_master.h"
5 #include "memory_manage.h"
6
7 struct reader_handle{
8         void (*except)(const wgChar *str);
9 };
10
11 static const struct reader_handle *dummy_open(void (*except)(const wgChar *str))
12 {
13         struct reader_handle *h;
14         h = Malloc(sizeof(struct reader_handle));
15         h->except = except;
16         return h;
17 }
18
19 static void dummy_close(const struct reader_handle *h)
20 {
21         Free((void *) h);
22 }
23
24 /*static void throw(const struct reader_handle *h)
25 {
26 #ifdef _UNICODE
27                 size_t length = strlen(usb_strerror());
28                 wchar_t *mm = Malloc(sizeof(wchar_t) * (length + 1));
29                 mbstowcs(mm, usb_strerror(), length + 1);
30                 h->except(mm);
31                 Free(mm);
32 #else
33                 h->except(usb_strerror());
34 #endif
35 }*/
36
37 static void dummy_read(const struct reader_handle *h, const struct gauge *g, long address, long length, uint8_t *data)
38 {
39         const int packet = 0x200;
40         while(length >= packet){
41                 wait(10);
42                 memset(data, 2, packet);
43                 data += packet;
44                 length -= packet;
45                 g->value_add(g->bar, g->label, packet);
46         }
47         if(length != 0){
48                 memset(data, 33, length);
49                 g->value_add(g->bar, g->label, length);
50         }
51 }
52
53 static void dummy_init(const struct reader_handle *h)
54 {
55 }
56
57 static void dummy_write(const struct reader_handle *h, long address, long length, const uint8_t *data)
58 {
59         Sleep(4);
60 }
61
62 static void dummy_flash_config(const struct reader_handle *h, long c000x, long c2aaa, long c5555, long unit, bool retry)
63 {
64 }
65
66 static void dummy_flash_erase(const struct reader_handle *h, long address, bool dowait)
67 {
68         if(dowait == true){
69                 wait(10);
70         }
71 }
72
73 static long dummy_flash_program(const struct reader_handle *h, const struct gauge *g, long address, long length, const uint8_t *data, bool dowait, bool skip)
74 {
75         if(dowait == true){
76                 wait(20);
77         }
78         g->value_add(g->bar, g->label, 0x200);
79         return 0x200;
80 }
81
82 static void dummy_flash_status(const struct reader_handle *h, uint8_t s[2])
83 {
84         s[0] = 0;
85         s[1] = 0;
86 }
87
88 static void dummy_flash_device_get(const struct reader_handle *h, uint8_t s[2])
89 {
90         s[0] = 0;
91         s[1] = 0;
92 }
93
94 static uint8_t dummy_vram_connection(const struct reader_handle *h)
95 {
96         return 0;
97 }
98
99 const struct reader_driver DRIVER_DUMMY = {
100         .cpu = {
101                 .memory_read = dummy_read, 
102                 .memory_write = dummy_write,
103                 .flash_config = dummy_flash_config,
104                 .flash_erase = dummy_flash_erase,
105                 .flash_program = dummy_flash_program,
106                 .flash_device_get = dummy_flash_device_get
107         }, .ppu = {
108                 .memory_read = dummy_read,
109                 .memory_write = dummy_write,
110                 .flash_config = dummy_flash_config,
111                 .flash_erase = dummy_flash_erase,
112                 .flash_program = dummy_flash_program,
113                 .flash_device_get = dummy_flash_device_get
114         }, .control  = {
115                 .name = wgT("dummy"),
116                 .open = dummy_open, .close = dummy_close,
117                 .init = dummy_init,
118                 .flash_status = dummy_flash_status,
119                 .vram_connection = dummy_vram_connection
120         }
121 };