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

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