root/platform/ixus40_sd300/main.c

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

DEFINITIONS

This source file includes following definitions.
  1. core_hook_task_create
  2. core_hook_task_delete
  3. spytask
  4. task_start_hook
  5. remount_filesystem
  6. task_fs
  7. capt_seq_hook
  8. movie_record_hook
  9. my_ncmp
  10. createHook
  11. deleteHook
  12. startup
  13. get_vbatt_min
  14. get_vbatt_max
  15. get_effective_focal_length
  16. get_focal_length
  17. get_zoom_x
  18. rec_mode_active
  19. hook_tyWriteOrig
  20. cam_console_init

   1 #define VBATT_DEFAULT_MIN (3500)
   2 #define VBATT_DEFAULT_MAX (4100)
   3 
   4 #include "lolevel.h"
   5 #include "platform.h"
   6 #include "core.h"
   7 #include "keyboard.h"
   8 #include "stdlib.h"
   9 
  10 /* Ours stuff */
  11 extern long link_bss_start;
  12 extern long link_bss_end;
  13 extern void boot();
  14 extern void mykbd_task(long ua, long ub, long uc, long ud, long ue, long uf);
  15 extern void kbd_process_task(long ua, long ub, long uc, long ud, long ue, long uf);
  16 
  17 static void core_hook_task_create(void *tcb)
  18 {
  19 }
  20 
  21 static void core_hook_task_delete(void *tcb)
  22 {
  23     char *name = (char*)(*(long*)((char*)tcb+0x34));
  24     if (strcmp(name,"tInitFileM")==0) core_spytask_can_start();
  25 }
  26 
  27 static int stop_hooking;
  28 
  29 static void (*taskprev)(
  30     long p0,    long p1,    long p2,    long p3,    long p4,
  31     long p5,    long p6,    long p7,    long p8,    long p9);
  32 
  33 static void (*taskfsprev)(
  34     long p0,    long p1,    long p2,    long p3,    long p4,
  35     long p5,    long p6,    long p7,    long p8,    long p9);
  36 
  37 
  38 
  39 void spytask(long ua, long ub, long uc, long ud, long ue, long uf)
  40         {
  41     core_spytask(); // This is the main CHDK loop
  42         }
  43 
  44 
  45 static void task_start_hook(
  46     long p0,    long p1,    long p2,    long p3,    long p4,
  47     long p5,    long p6,    long p7,    long p8,    long p9)
  48         {
  49     _CreateTask("SpyTask", 0x19, 0x2000, spytask, 0); // First creates the SpyTask, i.e. the main CHDK loop
  50     
  51     //create our second keypress task
  52                 _CreateTask("SpyTask2", 0x18, 0x2000, kbd_process_task, 0); 
  53     
  54     taskprev(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9 ); // then, whatever was the call intended to be...
  55         }
  56 
  57 
  58 static void remount_filesystem()
  59 {
  60     _Unmount_FileSystem();
  61     _Mount_FileSystem();
  62 }
  63 
  64 
  65 static void task_fs(
  66     long p0,    long p1,    long p2,    long p3,    long p4,
  67     long p5,    long p6,    long p7,    long p8,    long p9)
  68         {
  69     remount_filesystem();
  70     taskfsprev(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9 );
  71         }
  72 
  73 
  74 static void capt_seq_hook(
  75     long p0,    long p1,    long p2,    long p3,    long p4,
  76     long p5,    long p6,    long p7,    long p8,    long p9)
  77         {
  78     capt_seq_task();
  79         }
  80 
  81 static void movie_record_hook(
  82     long p0,    long p1,    long p2,    long p3,    long p4,
  83     long p5,    long p6,    long p7,    long p8,    long p9)
  84         {
  85     movie_record_task();
  86         }
  87 
  88 
  89 
  90 static int my_ncmp(const char *s1, const char *s2, long len)
  91         {
  92     int i;
  93     for (i=0;i<len;i++)
  94                 {
  95                 if (s1[i] != s2[i])
  96                         return 1;
  97                 }
  98     return 0;
  99         }
 100 
 101 void createHook (void *pNewTcb)
 102 {
 103     char *name = (char*)(*(long*)((char*)pNewTcb+0x34));
 104     long *entry = (long*)((char*)pNewTcb+0x74);
 105     
 106     //volatile long *p; p=(void*) 0xc02200E0; *p=0x46; //debug led
 107     
 108     // always hook first task creation
 109     // to create SpyTask
 110     if (!stop_hooking){
 111         taskprev = (void*)(*entry);
 112         *entry = (long)task_start_hook;
 113         stop_hooking = 1;
 114     }else{
 115         // hook/replace another tasks
 116         // Replace the call to "SwitchCheckTask" with our own procedure
 117         if (my_ncmp(name, "tSwitchChe", 10) == 0){
 118             *entry = (long)mykbd_task;
 119         }
 120         
 121         // Replace the call to "InitFileModules" with our own procedure
 122         if (my_ncmp(name, "tInitFileM", 10) == 0){
 123             taskfsprev = (void*)(*entry);
 124             *entry = (long)task_fs;
 125         }
 126         
 127         // Replace the call to "CaptSeqTask" with our own procedure
 128         if (my_ncmp(name, "tCaptSeqTa", 10) == 0){
 129             *entry = (long)capt_seq_hook;
 130         }
 131 
 132         if (my_ncmp(name, "tMovieRecT", 10) == 0){
 133             *entry = (long)movie_record_hook;
 134         }
 135 
 136 core_hook_task_create(pNewTcb);
 137 }
 138         }
 139 
 140 void deleteHook (void *pTcb)
 141         {
 142     core_hook_task_delete(pTcb);
 143         }
 144 
 145 void startup()
 146         {
 147     long *bss = &link_bss_start;
 148 
 149     //volatile long *p; p=(void*) 0xc02200E0; *p=0x46; //debug led
 150 
 151     // sanity check
 152     if ((long)&link_bss_end > (MEMISOSTART + MEMISOSIZE)) {
 153                         started();
 154                         shutdown();
 155     }
 156 
 157     // initialize .bss segment
 158     while (bss<&link_bss_end)
 159                 *bss++ = 0;
 160 
 161     // fill memory with this magic value so we could see what
 162     // parts of memory were or not used
 163     
 164     // update:
 165     // this seems to be required for unknown reason
 166     // or else sryproc startup will fail from
 167     // time to time...
 168 #if 0
 169     long *ptr;
 170     for (ptr=(void*)MEMBASEADDR;((long)ptr)<MEMISOSTART;ptr+=4)
 171                 {
 172                 ptr[0]=0x55555555;
 173                 ptr[1]=0x55555555;
 174                 ptr[2]=0x55555555;
 175                 ptr[3]=0x55555555;
 176                 }
 177 #endif
 178 
 179     boot();
 180         }
 181 
 182 long get_vbatt_min()
 183         {
 184     return 3500;
 185         }
 186 
 187 long get_vbatt_max()
 188         {
 189     return 4100;
 190         }
 191 
 192 // Focus length table in firmware @0xffd792e8
 193 #define NUM_FL      7   // 0 - 6, entries in firmware
 194 #define NUM_DATA    3   // 3 words each entry, first is FL
 195 extern int focus_len_table[NUM_FL*NUM_DATA];
 196 
 197 // Conversion factor lens FL --> 35mm equiv
 198 // lens      35mm     CF
 199 // ----      ----     --
 200 // 5.8       35       ( 35/ 5.8) * 580 = 3500  (min FL)
 201 // 17.4      105      (105/17.4) * 580 = 3500  (max FL)
 202 #define CF_EFL      3500
 203 #define CF_EFL_DIV  580
 204 
 205 const int zoom_points = NUM_FL;
 206 
 207 int get_effective_focal_length(int zp) {
 208     return (CF_EFL*get_focal_length(zp))/CF_EFL_DIV;
 209 }
 210 
 211 int get_focal_length(int zp) {
 212     if (zp < 0) zp = 0;
 213     else if (zp >= NUM_FL) zp = NUM_FL-1;
 214     return focus_len_table[zp*NUM_DATA];
 215 }
 216 
 217 int get_zoom_x(int zp) {
 218     return get_focal_length(zp)*10/focus_len_table[0];
 219 }
 220 
 221 int rec_mode_active(void) {
 222     //return ((physw_status[0]&0x03)==0x01) ? 0 : 1;
 223     return (playrec_mode==1); //(0 in play, 1 in record, 2 in record review)
 224 }
 225 
 226 #if 0
 227   //CAM_CONSOLE_LOG_ENABLED
 228 #define DEV_HDR_WRITE_OFFSET (0x14C/4)
 229 
 230 typedef int DEV_HDR;
 231 
 232 int (*_tyWriteOrig)(DEV_HDR *hdr, char *buf, int len);
 233 
 234 
 235 int hook_tyWriteOrig(DEV_HDR *hdr, char *buf, int len)
 236 {
 237         // Slow, but stable writes
 238         FILE *fd = fopen("A/stdout.txt", "a");
 239         if (fd) {
 240             fwrite(buf, 1, len, fd);
 241             fclose(fd);
 242         }
 243 
 244     return _tyWriteOrig(hdr, buf, len);
 245 
 246 }
 247 
 248 void cam_console_init()
 249 {
 250     DEV_HDR *DRV_struct;
 251 
 252     DRV_struct = _iosDevFind("/tyCo/0", 0);
 253 
 254     _tyWriteOrig = (void*)DRV_struct[DEV_HDR_WRITE_OFFSET];
 255 
 256         FILE *fd = fopen("A/chdklog.txt", "a");
 257         if (fd) {
 258             // can't be used with "Fut" API
 259             //fprintf(fd, "DRV_struct: %x, _tyWriteOrig: %x\n", DRV_struct, _tyWriteOrig);
 260             char buf[256];
 261             int buflen = sprintf(buf, "DRV_struct: %x, _tyWriteOrig: %x\n", DRV_struct, _tyWriteOrig);
 262             fwrite(buf, 1, buflen, fd);
 263         }
 264 
 265         FILE *fdout = fopen("A/stdout.txt", "r");
 266         if (fdout)
 267         {
 268         DRV_struct[DEV_HDR_WRITE_OFFSET] = (int)hook_tyWriteOrig;
 269         fclose(fdout);
 270             // fprintf(fd, "tyWrite replaced, camera log enabled\n");
 271             fwrite("tyWrite replaced, camera log enabled\n", 1, sizeof("tyWrite replaced, camera log enabled\n"), fd);
 272     }
 273 
 274         if (fd)
 275         {
 276             fclose(fd);
 277         }
 278 
 279 }
 280 xx
 281 #endif

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