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

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