CHDK_DE Vorschauversion  Trunk Rev. 5298
 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 2195 der Datei ubasic.c.

2196 {
2197  return libshothisto->shot_histogram_set(enable);
2198 }
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 1611 der Datei ubasic.c.

1612 {
1613  if (get_tick_count() >= action_top(2))
1614  {
1615  action_pop_func(1);
1616  return 1;
1617  }
1618  return 0;
1619 }
static int action_stack_AS_UBASIC_WAIT_CLICK ( )
static

Definiert in Zeile 1916 der Datei ubasic.c.

1917 {
1918  // Check key pressed or timeout
1920  {
1921  // If timed out set key state to "no_key", otherwise key pressed so set last checked time
1924  else
1926 
1927  action_pop_func(1);
1928  return 1;
1929  }
1930 
1931  return 0;
1932 }
static void case_else_statement ( void  )
static

Definiert in Zeile 1247 der Datei ubasic.c.

1248 {
1249  short case_goto = 0, case_gosub = 0;
1250  int cur_ln, gosub_ln = 0;
1251 
1253  if(select_stack_ptr > 0) {
1254  if (!select_stack[select_stack_ptr - 1].case_run) {
1255  case_goto = (tokenizer_token() == TOKENIZER_GOTO);
1256  case_gosub = (tokenizer_token() == TOKENIZER_GOSUB);
1257 //GOSUB - save curr linenumber
1258  cur_ln = tokenizer_line_number();
1259 //GOSUB
1260  statement();
1261 //GOSUB - save new linenumber, reset to curr linenumber
1262  if (case_gosub) {
1263  gosub_ln = tokenizer_line_number();
1264  jump_line(cur_ln+1);
1265  DEBUG_PRINTF("case_else_statement: GOSUB: toLN=%d, nextLN=%d\n", gosub_ln, cur_ln+1);
1266  }
1267 //GOSUB
1268  DEBUG_PRINTF("case_else_statement: case_else execute\n");
1269  } else {
1270  DEBUG_PRINTF("case_else_statement: case_else jump; case_run: %d\n", select_stack[select_stack_ptr - 1].case_run);
1271  accept_cr();
1272  }
1273 //REM
1274  while ((tokenizer_token() == TOKENIZER_REM) && (!case_goto)) {statement();}
1275 //REM
1276  if (case_goto) { dec_select_stack(); } else {
1277 //GOSUB test for end_select and set to gosub-linenumber
1279  DEBUG_PRINTF("ubasic.c: select_statement(): don't found end_select\n");
1280  ended = 1;
1282  } else {
1284  if (case_gosub) {
1286  jump_line(gosub_ln);
1287  DEBUG_PRINTF("end_select_statement: GOSUB: returnLN=%d\n", gosub_stack[gosub_stack_ptr-1]);
1288  }
1289  }
1290 //GOSUB
1291  }
1292  } else {
1293  DEBUG_PRINTF("case_else_statement: SELECT-Stack fault\n");
1294  ended = 1;
1296  }
1297 }
static void case_statement ( void  )
static

Definiert in Zeile 1157 der Datei ubasic.c.

1158 {
1159  int select_value, case_value_1, case_value_2, case_value_eq;
1160  short case_run, case_goto = 0, case_gosub = 0;
1161  int cur_ln, gosub_ln = 0;
1162 
1164  if(select_stack_ptr > 0) {
1165  select_value = select_stack[select_stack_ptr - 1].select_value;
1166  case_run = select_stack[select_stack_ptr - 1].case_run;
1167 
1168  if (!case_run) {
1169  case_value_1 = expr();
1170  case_value_eq = (select_value == case_value_1);
1171  if (case_value_eq) { DEBUG_PRINTF("case_statement: case_value_eq %d, case_value %d\n", case_value_eq, case_value_1); }
1172 
1173  if(tokenizer_token() == TOKENIZER_TO) {
1175  case_value_2 = expr();
1176  if (case_value_1 < case_value_2) {
1177  case_value_eq = ((select_value >= case_value_1) && (select_value <= case_value_2));
1178  DEBUG_PRINTF("case_statement: case_value %d to %d\n", case_value_1, case_value_2);
1179  } else {
1180  case_value_eq = ((select_value >= case_value_2) && (select_value <= case_value_1));
1181  DEBUG_PRINTF("case_statement: case_value %d to %d\n", case_value_2, case_value_1);
1182  }
1183  } else if (tokenizer_token() == TOKENIZER_COMMA) {
1184  do {
1186  if (case_value_eq) {
1187  case_value_2 = expr();
1188  } else {
1189  case_value_1 = expr();
1190  case_value_eq = (select_value == case_value_1);
1191  }
1192  } while (tokenizer_token() == TOKENIZER_COMMA);
1193  DEBUG_PRINTF("case_statement: case_value_eq %d, case_value_comma %d\n", case_value_eq, case_value_1);
1194  }
1195 
1197  if (case_value_eq) {
1198  case_goto = (tokenizer_token() == TOKENIZER_GOTO);
1199  case_gosub = (tokenizer_token() == TOKENIZER_GOSUB);
1200 //GOSUB - save curr linenumber
1201  cur_ln = tokenizer_line_number();
1202 //GOSUB
1203  statement();
1204 //GOSUB - save new linenumber, reset to curr linenumber
1205  if (case_gosub) {
1206  gosub_ln = tokenizer_line_number();
1207  jump_line(cur_ln+1);
1208  DEBUG_PRINTF("case_statement: GOSUB: toLN=%d, nextLN=%d\n", gosub_ln, cur_ln+1);
1209  }
1210 //GOSUB
1211  DEBUG_PRINTF("case_statement: case execute\n");
1212  case_run = 1;
1213  select_stack[select_stack_ptr - 1].case_run = case_run;
1214  } else {
1215  DEBUG_PRINTF("case_statement: case jump; case_run: %d\n", case_run);
1216  accept_cr();
1217  }
1218  } else {accept_cr();}
1219 //REM
1220  while ((tokenizer_token() == TOKENIZER_REM) && (!case_goto)) {statement();}
1221 //REM
1222  if (case_goto) { dec_select_stack(); } else {
1225  DEBUG_PRINTF("ubasic.c: select_statement(): don't found case, case_else or end_select\n");
1226  ended = 1;
1228  } else {
1229 //GOSUB test for end_select and set to gosub-linenumber
1231  if (case_gosub) {
1233  jump_line(gosub_ln);
1234  DEBUG_PRINTF("end_select_statement: GOSUB: returnLN=%d\n", gosub_stack[gosub_stack_ptr-1]);
1235  }
1236  }
1237 //GOSUB
1238  }
1239  } else {
1240  DEBUG_PRINTF("case_statement: SELECT-Stack fail\n");
1241  ended = 1;
1243  }
1244 }
static void click_statement ( void  )
static

Definiert in Zeile 1567 der Datei ubasic.c.

1568 {
1569  int k;
1571  k = ubasic_get_key_arg();
1572  if (k > 0) {
1573  action_push_click(k);
1574  flag_yield=1;
1575  }
1576 
1577  DEBUG_PRINTF("End of click\n");
1578  accept_cr();
1579 }
static void cls_statement ( void  )
static

Definiert in Zeile 1355 der Datei ubasic.c.

1356 {
1358  console_clear();
1359  DEBUG_PRINTF("cls_statement\n");
1361 }
static void console_redraw_statement ( void  )
static

Definiert in Zeile 1686 der Datei ubasic.c.

1687 {
1689  console_redraw();
1690  accept_cr();
1691 }
static void dec_select_stack ( void  )
static

Definiert in Zeile 1131 der Datei ubasic.c.

1132 {
1133  if(select_stack_ptr > 0) {
1134  select_stack_ptr--;
1135  } else {
1136  DEBUG_PRINTF("select_statement: SELECT-Stack fail\n");
1137  ended = 1;
1139  }
1140 }
static void do_statement ( void  )
static

Definiert in Zeile 1469 der Datei ubasic.c.

1470 {
1475  do_stack_ptr++;
1476  } else {
1477  DEBUG_PRINTF("do_statement: do stack depth exceeded\n");
1478  ended = 1;
1480  }
1481 }
static void else_statement ( void  )
static

Definiert in Zeile 1065 der Datei ubasic.c.

1066 {
1067  int r=0, endif_cntr, f_nt;
1068 
1070  if(if_stack_ptr > 0) {
1071  r = if_stack[if_stack_ptr-1];
1072  }
1073  else{
1074  DEBUG_PRINTF("ubasic.c: else_statement(): else without if-statement\n");
1075  ended = 1;
1077  return;
1078  }
1079  DEBUG_PRINTF("else_statement: relation %d\n", r);
1080 
1081  if (tokenizer_token() == TOKENIZER_CR) {
1083  if(!r) {
1084  DEBUG_PRINTF("else_statement: result true\n");
1085  return;
1086  } else {
1087  DEBUG_PRINTF("else_statement: result false\n");
1088  endif_cntr=0;
1089  while(((tokenizer_token() != TOKENIZER_ENDIF )
1090  || endif_cntr) && tokenizer_token() != TOKENIZER_ENDOFINPUT){
1091  f_nt=0;
1092  if( tokenizer_token() == TOKENIZER_IF) {
1093  endif_cntr+=1;
1094  }
1095  if( tokenizer_token() == TOKENIZER_THEN) {
1096  tokenizer_next();
1097  // then followed by CR -> multi line
1098  if (tokenizer_token() == TOKENIZER_CR) {
1099  f_nt=1;
1100  } else { // single line
1101  endif_cntr--;
1104  tokenizer_next();
1105  }
1107  DEBUG_PRINTF("ubasic.c: else_statement(): endif in singleline if-statement\n");
1108  ended = 1;
1110  return;
1111  }
1112  }
1113  }
1114  if( tokenizer_token() == TOKENIZER_ENDIF) { endif_cntr--; }
1115  if (!f_nt) { tokenizer_next(); }
1116  }
1117  }
1118  endif_statement();
1119  }else{
1120  DEBUG_PRINTF("ubasic.c: else_statement(): CR after ELSE expected\n");
1121  ended = 1;
1123  }
1124 }
static void end_select_statement ( void  )
static

Definiert in Zeile 1143 der Datei ubasic.c.

1144 {
1145  if(select_stack_ptr > 0) {
1148  dec_select_stack();
1149  } else {
1150  DEBUG_PRINTF("ubasic.c: end_select_statement(): end_select without select-statement\n");
1151  ended = 1;
1153  }
1154 }
static void end_statement ( void  )
static

Definiert in Zeile 1560 der Datei ubasic.c.

1561 {
1563  ended = 1;
1564 }
static void endif_statement ( void  )
static

Definiert in Zeile 944 der Datei ubasic.c.

945 {
946  if(if_stack_ptr > 0) {
949  if_stack_ptr--;
950  } else {
951  DEBUG_PRINTF("ubasic.c: endif_statement(): endif without if-statement\n");
952  ended = 1;
954  }
955 }
static int expr ( void  )
static

Definiert in Zeile 776 der Datei ubasic.c.

777 {
778  int t1, t2;
779  int op;
780 
781  t1 = term();
782  op = tokenizer_token();
783  DEBUG_PRINTF("expr: token %d\n", op);
784  while(op == TOKENIZER_PLUS ||
785  op == TOKENIZER_MINUS ||
786  op == TOKENIZER_AND ||
787  op == TOKENIZER_LOR ||
788  op == TOKENIZER_XOR) {
789  tokenizer_next();
790  t2 = term();
791  DEBUG_PRINTF("expr: %d %d %d\n", t1, op, t2);
792  switch(op) {
793  case TOKENIZER_PLUS:
794  t1 = t1 + t2;
795  break;
796  case TOKENIZER_MINUS:
797  t1 = t1 - t2;
798  break;
799  case TOKENIZER_AND:
800  t1 = t1 & t2;
801  break;
802  case TOKENIZER_LOR:
803  t1 = t1 || t2;
804  break;
805  }
806  op = tokenizer_token();
807  }
808  DEBUG_PRINTF("expr: %d\n", t1);
809  return t1;
810 }
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;
701 
702  //ARM Begin
703 
704  default:
705  r = varfactor();
706  break;
707  }
708  return r;
709 }
static void for_statement ( void  )
static

Definiert in Zeile 1433 der Datei ubasic.c.

1434 {
1435  int for_variable, to, step;
1436 
1438  for_variable = tokenizer_variable_num();
1441  ubasic_set_variable(for_variable, expr());
1443  to = expr();
1444  step = 1;
1445  if (tokenizer_token() != TOKENIZER_CR) {
1447  step = expr();
1448  }
1450 
1453  for_stack[for_stack_ptr].for_variable = for_variable;
1456  DEBUG_PRINTF("for_statement: new for, var %d to %d\n",
1457  for_stack[for_stack_ptr].for_variable,
1458  for_stack[for_stack_ptr].to);
1459 
1460  for_stack_ptr++;
1461  } else {
1462  DEBUG_PRINTF("for_statement: for stack depth exceeded\n");
1463  ended = 1;
1465  }
1466 }
static void get_config_value_statement ( )
static

Definiert in Zeile 2003 der Datei ubasic.c.

2004 {
2005  int var, var1, var2;
2006  tConfigVal configVal;
2008  var = expr();
2009  var1 = expr();
2010  var2 = tokenizer_variable_num();
2012  if( conf_getValue(var, &configVal) == CONF_VALUE ) {
2013  ubasic_set_variable(var2, configVal.numb);
2014  } else {
2015  ubasic_set_variable(var2, var1);
2016  }
2017  accept_cr();
2018 }
static void get_int_var_statement ( int  token,
int(*)(void)  func 
)
static

Definiert in Zeile 1719 der Datei ubasic.c.

1720 {
1721  int var;
1722  accept(token);
1723  var = tokenizer_variable_num();
1725  ubasic_set_variable(var, func());
1726  accept_cr();
1727 }
static void get_prop_statement ( )
static

Definiert in Zeile 1729 der Datei ubasic.c.

1730 {
1731  int var, var1;
1733  var = expr();
1734  var1 = tokenizer_variable_num();
1737 
1738  accept_cr();
1739 }
static void get_short_var_statement ( int  token,
short(*)(void)  func 
)
static

Definiert in Zeile 1708 der Datei ubasic.c.

1709 {
1710  int var;
1711  accept(token);
1712  var = tokenizer_variable_num();
1714  ubasic_set_variable(var, func());
1715  accept_cr();
1716 }
static void gosub_statement ( void  )
static

Definiert in Zeile 1364 der Datei ubasic.c.

1365 {
1368  tokenizer_string(string, sizeof(string));
1369  do {
1370  tokenizer_next();
1371  } while(tokenizer_token() != TOKENIZER_CR);
1374 /* tokenizer_line_number_inc();*/
1376  gosub_stack_ptr++;
1377  jump_label(string);
1378  } else {
1379  DEBUG_PRINTF("gosub_statement: gosub stack exhausted\n");
1380  ended = 1;
1382  }
1383  } else {
1384  DEBUG_PRINTF("ubasic.c: goto_statement(): no label specified\n");
1385  ended = 1;
1387  }
1388 }
static void goto_statement ( void  )
static

Definiert in Zeile 900 der Datei ubasic.c.

901 {
904  tokenizer_string(string, sizeof(string));
905  tokenizer_next();
906  jump_label(string);
907  } else {
908  DEBUG_PRINTF("ubasic.c: goto_statement(): no label specified\n");
909  ended = 1;
911  }
912 }
static void if_statement ( void  )
static

Definiert in Zeile 958 der Datei ubasic.c.

959 {
960  int r, else_cntr,endif_cntr,f_nt,f_sl;
961 
963  DEBUG_PRINTF("if_statement: get_relation\n");
964  r = relation();
965  DEBUG_PRINTF("if_statement: relation %d\n", r);
967  if (ended) {
968  return;
969  }
970 
971  if (tokenizer_token() == TOKENIZER_CR) {
972  // CR after then -> multiline IF-Statement
974  if_stack[if_stack_ptr] = r;
975  if_stack_ptr++;
976  } else {
977  DEBUG_PRINTF("if_statement: IF-stack depth exceeded\n");
978  ended = 1;
980  return;
981  }
982  DEBUG_PRINTF("if_statement: stack_ptr %d\n", if_stack_ptr);
984  if(r) {
985  DEBUG_PRINTF("if_statement: result true\n");
986  return;
987  }else {
988  DEBUG_PRINTF("if_statement: result false\n");
989 
990  else_cntr=endif_cntr=0; // number of else/endif possible in current nesting
991  f_nt=f_sl=0; // f_nt flag for additional next token, f_fs flag single line
992 
994  || else_cntr || endif_cntr) && tokenizer_token() != TOKENIZER_ENDOFINPUT){
995  f_nt=0;
996  // nested if
997  if( tokenizer_token() == TOKENIZER_IF) {
998  else_cntr+=1;
999  endif_cntr+=1;
1000  f_sl=0;
1001  DEBUG_PRINTF("IF: line %d, token %d, else %d, end %d\n", tokenizer_line_number(),tokenizer_token(),else_cntr,endif_cntr);
1002  }
1003  if( tokenizer_token() == TOKENIZER_THEN) {
1004  f_nt=1;
1005  tokenizer_next();
1006  DEBUG_PRINTF("THEN: line %d, token %d, else %d, end %d\n", tokenizer_line_number(),tokenizer_token(),else_cntr,endif_cntr);
1007  if (tokenizer_token() != TOKENIZER_CR) { f_sl=1; }
1008  DEBUG_PRINTF("THEN_SL: line %d, token %d, else %d, end %d\n", tokenizer_line_number(),tokenizer_token(),else_cntr,endif_cntr);
1009  }
1010  if(tokenizer_token() == TOKENIZER_ELSE) {
1011  else_cntr--;
1012  DEBUG_PRINTF("ELSE: line %d, token %d, else %d, end %d\n", tokenizer_line_number(),tokenizer_token(),else_cntr,endif_cntr);
1013  if (else_cntr<0) {
1014  DEBUG_PRINTF("ubasic.c: if_statement(): else without if-statement\n");
1015  ended = 1;
1017  return;
1018  }
1019  }
1020  if(!f_sl && (tokenizer_token() == TOKENIZER_ENDIF)) {
1021  endif_cntr--;
1022  if (endif_cntr != else_cntr) else_cntr--;
1023  DEBUG_PRINTF("ENDIF: line %d, token %d, else %d, end %d\n", tokenizer_line_number(),tokenizer_token(),else_cntr,endif_cntr);
1024  } else {
1025  if (f_sl && (tokenizer_token() == TOKENIZER_CR)) {
1026  f_sl=0;
1027  endif_cntr--;
1028  if (endif_cntr != else_cntr) else_cntr--;
1029  DEBUG_PRINTF("ENDIF_SL: line %d, token %d, else %d, end %d\n", tokenizer_line_number(),tokenizer_token(),else_cntr,endif_cntr);
1030  }else{
1032  DEBUG_PRINTF("ubasic.c: if_statement(): endif in singleline if-statement\n");
1033  ended = 1;
1035  return;
1036  }
1037  }
1038  }
1039  if (!f_nt) { tokenizer_next(); }
1040  }
1041  if(tokenizer_token() == TOKENIZER_ELSE) { return; }
1042  }
1043  endif_statement();
1044  }else {
1045  // Singleline IF-Statement
1046  if(r) {
1047  statement();
1048  } else {
1049  do {
1050  tokenizer_next();
1051  } while(tokenizer_token() != TOKENIZER_ELSE &&
1054  if(tokenizer_token() == TOKENIZER_ELSE) {
1056  statement();
1057  } else {
1059  }
1060  }
1061  }
1062 }
static void is_key_statement ( void  )
static

Definiert in Zeile 1965 der Datei ubasic.c.

1966 {
1967  int var;
1969  var = tokenizer_variable_num();
1972  DEBUG_PRINTF("End of is_key\n");
1973  accept_cr();
1974 }
int jump_label ( char *  label)

Definiert in Zeile 871 der Datei ubasic.c.

872 {
873  char currLabel[MAX_STRINGLEN];
875  currLabel[0] = 0;
877  tokenizer_next();
878  if (tokenizer_token() == TOKENIZER_LABEL) {
879  tokenizer_label(currLabel, sizeof(currLabel));
880  tokenizer_next();
881  if(strcmp(label, currLabel) == 0) {
883  DEBUG_PRINTF("jump_linenum: Found line %d\n", tokenizer_line_number());
884  break;
885  }
886  }
887  }
890  DEBUG_PRINTF("Label %s not found", label);
892  }
893  return 0;
894  } else {
895  return 1;
896  }
897 }
static void jump_line ( int  linenum)
static

Definiert in Zeile 858 der Datei ubasic.c.

859 {
861  while(tokenizer_line_number() != linenum) {
862  tokenizer_next();
863  }
864  /* swallow the CR that would be read next */
866 
867 }
static void let_statement ( void  )
static

Definiert in Zeile 1332 der Datei ubasic.c.

1333 {
1334 
1335  int var;
1336 
1337  var = tokenizer_variable_num();
1338 
1341  ubasic_set_variable(var, expr());
1342  DEBUG_PRINTF("let_statement: assign %d to %d\n", variables[var], var);
1343  accept_cr();
1344 }
static void line_statement ( void  )
static

Definiert in Zeile 2614 der Datei ubasic.c.

2615 {
2616  /* line numbers have been removed */
2617  DEBUG_PRINTF("----------- Line number %d ---------\n", tokenizer_line_number());
2618  /* current_linenum = tokenizer_num();*/
2619 #if 0
2620  if (tokenizer_token() == TOKENIZER_LABEL) {
2621 #ifdef DEBUG
2622  tokenizer_label(string, sizeof(string));
2623  DEBUG_PRINTF("line_statement: label: %s\n", string );
2624 #endif
2627  return;
2628  }
2629 #endif
2630  /* reyalp - eat up to 100 labels or rems at a time so they don't cost 10ms each */
2631  int count = 100;
2632  do {
2633  int r=tokenizer_token();
2634  if ( r == TOKENIZER_LABEL ) {
2635  /* hit limit and we are on a label, return */
2636  if( count == 1 )
2637  return;
2638 #ifdef DEBUG
2639  tokenizer_label(string, sizeof(string));
2640  DEBUG_PRINTF("line_statement: label: %s\n", string );
2641 #endif
2644  }
2645  else if ( r == TOKENIZER_REM ) {
2646  rem_statement();
2647  }
2648  else {
2649  break;
2650  }
2651  } while(--count);
2652  statement();
2653  return;
2654 }
static void md_detect_motion_statement ( )
static

Definiert in Zeile 2104 der Datei ubasic.c.

2105 {
2106  int columns;
2107  int rows;
2108  int pixel_measure_mode;
2109  int detection_timeout;
2110  int measure_interval;
2111  int threshold;
2112  int draw_grid=0;
2113  int clipping_region_mode=0;
2114  int clipping_region_row1=0;
2115  int clipping_region_column1=0;
2116  int clipping_region_row2=0;
2117  int clipping_region_column2=0;
2118  int parameters=0;
2119  int pixels_step=1;
2120  int msecs_before_trigger=0;
2121 
2123 
2124  columns=expr();tokenizer_next();
2125 
2126  rows=expr();tokenizer_next();
2127 
2128  pixel_measure_mode=expr();tokenizer_next();
2129 
2130  detection_timeout=expr();tokenizer_next();
2131 
2132  measure_interval=expr();tokenizer_next();
2133 
2134  threshold=expr();tokenizer_next();
2135 
2136  draw_grid=expr();tokenizer_next();
2137 
2139 
2141 
2143  // eat COMA
2144  // tokenizer_next();
2145  }
2146 
2148  tokenizer_next();
2149  clipping_region_mode = expr();
2150  }
2152  tokenizer_next();
2153  clipping_region_column1 = expr();
2154  }
2156  tokenizer_next();
2157  clipping_region_row1 = expr();
2158  }
2160  tokenizer_next();
2161  clipping_region_column2 = expr();
2162  }
2164  tokenizer_next();
2165  clipping_region_row2 = expr();
2166  }
2168  tokenizer_next();
2169  parameters = expr();
2170  }
2172  tokenizer_next();
2173  pixels_step = expr();
2174  }
2175 
2177  tokenizer_next();
2178  msecs_before_trigger = expr();
2179  }
2180 
2181  accept_cr();
2182 
2184  columns, rows, pixel_measure_mode, detection_timeout,
2185  measure_interval, threshold, draw_grid,
2186  clipping_region_mode,
2187  clipping_region_column1, clipping_region_row1,
2188  clipping_region_column2, clipping_region_row2,
2189  parameters, pixels_step, msecs_before_trigger);
2190 
2191  flag_yield=1;
2192 }
static void md_get_cell_diff_statement ( )
static

Definiert in Zeile 2072 der Datei ubasic.c.

2073 {
2074  int var, col, row;
2076 
2077  col=expr();tokenizer_next();
2078 
2079  row=expr();tokenizer_next();
2080 
2081  var = tokenizer_variable_num();
2083  accept_cr();
2084 
2086 }
static void md_get_cell_val_statement ( )
static

Definiert in Zeile 2088 der Datei ubasic.c.

2089 {
2090  int var, col, row;
2092 
2093  col=expr();tokenizer_next();
2094 
2095  row=expr();tokenizer_next();
2096 
2097  var = tokenizer_variable_num();
2099  accept_cr();
2100 
2102 }
static void next_statement ( void  )
static

Definiert in Zeile 1405 der Datei ubasic.c.

1406 {
1407  int var, value;
1408 
1410  var = tokenizer_variable_num();
1412  if(for_stack_ptr > 0 &&
1413  var == for_stack[for_stack_ptr - 1].for_variable) {
1414  value = ubasic_get_variable(var) + for_stack[for_stack_ptr - 1].step;
1415  ubasic_set_variable(var, value);
1416 
1417  if(((for_stack[for_stack_ptr - 1].step > 0) && (value <= for_stack[for_stack_ptr - 1].to)) ||
1418  ((for_stack[for_stack_ptr - 1].step < 0) && (value >= for_stack[for_stack_ptr - 1].to)))
1419  jump_line(for_stack[for_stack_ptr - 1].line_after_for);
1420  else {
1421  for_stack_ptr--;
1423  }
1424  } else {
1425  DEBUG_PRINTF("next_statement: non-matching next (expected %d, found %d)\n", for_stack[for_stack_ptr - 1].for_variable, var);
1426  ended = 1;
1428  }
1429 
1430 }
static void on_off_statement ( int  token,
void(*)(void)  on,
void(*)(void)  off 
)
static

Definiert in Zeile 2020 der Datei ubasic.c.

2021 {
2022  accept(token);
2023  if (expr() > 0) on();
2024  else off();
2025  accept_cr();
2026 }
static void one_int_param_function ( int  token,
void(*)(int)  func 
)
static

Definiert in Zeile 1744 der Datei ubasic.c.

1745 {
1746  accept(token);
1747  func(expr());
1748  accept_cr();
1749 }
static void one_int_param_plus_const_function ( int  token,
void(*)(int, short)  func,
short  p2 
)
static

Definiert in Zeile 1760 der Datei ubasic.c.

1761 {
1762  accept(token);
1763  func(expr(),p2);
1764  accept_cr();
1765 }
static void one_short_param_function ( int  token,
void(*)(short)  func 
)
static

Definiert in Zeile 1752 der Datei ubasic.c.

1753 {
1754  accept(token);
1755  func(expr());
1756  accept_cr();
1757 }
static void one_short_param_plus_const_function ( int  token,
void(*)(short, short)  func,
short  p2 
)
static

Definiert in Zeile 1768 der Datei ubasic.c.

1769 {
1770  accept(token);
1771  func(expr(),p2);
1772  accept_cr();
1773 }
static void press_statement ( void  )
static

Definiert in Zeile 1582 der Datei ubasic.c.

1583 {
1584  int k;
1586  k = ubasic_get_key_arg();
1587  if (k > 0) {
1588  action_push_press(k);
1589  flag_yield=1;
1590  }
1591  DEBUG_PRINTF("End of press\n");
1592  accept_cr();
1593 }
static void print_statement ( void  )
static

Definiert in Zeile 915 der Datei ubasic.c.

916 {
917  static char buf[128];
918 
919  buf[0]=0;
921  do {
922  DEBUG_PRINTF("Print loop\n");
924  tokenizer_string(string, sizeof(string));
925  sprintf(buf+strlen(buf), "%s", string);
926  tokenizer_next();
927  } else if(tokenizer_token() == TOKENIZER_COMMA) {
928  strcat(buf, " ");
929  tokenizer_next();
930  } else if(tokenizer_token() == TOKENIZER_SEMICOLON) {
931  tokenizer_next();
932  } else {
933  sprintf(buf+strlen(buf), "%d", expr());
934  }
936  script_console_add_line((long)buf);
937  DEBUG_PRINTF("End of print\n");
938  accept_cr();
939 }
static void reboot_statement ( )
static

Definiert in Zeile 1886 der Datei ubasic.c.

1886  {
1889  tokenizer_string(string, sizeof(string));
1890  tokenizer_next();
1891  reboot(string);
1892  } else {
1893  reboot(NULL);
1894  }
1895 }
static int relation ( void  )
static

Definiert in Zeile 813 der Datei ubasic.c.

814 {
815  int r1, r2;
816  int op;
817 
818  r1 = expr();
819  op = tokenizer_token();
820  DEBUG_PRINTF("relation: token %d\n", op);
821  while(op == TOKENIZER_LAND) {
822  tokenizer_next();
823  r2 = expr();
824  DEBUG_PRINTF("relation: %d %d %d\n", r1, op, r2);
825  switch(op) {
826  case TOKENIZER_LAND:
827  r1 = r1 && r2;
828  break;
829  }
830  op = tokenizer_token();
831  }
832  return r1;
833 }
static void release_statement ( void  )
static

Definiert in Zeile 1596 der Datei ubasic.c.

1597 {
1598  int k;
1600  k = ubasic_get_key_arg();
1601  if (k > 0) {
1603  flag_yield=1;
1604  }
1605  DEBUG_PRINTF("End of release\n");
1606  accept_cr();
1607 }
static void rem_statement ( void  )
static

Definiert in Zeile 1347 der Datei ubasic.c.

1348 {
1350  DEBUG_PRINTF("rem_statement\n");
1352 }
static void return_statement ( void  )
static

Definiert in Zeile 1391 der Datei ubasic.c.

1392 {
1394  if(gosub_stack_ptr > 0) {
1395  gosub_stack_ptr--;
1397  } else {
1398  DEBUG_PRINTF("return_statement: non-matching return\n");
1399  ended = 1;
1401  }
1402 }
static void select_statement ( void  )
static

Definiert in Zeile 1300 der Datei ubasic.c.

1301 {
1302 
1303  int select_value;
1304 
1306  select_value = expr();
1308 //REM
1309  while (tokenizer_token() == TOKENIZER_REM) {statement();}
1310 //REM
1311 
1313  select_stack[select_stack_ptr].select_value = select_value;
1315  DEBUG_PRINTF("select_statement: new select, value %d\n",select_stack[select_stack_ptr].select_value);
1316  select_stack_ptr++;
1317  if (tokenizer_token() != TOKENIZER_CASE) {
1318  DEBUG_PRINTF("ubasic.c: select_statement(): don't found case-statement\n");
1319  ended = 1;
1321  }
1322  else { case_statement(); }
1323  } else {
1324  DEBUG_PRINTF("select_statement: SELECT-stack depth exceeded\n");
1325  ended = 1;
1327  }
1328 }
static void set_autostart_statement ( )
static

Definiert in Zeile 1862 der Datei ubasic.c.

1863 {
1864  int to;
1866  to = expr();
1867 #ifndef UBASIC_TEST
1868  if (to >= 0 && to <= 3) conf.script_startup=to;
1869  conf_save();
1870 #endif
1871  accept_cr();
1872 }
static void set_capture_mode_canon_statement ( )
static

Definiert in Zeile 1874 der Datei ubasic.c.

1875 {
1876  int to;
1878  to = expr();
1879  // if the value as negative, assume it is a mistakenly sign extended PROPCASE_SHOOTING_MODE value
1880  if( to < 0)
1881  to &= 0xFFFF;
1883  accept_cr();
1884 }
static void set_config_value_statement ( )
static

Definiert in Zeile 1897 der Datei ubasic.c.

1898 {
1899  int id, value;
1900  tConfigVal configVal = {0,0,0,0};
1901 
1903  id = expr();
1904  value = expr();
1905  if( conf_getValue(id, &configVal) == CONF_VALUE ) {
1906  configVal.numb = value;
1907  configVal.isNumb = 1;
1908  conf_setValue(id, configVal);
1909  }
1910  accept_cr();
1911 }
static void set_console_autoredraw ( void  )
static

Definiert in Zeile 1679 der Datei ubasic.c.

1680 {
1683  accept_cr();
1684 }
static void set_console_layout ( void  )
static

Definiert in Zeile 1667 der Datei ubasic.c.

1668 {
1669  int x1,y1,x2,y2;
1671  x1 = expr();
1672  y1 = expr();
1673  x2 = expr();
1674  y2 = expr();
1675  console_set_layout(x1,y1,x2,y2);
1676  accept_cr();
1677 }
static void set_ev_statement ( )
static

Definiert in Zeile 1778 der Datei ubasic.c.

1779  {
1780  int to;
1782  to = expr();
1785  accept_cr();
1786  }
static void set_exit_key_statement ( )
static

Definiert in Zeile 1976 der Datei ubasic.c.

1977 {
1978  int k;
1981  {
1982  tokenizer_string(string, sizeof(string));
1983  k = script_keyid_by_name(string);
1984  if (k <= 0)
1985  {
1987  ended = 1 ;
1988  }
1989  else
1990  {
1991  script_set_terminate_key(k,string);
1992  }
1993  }
1994  else
1995  {
1996  DEBUG_PRINTF("ubasic.c: set_exit_key no key specified\n");
1997  ended = 1;
1999  }
2000  accept_cr() ;
2001 }
static void set_focus_statement ( )
static

Definiert in Zeile 1812 der Datei ubasic.c.

1813 {
1815  int sd = expr();
1816  // if sd override not available now, fail immediately without calling set_focus
1817  // to avoid unexpected results with SET_LATER
1818  if(shooting_can_focus()) {
1819  // NOTE duplicated in modules/luascript.c and lib/ubasic/ubasic.c
1820  // in AF lock or MF (canon or set by MF functions), set focus now
1823  || camera_info.state.mode_video) // TODO video needs to be investigated, carried over from old code
1824  {
1826  }
1827  else
1828  {
1829  // in an AF mode, set later
1831  }
1832  }
1833  accept_cr();
1834 }
static void set_led_statement ( )
static

Definiert in Zeile 1836 der Datei ubasic.c.

1837 {
1838  int to, to1, to2;
1840  to = expr();
1841  to1 = expr();
1842  to2 = 200;
1844  to2 = expr();
1845  }
1846  camera_set_led(to, to1, to2);
1847  accept_cr();
1848 }
static void set_mf_statement ( )
static

Definiert in Zeile 1804 der Datei ubasic.c.

1805 {
1807  if (expr() > 0) DoMFLock();
1808  else UnlockMF();
1809  accept_cr();
1810 }
static void set_movie_status_statement ( )
static

Definiert in Zeile 1788 der Datei ubasic.c.

1789 {
1792  accept_cr();
1793 }
static void set_prop_statement ( )
static

Definiert in Zeile 1850 der Datei ubasic.c.

1851 {
1852  int to, to1;
1854  to = expr();
1855  to1 = expr();
1856  shooting_set_prop(to, to1);
1857  accept_cr();
1858 }
static void set_propcase_statement ( int  token,
int  prop 
)
static

Definiert in Zeile 1796 der Datei ubasic.c.

1797 {
1798  accept(token);
1799  shooting_set_prop(prop, expr());
1800  accept_cr();
1801 }
static void set_yield_statement ( )
static

Definiert in Zeile 1693 der Datei ubasic.c.

1694 {
1696  int val = expr();
1698  val = expr();
1700  accept_cr();
1701 }
static void shoot_statement ( void  )
static

Definiert in Zeile 1651 der Datei ubasic.c.

1652 {
1654  ubasic_as_ret_var_num = -1;
1655  if (tokenizer_token() != TOKENIZER_CR)
1656  {
1659  }
1660  action_push_shoot(1);
1661  flag_yield=1;
1662  DEBUG_PRINTF("End of shoot\n");
1663  accept_cr();
1664 }
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 2029 der Datei ubasic.c.

2029  {
2032  accept_cr();
2033 }
static int sleep_delay ( int  delay)
static

Definiert in Zeile 1621 der Datei ubasic.c.

1622 {
1623  /* delay of -1 signals indefinite (actually 1 day) delay */
1624  if (delay == -1)
1625  delay = 86400000;
1626 
1627  if (delay > 0)
1628  return delay + get_tick_count();
1629 
1630  return 0;
1631 }
static void sleep_statement ( void  )
static

Definiert in Zeile 1634 der Datei ubasic.c.

1635 {
1637 
1638  int delay = sleep_delay(expr());
1639  if (delay > 0)
1640  {
1641  action_push(delay);
1643  }
1644 
1645  flag_yield=1;
1646  DEBUG_PRINTF("End of sleep\n");
1647  accept_cr();
1648 }
static void statement ( void  )
static

Definiert in Zeile 2203 der Datei ubasic.c.

2204 {
2206 
2207  token = tokenizer_token();
2208 
2209  switch(token) {
2210  // aelock
2211  case TOKENIZER_SET_AELOCK:
2213  break;
2214  // aflock
2215  case TOKENIZER_SET_AFLOCK:
2217  break;
2218 
2221  break;
2222  case TOKENIZER_PRINT:
2223  print_statement();
2224  break;
2225 
2226  case TOKENIZER_SLEEP:
2227  sleep_statement();
2228  break;
2229  case TOKENIZER_CLICK:
2230  click_statement();
2231  break;
2232  case TOKENIZER_PRESS:
2233  press_statement();
2234  break;
2235  case TOKENIZER_RELEASE:
2237  break;
2238  case TOKENIZER_SHOOT:
2239  shoot_statement();
2240  break;
2243  break;
2246  break;
2249  break;
2250 #ifdef INCLUDE_OLD_GET__SYNTAX
2251  case TOKENIZER_GET_TV96:
2253  break;
2256  break;
2259  break;
2260  case TOKENIZER_GET_AV96:
2262  break;
2265  break;
2268  break;
2269  case TOKENIZER_GET_ZOOM:
2271  break;
2272  case TOKENIZER_GET_FOCUS:
2274  break;
2277  break;
2280  break;
2281  case TOKENIZER_GET_DOF:
2283  break;
2286  break;
2289  break;
2292  break;
2293  case TOKENIZER_GET_BV96:
2295  break;
2296  case TOKENIZER_GET_SV96:
2298  break;
2301  break;
2302  case TOKENIZER_GET_VBATT:
2303  get_int_var_statement(token, (int (*)(void))stat_get_vbatt);
2304  break;
2306  get_int_var_statement(token, (int (*)(void))GetTotalCardSpaceKb);
2307  break;
2309  get_int_var_statement(token, (int (*)(void))GetFreeCardSpaceKb);
2310  break;
2312  get_int_var_statement(token, (int (*)(void))GetJpgCount);
2313  break;
2315  get_int_var_statement(token, (int (*)(void))GetRawCount);
2316  break;
2317  case TOKENIZER_GET_PROP:
2319  break;
2320 #endif
2323  break;
2324  case TOKENIZER_SET_TV96:
2326  break;
2327  case TOKENIZER_PLAY_SOUND:
2328  one_int_param_function(token, (void (*)(int))play_sound);
2329  break;
2332  break;
2335  break;
2338  break;
2341  break;
2342  case TOKENIZER_SET_AV96:
2344  break;
2345 
2348  break;
2351  break;
2354  break;
2355 
2358  break;
2359 
2360  case TOKENIZER_SET_ZOOM:
2362  break;
2365  break;
2368  break;
2369  case TOKENIZER_SET_FOCUS:
2371  break;
2372  case TOKENIZER_SET_MF:
2373  set_mf_statement();
2374  break;
2375 
2376 /*
2377  case TOKENIZER_SET_ISO_MARKET:
2378  one_int_param_function(token, shooting_set_iso_market);
2379  break;
2380  case TOKENIZER_SET_ISO_DL_F_B:
2381  one_int_param_function(token, shooting_set_iso_real_delta_from_base);
2382  break;
2383 */
2384  //ARM End
2385 
2388  break;
2389  case TOKENIZER_SET_SV96:
2391  break;
2392 
2395  break;
2396 
2397  case TOKENIZER_SET_PROP:
2399  break;
2400  case TOKENIZER_SET_LED:
2402  break;
2403 
2404  case TOKENIZER_SET_EV:
2405  set_ev_statement();
2406  break;
2407 
2410  break;
2413  break;
2414  case TOKENIZER_SET_QUALITY:
2416  break;
2417 
2418  case TOKENIZER_WAIT_CLICK:
2420  break;
2421  case TOKENIZER_IS_KEY:
2422  is_key_statement();
2423  break;
2426  break;
2427 
2428  case TOKENIZER_WHEEL_LEFT:
2429  accept(token);
2430  JogDial_CCW();
2431  accept_cr();
2432  break;
2433  case TOKENIZER_WHEEL_RIGHT:
2434  accept(token);
2435  JogDial_CW();
2436  accept_cr();
2437  break;
2438 
2439  case TOKENIZER_IF:
2440  if_statement();
2441  break;
2442  case TOKENIZER_ELSE:
2443  else_statement();
2444  break;
2445  case TOKENIZER_ENDIF:
2446  endif_statement();
2447  break;
2448  case TOKENIZER_SELECT:
2449  select_statement();
2450  break;
2451  case TOKENIZER_CASE:
2452  case_statement();
2453  break;
2454  case TOKENIZER_CASE_ELSE:
2456  break;
2457  case TOKENIZER_GOTO:
2458  goto_statement();
2459  break;
2460  case TOKENIZER_GOSUB:
2461  gosub_statement();
2462  break;
2463  case TOKENIZER_RETURN:
2464  return_statement();
2465  break;
2466  case TOKENIZER_FOR:
2467  for_statement();
2468  break;
2469  case TOKENIZER_NEXT:
2470  next_statement();
2471  break;
2472  case TOKENIZER_DO:
2473  do_statement();
2474  break;
2475  case TOKENIZER_UNTIL:
2476  until_statement();
2477  break;
2478  case TOKENIZER_WHILE:
2479  while_statement();
2480  break;
2481  case TOKENIZER_WEND:
2482  wend_statement();
2483  break;
2484  case TOKENIZER_END:
2485  end_statement();
2486  break;
2487  case TOKENIZER_LET:
2489  /* Fall through. */
2490  case TOKENIZER_VARIABLE:
2491  let_statement();
2492  break;
2493  case TOKENIZER_REM:
2494  rem_statement();
2495  break;
2496  case TOKENIZER_CLS:
2497  cls_statement();
2498  break;
2499  case TOKENIZER_SET_RAW:
2500  accept(token);
2501  conf.save_raw = expr();
2502  accept_cr();
2503  break;
2504  case TOKENIZER_SET_RAW_NR:
2505  accept(token);
2506  conf.raw_nr = expr();
2507  accept_cr();
2508  break;
2511  break;
2512  case TOKENIZER_EXIT_ALT:
2514  break;
2515  case TOKENIZER_ENTER_ALT:
2517  break;
2518  case TOKENIZER_SHUT_DOWN:
2522  break;
2525  break;
2527  accept(token);
2529  accept_cr();
2530  break;
2531 
2532  // >> mx3 . motion detector
2535  break;
2538  break;
2541  break;
2542  // << mx3 . motion_detector
2543 
2545  accept(token);
2548  if ((camera_info.perf.md_af_on_time > 0) && (camera_info.cam_af_led >= 0)) {
2549  camera_info.perf.md_af_tuning = 1; // Enable MD testing with AF LED
2550  // clear previous values
2552  camera_info.perf.af_led.min = 0xFFFFFFFF;
2553  } else {
2554  camera_info.perf.md_af_tuning = 0; // Disable MD testing
2555  }
2556  accept_cr();
2557  break;
2558 
2560  one_int_param_function(token, (void (*)(int))_shot_histogram_set);
2561  break;
2562 
2563  case TOKENIZER_SET_RECORD:
2565  break;
2566 
2568  one_int_param_function(token, (void (*)(int))shooting_set_mode_chdk);
2569  break;
2570 
2573  break;
2574 
2575  case TOKENIZER_REBOOT:
2576  reboot_statement();
2577  break;
2578 
2581  break;
2582 
2585  break;
2586  case TOKENIZER_SET_YIELD:
2588  break;
2589 
2592  if (expr()) usb_sync_wait_flag = 1;
2593  else usb_sync_wait_flag = 0;
2594  accept_cr();
2595  break;
2596 
2599  int hpenable= expr();
2600  if ( hpenable > 0) start_usb_HPtimer(hpenable);
2601  else stop_usb_HPtimer();
2602  accept_cr();
2603  break;
2604 
2605  default:
2606  DEBUG_PRINTF("ubasic.c: statement(): not implemented %d\n", token);
2607  ended = 1;
2609  }
2610 }
static int term ( void  )
static

Definiert in Zeile 712 der Datei ubasic.c.

713 {
714  int f1, f2;
715  int op;
716 
717  f1 = factor();
718  op = tokenizer_token();
719  DEBUG_PRINTF("term: token %d\n", op);
720  while(op == TOKENIZER_ASTR ||
721  op == TOKENIZER_SLASH ||
722  op == TOKENIZER_LT ||
723  op == TOKENIZER_GT ||
724  op == TOKENIZER_GE ||
725  op == TOKENIZER_LE ||
726  op == TOKENIZER_NE ||
727  op == TOKENIZER_EQ ||
728  op == TOKENIZER_XOR ||
729  op == TOKENIZER_OR ||
730  op == TOKENIZER_MOD) {
731  tokenizer_next();
732  f2 = factor();
733  DEBUG_PRINTF("term: %d %d %d\n", f1, op, f2);
734  switch(op) {
735  case TOKENIZER_ASTR:
736  f1 = f1 * f2;
737  break;
738  case TOKENIZER_SLASH:
739  f1 = f1 / f2;
740  break;
741  case TOKENIZER_MOD:
742  f1 = f1 % f2;
743  break;
744  case TOKENIZER_LT:
745  f1 = f1 < f2;
746  break;
747  case TOKENIZER_GT:
748  f1 = f1 > f2;
749  break;
750  case TOKENIZER_EQ:
751  f1 = f1 == f2;
752  break;
753  case TOKENIZER_NE:
754  f1 = f1 != f2;
755  break;
756  case TOKENIZER_LE:
757  f1 = f1 <= f2;
758  break;
759  case TOKENIZER_GE:
760  f1 = f1 >= f2;
761  break;
762  case TOKENIZER_OR:
763  f1 = f1 | f2;
764  break;
765  case TOKENIZER_XOR:
766  f1 = f1 ^ f2;
767  break;
768  }
769  op = tokenizer_token();
770  }
771  DEBUG_PRINTF("term: %d\n", f1);
772  return f1;
773 }
static void uB_set_av96 ( int  param)
static

Definiert in Zeile 2035 der Datei ubasic.c.

2035  {
2037  return ;
2038 }
static void uB_set_av96_direct ( int  param)
static

Definiert in Zeile 2040 der Datei ubasic.c.

2040  {
2042  return ;
2043 }
static void uB_set_iso_real ( int  param)
static

Definiert in Zeile 2065 der Datei ubasic.c.

2065  {
2067  return ;
2068 }
static void uB_set_nd_filter_state ( int  param)
static

Definiert in Zeile 2060 der Datei ubasic.c.

2060  {
2062  return ;
2063 }
static void uB_set_sv96 ( int  param)
static

Definiert in Zeile 2055 der Datei ubasic.c.

2055  {
2057  return ;
2058 }
static void uB_set_tv96 ( int  param)
static

Definiert in Zeile 2045 der Datei ubasic.c.

2045  {
2047  return ;
2048 }
static void uB_set_tv96_direct ( int  param)
static

Definiert in Zeile 2050 der Datei ubasic.c.

2050  {
2052  return ;
2053 }
void ubasic_end ( void  )

Definiert in Zeile 2721 der Datei ubasic.c.

2721  {
2722 }
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 2712 der Datei ubasic.c.

2713 {
2714  if(varnum >= 0 && varnum < MAX_VARNUM) {
2715  return variables[varnum];
2716  }
2717  return 0;
2718 }
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 2656 der Datei ubasic.c.

2657 {
2658  unsigned start_tick = get_tick_count();
2659  unsigned lines = 0;
2660  flag_yield = 0;
2661 
2662  do
2663  {
2664  if ( ended || tokenizer_finished() )
2665  {
2666  DEBUG_PRINTF("uBASIC program finished\n");
2667  if (ubasic_error)
2668  {
2669  // Generate error message
2670  char buf[100];
2671  const char *msg;
2673  {
2675  }
2676  else
2677  {
2679  }
2680  sprintf(buf, "uBASIC:%d %s ", ubasic_linenumber(), msg);
2681  // Show error message
2682  script_console_add_error((long)buf);
2684  return SCRIPT_RUN_ERROR;
2685  }
2686  // Show 'Finished' message
2688  return SCRIPT_RUN_ENDED;
2689  }
2690 
2691  line_statement();
2692 
2693  // Return control to CHDK only if external processing required
2694  if ( flag_yield )
2695  return SCRIPT_RUN_RUNNING;
2696 
2697  lines++;
2698  } while (lines < yield_max_lines && get_tick_count() - start_tick < yield_max_ms);
2699 
2700  return SCRIPT_RUN_RUNNING;
2701 }
void ubasic_set_as_ret ( int  md_ret)

Definiert in Zeile 2726 der Datei ubasic.c.

2727 {
2728  if (ubasic_as_ret_var_num >= 0)
2730 }
void ubasic_set_variable ( int  varum,
int  value 
)

Definiert in Zeile 2704 der Datei ubasic.c.

2705 {
2706  if(varnum >= 0 && varnum < MAX_VARNUM) {
2707  variables[varnum] = value;
2708  }
2709 }
static void until_statement ( void  )
static

Definiert in Zeile 1484 der Datei ubasic.c.

1485 {
1486  int r;
1487 
1489  r = relation();
1490  if(do_stack_ptr > 0) {
1491  if(!r) {
1493  } else {
1494  do_stack_ptr--;
1495  accept_cr();
1496  }
1497  } else {
1498  DEBUG_PRINTF("until_statement: unmatched until\n");
1499  ended = 1;
1501  }
1502 }
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 1934 der Datei ubasic.c.

1935 {
1937 
1938  int delay = -1;
1940  {
1941  delay = expr();
1942  if (delay == 0) delay = -1;
1943  }
1944  delay = sleep_delay(delay);
1945 
1946  accept_cr();
1947 
1948  // Reset 'clicked' key if it has not changed since last time
1950  {
1952  }
1953 
1954  // Set up for wait or click testing
1955  action_push(delay);
1957 
1958  // Check for short delay or key already pressed by calling action stack routine once now
1960  {
1961  flag_yield=1;
1962  }
1963 }
static void wend_statement ( void  )
static

Definiert in Zeile 1547 der Datei ubasic.c.

1548 {
1550  if(while_stack_ptr > 0) {
1552  } else {
1553  DEBUG_PRINTF("wend_statement: unmatched wend\n");
1554  ended = 1;
1556  }
1557 }
static void while_statement ( void  )
static

Definiert in Zeile 1505 der Datei ubasic.c.

1506 {
1507  int r, while_cntr;
1508 
1513  while_stack_ptr++;
1514  }
1515  } else {
1516  DEBUG_PRINTF("while_statement: while stack depth exceeded\n");
1517  ended = 1;
1519  return;
1520  }
1521 
1522  r = relation();
1523  if(while_stack_ptr > 0) {
1524  if(!r) {
1525  while_cntr=0;
1526  while((tokenizer_token() != TOKENIZER_WEND || while_cntr ) &&
1528  if (tokenizer_token() == TOKENIZER_WHILE) while_cntr+=1;
1529  if (tokenizer_token() == TOKENIZER_WEND) while_cntr-=1;
1530  tokenizer_next();
1531  }
1532  while_stack_ptr--;
1533 
1535  accept(TOKENIZER_CR);
1536  } else {
1537  accept_cr();
1538  }
1539  } else {
1540  DEBUG_PRINTF("while_statement: unmatched wend\n");
1541  ended = 1;
1543  }
1544 }

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.