root/platform/s2is/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. screen_opened
  19. screen_rotated
  20. rec_mode_active

   1 #define VBATT_DEFAULT_MIN (4550)
   2 #define VBATT_DEFAULT_MAX (5150)
   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 
  15 static void core_hook_task_create(__attribute__ ((unused))void *tcb)
  16 {
  17 }
  18 
  19 static void core_hook_task_delete(void *tcb)
  20 {
  21     char *name = (char*)(*(long*)((char*)tcb+0x34));
  22     if (strcmp(name,"tInitFileM")==0) core_spytask_can_start();
  23 }
  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();
  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);
  50 
  51     taskprev(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9 );
  52 }
  53 
  54 
  55 static void remount_filesystem()
  56 {
  57     _Unmount_FileSystem();
  58     _Mount_FileSystem();
  59 }
  60 
  61 
  62 static void task_fs(
  63     long p0,    long p1,    long p2,    long p3,    long p4,
  64     long p5,    long p6,    long p7,    long p8,    long p9)
  65 {
  66     remount_filesystem();
  67     taskfsprev(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9 );
  68 }
  69 
  70 
  71 static void capt_seq_hook(
  72     long p0,    long p1,    long p2,    long p3,    long p4,
  73     long p5,    long p6,    long p7,    long p8,    long p9)
  74 {
  75     (void)p0; (void)p1; (void)p2; (void)p3; (void)p4; (void)p5; (void)p6; (void)p7; (void)p8; (void)p9;
  76     capt_seq_task();
  77 }
  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 static int my_ncmp(const char *s1, const char *s2, long len)
  90 {
  91     int i;
  92     for (i=0;i<len;i++){
  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     // always hook first task creation
 105     // to create SpyProc
 106     if (!stop_hooking){
 107         taskprev = (void*)(*entry);
 108         *entry = (long)task_start_hook;
 109         stop_hooking = 1;
 110     } else {
 111         // hook/replace another tasks
 112         if (my_ncmp(name, "tSwitchChe", 10) == 0){
 113             *entry = (long)mykbd_task;
 114         }
 115         if (my_ncmp(name, "tInitFileM", 10) == 0){
 116             taskfsprev = (void*)(*entry);
 117             *entry = (long)task_fs;
 118         }
 119 
 120         if (my_ncmp(name, "tCaptSeqTa", 10) == 0){
 121             *entry = (long)capt_seq_hook;
 122         }
 123 
 124         if (my_ncmp(name, "tMovieRecT", 10) == 0){
 125             *entry = (long)movie_record_hook;
 126         }
 127 
 128         core_hook_task_create(pNewTcb);
 129     }
 130 }
 131 
 132 void deleteHook (void *pTcb)
 133 {
 134     core_hook_task_delete(pTcb);
 135 }
 136 
 137 void startup()
 138 {
 139     long *bss = &link_bss_start;
 140 
 141 
 142     // sanity check
 143     if ((long)&link_bss_end > (MEMISOSTART + MEMISOSIZE)){
 144         started();
 145         shutdown();
 146     }
 147 
 148     // initialize .bss senment
 149     while (bss<&link_bss_end)
 150         *bss++ = 0;
 151 
 152     // fill memory with this magic value so we could see what
 153     // parts of memory were or not used
 154     
 155     // update:
 156     // this seems to be required for unknown reason
 157     // or else sryproc startup will fail from
 158     // time to time...
 159 #if 0
 160     long *ptr;
 161     for (ptr=(void*)MEMBASEADDR;((long)ptr)<MEMISOSTART;ptr+=4){
 162         ptr[0]=0x55555555;
 163         ptr[1]=0x55555555;
 164         ptr[2]=0x55555555;
 165         ptr[3]=0x55555555;
 166     }
 167 #endif
 168 
 169     boot();
 170 }
 171 
 172 long get_vbatt_min()
 173 {
 174     return 4550;
 175 }
 176 
 177 long get_vbatt_max()
 178 {
 179     return 5150;
 180 }
 181 
 182 static const struct {
 183     int zp, fl;
 184 } fl_tbl[] = {
 185     {   0,   6000 },
 186     {  11,   6400 },
 187     {  41,  12100 },
 188     {  64,  21300 },
 189     {  86,  41600 },
 190     { 105,  61400 },
 191     { 128,  72000 },
 192 };
 193 #define NUM_FL (int)(sizeof(fl_tbl)/sizeof(fl_tbl[0]))
 194 #define CF_EFL 6000
 195 
 196 const int zoom_points = 129;
 197 
 198 int get_effective_focal_length(int zp) {
 199     return (CF_EFL*get_focal_length(zp))/1000;
 200 }
 201 
 202 int get_focal_length(int zp) {
 203     int i;
 204 
 205     if (zp<fl_tbl[0].zp)
 206         return fl_tbl[0].fl;
 207     else if (zp>fl_tbl[NUM_FL-1].zp)
 208         return fl_tbl[NUM_FL-1].fl;
 209     else 
 210         for (i=1; i<NUM_FL; ++i) {
 211            if (zp==fl_tbl[i-1].zp) 
 212                return fl_tbl[i-1].fl;
 213            else if (zp==fl_tbl[i].zp) 
 214                return fl_tbl[i].fl;
 215            else if (zp<fl_tbl[i].zp)
 216                return fl_tbl[i-1].fl+(zp-fl_tbl[i-1].zp)*(fl_tbl[i].fl-fl_tbl[i-1].fl)/(fl_tbl[i].zp-fl_tbl[i-1].zp);
 217         }
 218     return fl_tbl[NUM_FL-1].fl;
 219 }
 220 
 221 int get_zoom_x(int zp) {
 222     return get_focal_length(zp)*10/fl_tbl[0].fl;
 223 }
 224 
 225 
 226 int screen_opened(void) {
 227 //    mode |= (physw_copy[1] & 0x00000001)?0:MODE_SCREEN_OPENED;
 228         return !(physw_copy[1] & 0x00000001);
 229 }
 230 
 231 int screen_rotated(void) {
 232 //    mode |= (physw_copy[1] & 0x00000002)?0:MODE_SCREEN_ROTATED;
 233         return !(physw_copy[1] & 0x00000002);
 234 }
 235 
 236 int rec_mode_active(void) {
 237 //    mode  = (playrec_mode==1)?MODE_REC:MODE_PLAY;
 238         return (playrec_mode==1);
 239 }

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