root/modules/gui_debug.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. gui_debug_init
  2. gui_debug_draw_values
  3. gui_debug_draw
  4. gui_debug_kbd_process
  5. gui_module_menu_kbd_process
  6. _run
  7. _module_can_unload
  8. _module_exit_alt

   1 #include "camera_info.h"
   2 #include "stdlib.h"
   3 #include "keyboard.h"
   4 #include "gui.h"
   5 #include "gui_draw.h"
   6 #include "gui_lang.h"
   7 #include "conf.h"
   8 
   9 #include "module_def.h"
  10 #include "simple_module.h"
  11 
  12 //-------------------------------------------------------------------
  13 void gui_debug_draw();
  14 
  15 //-------------------------------------------------------------------
  16 
  17 void gui_module_menu_kbd_process();
  18 int gui_debug_kbd_process();
  19 
  20 gui_handler GUI_MODE_DEBUG = 
  21 /*GUI_MODE_DEBUG*/  { GUI_MODE_MODULE, gui_debug_draw, gui_debug_kbd_process, gui_module_menu_kbd_process, 0, 0 };
  22 
  23 //-------------------------------------------------------------------
  24 static int running = 0;
  25 static void *addr;
  26 static char debug_to_draw;
  27 static char debug_cont_update;
  28 static char buf[32];
  29 static char *bad_address = "Invalid Address               ";
  30 static unsigned int step;
  31 
  32 //-------------------------------------------------------------------
  33 void gui_debug_init(void *st_addr)
  34 {
  35     running = 1;
  36     addr = st_addr;
  37     debug_to_draw = 1;
  38     debug_cont_update = 1;
  39     step = 4;
  40     gui_set_mode(&GUI_MODE_DEBUG);
  41 }
  42 
  43 //-------------------------------------------------------------------
  44 static void gui_debug_draw_values(const coord y, void* addr) {
  45     int i;
  46 
  47     if ((addr<=(void*)camera_info.maxramaddr || addr>=(void*)camera_info.rombaseaddr))
  48     {
  49         sprintf(buf, "0x%08X (%10u)", *((unsigned int*)addr), *((unsigned int*)addr));
  50         draw_string(10*FONT_WIDTH, y, buf, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
  51 
  52         sprintf(buf, "0x%04X     (     %5hu)", *((unsigned short*)addr), *((unsigned short*)addr));
  53         draw_string(10*FONT_WIDTH, y+FONT_HEIGHT, buf, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
  54 
  55         sprintf(buf, "0x%02X       (       %3hu)", *((unsigned char*)addr), *((unsigned char*)addr));
  56         draw_string(10*FONT_WIDTH, y+2*FONT_HEIGHT, buf, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
  57 
  58         for (i=0; i<30; ++i) {
  59             if (*((char*)(addr+i))) buf[i]=*((char*)(addr+i));
  60             else break;
  61         }
  62         while (i<30) {
  63             buf[i++]=' ';
  64         }
  65         buf[i]=0;
  66         draw_string(10*FONT_WIDTH, y+3*FONT_HEIGHT, buf, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
  67     }
  68     else
  69     {
  70         draw_string(10*FONT_WIDTH, y, bad_address, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
  71         draw_string(10*FONT_WIDTH, y+FONT_HEIGHT, bad_address, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
  72         draw_string(10*FONT_WIDTH, y+2*FONT_HEIGHT, bad_address, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
  73         draw_string(10*FONT_WIDTH, y+3*FONT_HEIGHT, bad_address, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
  74     }
  75 }
  76 
  77 //-------------------------------------------------------------------
  78 void gui_debug_draw() {
  79     switch (debug_to_draw) {
  80         case 1:
  81             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);
  82             draw_string(1*FONT_WIDTH, 0*FONT_HEIGHT, "Address:", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
  83             draw_string(22*FONT_WIDTH,0*FONT_HEIGHT, "Incr:", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
  84             draw_string(39*FONT_WIDTH,0*FONT_HEIGHT, "Auto:", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
  85             draw_string(1*FONT_WIDTH, 1*FONT_HEIGHT, "Values:",  MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
  86             draw_string(2*FONT_WIDTH, 2*FONT_HEIGHT, "DWORD  :", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
  87             draw_string(2*FONT_WIDTH, 3*FONT_HEIGHT, "WORD   :", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
  88             draw_string(2*FONT_WIDTH, 4*FONT_HEIGHT, "BYTE   :", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
  89             draw_string(2*FONT_WIDTH, 5*FONT_HEIGHT, "STRING :", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
  90             draw_string(1*FONT_WIDTH, 7*FONT_HEIGHT, "Dereferencing:",  MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
  91             draw_string(2*FONT_WIDTH, 8*FONT_HEIGHT, "DWORD  :", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
  92             draw_string(2*FONT_WIDTH, 9*FONT_HEIGHT, "WORD   :", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
  93             draw_string(2*FONT_WIDTH, 10*FONT_HEIGHT,"BYTE   :", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
  94             draw_string(2*FONT_WIDTH, 11*FONT_HEIGHT,"STRING :", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
  95 
  96             debug_to_draw = 2;
  97             break;
  98         case 2:
  99             sprintf(buf, "0x%08X", addr);
 100             draw_string(10*FONT_WIDTH, 0, buf, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 101             sprintf(buf, "0x%08X", step);
 102             draw_string(28*FONT_WIDTH, 0, buf, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 103             sprintf(buf,"%0d",debug_cont_update);
 104             draw_string(44*FONT_WIDTH, 0, buf, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 105             gui_debug_draw_values(2*FONT_HEIGHT, addr);
 106             if ((addr<=(void*)camera_info.maxramaddr || addr>=(void*)camera_info.rombaseaddr))
 107                 gui_debug_draw_values(8*FONT_HEIGHT, *((void**)addr));
 108             else
 109                 gui_debug_draw_values(8*FONT_HEIGHT, addr);
 110             conf.mem_view_addr_init = (long)addr;
 111 
 112             if (debug_cont_update==0) debug_to_draw = 0;
 113             break;
 114         default:
 115             debug_to_draw = 0;
 116             break;
 117     }
 118 }
 119 
 120 //-------------------------------------------------------------------
 121 int gui_debug_kbd_process() {
 122     switch (kbd_get_autoclicked_key()) {
 123     case KEY_DOWN:
 124         break;
 125     case KEY_UP:
 126         debug_cont_update = !debug_cont_update;
 127         debug_to_draw = 2;
 128         break;
 129     case KEY_LEFT:
 130         addr-=step;
 131         debug_to_draw = 2;
 132         break;
 133     case KEY_RIGHT:
 134         addr+=step;
 135         debug_to_draw = 2;
 136         break;
 137     case KEY_DISPLAY:
 138         switch (step) {
 139             case 0x00000004: step = 0x00000010; break;
 140             case 0x10000000: step = 0x00000004; break;
 141             default: step<<=4; break;
 142         }
 143         debug_to_draw = 2;
 144         break;
 145     case KEY_ZOOM_IN:    // reduce step
 146         switch (step) {
 147             case 0x00000010: step = 0x0000004; break;
 148             case 0x00000004: break;
 149             default: step>>=4; break;
 150         }
 151         debug_to_draw = 2;
 152         break;
 153     case KEY_ZOOM_OUT:    // increase step
 154         switch (step) {
 155             case 0x00000004: step = 0x00000010; break;
 156             case 0x10000000: break;
 157             default: step<<=4; break;
 158         }
 159         debug_to_draw = 2;
 160         break;
 161     }
 162     return 0;
 163 }
 164 
 165 //-------------------------------------------------------------------
 166 
 167 void gui_module_menu_kbd_process()
 168 {
 169     running = 0;
 170     gui_default_kbd_process_menu_btn();
 171 }
 172 
 173 
 174 // =========  MODULE INIT =================
 175 
 176 /***************** BEGIN OF AUXILARY PART *********************
 177 ATTENTION: DO NOT REMOVE OR CHANGE SIGNATURES IN THIS SECTION
 178 **************************************************************/
 179 
 180 int _run()
 181 {
 182     void* adr =(char*)(conf.mem_view_addr_init);
 183     gui_debug_init(adr);
 184 
 185     return 0;
 186 }
 187 
 188 int _module_can_unload()
 189 {
 190     return running == 0;
 191 }
 192 
 193 int _module_exit_alt()
 194 {
 195     running = 0;
 196     return 0;
 197 }
 198 
 199 /******************** Module Information structure ******************/
 200 
 201 libsimple_sym _librun =
 202 {
 203     {
 204          0, 0, _module_can_unload, _module_exit_alt, _run
 205     }
 206 };
 207 
 208 ModuleInfo _module_info =
 209 {
 210     MODULEINFO_V1_MAGICNUM,
 211     sizeof(ModuleInfo),
 212     SIMPLE_MODULE_VERSION,              // Module version
 213 
 214     ANY_CHDK_BRANCH, 0, OPT_ARCHITECTURE,                       // Requirements of CHDK version
 215     ANY_PLATFORM_ALLOWED,               // Specify platform dependency
 216 
 217     -LANG_MENU_DEBUG_MEMORY_BROWSER,
 218     MTYPE_TOOL,             //Simple memory content browser
 219 
 220     &_librun.base,
 221 
 222     CONF_VERSION,               // CONF version
 223     CAM_SCREEN_VERSION,         // CAM SCREEN version
 224     ANY_VERSION,                // CAM SENSOR version
 225     CAM_INFO_VERSION,           // CAM INFO version
 226 
 227     0x2a,                       // Menu symbol
 228 };
 229 
 230 /*************** END OF AUXILARY PART *******************/

/* [<][>][^][v][top][bottom][index][help] */