CHDK_DE Vorschauversion  Trunk Rev. 5575
 Alle Datenstrukturen Dateien Funktionen Variablen Typdefinitionen Aufzählungen Aufzählungswerte Makrodefinitionen
ubasic.c-Dateireferenz
#include "camera_info.h"
#include "conf.h"
#include "ubasic.h"
#include "script.h"
#include "script_key_funcs.h"
#include "shot_histogram.h"
#include "stdlib.h"
#include "levent.h"
#include "console.h"
#include "modes.h"
#include "shooting.h"
#include "sd_card.h"
#include "backlight.h"
#include "battery.h"
#include "temperature.h"
#include "clock.h"
#include "properties.h"
#include "file_counter.h"
#include "lens.h"
#include "debug_led.h"
#include "keyboard.h"
#include "usb_remote.h"
#include "shutdown.h"
#include "sound.h"
#include "motion_detector.h"
#include "action_stack.h"
#include "tokenizer.h"
#include "lang.h"
#include "gui_lang.h"
+ Include-Abhängigkeitsdiagramm für ubasic.c:

gehe zum Quellcode dieser Datei

Datenstrukturen

struct  select_state
 
struct  for_state
 

Makrodefinitionen

#define DEBUG_PRINTF(...)
 
#define INCLUDE_OLD_GET__SYNTAX
 
#define MAX_STRINGLEN   40
 
#define MAX_GOSUB_STACK_DEPTH   10
 
#define MAX_IF_STACK_DEPTH   4
 
#define MAX_SELECT_STACK_DEPTH   4
 
#define MAX_WHILE_STACK_DEPTH   4
 
#define MAX_DO_STACK_DEPTH   4
 
#define MAX_FOR_STACK_DEPTH   4
 
#define MAX_VARNUM   52
 
#define YIELD_MAX_LINES_DEFAULT   1
 
#define YIELD_MAX_MS_DEFAULT   10
 

Funktionen

int ubasic_get_variable (int varnum)
 
void ubasic_set_variable (int varum, int value)
 
static int expr (void)
 
static void line_statement (void)
 
static void statement (void)
 
static int relation (void)
 
int ubasic_linenumber ()
 
int ubasic_init (const char *program, int is_ptp)
 
static int ubasic_get_key_arg ()
 
static void accept (int token)
 
static void accept_cr ()
 
static int varfactor (void)
 
static int shooting_get_near_limit_of_acceptable_sharpness ()
 
static int shooting_get_far_limit_of_acceptable_sharpness ()
 
static int shooting_get_depth_of_field ()
 
static int shooting_get_min_stack_distance ()
 
static int factor (void)
 
static int term (void)
 
static void jump_line (int linenum)
 
int jump_label (char *label)
 
static void goto_statement (void)
 
static void print_statement (void)
 
static void endif_statement (void)
 
static void if_statement (void)
 
static void else_statement (void)
 
static void dec_select_stack (void)
 
static void end_select_statement (void)
 
static void case_statement (void)
 
static void case_else_statement (void)
 
static void select_statement (void)
 
static void let_statement (void)
 
static void rem_statement (void)
 
static void cls_statement (void)
 
static void gosub_statement (void)
 
static void return_statement (void)
 
static void next_statement (void)
 
static void for_statement (void)
 
static void do_statement (void)
 
static void until_statement (void)
 
static void while_statement (void)
 
static void wend_statement (void)
 
static void end_statement (void)
 
static void click_statement (void)
 
static void press_statement (void)
 
static void release_statement (void)
 
static int action_stack_AS_UBASIC_SLEEP ()
 
static int sleep_delay (int delay)
 
static void sleep_statement (void)
 
static void shoot_statement (void)
 
static void set_console_layout (void)
 
static void set_console_autoredraw (void)
 
static void console_redraw_statement (void)
 
static void set_yield_statement ()
 
static void get_short_var_statement (int token, short(*func)(void))
 
static void get_int_var_statement (int token, int(*func)(void))
 
static void get_prop_statement ()
 
static void one_int_param_function (int token, void(*func)(int))
 
static void one_short_param_function (int token, void(*func)(short))
 
static void one_int_param_plus_const_function (int token, void(*func)(int, short), short p2)
 
static void one_short_param_plus_const_function (int token, void(*func)(short, short), short p2)
 
static void set_ev_statement ()
 
static void set_movie_status_statement ()
 
static void set_propcase_statement (int token, int prop)
 
static void set_mf_statement ()
 
static void set_focus_statement ()
 
static void set_led_statement ()
 
static void set_prop_statement ()
 
static void set_autostart_statement ()
 
static void set_capture_mode_canon_statement ()
 
static void reboot_statement ()
 
static void set_config_value_statement ()
 
static int action_stack_AS_UBASIC_WAIT_CLICK ()
 
static void wait_click_statement ()
 
static void is_key_statement (void)
 
static void set_exit_key_statement ()
 
static void get_config_value_statement ()
 
static void on_off_statement (int token, void(*on)(void), void(*off)(void))
 
static void shutdown_statement (void)
 
static void uB_set_av96 (int param)
 
static void uB_set_av96_direct (int param)
 
static void uB_set_tv96 (int param)
 
static void uB_set_tv96_direct (int param)
 
static void uB_set_sv96 (int param)
 
static void uB_set_nd_filter_state (int param)
 
static void uB_set_iso_real (int param)
 
static void md_get_cell_diff_statement ()
 
static void md_get_cell_val_statement ()
 
static void md_detect_motion_statement ()
 
static int _shot_histogram_set (int enable)
 
int ubasic_run (void)
 
void ubasic_end ()
 
void ubasic_set_as_ret (int md_ret)
 

Variablen

static char constprogram_ptr
 
static char string [MAX_STRINGLEN]
 
static short gosub_stack [MAX_GOSUB_STACK_DEPTH]
 
static int gosub_stack_ptr
 
static short if_stack [MAX_IF_STACK_DEPTH]
 
static int if_stack_ptr
 
static struct select_state select_stack [MAX_SELECT_STACK_DEPTH]
 
static int select_stack_ptr
 
static short while_stack [MAX_WHILE_STACK_DEPTH]
 
static int while_stack_ptr
 
static short do_stack [MAX_DO_STACK_DEPTH]
 
static int do_stack_ptr
 
static struct for_state for_stack [MAX_FOR_STACK_DEPTH]
 
static int for_stack_ptr
 
static int variables [MAX_VARNUM]
 
static int ended
 
static int ubasic_as_ret_var_num
 
static unsigned yield_max_lines
 
static unsigned yield_max_ms
 
static int flag_yield
 
int ubasic_error
 
const char * ubasic_errstrings [UBASIC_E_ENDMARK]
 

Makro-Dokumentation

#define DEBUG_PRINTF (   ...)

Definiert in Zeile 34 der Datei ubasic.c.

#define INCLUDE_OLD_GET__SYNTAX

Definiert in Zeile 86 der Datei ubasic.c.

#define MAX_DO_STACK_DEPTH   4

Definiert in Zeile 112 der Datei ubasic.c.

#define MAX_FOR_STACK_DEPTH   4

Definiert in Zeile 122 der Datei ubasic.c.

#define MAX_GOSUB_STACK_DEPTH   10

Definiert in Zeile 92 der Datei ubasic.c.

#define MAX_IF_STACK_DEPTH   4

Definiert in Zeile 96 der Datei ubasic.c.

#define MAX_SELECT_STACK_DEPTH   4

Definiert in Zeile 104 der Datei ubasic.c.

#define MAX_STRINGLEN   40

Definiert in Zeile 89 der Datei ubasic.c.

#define MAX_VARNUM   52

Definiert in Zeile 126 der Datei ubasic.c.

#define MAX_WHILE_STACK_DEPTH   4

Definiert in Zeile 108 der Datei ubasic.c.

#define YIELD_MAX_LINES_DEFAULT   1

Definiert in Zeile 144 der Datei ubasic.c.

#define YIELD_MAX_MS_DEFAULT   10

Definiert in Zeile 145 der Datei ubasic.c.

Dokumentation der Funktionen

static int _shot_histogram_set ( int  enable)
static

Definiert in Zeile 2226 der Datei ubasic.c.

2227 {
2228  return libshothisto->shot_histogram_set(enable);
2229 }
static void accept ( int  token)
static

Definiert in Zeile 212 der Datei ubasic.c.

213 {
214  if(token != tokenizer_token()) {
215  DEBUG_PRINTF("Token not what was expected (expected %d, got %d)\n",
218  tokenizer_next();
219  ended = 1;
221  return;
222  }
223  DEBUG_PRINTF("Expected %d, got it\n", token);
224  tokenizer_next();
225 }
static void accept_cr ( )
static

Definiert in Zeile 228 der Datei ubasic.c.

229 {
230  while(tokenizer_token() != TOKENIZER_CR &&
232  tokenizer_next();
234 }
static int action_stack_AS_UBASIC_SLEEP ( )
static

Definiert in Zeile 1642 der Datei ubasic.c.

1643 {
1644  if (get_tick_count() >= action_top(2))
1645  {
1646  action_pop_func(1);
1647  return 1;
1648  }
1649  return 0;
1650 }
static int action_stack_AS_UBASIC_WAIT_CLICK ( )
static

Definiert in Zeile 1947 der Datei ubasic.c.

1948 {
1949  // Check key pressed or timeout
1951  {
1952  // If timed out set key state to "no_key", otherwise key pressed so set last checked time
1955  else
1957 
1958  action_pop_func(1);
1959  return 1;
1960  }
1961 
1962  return 0;
1963 }
static void case_else_statement ( void  )
static

Definiert in Zeile 1278 der Datei ubasic.c.

1279 {
1280  short case_goto = 0, case_gosub = 0;
1281  int cur_ln, gosub_ln = 0;
1282 
1284  if(select_stack_ptr > 0) {
1285  if (!select_stack[select_stack_ptr - 1].case_run) {
1286  case_goto = (tokenizer_token() == TOKENIZER_GOTO);
1287  case_gosub = (tokenizer_token() == TOKENIZER_GOSUB);
1288 //GOSUB - save curr linenumber
1289  cur_ln = tokenizer_line_number();
1290 //GOSUB
1291  statement();
1292 //GOSUB - save new linenumber, reset to curr linenumber
1293  if (case_gosub) {
1294  gosub_ln = tokenizer_line_number();
1295  jump_line(cur_ln+1);
1296  DEBUG_PRINTF("case_else_statement: GOSUB: toLN=%d, nextLN=%d\n", gosub_ln, cur_ln+1);
1297  }
1298 //GOSUB
1299  DEBUG_PRINTF("case_else_statement: case_else execute\n");
1300  } else {
1301  DEBUG_PRINTF("case_else_statement: case_else jump; case_run: %d\n", select_stack[select_stack_ptr - 1].case_run);
1302  accept_cr();
1303  }
1304 //REM
1305  while ((tokenizer_token() == TOKENIZER_REM) && (!case_goto)) {statement();}
1306 //REM
1307  if (case_goto) { dec_select_stack(); } else {
1308 //GOSUB test for end_select and set to gosub-linenumber
1310  DEBUG_PRINTF("ubasic.c: select_statement(): don't found end_select\n");
1311  ended = 1;
1313  } else {
1315  if (case_gosub) {
1317  jump_line(gosub_ln);
1318  DEBUG_PRINTF("end_select_statement: GOSUB: returnLN=%d\n", gosub_stack[gosub_stack_ptr-1]);
1319  }
1320  }
1321 //GOSUB
1322  }
1323  } else {
1324  DEBUG_PRINTF("case_else_statement: SELECT-Stack fault\n");
1325  ended = 1;
1327  }
1328 }
static void case_statement ( void  )
static

Definiert in Zeile 1188 der Datei ubasic.c.

1189 {
1190  int select_value, case_value_1, case_value_2, case_value_eq;
1191  short case_run, case_goto = 0, case_gosub = 0;
1192  int cur_ln, gosub_ln = 0;
1193 
1195  if(select_stack_ptr > 0) {
1196  select_value = select_stack[select_stack_ptr - 1].select_value;
1197  case_run = select_stack[select_stack_ptr - 1].case_run;
1198 
1199  if (!case_run) {
1200  case_value_1 = expr();
1201  case_value_eq = (select_value == case_value_1);
1202  if (case_value_eq) { DEBUG_PRINTF("case_statement: case_value_eq %d, case_value %d\n", case_value_eq, case_value_1); }
1203 
1204  if(tokenizer_token() == TOKENIZER_TO) {
1206  case_value_2 = expr();
1207  if (case_value_1 < case_value_2) {
1208  case_value_eq = ((select_value >= case_value_1) && (select_value <= case_value_2));
1209  DEBUG_PRINTF("case_statement: case_value %d to %d\n", case_value_1, case_value_2);
1210  } else {
1211  case_value_eq = ((select_value >= case_value_2) && (select_value <= case_value_1));
1212  DEBUG_PRINTF("case_statement: case_value %d to %d\n", case_value_2, case_value_1);
1213  }
1214  } else if (tokenizer_token() == TOKENIZER_COMMA) {
1215  do {
1217  if (case_value_eq) {
1218  case_value_2 = expr();
1219  } else {
1220  case_value_1 = expr();
1221  case_value_eq = (select_value == case_value_1);
1222  }
1223  } while (tokenizer_token() == TOKENIZER_COMMA);
1224  DEBUG_PRINTF("case_statement: case_value_eq %d, case_value_comma %d\n", case_value_eq, case_value_1);
1225  }
1226 
1228  if (case_value_eq) {
1229  case_goto = (tokenizer_token() == TOKENIZER_GOTO);
1230  case_gosub = (tokenizer_token() == TOKENIZER_GOSUB);
1231 //GOSUB - save curr linenumber
1232  cur_ln = tokenizer_line_number();
1233 //GOSUB
1234  statement();
1235 //GOSUB - save new linenumber, reset to curr linenumber
1236  if (case_gosub) {
1237  gosub_ln = tokenizer_line_number();
1238  jump_line(cur_ln+1);
1239  DEBUG_PRINTF("case_statement: GOSUB: toLN=%d, nextLN=%d\n", gosub_ln, cur_ln+1);
1240  }
1241 //GOSUB
1242  DEBUG_PRINTF("case_statement: case execute\n");
1243  case_run = 1;
1244  select_stack[select_stack_ptr - 1].case_run = case_run;
1245  } else {
1246  DEBUG_PRINTF("case_statement: case jump; case_run: %d\n", case_run);
1247  accept_cr();
1248  }
1249  } else {accept_cr();}
1250 //REM
1251  while ((tokenizer_token() == TOKENIZER_REM) && (!case_goto)) {statement();}
1252 //REM
1253  if (case_goto) { dec_select_stack(); } else {
1256  DEBUG_PRINTF("ubasic.c: select_statement(): don't found case, case_else or end_select\n");
1257  ended = 1;
1259  } else {
1260 //GOSUB test for end_select and set to gosub-linenumber
1262  if (case_gosub) {
1264  jump_line(gosub_ln);
1265  DEBUG_PRINTF("end_select_statement: GOSUB: returnLN=%d\n", gosub_stack[gosub_stack_ptr-1]);
1266  }
1267  }
1268 //GOSUB
1269  }
1270  } else {
1271  DEBUG_PRINTF("case_statement: SELECT-Stack fail\n");
1272  ended = 1;
1274  }
1275 }
static void click_statement ( void  )
static

Definiert in Zeile 1598 der Datei ubasic.c.

1599 {
1600  int k;
1602  k = ubasic_get_key_arg();
1603  if (k > 0) {
1604  action_push_click(k);
1605  flag_yield=1;
1606  }
1607 
1608  DEBUG_PRINTF("End of click\n");
1609  accept_cr();
1610 }
static void cls_statement ( void  )
static

Definiert in Zeile 1386 der Datei ubasic.c.

1387 {
1389  console_clear();
1390  DEBUG_PRINTF("cls_statement\n");
1392 }
static void console_redraw_statement ( void  )
static

Definiert in Zeile 1717 der Datei ubasic.c.

1718 {
1720  console_redraw();
1721  accept_cr();
1722 }
static void dec_select_stack ( void  )
static

Definiert in Zeile 1162 der Datei ubasic.c.

1163 {
1164  if(select_stack_ptr > 0) {
1165  select_stack_ptr--;
1166  } else {
1167  DEBUG_PRINTF("select_statement: SELECT-Stack fail\n");
1168  ended = 1;
1170  }
1171 }
static void do_statement ( void  )
static

Definiert in Zeile 1500 der Datei ubasic.c.

1501 {
1506  do_stack_ptr++;
1507  } else {
1508  DEBUG_PRINTF("do_statement: do stack depth exceeded\n");
1509  ended = 1;
1511  }
1512 }
static void else_statement ( void  )
static

Definiert in Zeile 1096 der Datei ubasic.c.

1097 {
1098  int r=0, endif_cntr, f_nt;
1099 
1101  if(if_stack_ptr > 0) {
1102  r = if_stack[if_stack_ptr-1];
1103  }
1104  else{
1105  DEBUG_PRINTF("ubasic.c: else_statement(): else without if-statement\n");
1106  ended = 1;
1108  return;
1109  }
1110  DEBUG_PRINTF("else_statement: relation %d\n", r);
1111 
1112  if (tokenizer_token() == TOKENIZER_CR) {
1114  if(!r) {
1115  DEBUG_PRINTF("else_statement: result true\n");
1116  return;
1117  } else {
1118  DEBUG_PRINTF("else_statement: result false\n");
1119  endif_cntr=0;
1120  while(((tokenizer_token() != TOKENIZER_ENDIF )
1121  || endif_cntr) && tokenizer_token() != TOKENIZER_ENDOFINPUT){
1122  f_nt=0;
1123  if( tokenizer_token() == TOKENIZER_IF) {
1124  endif_cntr+=1;
1125  }
1126  if( tokenizer_token() == TOKENIZER_THEN) {
1127  tokenizer_next();
1128  // then followed by CR -> multi line
1129  if (tokenizer_token() == TOKENIZER_CR) {
1130  f_nt=1;
1131  } else { // single line
1132  endif_cntr--;
1135  tokenizer_next();
1136  }
1138  DEBUG_PRINTF("ubasic.c: else_statement(): endif in singleline if-statement\n");
1139  ended = 1;
1141  return;
1142  }
1143  }
1144  }
1145  if( tokenizer_token() == TOKENIZER_ENDIF) { endif_cntr--; }
1146  if (!f_nt) { tokenizer_next(); }
1147  }
1148  }
1149  endif_statement();
1150  }else{
1151  DEBUG_PRINTF("ubasic.c: else_statement(): CR after ELSE expected\n");
1152  ended = 1;
1154  }
1155 }
static void end_select_statement ( void  )
static

Definiert in Zeile 1174 der Datei ubasic.c.

1175 {
1176  if(select_stack_ptr > 0) {
1179  dec_select_stack();
1180  } else {
1181  DEBUG_PRINTF("ubasic.c: end_select_statement(): end_select without select-statement\n");
1182  ended = 1;
1184  }
1185 }
static void end_statement ( void  )
static

Definiert in Zeile 1591 der Datei ubasic.c.

1592 {
1594  ended = 1;
1595 }
static void endif_statement ( void  )
static

Definiert in Zeile 975 der Datei ubasic.c.

976 {
977  if(if_stack_ptr > 0) {
980  if_stack_ptr--;
981  } else {
982  DEBUG_PRINTF("ubasic.c: endif_statement(): endif without if-statement\n");
983  ended = 1;
985  }
986 }
static int expr ( void  )
static

Definiert in Zeile 807 der Datei ubasic.c.

808 {
809  int t1, t2;
810  int op;
811 
812  t1 = term();
813  op = tokenizer_token();
814  DEBUG_PRINTF("expr: token %d\n", op);
815  while(op == TOKENIZER_PLUS ||
816  op == TOKENIZER_MINUS ||
817  op == TOKENIZER_AND ||
818  op == TOKENIZER_LOR ||
819  op == TOKENIZER_XOR) {
820  tokenizer_next();
821  t2 = term();
822  DEBUG_PRINTF("expr: %d %d %d\n", t1, op, t2);
823  switch(op) {
824  case TOKENIZER_PLUS:
825  t1 = t1 + t2;
826  break;
827  case TOKENIZER_MINUS:
828  t1 = t1 - t2;
829  break;
830  case TOKENIZER_AND:
831  t1 = t1 & t2;
832  break;
833  case TOKENIZER_LOR:
834  t1 = t1 || t2;
835  break;
836  }
837  op = tokenizer_token();
838  }
839  DEBUG_PRINTF("expr: %d\n", t1);
840  return t1;
841 }
static int factor ( void  )
static

Definiert in Zeile 270 der Datei ubasic.c.

271 {
272  int r = 0;
273  tConfigVal configVal;
274 
275  DEBUG_PRINTF("factor: token %d\n", tokenizer_token());
276  switch(tokenizer_token()) {
277  case TOKENIZER_NUMBER:
278  r = tokenizer_num();
279  DEBUG_PRINTF("factor: number %d\n", r);
281  break;
282  case TOKENIZER_LEFTPAREN:
284  r = relation();
286  break;
287  case TOKENIZER_PLUS:
289  r = factor();
290  break;
291  case TOKENIZER_MINUS:
293  r = - factor();
294  break;
295  case TOKENIZER_LNOT:
297  r = ! relation();
298  break;
299  case TOKENIZER_GET_VBATT:
301  r = (unsigned short) stat_get_vbatt();
302  break;
304  {
306  struct tm *ttm;
307  ttm = get_localtime();
308  r = ttm->tm_hour * 3600 + ttm->tm_min * 60 + ttm->tm_sec;
309  }
310  break;
313  r = get_tick_count();
314  break;
315  case TOKENIZER_GET_MODE:
317  if (!camera_info.state.mode_play) r = 0;
318  if (camera_info.state.mode_play) r = 1;
320  break;
323  r = conf.raw_nr;
324  break;
325  case TOKENIZER_IS_KEY:
328  break;
332  break;
335 #ifdef UBASIC_TEST
336  r = 0;
337 #else
338  r = conf.script_startup;
339 #endif
340  break;
343  int usbpwr = 0 ;
344  if (tokenizer_token() != TOKENIZER_CR &&
346  usbpwr = expr();
347  }
348  r = get_usb_power(usbpwr);
349  break;
352  r = get_exposure_counter();
353  break;
357  break;
358  case TOKENIZER_RANDOM:
360  int min = expr();
361  int max = expr();
362  // shouldn't srand every time...
363  srand((int)shooting_get_bv96()+(unsigned short)stat_get_vbatt()+get_tick_count());
364  // wtf
365  action_push_delay(rand()%10);
366  flag_yield=1;
367  r = min + rand()%(max-min+1);
368  break;
371  r = get_movie_status();
372  break;
375  r = conf.platformid;
376  break;
380  break;
384  break;
388  break;
391  r = shooting_get_focus_ok();
392  break;
396  break;
400  break;
403  r = shooting_in_progress();
404  break;
407  r = shooting_is_flash();
408  break;
411  r = shooting_get_is_mode();
412  break;
413  case TOKENIZER_GET_EV:
416  break;
420  break;
424  break;
428  break;
431  r = zoom_points;
432  break;
436  {
437  r = 0;
438  }
439  else
440  {
442  {
443  r = 1;
444  }
445  else
446  {
447  r = 2;
448  }
449  }
450  break;
454  break;
455  case TOKENIZER_GET_TV96:
457  r = shooting_get_tv96();
458  break;
462  break;
466  break;
467  case TOKENIZER_GET_AV96:
469  r = shooting_get_av96();
470  break;
474  break;
478  break;
479  case TOKENIZER_GET_ZOOM:
481  r = shooting_get_zoom();
482  break;
483  case TOKENIZER_GET_FOCUS:
486  break;
490  break;
494  break;
495  case TOKENIZER_GET_DOF:
498  break;
502  break;
505  r = sd_over_modes() ;
506  break;
509  r = (int)shooting_get_iso_market();
510  break;
513  r = (int)shooting_get_iso_real();
514  break;
515  case TOKENIZER_GET_BV96:
517  r = (int)shooting_get_bv96();
518  break;
519  case TOKENIZER_GET_SV96:
521  r = (int)shooting_get_sv96_real();
522  break;
525  r = shooting_get_iso_mode();
526  break;
529  r = GetTotalCardSpaceKb();
530  break;
533  r = GetFreeCardSpaceKb();
534  break;
537  r = GetJpgCount();
538  break;
541  r = (camera_info.cam_has_video_button) ? 1 : 0;
542  break;
545  r = is_video_recording();
546  break;
549  r = GetRawCount();
550  break;
551  case TOKENIZER_GET_PROP:
553  int var = expr();
554  r = shooting_get_prop(var);
555  break;
558  int from = expr();
559  int to = expr();
560  r = (unsigned short)libshothisto->shot_histogram_get_range(from, to);
561  break;
564  int temp = expr();
565  switch (temp)
566  {
567  case 0:
568  r = get_optical_temp();
569  break;
570  case 1:
571  r = get_ccd_temp();
572  break;
573  case 2:
574  r = get_battery_temp();
575  break;
576  default: // do something sane if given a bad index
577  r = 0;
578  }
579  break;
580  case TOKENIZER_GET_TIME:
582  int tmode = expr();
583  static struct tm *ttm;
584  ttm = get_localtime();
585  if (tmode==0) r = ttm->tm_sec;
586  else if (tmode==1) r = ttm->tm_min;
587  else if (tmode==2) r = ttm->tm_hour;
588  else if (tmode==3) r = ttm->tm_mday;
589  else if (tmode==4) r = ttm->tm_mon+1;
590  else if (tmode==5) r = 1900+ttm->tm_year;
591  break;
592  case TOKENIZER_GET_RAW:
594 #ifdef UBASIC_TEST
595  r = 1;
596 #else
597  r = conf.save_raw;
598 #endif
599  break;
600  // get CHDK capture mode value, or 0 if in playback or unknown (broken modemap)
601  // NOTE: different from get_mode, since this returns the actual value
606  else
607  r = 0;
608  break;
609  // check if CHDK capture mode exists in modemap of this camera
612  int modenum = expr();
613  if (shooting_mode_chdk2canon(modenum) == -1)
614  r = 0;
615  else
616  r = 1;
617  break;
621  break;
625  break;
628  int var1 = expr();
629  int var2 = expr();
630  if( conf_getValue(var1, &configVal) == CONF_VALUE) r = configVal.numb; else r = var2;
631  break;
634  int partNr = expr();
635  r = swap_partitions(partNr);
636  break;
637 
638  // APEX functions
642  break;
646  break;
650  break;
654  break;
658  break;
662  break;
666  break;
670  break;
673  r = shooting_get_tv96_from_shutter_speed((float)expr()/1000000.0);
674  break;
677  r = (int)(shooting_get_shutter_speed_from_tv96(expr()) * 1000000.0 + 0.5);
678  break;
681  int n = expr();
682  int d = expr();
683  r = shooting_get_tv96_from_shutter_speed((float)n/(float)d);
684  break;
688  break;
691  r=force_usb_state(expr()) ;
692  break;
695  r = (camera_info.state.gui_mode != 0);
696  break;
700  break;
704  break;
708  break;
712  break;
715  r = shooting_get_max_av96(); // NOTE -1 if not available, i.e. playback
716  break;
719  r = shooting_get_min_av96(); // NOTE -1 if not available, i.e. playback
720  break;
724  break;
728  break;
729  case TOKENIZER_GET_DIGIC:
732  break;
733  //ARM Begin
734 
735  default:
736  r = varfactor();
737  break;
738  }
739  return r;
740 }
static void for_statement ( void  )
static

Definiert in Zeile 1464 der Datei ubasic.c.

1465 {
1466  int for_variable, to, step;
1467 
1469  for_variable = tokenizer_variable_num();
1472  ubasic_set_variable(for_variable, expr());
1474  to = expr();
1475  step = 1;
1476  if (tokenizer_token() != TOKENIZER_CR) {
1478  step = expr();
1479  }
1481 
1484  for_stack[for_stack_ptr].for_variable = for_variable;
1487  DEBUG_PRINTF("for_statement: new for, var %d to %d\n",
1488  for_stack[for_stack_ptr].for_variable,
1489  for_stack[for_stack_ptr].to);
1490 
1491  for_stack_ptr++;
1492  } else {
1493  DEBUG_PRINTF("for_statement: for stack depth exceeded\n");
1494  ended = 1;
1496  }
1497 }
static void get_config_value_statement ( )
static

Definiert in Zeile 2034 der Datei ubasic.c.

2035 {
2036  int var, var1, var2;
2037  tConfigVal configVal;
2039  var = expr();
2040  var1 = expr();
2041  var2 = tokenizer_variable_num();
2043  if( conf_getValue(var, &configVal) == CONF_VALUE ) {
2044  ubasic_set_variable(var2, configVal.numb);
2045  } else {
2046  ubasic_set_variable(var2, var1);
2047  }
2048  accept_cr();
2049 }
static void get_int_var_statement ( int  token,
int(*)(void)  func 
)
static

Definiert in Zeile 1750 der Datei ubasic.c.

1751 {
1752  int var;
1753  accept(token);
1754  var = tokenizer_variable_num();
1756  ubasic_set_variable(var, func());
1757  accept_cr();
1758 }
static void get_prop_statement ( )
static

Definiert in Zeile 1760 der Datei ubasic.c.

1761 {
1762  int var, var1;
1764  var = expr();
1765  var1 = tokenizer_variable_num();
1768 
1769  accept_cr();
1770 }
static void get_short_var_statement ( int  token,
short(*)(void)  func 
)
static

Definiert in Zeile 1739 der Datei ubasic.c.

1740 {
1741  int var;
1742  accept(token);
1743  var = tokenizer_variable_num();
1745  ubasic_set_variable(var, func());
1746  accept_cr();
1747 }
static void gosub_statement ( void  )
static

Definiert in Zeile 1395 der Datei ubasic.c.

1396 {
1399  tokenizer_string(string, sizeof(string));
1400  do {
1401  tokenizer_next();
1402  } while(tokenizer_token() != TOKENIZER_CR);
1405 /* tokenizer_line_number_inc();*/
1407  gosub_stack_ptr++;
1408  jump_label(string);
1409  } else {
1410  DEBUG_PRINTF("gosub_statement: gosub stack exhausted\n");
1411  ended = 1;
1413  }
1414  } else {
1415  DEBUG_PRINTF("ubasic.c: goto_statement(): no label specified\n");
1416  ended = 1;
1418  }
1419 }
static void goto_statement ( void  )
static

Definiert in Zeile 931 der Datei ubasic.c.

932 {
935  tokenizer_string(string, sizeof(string));
936  tokenizer_next();
937  jump_label(string);
938  } else {
939  DEBUG_PRINTF("ubasic.c: goto_statement(): no label specified\n");
940  ended = 1;
942  }
943 }
static void if_statement ( void  )
static

Definiert in Zeile 989 der Datei ubasic.c.

990 {
991  int r, else_cntr,endif_cntr,f_nt,f_sl;
992 
994  DEBUG_PRINTF("if_statement: get_relation\n");
995  r = relation();
996  DEBUG_PRINTF("if_statement: relation %d\n", r);
998  if (ended) {
999  return;
1000  }
1001 
1002  if (tokenizer_token() == TOKENIZER_CR) {
1003  // CR after then -> multiline IF-Statement
1005  if_stack[if_stack_ptr] = r;
1006  if_stack_ptr++;
1007  } else {
1008  DEBUG_PRINTF("if_statement: IF-stack depth exceeded\n");
1009  ended = 1;
1011  return;
1012  }
1013  DEBUG_PRINTF("if_statement: stack_ptr %d\n", if_stack_ptr);
1015  if(r) {
1016  DEBUG_PRINTF("if_statement: result true\n");
1017  return;
1018  }else {
1019  DEBUG_PRINTF("if_statement: result false\n");
1020 
1021  else_cntr=endif_cntr=0; // number of else/endif possible in current nesting
1022  f_nt=f_sl=0; // f_nt flag for additional next token, f_fs flag single line
1023 
1025  || else_cntr || endif_cntr) && tokenizer_token() != TOKENIZER_ENDOFINPUT){
1026  f_nt=0;
1027  // nested if
1028  if( tokenizer_token() == TOKENIZER_IF) {
1029  else_cntr+=1;
1030  endif_cntr+=1;
1031  f_sl=0;
1032  DEBUG_PRINTF("IF: line %d, token %d, else %d, end %d\n", tokenizer_line_number(),tokenizer_token(),else_cntr,endif_cntr);
1033  }
1034  if( tokenizer_token() == TOKENIZER_THEN) {
1035  f_nt=1;
1036  tokenizer_next();
1037  DEBUG_PRINTF("THEN: line %d, token %d, else %d, end %d\n", tokenizer_line_number(),tokenizer_token(),else_cntr,endif_cntr);
1038  if (tokenizer_token() != TOKENIZER_CR) { f_sl=1; }
1039  DEBUG_PRINTF("THEN_SL: line %d, token %d, else %d, end %d\n", tokenizer_line_number(),tokenizer_token(),else_cntr,endif_cntr);
1040  }
1041  if(tokenizer_token() == TOKENIZER_ELSE) {
1042  else_cntr--;
1043  DEBUG_PRINTF("ELSE: line %d, token %d, else %d, end %d\n", tokenizer_line_number(),tokenizer_token(),else_cntr,endif_cntr);
1044  if (else_cntr<0) {
1045  DEBUG_PRINTF("ubasic.c: if_statement(): else without if-statement\n");
1046  ended = 1;
1048  return;
1049  }
1050  }
1051  if(!f_sl && (tokenizer_token() == TOKENIZER_ENDIF)) {
1052  endif_cntr--;
1053  if (endif_cntr != else_cntr) else_cntr--;
1054  DEBUG_PRINTF("ENDIF: line %d, token %d, else %d, end %d\n", tokenizer_line_number(),tokenizer_token(),else_cntr,endif_cntr);
1055  } else {
1056  if (f_sl && (tokenizer_token() == TOKENIZER_CR)) {
1057  f_sl=0;
1058  endif_cntr--;
1059  if (endif_cntr != else_cntr) else_cntr--;
1060  DEBUG_PRINTF("ENDIF_SL: line %d, token %d, else %d, end %d\n", tokenizer_line_number(),tokenizer_token(),else_cntr,endif_cntr);
1061  }else{
1063  DEBUG_PRINTF("ubasic.c: if_statement(): endif in singleline if-statement\n");
1064  ended = 1;
1066  return;
1067  }
1068  }
1069  }
1070  if (!f_nt) { tokenizer_next(); }
1071  }
1072  if(tokenizer_token() == TOKENIZER_ELSE) { return; }
1073  }
1074  endif_statement();
1075  }else {
1076  // Singleline IF-Statement
1077  if(r) {
1078  statement();
1079  } else {
1080  do {
1081  tokenizer_next();
1082  } while(tokenizer_token() != TOKENIZER_ELSE &&
1085  if(tokenizer_token() == TOKENIZER_ELSE) {
1087  statement();
1088  } else {
1090  }
1091  }
1092  }
1093 }
static void is_key_statement ( void  )
static

Definiert in Zeile 1996 der Datei ubasic.c.

1997 {
1998  int var;
2000  var = tokenizer_variable_num();
2003  DEBUG_PRINTF("End of is_key\n");
2004  accept_cr();
2005 }
int jump_label ( char *  label)

Definiert in Zeile 902 der Datei ubasic.c.

903 {
904  char currLabel[MAX_STRINGLEN];
906  currLabel[0] = 0;
908  tokenizer_next();
909  if (tokenizer_token() == TOKENIZER_LABEL) {
910  tokenizer_label(currLabel, sizeof(currLabel));
911  tokenizer_next();
912  if(strcmp(label, currLabel) == 0) {
914  DEBUG_PRINTF("jump_linenum: Found line %d\n", tokenizer_line_number());
915  break;
916  }
917  }
918  }
921  DEBUG_PRINTF("Label %s not found", label);
923  }
924  return 0;
925  } else {
926  return 1;
927  }
928 }
static void jump_line ( int  linenum)
static

Definiert in Zeile 889 der Datei ubasic.c.

890 {
892  while(tokenizer_line_number() != linenum) {
893  tokenizer_next();
894  }
895  /* swallow the CR that would be read next */
897 
898 }
static void let_statement ( void  )
static

Definiert in Zeile 1363 der Datei ubasic.c.

1364 {
1365 
1366  int var;
1367 
1368  var = tokenizer_variable_num();
1369 
1372  ubasic_set_variable(var, expr());
1373  DEBUG_PRINTF("let_statement: assign %d to %d\n", variables[var], var);
1374  accept_cr();
1375 }
static void line_statement ( void  )
static

Definiert in Zeile 2645 der Datei ubasic.c.

2646 {
2647  /* line numbers have been removed */
2648  DEBUG_PRINTF("----------- Line number %d ---------\n", tokenizer_line_number());
2649  /* current_linenum = tokenizer_num();*/
2650 #if 0
2651  if (tokenizer_token() == TOKENIZER_LABEL) {
2652 #ifdef DEBUG
2653  tokenizer_label(string, sizeof(string));
2654  DEBUG_PRINTF("line_statement: label: %s\n", string );
2655 #endif
2658  return;
2659  }
2660 #endif
2661  /* reyalp - eat up to 100 labels or rems at a time so they don't cost 10ms each */
2662  int count = 100;
2663  do {
2664  int r=tokenizer_token();
2665  if ( r == TOKENIZER_LABEL ) {
2666  /* hit limit and we are on a label, return */
2667  if( count == 1 )
2668  return;
2669 #ifdef DEBUG
2670  tokenizer_label(string, sizeof(string));
2671  DEBUG_PRINTF("line_statement: label: %s\n", string );
2672 #endif
2675  }
2676  else if ( r == TOKENIZER_REM ) {
2677  rem_statement();
2678  }
2679  else {
2680  break;
2681  }
2682  } while(--count);
2683  statement();
2684  return;
2685 }
static void md_detect_motion_statement ( )
static

Definiert in Zeile 2135 der Datei ubasic.c.

2136 {
2137  int columns;
2138  int rows;
2139  int pixel_measure_mode;
2140  int detection_timeout;
2141  int measure_interval;
2142  int threshold;
2143  int draw_grid=0;
2144  int clipping_region_mode=0;
2145  int clipping_region_row1=0;
2146  int clipping_region_column1=0;
2147  int clipping_region_row2=0;
2148  int clipping_region_column2=0;
2149  int parameters=0;
2150  int pixels_step=1;
2151  int msecs_before_trigger=0;
2152 
2154 
2155  columns=expr();tokenizer_next();
2156 
2157  rows=expr();tokenizer_next();
2158 
2159  pixel_measure_mode=expr();tokenizer_next();
2160 
2161  detection_timeout=expr();tokenizer_next();
2162 
2163  measure_interval=expr();tokenizer_next();
2164 
2165  threshold=expr();tokenizer_next();
2166 
2167  draw_grid=expr();tokenizer_next();
2168 
2170 
2172 
2174  // eat COMA
2175  // tokenizer_next();
2176  }
2177 
2179  tokenizer_next();
2180  clipping_region_mode = expr();
2181  }
2183  tokenizer_next();
2184  clipping_region_column1 = expr();
2185  }
2187  tokenizer_next();
2188  clipping_region_row1 = expr();
2189  }
2191  tokenizer_next();
2192  clipping_region_column2 = expr();
2193  }
2195  tokenizer_next();
2196  clipping_region_row2 = expr();
2197  }
2199  tokenizer_next();
2200  parameters = expr();
2201  }
2203  tokenizer_next();
2204  pixels_step = expr();
2205  }
2206 
2208  tokenizer_next();
2209  msecs_before_trigger = expr();
2210  }
2211 
2212  accept_cr();
2213 
2215  columns, rows, pixel_measure_mode, detection_timeout,
2216  measure_interval, threshold, draw_grid,
2217  clipping_region_mode,
2218  clipping_region_column1, clipping_region_row1,
2219  clipping_region_column2, clipping_region_row2,
2220  parameters, pixels_step, msecs_before_trigger);
2221 
2222  flag_yield=1;
2223 }
static void md_get_cell_diff_statement ( )
static

Definiert in Zeile 2103 der Datei ubasic.c.

2104 {
2105  int var, col, row;
2107 
2108  col=expr();tokenizer_next();
2109 
2110  row=expr();tokenizer_next();
2111 
2112  var = tokenizer_variable_num();
2114  accept_cr();
2115 
2117 }
static void md_get_cell_val_statement ( )
static

Definiert in Zeile 2119 der Datei ubasic.c.

2120 {
2121  int var, col, row;
2123 
2124  col=expr();tokenizer_next();
2125 
2126  row=expr();tokenizer_next();
2127 
2128  var = tokenizer_variable_num();
2130  accept_cr();
2131 
2133 }
static void next_statement ( void  )
static

Definiert in Zeile 1436 der Datei ubasic.c.

1437 {
1438  int var, value;
1439 
1441  var = tokenizer_variable_num();
1443  if(for_stack_ptr > 0 &&
1444  var == for_stack[for_stack_ptr - 1].for_variable) {
1445  value = ubasic_get_variable(var) + for_stack[for_stack_ptr - 1].step;
1446  ubasic_set_variable(var, value);
1447 
1448  if(((for_stack[for_stack_ptr - 1].step > 0) && (value <= for_stack[for_stack_ptr - 1].to)) ||
1449  ((for_stack[for_stack_ptr - 1].step < 0) && (value >= for_stack[for_stack_ptr - 1].to)))
1450  jump_line(for_stack[for_stack_ptr - 1].line_after_for);
1451  else {
1452  for_stack_ptr--;
1454  }
1455  } else {
1456  DEBUG_PRINTF("next_statement: non-matching next (expected %d, found %d)\n", for_stack[for_stack_ptr - 1].for_variable, var);
1457  ended = 1;
1459  }
1460 
1461 }
static void on_off_statement ( int  token,
void(*)(void)  on,
void(*)(void)  off 
)
static

Definiert in Zeile 2051 der Datei ubasic.c.

2052 {
2053  accept(token);
2054  if (expr() > 0) on();
2055  else off();
2056  accept_cr();
2057 }
static void one_int_param_function ( int  token,
void(*)(int)  func 
)
static

Definiert in Zeile 1775 der Datei ubasic.c.

1776 {
1777  accept(token);
1778  func(expr());
1779  accept_cr();
1780 }
static void one_int_param_plus_const_function ( int  token,
void(*)(int, short)  func,
short  p2 
)
static

Definiert in Zeile 1791 der Datei ubasic.c.

1792 {
1793  accept(token);
1794  func(expr(),p2);
1795  accept_cr();
1796 }
static void one_short_param_function ( int  token,
void(*)(short)  func 
)
static

Definiert in Zeile 1783 der Datei ubasic.c.

1784 {
1785  accept(token);
1786  func(expr());
1787  accept_cr();
1788 }
static void one_short_param_plus_const_function ( int  token,
void(*)(short, short)  func,
short  p2 
)
static

Definiert in Zeile 1799 der Datei ubasic.c.

1800 {
1801  accept(token);
1802  func(expr(),p2);
1803  accept_cr();
1804 }
static void press_statement ( void  )
static

Definiert in Zeile 1613 der Datei ubasic.c.

1614 {
1615  int k;
1617  k = ubasic_get_key_arg();
1618  if (k > 0) {
1619  action_push_press(k);
1620  flag_yield=1;
1621  }
1622  DEBUG_PRINTF("End of press\n");
1623  accept_cr();
1624 }
static void print_statement ( void  )
static

Definiert in Zeile 946 der Datei ubasic.c.

947 {
948  static char buf[128];
949 
950  buf[0]=0;
952  do {
953  DEBUG_PRINTF("Print loop\n");
955  tokenizer_string(string, sizeof(string));
956  sprintf(buf+strlen(buf), "%s", string);
957  tokenizer_next();
958  } else if(tokenizer_token() == TOKENIZER_COMMA) {
959  strcat(buf, " ");
960  tokenizer_next();
961  } else if(tokenizer_token() == TOKENIZER_SEMICOLON) {
962  tokenizer_next();
963  } else {
964  sprintf(buf+strlen(buf), "%d", expr());
965  }
967  script_console_add_line((long)buf);
968  DEBUG_PRINTF("End of print\n");
969  accept_cr();
970 }
static void reboot_statement ( )
static

Definiert in Zeile 1917 der Datei ubasic.c.

1917  {
1920  tokenizer_string(string, sizeof(string));
1921  tokenizer_next();
1922  reboot(string);
1923  } else {
1924  reboot(NULL);
1925  }
1926 }
static int relation ( void  )
static

Definiert in Zeile 844 der Datei ubasic.c.

845 {
846  int r1, r2;
847  int op;
848 
849  r1 = expr();
850  op = tokenizer_token();
851  DEBUG_PRINTF("relation: token %d\n", op);
852  while(op == TOKENIZER_LAND) {
853  tokenizer_next();
854  r2 = expr();
855  DEBUG_PRINTF("relation: %d %d %d\n", r1, op, r2);
856  switch(op) {
857  case TOKENIZER_LAND:
858  r1 = r1 && r2;
859  break;
860  }
861  op = tokenizer_token();
862  }
863  return r1;
864 }
static void release_statement ( void  )
static

Definiert in Zeile 1627 der Datei ubasic.c.

1628 {
1629  int k;
1631  k = ubasic_get_key_arg();
1632  if (k > 0) {
1634  flag_yield=1;
1635  }
1636  DEBUG_PRINTF("End of release\n");
1637  accept_cr();
1638 }
static void rem_statement ( void  )
static

Definiert in Zeile 1378 der Datei ubasic.c.

1379 {
1381  DEBUG_PRINTF("rem_statement\n");
1383 }
static void return_statement ( void  )
static

Definiert in Zeile 1422 der Datei ubasic.c.

1423 {
1425  if(gosub_stack_ptr > 0) {
1426  gosub_stack_ptr--;
1428  } else {
1429  DEBUG_PRINTF("return_statement: non-matching return\n");
1430  ended = 1;
1432  }
1433 }
static void select_statement ( void  )
static

Definiert in Zeile 1331 der Datei ubasic.c.

1332 {
1333 
1334  int select_value;
1335 
1337  select_value = expr();
1339 //REM
1340  while (tokenizer_token() == TOKENIZER_REM) {statement();}
1341 //REM
1342 
1344  select_stack[select_stack_ptr].select_value = select_value;
1346  DEBUG_PRINTF("select_statement: new select, value %d\n",select_stack[select_stack_ptr].select_value);
1347  select_stack_ptr++;
1348  if (tokenizer_token() != TOKENIZER_CASE) {
1349  DEBUG_PRINTF("ubasic.c: select_statement(): don't found case-statement\n");
1350  ended = 1;
1352  }
1353  else { case_statement(); }
1354  } else {
1355  DEBUG_PRINTF("select_statement: SELECT-stack depth exceeded\n");
1356  ended = 1;
1358  }
1359 }
static void set_autostart_statement ( )
static

Definiert in Zeile 1893 der Datei ubasic.c.

1894 {
1895  int to;
1897  to = expr();
1898 #ifndef UBASIC_TEST
1899  if (to >= 0 && to <= 3) conf.script_startup=to;
1900  conf_save();
1901 #endif
1902  accept_cr();
1903 }
static void set_capture_mode_canon_statement ( )
static

Definiert in Zeile 1905 der Datei ubasic.c.

1906 {
1907  int to;
1909  to = expr();
1910  // if the value as negative, assume it is a mistakenly sign extended PROPCASE_SHOOTING_MODE value
1911  if( to < 0)
1912  to &= 0xFFFF;
1914  accept_cr();
1915 }
static void set_config_value_statement ( )
static

Definiert in Zeile 1928 der Datei ubasic.c.

1929 {
1930  int id, value;
1931  tConfigVal configVal = {0,0,0,0};
1932 
1934  id = expr();
1935  value = expr();
1936  if( conf_getValue(id, &configVal) == CONF_VALUE ) {
1937  configVal.numb = value;
1938  configVal.isNumb = 1;
1939  conf_setValue(id, configVal);
1940  }
1941  accept_cr();
1942 }
static void set_console_autoredraw ( void  )
static

Definiert in Zeile 1710 der Datei ubasic.c.

1711 {
1714  accept_cr();
1715 }
static void set_console_layout ( void  )
static

Definiert in Zeile 1698 der Datei ubasic.c.

1699 {
1700  int x1,y1,x2,y2;
1702  x1 = expr();
1703  y1 = expr();
1704  x2 = expr();
1705  y2 = expr();
1706  console_set_layout(x1,y1,x2,y2);
1707  accept_cr();
1708 }
static void set_ev_statement ( )
static

Definiert in Zeile 1809 der Datei ubasic.c.

1810  {
1811  int to;
1813  to = expr();
1816  accept_cr();
1817  }
static void set_exit_key_statement ( )
static

Definiert in Zeile 2007 der Datei ubasic.c.

2008 {
2009  int k;
2012  {
2013  tokenizer_string(string, sizeof(string));
2014  k = script_keyid_by_name(string);
2015  if (k <= 0)
2016  {
2018  ended = 1 ;
2019  }
2020  else
2021  {
2022  script_set_terminate_key(k,string);
2023  }
2024  }
2025  else
2026  {
2027  DEBUG_PRINTF("ubasic.c: set_exit_key no key specified\n");
2028  ended = 1;
2030  }
2031  accept_cr() ;
2032 }
static void set_focus_statement ( )
static

Definiert in Zeile 1843 der Datei ubasic.c.

1844 {
1846  int sd = expr();
1847  // if sd override not available now, fail immediately without calling set_focus
1848  // to avoid unexpected results with SET_LATER
1849  if(shooting_can_focus()) {
1850  // NOTE duplicated in modules/luascript.c and lib/ubasic/ubasic.c
1851  // in AF lock or MF (canon or set by MF functions), set focus now
1854  || camera_info.state.mode_video) // TODO video needs to be investigated, carried over from old code
1855  {
1857  }
1858  else
1859  {
1860  // in an AF mode, set later
1862  }
1863  }
1864  accept_cr();
1865 }
static void set_led_statement ( )
static

Definiert in Zeile 1867 der Datei ubasic.c.

1868 {
1869  int to, to1, to2;
1871  to = expr();
1872  to1 = expr();
1873  to2 = 200;
1875  to2 = expr();
1876  }
1877  camera_set_led(to, to1, to2);
1878  accept_cr();
1879 }
static void set_mf_statement ( )
static

Definiert in Zeile 1835 der Datei ubasic.c.

1836 {
1838  if (expr() > 0) DoMFLock();
1839  else UnlockMF();
1840  accept_cr();
1841 }
static void set_movie_status_statement ( )
static

Definiert in Zeile 1819 der Datei ubasic.c.

1820 {
1823  accept_cr();
1824 }
static void set_prop_statement ( )
static

Definiert in Zeile 1881 der Datei ubasic.c.

1882 {
1883  int to, to1;
1885  to = expr();
1886  to1 = expr();
1887  shooting_set_prop(to, to1);
1888  accept_cr();
1889 }
static void set_propcase_statement ( int  token,
int  prop 
)
static

Definiert in Zeile 1827 der Datei ubasic.c.

1828 {
1829  accept(token);
1830  shooting_set_prop(prop, expr());
1831  accept_cr();
1832 }
static void set_yield_statement ( )
static

Definiert in Zeile 1724 der Datei ubasic.c.

1725 {
1727  int val = expr();
1729  val = expr();
1731  accept_cr();
1732 }
static void shoot_statement ( void  )
static

Definiert in Zeile 1682 der Datei ubasic.c.

1683 {
1685  ubasic_as_ret_var_num = -1;
1686  if (tokenizer_token() != TOKENIZER_CR)
1687  {
1690  }
1691  action_push_shoot(1);
1692  flag_yield=1;
1693  DEBUG_PRINTF("End of shoot\n");
1694  accept_cr();
1695 }
static int shooting_get_depth_of_field ( )
static

Definiert in Zeile 258 der Datei ubasic.c.

259 {
262 }
static int shooting_get_far_limit_of_acceptable_sharpness ( )
static

Definiert in Zeile 252 der Datei ubasic.c.

253 {
256 }
static int shooting_get_min_stack_distance ( )
static

Definiert in Zeile 264 der Datei ubasic.c.

static int shooting_get_near_limit_of_acceptable_sharpness ( )
static

Definiert in Zeile 246 der Datei ubasic.c.

247 {
250 }
static void shutdown_statement ( void  )
static

Definiert in Zeile 2060 der Datei ubasic.c.

2060  {
2063  accept_cr();
2064 }
static int sleep_delay ( int  delay)
static

Definiert in Zeile 1652 der Datei ubasic.c.

1653 {
1654  /* delay of -1 signals indefinite (actually 1 day) delay */
1655  if (delay == -1)
1656  delay = 86400000;
1657 
1658  if (delay > 0)
1659  return delay + get_tick_count();
1660 
1661  return 0;
1662 }
static void sleep_statement ( void  )
static

Definiert in Zeile 1665 der Datei ubasic.c.

1666 {
1668 
1669  int delay = sleep_delay(expr());
1670  if (delay > 0)
1671  {
1672  action_push(delay);
1674  }
1675 
1676  flag_yield=1;
1677  DEBUG_PRINTF("End of sleep\n");
1678  accept_cr();
1679 }
static void statement ( void  )
static

Definiert in Zeile 2234 der Datei ubasic.c.

2235 {
2237 
2238  token = tokenizer_token();
2239 
2240  switch(token) {
2241  // aelock
2242  case TOKENIZER_SET_AELOCK:
2244  break;
2245  // aflock
2246  case TOKENIZER_SET_AFLOCK:
2248  break;
2249 
2252  break;
2253  case TOKENIZER_PRINT:
2254  print_statement();
2255  break;
2256 
2257  case TOKENIZER_SLEEP:
2258  sleep_statement();
2259  break;
2260  case TOKENIZER_CLICK:
2261  click_statement();
2262  break;
2263  case TOKENIZER_PRESS:
2264  press_statement();
2265  break;
2266  case TOKENIZER_RELEASE:
2268  break;
2269  case TOKENIZER_SHOOT:
2270  shoot_statement();
2271  break;
2274  break;
2277  break;
2280  break;
2281 #ifdef INCLUDE_OLD_GET__SYNTAX
2282  case TOKENIZER_GET_TV96:
2284  break;
2287  break;
2290  break;
2291  case TOKENIZER_GET_AV96:
2293  break;
2296  break;
2299  break;
2300  case TOKENIZER_GET_ZOOM:
2302  break;
2303  case TOKENIZER_GET_FOCUS:
2305  break;
2308  break;
2311  break;
2312  case TOKENIZER_GET_DOF:
2314  break;
2317  break;
2320  break;
2323  break;
2324  case TOKENIZER_GET_BV96:
2326  break;
2327  case TOKENIZER_GET_SV96:
2329  break;
2332  break;
2333  case TOKENIZER_GET_VBATT:
2334  get_int_var_statement(token, (int (*)(void))stat_get_vbatt);
2335  break;
2337  get_int_var_statement(token, (int (*)(void))GetTotalCardSpaceKb);
2338  break;
2340  get_int_var_statement(token, (int (*)(void))GetFreeCardSpaceKb);
2341  break;
2343  get_int_var_statement(token, (int (*)(void))GetJpgCount);
2344  break;
2346  get_int_var_statement(token, (int (*)(void))GetRawCount);
2347  break;
2348  case TOKENIZER_GET_PROP:
2350  break;
2351 #endif
2354  break;
2355  case TOKENIZER_SET_TV96:
2357  break;
2358  case TOKENIZER_PLAY_SOUND:
2359  one_int_param_function(token, (void (*)(int))play_sound);
2360  break;
2363  break;
2366  break;
2369  break;
2372  break;
2373  case TOKENIZER_SET_AV96:
2375  break;
2376 
2379  break;
2382  break;
2385  break;
2386 
2389  break;
2390 
2391  case TOKENIZER_SET_ZOOM:
2393  break;
2396  break;
2399  break;
2400  case TOKENIZER_SET_FOCUS:
2402  break;
2403  case TOKENIZER_SET_MF:
2404  set_mf_statement();
2405  break;
2406 
2407 /*
2408  case TOKENIZER_SET_ISO_MARKET:
2409  one_int_param_function(token, shooting_set_iso_market);
2410  break;
2411  case TOKENIZER_SET_ISO_DL_F_B:
2412  one_int_param_function(token, shooting_set_iso_real_delta_from_base);
2413  break;
2414 */
2415  //ARM End
2416 
2419  break;
2420  case TOKENIZER_SET_SV96:
2422  break;
2423 
2426  break;
2427 
2428  case TOKENIZER_SET_PROP:
2430  break;
2431  case TOKENIZER_SET_LED:
2433  break;
2434 
2435  case TOKENIZER_SET_EV:
2436  set_ev_statement();
2437  break;
2438 
2441  break;
2444  break;
2445  case TOKENIZER_SET_QUALITY:
2447  break;
2448 
2449  case TOKENIZER_WAIT_CLICK:
2451  break;
2452  case TOKENIZER_IS_KEY:
2453  is_key_statement();
2454  break;
2457  break;
2458 
2459  case TOKENIZER_WHEEL_LEFT:
2460  accept(token);
2461  JogDial_CCW();
2462  accept_cr();
2463  break;
2464  case TOKENIZER_WHEEL_RIGHT:
2465  accept(token);
2466  JogDial_CW();
2467  accept_cr();
2468  break;
2469 
2470  case TOKENIZER_IF:
2471  if_statement();
2472  break;
2473  case TOKENIZER_ELSE:
2474  else_statement();
2475  break;
2476  case TOKENIZER_ENDIF:
2477  endif_statement();
2478  break;
2479  case TOKENIZER_SELECT:
2480  select_statement();
2481  break;
2482  case TOKENIZER_CASE:
2483  case_statement();
2484  break;
2485  case TOKENIZER_CASE_ELSE:
2487  break;
2488  case TOKENIZER_GOTO:
2489  goto_statement();
2490  break;
2491  case TOKENIZER_GOSUB:
2492  gosub_statement();
2493  break;
2494  case TOKENIZER_RETURN:
2495  return_statement();
2496  break;
2497  case TOKENIZER_FOR:
2498  for_statement();
2499  break;
2500  case TOKENIZER_NEXT:
2501  next_statement();
2502  break;
2503  case TOKENIZER_DO:
2504  do_statement();
2505  break;
2506  case TOKENIZER_UNTIL:
2507  until_statement();
2508  break;
2509  case TOKENIZER_WHILE:
2510  while_statement();
2511  break;
2512  case TOKENIZER_WEND:
2513  wend_statement();
2514  break;
2515  case TOKENIZER_END:
2516  end_statement();
2517  break;
2518  case TOKENIZER_LET:
2520  /* Fall through. */
2521  case TOKENIZER_VARIABLE:
2522  let_statement();
2523  break;
2524  case TOKENIZER_REM:
2525  rem_statement();
2526  break;
2527  case TOKENIZER_CLS:
2528  cls_statement();
2529  break;
2530  case TOKENIZER_SET_RAW:
2531  accept(token);
2532  conf.save_raw = expr();
2533  accept_cr();
2534  break;
2535  case TOKENIZER_SET_RAW_NR:
2536  accept(token);
2537  conf.raw_nr = expr();
2538  accept_cr();
2539  break;
2542  break;
2543  case TOKENIZER_EXIT_ALT:
2545  break;
2546  case TOKENIZER_ENTER_ALT:
2548  break;
2549  case TOKENIZER_SHUT_DOWN:
2553  break;
2556  break;
2558  accept(token);
2560  accept_cr();
2561  break;
2562 
2563  // >> mx3 . motion detector
2566  break;
2569  break;
2572  break;
2573  // << mx3 . motion_detector
2574 
2576  accept(token);
2579  if ((camera_info.perf.md_af_on_time > 0) && (camera_info.cam_af_led >= 0)) {
2580  camera_info.perf.md_af_tuning = 1; // Enable MD testing with AF LED
2581  // clear previous values
2583  camera_info.perf.af_led.min = 0xFFFFFFFF;
2584  } else {
2585  camera_info.perf.md_af_tuning = 0; // Disable MD testing
2586  }
2587  accept_cr();
2588  break;
2589 
2591  one_int_param_function(token, (void (*)(int))_shot_histogram_set);
2592  break;
2593 
2594  case TOKENIZER_SET_RECORD:
2596  break;
2597 
2599  one_int_param_function(token, (void (*)(int))shooting_set_mode_chdk);
2600  break;
2601 
2604  break;
2605 
2606  case TOKENIZER_REBOOT:
2607  reboot_statement();
2608  break;
2609 
2612  break;
2613 
2616  break;
2617  case TOKENIZER_SET_YIELD:
2619  break;
2620 
2623  if (expr()) usb_sync_wait_flag = 1;
2624  else usb_sync_wait_flag = 0;
2625  accept_cr();
2626  break;
2627 
2630  int hpenable= expr();
2631  if ( hpenable > 0) start_usb_HPtimer(hpenable);
2632  else stop_usb_HPtimer();
2633  accept_cr();
2634  break;
2635 
2636  default:
2637  DEBUG_PRINTF("ubasic.c: statement(): not implemented %d\n", token);
2638  ended = 1;
2640  }
2641 }
static int term ( void  )
static

Definiert in Zeile 743 der Datei ubasic.c.

744 {
745  int f1, f2;
746  int op;
747 
748  f1 = factor();
749  op = tokenizer_token();
750  DEBUG_PRINTF("term: token %d\n", op);
751  while(op == TOKENIZER_ASTR ||
752  op == TOKENIZER_SLASH ||
753  op == TOKENIZER_LT ||
754  op == TOKENIZER_GT ||
755  op == TOKENIZER_GE ||
756  op == TOKENIZER_LE ||
757  op == TOKENIZER_NE ||
758  op == TOKENIZER_EQ ||
759  op == TOKENIZER_XOR ||
760  op == TOKENIZER_OR ||
761  op == TOKENIZER_MOD) {
762  tokenizer_next();
763  f2 = factor();
764  DEBUG_PRINTF("term: %d %d %d\n", f1, op, f2);
765  switch(op) {
766  case TOKENIZER_ASTR:
767  f1 = f1 * f2;
768  break;
769  case TOKENIZER_SLASH:
770  f1 = f1 / f2;
771  break;
772  case TOKENIZER_MOD:
773  f1 = f1 % f2;
774  break;
775  case TOKENIZER_LT:
776  f1 = f1 < f2;
777  break;
778  case TOKENIZER_GT:
779  f1 = f1 > f2;
780  break;
781  case TOKENIZER_EQ:
782  f1 = f1 == f2;
783  break;
784  case TOKENIZER_NE:
785  f1 = f1 != f2;
786  break;
787  case TOKENIZER_LE:
788  f1 = f1 <= f2;
789  break;
790  case TOKENIZER_GE:
791  f1 = f1 >= f2;
792  break;
793  case TOKENIZER_OR:
794  f1 = f1 | f2;
795  break;
796  case TOKENIZER_XOR:
797  f1 = f1 ^ f2;
798  break;
799  }
800  op = tokenizer_token();
801  }
802  DEBUG_PRINTF("term: %d\n", f1);
803  return f1;
804 }
static void uB_set_av96 ( int  param)
static

Definiert in Zeile 2066 der Datei ubasic.c.

2066  {
2068  return ;
2069 }
static void uB_set_av96_direct ( int  param)
static

Definiert in Zeile 2071 der Datei ubasic.c.

2071  {
2073  return ;
2074 }
static void uB_set_iso_real ( int  param)
static

Definiert in Zeile 2096 der Datei ubasic.c.

2096  {
2098  return ;
2099 }
static void uB_set_nd_filter_state ( int  param)
static

Definiert in Zeile 2091 der Datei ubasic.c.

2091  {
2093  return ;
2094 }
static void uB_set_sv96 ( int  param)
static

Definiert in Zeile 2086 der Datei ubasic.c.

2086  {
2088  return ;
2089 }
static void uB_set_tv96 ( int  param)
static

Definiert in Zeile 2076 der Datei ubasic.c.

2076  {
2078  return ;
2079 }
static void uB_set_tv96_direct ( int  param)
static

Definiert in Zeile 2081 der Datei ubasic.c.

2081  {
2083  return ;
2084 }
void ubasic_end ( void  )

Definiert in Zeile 2752 der Datei ubasic.c.

2752  {
2753 }
static int ubasic_get_key_arg ( )
static

Definiert in Zeile 201 der Datei ubasic.c.

201  {
202  int k;
203  tokenizer_string(string, sizeof(string));
204  tokenizer_next();
205  k = script_keyid_by_name(string);
206  if (k <= 0)
208  return k;
209 }
int ubasic_get_variable ( int  varnum)

Definiert in Zeile 2743 der Datei ubasic.c.

2744 {
2745  if(varnum >= 0 && varnum < MAX_VARNUM) {
2746  return variables[varnum];
2747  }
2748  return 0;
2749 }
int ubasic_init ( const char *  program,
int  is_ptp 
)

Definiert in Zeile 186 der Datei ubasic.c.

187 {
188  program_ptr = program;
189  flag_yield = 0;
191  tokenizer_init(program);
192  ended = 0;
196  return 1;
197 }
int ubasic_linenumber ( )

Definiert in Zeile 179 der Datei ubasic.c.

180 {
181  return tokenizer_line_number();
182 }
int ubasic_run ( void  )

Definiert in Zeile 2687 der Datei ubasic.c.

2688 {
2689  unsigned start_tick = get_tick_count();
2690  unsigned lines = 0;
2691  flag_yield = 0;
2692 
2693  do
2694  {
2695  if ( ended || tokenizer_finished() )
2696  {
2697  DEBUG_PRINTF("uBASIC program finished\n");
2698  if (ubasic_error)
2699  {
2700  // Generate error message
2701  char buf[100];
2702  const char *msg;
2704  {
2706  }
2707  else
2708  {
2710  }
2711  sprintf(buf, "uBASIC:%d %s ", ubasic_linenumber(), msg);
2712  // Show error message
2713  script_console_add_error((long)buf);
2715  return SCRIPT_RUN_ERROR;
2716  }
2717  // Show 'Finished' message
2719  return SCRIPT_RUN_ENDED;
2720  }
2721 
2722  line_statement();
2723 
2724  // Return control to CHDK only if external processing required
2725  if ( flag_yield )
2726  return SCRIPT_RUN_RUNNING;
2727 
2728  lines++;
2729  } while (lines < yield_max_lines && get_tick_count() - start_tick < yield_max_ms);
2730 
2731  return SCRIPT_RUN_RUNNING;
2732 }
void ubasic_set_as_ret ( int  md_ret)

Definiert in Zeile 2757 der Datei ubasic.c.

2758 {
2759  if (ubasic_as_ret_var_num >= 0)
2761 }
void ubasic_set_variable ( int  varum,
int  value 
)

Definiert in Zeile 2735 der Datei ubasic.c.

2736 {
2737  if(varnum >= 0 && varnum < MAX_VARNUM) {
2738  variables[varnum] = value;
2739  }
2740 }
static void until_statement ( void  )
static

Definiert in Zeile 1515 der Datei ubasic.c.

1516 {
1517  int r;
1518 
1520  r = relation();
1521  if(do_stack_ptr > 0) {
1522  if(!r) {
1524  } else {
1525  do_stack_ptr--;
1526  accept_cr();
1527  }
1528  } else {
1529  DEBUG_PRINTF("until_statement: unmatched until\n");
1530  ended = 1;
1532  }
1533 }
static int varfactor ( void  )
static

Definiert in Zeile 237 der Datei ubasic.c.

238 {
239  int r;
240  DEBUG_PRINTF("varfactor: obtaining %d from variable %d\n", variables[tokenizer_variable_num()], tokenizer_variable_num());
243  return r;
244 }
static void wait_click_statement ( )
static

Definiert in Zeile 1965 der Datei ubasic.c.

1966 {
1968 
1969  int delay = -1;
1971  {
1972  delay = expr();
1973  if (delay == 0) delay = -1;
1974  }
1975  delay = sleep_delay(delay);
1976 
1977  accept_cr();
1978 
1979  // Reset 'clicked' key if it has not changed since last time
1981  {
1983  }
1984 
1985  // Set up for wait or click testing
1986  action_push(delay);
1988 
1989  // Check for short delay or key already pressed by calling action stack routine once now
1991  {
1992  flag_yield=1;
1993  }
1994 }
static void wend_statement ( void  )
static

Definiert in Zeile 1578 der Datei ubasic.c.

1579 {
1581  if(while_stack_ptr > 0) {
1583  } else {
1584  DEBUG_PRINTF("wend_statement: unmatched wend\n");
1585  ended = 1;
1587  }
1588 }
static void while_statement ( void  )
static

Definiert in Zeile 1536 der Datei ubasic.c.

1537 {
1538  int r, while_cntr;
1539 
1544  while_stack_ptr++;
1545  }
1546  } else {
1547  DEBUG_PRINTF("while_statement: while stack depth exceeded\n");
1548  ended = 1;
1550  return;
1551  }
1552 
1553  r = relation();
1554  if(while_stack_ptr > 0) {
1555  if(!r) {
1556  while_cntr=0;
1557  while((tokenizer_token() != TOKENIZER_WEND || while_cntr ) &&
1559  if (tokenizer_token() == TOKENIZER_WHILE) while_cntr+=1;
1560  if (tokenizer_token() == TOKENIZER_WEND) while_cntr-=1;
1561  tokenizer_next();
1562  }
1563  while_stack_ptr--;
1564 
1566  accept(TOKENIZER_CR);
1567  } else {
1568  accept_cr();
1569  }
1570  } else {
1571  DEBUG_PRINTF("while_statement: unmatched wend\n");
1572  ended = 1;
1574  }
1575 }

Variablen-Dokumentation

short do_stack[MAX_DO_STACK_DEPTH]
static

Definiert in Zeile 113 der Datei ubasic.c.

int do_stack_ptr
static

Definiert in Zeile 114 der Datei ubasic.c.

int ended
static

Definiert in Zeile 129 der Datei ubasic.c.

int flag_yield
static

Definiert in Zeile 152 der Datei ubasic.c.

struct for_state for_stack[MAX_FOR_STACK_DEPTH]
static

Definiert in Zeile 123 der Datei ubasic.c.

int for_stack_ptr
static

Definiert in Zeile 124 der Datei ubasic.c.

short gosub_stack[MAX_GOSUB_STACK_DEPTH]
static

Definiert in Zeile 93 der Datei ubasic.c.

int gosub_stack_ptr
static

Definiert in Zeile 94 der Datei ubasic.c.

short if_stack[MAX_IF_STACK_DEPTH]
static

Definiert in Zeile 97 der Datei ubasic.c.

int if_stack_ptr
static

Definiert in Zeile 98 der Datei ubasic.c.

char const* program_ptr
static

Definiert in Zeile 88 der Datei ubasic.c.

struct select_state select_stack[MAX_SELECT_STACK_DEPTH]
static

Definiert in Zeile 105 der Datei ubasic.c.

int select_stack_ptr
static

Definiert in Zeile 106 der Datei ubasic.c.

char string[MAX_STRINGLEN]
static

Definiert in Zeile 90 der Datei ubasic.c.

int ubasic_as_ret_var_num
static

Definiert in Zeile 132 der Datei ubasic.c.

int ubasic_error

Definiert in Zeile 154 der Datei ubasic.c.

const char* ubasic_errstrings[UBASIC_E_ENDMARK]
Initialisierung:
=
{
"No err",
"Parse err",
"Unk stmt",
"Unk key",
"Unk label",
"gosub: Stack ful",
"bad return",
"if: Stack ful",
"bad endif",
"select: Stack ful",
"bad end_select",
"for: Stack ful",
"bad next",
"do: Stack ful",
"bad until",
"while: Stack ful",
"bad wend",
"Unk err"
}

Definiert in Zeile 155 der Datei ubasic.c.

int variables[MAX_VARNUM]
static

Definiert in Zeile 127 der Datei ubasic.c.

short while_stack[MAX_WHILE_STACK_DEPTH]
static

Definiert in Zeile 109 der Datei ubasic.c.

int while_stack_ptr
static

Definiert in Zeile 110 der Datei ubasic.c.

unsigned yield_max_lines
static

Definiert in Zeile 147 der Datei ubasic.c.

unsigned yield_max_ms
static

Definiert in Zeile 149 der Datei ubasic.c.