OSDN Git Service

RAM access mode support, CUI only
[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 == 1){
62                 h->log->append(h->log->object, wgT(" cpu_write $%04x <- $%02x\n"), (int) address, *data);
63         }
64         Sleep(4);
65 }
66
67 static void dummy_write(const struct reader_handle *h, long address, long length, const uint8_t *data)
68 {
69         Sleep(4);
70 }
71
72 static void dummy_flash_config(const struct reader_handle *h, long c000x, long c2aaa, long c5555, long unit, bool retry)
73 {
74 }
75
76 static void dummy_flash_erase(const struct reader_handle *h, long address, bool dowait)
77 {
78         if(dowait == true){
79                 wait(10);
80         }
81 }
82
83 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)
84 {
85         if(dowait == true){
86                 wait(20);
87         }
88         g->value_add(g->bar, g->label, 0x200);
89         return 0x200;
90 }
91
92 static void dummy_flash_status(const struct reader_handle *h, uint8_t s[2])
93 {
94         s[0] = 0;
95         s[1] = 0;
96 }
97
98 static void dummy_flash_device_get(const struct reader_handle *h, uint8_t s[2])
99 {
100         s[0] = 0;
101         s[1] = 0;
102 }
103
104 static uint8_t dummy_vram_connection(const struct reader_handle *h)
105 {
106         return 0;
107 }
108
109 const struct reader_driver DRIVER_DUMMY = {
110         .cpu = {
111                 .memory_read = dummy_read, 
112                 .memory_write = dummy_cpu_write,
113                 .flash_config = dummy_flash_config,
114                 .flash_erase = dummy_flash_erase,
115                 .flash_program = dummy_flash_program,
116                 .flash_device_get = dummy_flash_device_get
117         }, .ppu = {
118                 .memory_read = dummy_read,
119                 .memory_write = dummy_write,
120                 .flash_config = dummy_flash_config,
121                 .flash_erase = dummy_flash_erase,
122                 .flash_program = dummy_flash_program,
123                 .flash_device_get = dummy_flash_device_get
124         }, .control  = {
125                 .name = wgT("dummy"),
126                 .open = dummy_open, .close = dummy_close,
127                 .init = dummy_init,
128                 .flash_status = dummy_flash_status,
129                 .vram_connection = dummy_vram_connection
130         }
131 };