This source file includes following definitions.
- _run
- _module_can_unload
- _module_exit_alt
- modinspect_unload_cb
- gui_module_kbd_process
- basic_module_init
- gui_module_menu_kbd_process
- gui_mem_info
- gui_module_draw
1 #include "camera_info.h"
2 #include "gui.h"
3 #include "gui_draw.h"
4 #include "meminfo.h"
5 #include "module_load.h"
6 #include "simple_module.h"
7
8
9
10 static int running = 0;
11
12 extern int basic_module_init();
13
14
15
16
17
18 int _run()
19 {
20 basic_module_init();
21
22 return 0;
23 }
24
25 int _module_can_unload()
26 {
27 return running == 0;
28 }
29
30 int _module_exit_alt()
31 {
32 running = 0;
33 return 0;
34 }
35
36
37
38 libsimple_sym _librun =
39 {
40 {
41 0, 0, _module_can_unload, _module_exit_alt, _run
42 }
43 };
44
45 ModuleInfo _module_info =
46 {
47 MODULEINFO_V1_MAGICNUM,
48 sizeof(ModuleInfo),
49 SIMPLE_MODULE_VERSION,
50
51 ANY_CHDK_BRANCH, 0, OPT_ARCHITECTURE,
52 ANY_PLATFORM_ALLOWED,
53
54 (int32_t)"Module Inspector",
55 MTYPE_EXTENSION,
56
57 &_librun.base,
58
59 ANY_VERSION,
60 CAM_SCREEN_VERSION,
61 ANY_VERSION,
62 ANY_VERSION,
63
64 0,
65 };
66
67
68
69
70
71 #include "gui_mbox.h"
72 #include "keyboard.h"
73
74 void gui_module_menu_kbd_process();
75 int gui_module_kbd_process();
76 void gui_module_draw();
77
78 gui_handler GUI_MODE_MODULE_INSPECTOR =
79 { GUI_MODE_MODULE, gui_module_draw, gui_module_kbd_process, gui_module_menu_kbd_process, 0, 0 };
80
81 int modinspect_redraw;
82 gui_handler *modinspect_old_guimode;
83
84 static void modinspect_unload_cb(unsigned int btn)
85 {
86 if (btn==MBOX_BTN_YES)
87 {
88 running = 0;
89 module_exit_alt();
90 gui_set_mode(modinspect_old_guimode);
91 }
92 modinspect_redraw=2;
93 }
94
95 int gui_module_kbd_process()
96 {
97 switch (kbd_get_autoclicked_key())
98 {
99 case KEY_SET:
100 modinspect_redraw = 2;
101 break;
102 case KEY_DISPLAY:
103 gui_mbox_init( (int)"Module Inspector", (int)"Unload all modules?",
104 MBOX_TEXT_CENTER|MBOX_BTN_YES_NO|MBOX_DEF_BTN2, modinspect_unload_cb);
105 break;
106 }
107 return 0;
108 }
109
110
111
112 int basic_module_init()
113 {
114 running = 1;
115 modinspect_redraw = 2;
116 modinspect_old_guimode = gui_set_mode(&GUI_MODE_MODULE_INSPECTOR);
117 return 1;
118 }
119
120 void gui_module_menu_kbd_process()
121 {
122 running = 0;
123 gui_set_mode(modinspect_old_guimode);
124 }
125
126 static void gui_mem_info(char *typ, cam_meminfo *meminfo, int showidx)
127 {
128 char txt[50];
129 sprintf(txt,"%-5s: %08x-%08x: %d",typ,meminfo->start_address, meminfo->end_address, meminfo->total_size);
130 draw_string(camera_screen.disp_left, showidx, txt, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
131 sprintf(txt,"alloc: now=%d(%d) max=%d", meminfo->allocated_size, meminfo->allocated_count, meminfo->allocated_peak);
132 draw_string(camera_screen.disp_left, showidx+FONT_HEIGHT, txt, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
133 sprintf(txt,"free: now=%d(%d) max=%d", meminfo->free_size, meminfo->free_block_count, meminfo->free_block_max_size);
134 draw_string(camera_screen.disp_left, showidx+2*FONT_HEIGHT, txt, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
135 }
136
137 void gui_module_draw()
138 {
139 int idx, showidx;
140
141 if (modinspect_redraw) {
142
143 draw_rectangle(camera_screen.disp_left, 0, camera_screen.disp_right, camera_screen.height-1, MAKE_COLOR(COLOR_BLACK, COLOR_BLACK), RECT_BORDER0|DRAW_FILLED);
144 draw_string(camera_screen.disp_left+5*FONT_WIDTH, 0, "*** Module Inspector ***", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
145 draw_string(camera_screen.disp_left+FONT_WIDTH, FONT_HEIGHT, "SET-redraw, DISP-unload_all, MENU-exit", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
146 draw_string(camera_screen.disp_left, 2*FONT_HEIGHT, "Idx Name Addr Size", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
147
148 showidx=3*FONT_HEIGHT;
149 for ( idx=0; idx<MAX_NUM_LOADED_MODULES; idx++)
150 {
151 module_entry* mod = module_get_adr(idx);;
152 if (mod == 0) continue;
153
154 char txt[50], name[13];
155
156 char *s = strrchr(mod->hMod->name, '/');
157 if (s) s = s + 1; else s = mod->hMod->name;
158 strncpy(name, s, 12); name[12] = 0;
159 sprintf(txt,"%02d: %-12s %08x - %d bytes", idx, name, (unsigned)mod->hdr, mod->hdr->reloc_start+mod->hdr->bss_size);
160 draw_string(camera_screen.disp_left, showidx, txt, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
161 showidx += FONT_HEIGHT;
162 }
163
164 showidx += FONT_HEIGHT;
165
166 cam_meminfo meminfo;
167
168
169
170 memset(&meminfo,0,sizeof(meminfo));
171 GetMemInfo(&meminfo);
172 gui_mem_info("MEM", &meminfo, showidx);
173 showidx += 3*FONT_HEIGHT;
174
175
176 memset(&meminfo,0,sizeof(meminfo));
177 if (GetARamInfo(&meminfo))
178 {
179 gui_mem_info("ARAM", &meminfo, showidx);
180 showidx += 3*FONT_HEIGHT;
181 }
182
183
184 memset(&meminfo,0,sizeof(meminfo));
185 if (GetExMemInfo(&meminfo))
186 {
187 gui_mem_info("EXMEM", &meminfo, showidx);
188 }
189 }
190
191 modinspect_redraw = 0;
192 }
193