OSDN Git Service

build path を変更
[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         const struct textcontrol *log;
10 };
11
12 static const struct reader_handle *dummy_open(void (*except)(const wgChar *str), const struct textcontrol *log)
13 {
14         struct reader_handle *h;
15         h = Malloc(sizeof(struct reader_handle));
16         h->except = except;
17         h->log = log;
18         return h;
19 }
20
21 static void dummy_close(const struct reader_handle *h)
22 {
23         Free((void *) h);
24 }
25
26 /*static void throw(const struct reader_handle *h)
27 {
28 #ifdef _UNICODE
29                 size_t length = strlen(usb_strerror());
30                 wchar_t *mm = Malloc(sizeof(wchar_t) * (length + 1));
31                 mbstowcs(mm, usb_strerror(), length + 1);
32                 h->except(mm);
33                 Free(mm);
34 #else
35                 h->except(usb_strerror());
36 #endif
37 }*/
38
39 static void dummy_read(const struct reader_handle *h, const struct gauge *g, long address, long length, uint8_t *data)
40 {
41         const int packet = 0x200;
42         while(length >= packet){
43                 wait(10);
44                 memset(data, 2, packet);
45                 data += packet;
46                 length -= packet;
47                 g->value_add(g->bar, g->label, packet);
48         }
49         if(length != 0){
50                 memset(data, 33, length);
51                 g->value_add(g->bar, g->label, length);
52         }
53 }
54
55 static void dummy_init(const struct reader_handle *h)
56 {
57 }
58
59 static void dummy_cpu_write(const struct reader_handle *h, long address, long length, const uint8_t *data)
60 {
61         if(length <= 8){
62                 long i;
63                 for(i = 0; i < length; i++){
64                         h->log->append(h->log->object, wgT(" cpu_write $%04x <- $%02x\n"), (int) address, *data);
65                         address++;
66                         data++;
67                 }
68         }
69         wait(4);
70 }
71
72 static void dummy_write(const struct reader_handle *h, long address, long length, const uint8_t *data)
73 {
74         wait(4);
75 }
76
77 static void dummy_flash_config(const struct reader_handle *h, long c000x, long c2aaa, long c5555, long unit, bool retry)
78 {
79 }
80
81 static void dummy_flash_erase(const struct reader_handle *h, long address, bool dowait)
82 {
83         if(dowait == true){
84                 wait(10);
85         }
86 }
87
88 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)
89 {
90         if(dowait == true){
91                 wait(20);
92         }
93         g->value_add(g->bar, g->label, 0x200);
94         return 0x200;
95 }
96
97 static void dummy_flash_status(const struct reader_handle *h, uint8_t s[2])
98 {
99         s[0] = 0;
100         s[1] = 0;
101 }
102
103 static void dummy_flash_device_get(const struct reader_handle *h, uint8_t s[2])
104 {
105         s[0] = 0;
106         s[1] = 0;
107 }
108
109 static uint8_t dummy_vram_connection(const struct reader_handle *h)
110 {
111         return 0;
112 }
113
114 const struct reader_driver DRIVER_DUMMY = {
115         .cpu = {
116                 .memory_read = dummy_read, 
117                 .memory_write = dummy_cpu_write,
118                 .flash_config = dummy_flash_config,
119                 .flash_erase = dummy_flash_erase,
120                 .flash_program = dummy_flash_program,
121                 .flash_device_get = dummy_flash_device_get
122         }, .ppu = {
123                 .memory_read = dummy_read,
124                 .memory_write = dummy_write,
125                 .flash_config = dummy_flash_config,
126                 .flash_erase = dummy_flash_erase,
127                 .flash_program = dummy_flash_program,
128                 .flash_device_get = dummy_flash_device_get
129         }, .control  = {
130                 .name = wgT("dummy"),
131                 .open = dummy_open, .close = dummy_close,
132                 .init = dummy_init,
133                 .flash_status = dummy_flash_status,
134                 .vram_connection = dummy_vram_connection
135         }
136 };