root/platform/ixus30_sd200/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 static void remount_filesystem()
  58 {
  59     _Unmount_FileSystem();
  60     _Mount_FileSystem();
  61 }
  62 
  63 static void task_fs(
  64     long p0,    long p1,    long p2,    long p3,    long p4,
  65     long p5,    long p6,    long p7,    long p8,    long p9)
  66         {
  67     remount_filesystem();
  68     taskfsprev(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9 );
  69         }
  70 
  71 
  72 static void capt_seq_hook(
  73     long p0,    long p1,    long p2,    long p3,    long p4,
  74     long p5,    long p6,    long p7,    long p8,    long p9)
  75         {
  76     capt_seq_task();
  77         }
  78 
  79 static void movie_record_hook(
  80     long p0,    long p1,    long p2,    long p3,    long p4,
  81     long p5,    long p6,    long p7,    long p8,    long p9)
  82         {
  83     movie_record_task();
  84         }
  85 
  86 
  87 
  88 static int my_ncmp(const char *s1, const char *s2, long len)
  89         {
  90     int i;
  91     for (i=0;i<len;i++)
  92                 {
  93                 if (s1[i] != s2[i])
  94                         return 1;
  95                 }
  96     return 0;
  97         }
  98 
  99 void createHook (void *pNewTcb)
 100 {
 101     char *name = (char*)(*(long*)((char*)pNewTcb+0x34));
 102     long *entry = (long*)((char*)pNewTcb+0x74);
 103     
 104     
 105     // always hook first task creation
 106     // to create SpyTask
 107     if (!stop_hooking){
 108 
 109         taskprev = (void*)(*entry);
 110         *entry = (long)task_start_hook;
 111         stop_hooking = 1;
 112 
 113     }else{
 114 
 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 
 133         if (my_ncmp(name, "tMovieRecT", 10) == 0){
 134             *entry = (long)movie_record_hook;
 135         }
 136 
 137         core_hook_task_create(pNewTcb);
 138         }
 139 }
 140 
 141 void deleteHook (void *pTcb)
 142         {
 143     core_hook_task_delete(pTcb);
 144         }
 145 
 146 void startup()
 147         {
 148     long *bss = &link_bss_start;
 149 
 150     // sanity check
 151     if ((long)&link_bss_end > (MEMISOSTART + MEMISOSIZE)) {
 152                         started();
 153                         shutdown();
 154     }
 155 
 156     // initialize .bss segment
 157     while (bss<&link_bss_end)
 158                 *bss++ = 0;
 159 
 160     // fill memory with this magic value so we could see what
 161     // parts of memory were or not used
 162     
 163     // update:
 164     // this seems to be required for unknown reason
 165     // or else sryproc startup will fail from
 166     // time to time...
 167 #if 0
 168     long *ptr;
 169     for (ptr=(void*)MEMBASEADDR;((long)ptr)<MEMISOSTART;ptr+=4)
 170                 {
 171                 ptr[0]=0x55555555;
 172                 ptr[1]=0x55555555;
 173                 ptr[2]=0x55555555;
 174                 ptr[3]=0x55555555;
 175                 }
 176 #endif
 177 
 178     boot();
 179         }
 180 
 181 long get_vbatt_min()
 182         {
 183     return 3500;
 184         }
 185 
 186 long get_vbatt_max()
 187         {
 188     return 4100;
 189         }
 190 
 191 // Focus length table in firmware @0xffd792e8
 192 #define NUM_FL      7   // 0 - 6, entries in firmware
 193 #define NUM_DATA    3   // 3 words each entry, first is FL
 194 extern int focus_len_table[NUM_FL*NUM_DATA];
 195 
 196 // Conversion factor lens FL --> 35mm equiv
 197 // lens      35mm     CF
 198 // ----      ----     --
 199 // 5.8       35       ( 35/ 5.8) * 580 = 3500  (min FL)
 200 // 17.4      105      (105/17.4) * 580 = 3500  (max FL)
 201 #define CF_EFL      3500
 202 #define CF_EFL_DIV  580
 203 
 204 const int zoom_points = NUM_FL;
 205 
 206 int get_effective_focal_length(int zp) {
 207     return (CF_EFL*get_focal_length(zp))/CF_EFL_DIV;
 208 }
 209 
 210 int get_focal_length(int zp) {
 211     if (zp < 0) zp = 0;
 212     else if (zp >= NUM_FL) zp = NUM_FL-1;
 213     return focus_len_table[zp*NUM_DATA];
 214 }
 215 
 216 int get_zoom_x(int zp) {
 217     return get_focal_length(zp)*10/focus_len_table[0];
 218 }
 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] */