source: trunk/core/main.c @ 1505

Revision 1505, 5.0 KB checked in by reyalp, 17 months ago (diff)

merge tsvstar module code from reyalp-flt branch, + fixups for r1499, see http://chdk.setepontos.com/index.php?topic=847.msg77690#msg77690 and following posts
NOTE modules in CHDK/MODULES are now required for CHDK to work properly. On multi-partition cards, this goes on the large card.
Adds tetris and snake, originally contributed by elektro255 in http://chdk.setepontos.com/index.php?topic=2925.0

  • Property svn:eol-style set to native
Line 
1#include "platform.h"
2#include "core.h"
3#include "conf.h"
4#include "keyboard.h"
5#include "stdlib.h"
6#include "gui.h"
7#include "histogram.h"
8#include "raw.h"
9#ifdef OPT_EDGEOVERLAY
10    #include "modules.h"
11#endif
12
13#include "module_load.h"
14#include "gui_draw.h"
15
16static int raw_need_postprocess;
17static volatile int spytask_can_start;
18
19void core_hook_task_create(void *tcb) {
20}
21
22void core_hook_task_delete(void *tcb) {
23    char *name = (char*)(*(long*)((char*)tcb+0x34));
24    if (strcmp(name,"tInitFileM")==0) core_spytask_can_start();
25}
26
27long core_get_noise_reduction_value() {
28    return conf.raw_nr;
29}
30
31void dump_memory() {
32    int fd;
33    static int cnt=1;
34    static char fn[32];
35
36    started();
37    mkdir("A/DCIM");
38    mkdir("A/DCIM/100CANON");
39    sprintf(fn, "A/DCIM/100CANON/CRW_%04d.JPG", cnt++);
40    fd = open(fn, O_WRONLY|O_CREAT, 0777);
41    if (fd) {
42        long val0 = *((long*)(0|CAM_UNCACHED_BIT));
43        write(fd, &val0, 4);
44        write(fd, (void*)4, MAXRAMADDR-3);   // MAXRAMADDR is last valid RAM location
45        close(fd);
46    }
47    vid_bitmap_refresh();
48    finished();
49}
50
51int core_get_free_memory() {
52#if defined(OPT_EXMEM_MALLOC) && !defined(OPT_EXMEM_TESTING)
53        // If using the exmem / suba memory allocation system then don't need
54        // to try allocating memory to find out how much is available
55        // Call function to scan free list for the largest free block available.
56    cam_meminfo camera_meminfo;
57    GetExMemInfo(&camera_meminfo);
58    return camera_meminfo.free_block_max_size;
59#elif defined(CAM_FIRMWARE_MEMINFO)
60    // Call firmware function to fill memory info structure and return size of largest free block
61    cam_meminfo camera_meminfo;
62    GetMemInfo(&camera_meminfo);
63    return camera_meminfo.free_block_max_size;
64#else
65        int size, l_size, d;
66    char* ptr;
67
68    size = 16;
69    while (1) {
70        ptr= malloc(size);
71        if (ptr) {
72            free(ptr);
73            size <<= 1;
74        } else
75            break;
76    }
77
78    l_size = size;
79    size >>= 1;
80    d=1024;
81    while (d) {
82        ptr = malloc(size);
83        if (ptr) {
84            free(ptr);
85            d = l_size-size;
86            if (d<0) d=-d;
87            l_size = size;
88            size += d>>1;
89        } else {
90            d = size-l_size;
91            if (d<0) d=-d;
92            l_size = size;
93            size -= d>>1;
94        }
95       
96    }
97    return size-1;
98#endif
99}
100
101static volatile long raw_data_available;
102
103// called from another process
104void core_rawdata_available() {
105    raw_data_available = 1;
106}
107
108void core_spytask_can_start() {
109    spytask_can_start = 1;
110}
111
112void core_spytask() {
113    int cnt = 1;
114    int i=0;
115
116    raw_need_postprocess = 0;
117
118    spytask_can_start=0;
119
120#ifdef OPT_EXMEM_MALLOC
121        exmem_malloc_init();
122#endif
123
124#ifdef CAM_CHDK_PTP
125    init_chdk_ptp_task();
126#endif
127
128    while((i++<400) && !spytask_can_start) msleep(10);
129
130    started();
131    msleep(50);
132    finished();
133    drv_self_unhide();
134
135    conf_restore();
136    gui_init();
137
138#if CAM_CONSOLE_LOG_ENABLED
139    cam_console_init();
140#endif
141
142    mkdir("A/CHDK");
143    mkdir("A/CHDK/FONTS");
144    mkdir("A/CHDK/SYMBOLS");
145    mkdir("A/CHDK/SCRIPTS");
146    mkdir("A/CHDK/LANG");
147    mkdir("A/CHDK/BOOKS");
148    mkdir("A/CHDK/MODULES");
149    mkdir("A/CHDK/GRIDS");
150#ifdef OPT_CURVES
151    mkdir("A/CHDK/CURVES");
152#endif
153    mkdir("A/CHDK/DATA");
154    mkdir("A/CHDK/LOGS");
155#ifdef OPT_EDGEOVERLAY
156    mkdir("A/CHDK/EDGE");
157#endif
158    auto_started = 0;
159
160#ifdef OPT_SCRIPTING
161    if (conf.script_startup==1) script_autostart();    // remote autostart
162    if (conf.script_startup==2) {
163        conf.script_startup=0;
164        conf_save();
165        script_autostart();
166    }
167#endif
168
169    while (1) {
170
171#ifdef  CAM_LOAD_CUSTOM_COLORS
172        load_chdk_palette();
173#endif
174
175        if (raw_data_available) {
176            raw_need_postprocess = raw_savefile();
177            hook_raw_save_complete();
178            raw_data_available = 0;
179            continue;
180        }
181
182        if ((state_shooting_progress != SHOOTING_PROGRESS_PROCESSING) || recreview_hold)
183                {
184            if (((cnt++) & 3) == 0)
185                gui_redraw();
186                }
187               
188        if (state_shooting_progress != SHOOTING_PROGRESS_PROCESSING)
189        {       
190            histogram_process();
191
192
193#ifdef OPT_EDGEOVERLAY
194            if(conf.edge_overlay_thresh && conf.edge_overlay_enable) {
195
196                                // We need to skip first tick because stability
197                                static int skip_counter=1;
198                               
199                                if (skip_counter>0) {
200                                        skip_counter--;
201                                }
202                                else if (module_edgeovr_load()) {
203                                        edge_overlay();
204                                }
205                        }
206#endif
207        }
208
209        if ((state_shooting_progress == SHOOTING_PROGRESS_PROCESSING) && (!shooting_in_progress())) {
210            state_shooting_progress = SHOOTING_PROGRESS_DONE;
211            if (raw_need_postprocess) raw_postprocess();
212        }
213
214#ifdef DEBUG_PRINT_TO_LCD
215                char osd_buf[30];
216                sprintf(osd_buf, "%d", cnt );   // modify cnt to what you want to display
217                draw_txt_string(2, 2, osd_buf, conf.osd_color);
218#endif 
219
220                // Process async module unload requests
221                module_tick_unloader();
222
223        msleep(20);
224    }
225}
226
227long ftell(FILE *file) {
228    if(!file) return -1;
229    return file->pos;
230}
Note: See TracBrowser for help on using the repository browser.