root/platform/s80/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. init_file_modules_hook
  7. capt_seq_hook
  8. physw_hook
  9. movie_record_hook
  10. task_JogDial_hook
  11. my_ncmp
  12. createHook
  13. deleteHook
  14. startup
  15. get_vbatt_min
  16. get_vbatt_max
  17. get_effective_focal_length
  18. get_focal_length
  19. get_zoom_x

   1 #include "camera.h"
   2 #include "lolevel.h"
   3 #include "platform.h"
   4 #include "core.h"
   5 #include "keyboard.h"
   6 #include "stdlib.h"
   7 
   8 /* Ours stuff */
   9 extern long link_bss_start;
  10 extern long link_bss_end;
  11 extern void boot();
  12 
  13 static void core_hook_task_create(void *tcb)
  14 {
  15 }
  16 
  17 static void core_hook_task_delete(void *tcb)
  18 {
  19     char *name = (char*)(*(long*)((char*)tcb+0x34));
  20     if (strcmp(name,"tInitFileM")==0) core_spytask_can_start();
  21 }
  22 
  23 
  24 static int stop_hooking;
  25 
  26 static void (*task_prev)(
  27     long p0,    long p1,    long p2,    long p3,    long p4,
  28     long p5,    long p6,    long p7,    long p8,    long p9);
  29 
  30 static void (*init_file_modules_prev)(
  31     long p0,    long p1,    long p2,    long p3,    long p4,
  32     long p5,    long p6,    long p7,    long p8,    long p9);
  33 
  34 
  35 
  36 void spytask(long ua, long ub, long uc, long ud, long ue, long uf)
  37 {
  38     core_spytask();
  39 }
  40 
  41 
  42 static void task_start_hook(
  43     long p0,    long p1,    long p2,    long p3,    long p4,
  44     long p5,    long p6,    long p7,    long p8,    long p9)
  45 {
  46     _CreateTask("SpyTask", 0x19, 0x2000, spytask, 0);
  47 
  48     task_prev(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9 );
  49 }
  50 
  51 
  52 static void remount_filesystem()
  53 {
  54     _Unmount_FileSystem();
  55     _Mount_FileSystem();
  56 }
  57 
  58 
  59 static void init_file_modules_hook(
  60     long p0,    long p1,    long p2,    long p3,    long p4,
  61     long p5,    long p6,    long p7,    long p8,    long p9)
  62 {
  63     remount_filesystem();
  64     init_file_modules_prev(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9 );
  65 }
  66 
  67 
  68 static void capt_seq_hook(
  69     long p0,    long p1,    long p2,    long p3,    long p4,
  70     long p5,    long p6,    long p7,    long p8,    long p9)
  71 {
  72     capt_seq_task();
  73 }
  74 
  75 
  76 static void physw_hook(
  77     long p0,    long p1,    long p2,    long p3,    long p4,
  78     long p5,    long p6,    long p7,    long p8,    long p9)
  79 {
  80     mykbd_task();
  81 }
  82 
  83 static void movie_record_hook(
  84     long p0,    long p1,    long p2,    long p3,    long p4,
  85     long p5,    long p6,    long p7,    long p8,    long p9)
  86 {
  87     movie_record_task();
  88 }
  89 
  90 extern void task_JogDial_my();
  91 
  92 static void task_JogDial_hook(
  93     long p0,    long p1,    long p2,    long p3,    long p4,
  94     long p5,    long p6,    long p7,    long p8,    long p9)
  95 {
  96     task_JogDial_my();
  97 }
  98 
  99 static int my_ncmp(const char *s1, const char *s2, long len)
 100 {
 101     int i;
 102     for (i=0;i<len;i++){
 103         if (s1[i] != s2[i])
 104             return 1;
 105     }
 106     return 0;
 107 }
 108 
 109 void createHook (void *pNewTcb)
 110 {
 111     char *name = (char*)(*(long*)((char*)pNewTcb+0x34));
 112     long *entry = (long*)((char*)pNewTcb+0x74);
 113 
 114     // always hook first task creation
 115     // to create SpyProc
 116     if (!stop_hooking){
 117         task_prev = (void*)(*entry);
 118         *entry = (long)task_start_hook;
 119         stop_hooking = 1;
 120     } else {
 121         // hook/replace another tasks
 122         if (my_ncmp(name, "tPhySw", 6) == 0){
 123             *entry = (long)physw_hook;
 124         }
 125         
 126         if (my_ncmp(name, "tInitFileM", 10) == 0){
 127             init_file_modules_prev = (void*)(*entry);
 128         #if CAM_MULTIPART
 129             *entry = (long)init_file_modules_task;
 130         #else
 131             *entry = (long)init_file_modules_hook;
 132         #endif
 133         }
 134         
 135         if (my_ncmp(name, "tCaptSeqTa", 10) == 0){
 136             *entry = (long)capt_seq_hook;
 137         }
 138         
 139         if (my_ncmp(name, "tJogDial", 8) == 0){
 140             *entry = (long)task_JogDial_hook;
 141         }
 142         
 143         if (my_ncmp(name, "tMovieReco", 10) == 0){
 144         #if CAM_CHDK_HAS_EXT_VIDEO_MENU
 145             *entry = (long)movie_record_hook;
 146         #endif
 147         }
 148         
 149         #if CAM_EXT_TV_RANGE
 150         if (my_ncmp(name, "tExpDrvTas", 10) == 0){
 151             *entry = (long)exp_drv_task;
 152         }
 153         #endif
 154         
 155         core_hook_task_create(pNewTcb);
 156     }
 157 }
 158 
 159 void deleteHook (void *pTcb)
 160 {
 161     core_hook_task_delete(pTcb);
 162 }
 163 
 164 void startup()
 165 {
 166     long *bss = &link_bss_start;
 167 
 168     // sanity check
 169     if ((long)&link_bss_end > (MEMISOSTART + MEMISOSIZE)){
 170         started();
 171         shutdown();
 172     }
 173 
 174     // initialize .bss senment
 175     while (bss<&link_bss_end)
 176         *bss++ = 0;
 177 
 178     boot();
 179 }
 180 
 181 /*********************************************************************/
 182 
 183 long get_vbatt_min()
 184 {
 185     return 6700;
 186 }
 187 
 188 long get_vbatt_max()
 189 {
 190     return 8100;
 191 }
 192 
 193 // Focus length table in firmware @0xfffe41f4
 194 #define NUM_FL      9   // 0 - 8, 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       28       ( 28/ 5.8) * 580 = 2800  (min FL)
 202 // 20.7      100      (100/20.7) * 580 = 2800  (max FL)
 203 #define CF_EFL      2800
 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 playrec_mode:
 224 3 when switched into play mode while in record mode
 225 2 record mode
 226 4 in recmode menu
 227 5 when recmode overlay animation is activated by the jogdial
 228 0 when switched on in play mode
 229 */

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