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

2224 {
2225  return libshothisto->shot_histogram_set(enable);
2226 }
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 1639 der Datei ubasic.c.

1640 {
1641  if (get_tick_count() >= action_top(2))
1642  {
1643  action_pop_func(1);
1644  return 1;
1645  }
1646  return 0;
1647 }
static int action_stack_AS_UBASIC_WAIT_CLICK ( )
static

Definiert in Zeile 1944 der Datei ubasic.c.

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

Definiert in Zeile 1275 der Datei ubasic.c.

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

Definiert in Zeile 1185 der Datei ubasic.c.

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

Definiert in Zeile 1595 der Datei ubasic.c.

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

Definiert in Zeile 1383 der Datei ubasic.c.

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

Definiert in Zeile 1714 der Datei ubasic.c.

1715 {
1717  console_redraw();
1718  accept_cr();
1719 }
static void dec_select_stack ( void  )
static

Definiert in Zeile 1159 der Datei ubasic.c.

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

Definiert in Zeile 1497 der Datei ubasic.c.

1498 {
1503  do_stack_ptr++;
1504  } else {
1505  DEBUG_PRINTF("do_statement: do stack depth exceeded\n");
1506  ended = 1;
1508  }
1509 }
static void else_statement ( void  )
static

Definiert in Zeile 1093 der Datei ubasic.c.

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

Definiert in Zeile 1171 der Datei ubasic.c.

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

Definiert in Zeile 1588 der Datei ubasic.c.

1589 {
1591  ended = 1;
1592 }
static void endif_statement ( void  )
static

Definiert in Zeile 972 der Datei ubasic.c.

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

Definiert in Zeile 804 der Datei ubasic.c.

805 {
806  int t1, t2;
807  int op;
808 
809  t1 = term();
810  op = tokenizer_token();
811  DEBUG_PRINTF("expr: token %d\n", op);
812  while(op == TOKENIZER_PLUS ||
813  op == TOKENIZER_MINUS ||
814  op == TOKENIZER_AND ||
815  op == TOKENIZER_LOR ||
816  op == TOKENIZER_XOR) {
817  tokenizer_next();
818  t2 = term();
819  DEBUG_PRINTF("expr: %d %d %d\n", t1, op, t2);
820  switch(op) {
821  case TOKENIZER_PLUS:
822  t1 = t1 + t2;
823  break;
824  case TOKENIZER_MINUS:
825  t1 = t1 - t2;
826  break;
827  case TOKENIZER_AND:
828  t1 = t1 & t2;
829  break;
830  case TOKENIZER_LOR:
831  t1 = t1 || t2;
832  break;
833  }
834  op = tokenizer_token();
835  }
836  DEBUG_PRINTF("expr: %d\n", t1);
837  return t1;
838 }
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 
730  //ARM Begin
731 
732  default:
733  r = varfactor();
734  break;
735  }
736  return r;
737 }
static void for_statement ( void  )
static

Definiert in Zeile 1461 der Datei ubasic.c.

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

Definiert in Zeile 2031 der Datei ubasic.c.

2032 {
2033  int var, var1, var2;
2034  tConfigVal configVal;
2036  var = expr();
2037  var1 = expr();
2038  var2 = tokenizer_variable_num();
2040  if( conf_getValue(var, &configVal) == CONF_VALUE ) {
2041  ubasic_set_variable(var2, configVal.numb);
2042  } else {
2043  ubasic_set_variable(var2, var1);
2044  }
2045  accept_cr();
2046 }
static void get_int_var_statement ( int  token,
int(*)(void)  func 
)
static

Definiert in Zeile 1747 der Datei ubasic.c.

1748 {
1749  int var;
1750  accept(token);
1751  var = tokenizer_variable_num();
1753  ubasic_set_variable(var, func());
1754  accept_cr();
1755 }
static void get_prop_statement ( )
static

Definiert in Zeile 1757 der Datei ubasic.c.

1758 {
1759  int var, var1;
1761  var = expr();
1762  var1 = tokenizer_variable_num();
1765 
1766  accept_cr();
1767 }
static void get_short_var_statement ( int  token,
short(*)(void)  func 
)
static

Definiert in Zeile 1736 der Datei ubasic.c.

1737 {
1738  int var;
1739  accept(token);
1740  var = tokenizer_variable_num();
1742  ubasic_set_variable(var, func());
1743  accept_cr();
1744 }
static void gosub_statement ( void  )
static

Definiert in Zeile 1392 der Datei ubasic.c.

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

Definiert in Zeile 928 der Datei ubasic.c.

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

Definiert in Zeile 986 der Datei ubasic.c.

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

Definiert in Zeile 1993 der Datei ubasic.c.

1994 {
1995  int var;
1997  var = tokenizer_variable_num();
2000  DEBUG_PRINTF("End of is_key\n");
2001  accept_cr();
2002 }
int jump_label ( char *  label)

Definiert in Zeile 899 der Datei ubasic.c.

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

Definiert in Zeile 886 der Datei ubasic.c.

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

Definiert in Zeile 1360 der Datei ubasic.c.

1361 {
1362 
1363  int var;
1364 
1365  var = tokenizer_variable_num();
1366 
1369  ubasic_set_variable(var, expr());
1370  DEBUG_PRINTF("let_statement: assign %d to %d\n", variables[var], var);
1371  accept_cr();
1372 }
static void line_statement ( void  )
static

Definiert in Zeile 2642 der Datei ubasic.c.

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

Definiert in Zeile 2132 der Datei ubasic.c.

2133 {
2134  int columns;
2135  int rows;
2136  int pixel_measure_mode;
2137  int detection_timeout;
2138  int measure_interval;
2139  int threshold;
2140  int draw_grid=0;
2141  int clipping_region_mode=0;
2142  int clipping_region_row1=0;
2143  int clipping_region_column1=0;
2144  int clipping_region_row2=0;
2145  int clipping_region_column2=0;
2146  int parameters=0;
2147  int pixels_step=1;
2148  int msecs_before_trigger=0;
2149 
2151 
2152  columns=expr();tokenizer_next();
2153 
2154  rows=expr();tokenizer_next();
2155 
2156  pixel_measure_mode=expr();tokenizer_next();
2157 
2158  detection_timeout=expr();tokenizer_next();
2159 
2160  measure_interval=expr();tokenizer_next();
2161 
2162  threshold=expr();tokenizer_next();
2163 
2164  draw_grid=expr();tokenizer_next();
2165 
2167 
2169 
2171  // eat COMA
2172  // tokenizer_next();
2173  }
2174 
2176  tokenizer_next();
2177  clipping_region_mode = expr();
2178  }
2180  tokenizer_next();
2181  clipping_region_column1 = expr();
2182  }
2184  tokenizer_next();
2185  clipping_region_row1 = expr();
2186  }
2188  tokenizer_next();
2189  clipping_region_column2 = expr();
2190  }
2192  tokenizer_next();
2193  clipping_region_row2 = expr();
2194  }
2196  tokenizer_next();
2197  parameters = expr();
2198  }
2200  tokenizer_next();
2201  pixels_step = expr();
2202  }
2203 
2205  tokenizer_next();
2206  msecs_before_trigger = expr();
2207  }
2208 
2209  accept_cr();
2210 
2212  columns, rows, pixel_measure_mode, detection_timeout,
2213  measure_interval, threshold, draw_grid,
2214  clipping_region_mode,
2215  clipping_region_column1, clipping_region_row1,
2216  clipping_region_column2, clipping_region_row2,
2217  parameters, pixels_step, msecs_before_trigger);
2218 
2219  flag_yield=1;
2220 }
static void md_get_cell_diff_statement ( )
static

Definiert in Zeile 2100 der Datei ubasic.c.

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

Definiert in Zeile 2116 der Datei ubasic.c.

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

Definiert in Zeile 1433 der Datei ubasic.c.

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

Definiert in Zeile 2048 der Datei ubasic.c.

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

Definiert in Zeile 1772 der Datei ubasic.c.

1773 {
1774  accept(token);
1775  func(expr());
1776  accept_cr();
1777 }
static void one_int_param_plus_const_function ( int  token,
void(*)(int, short)  func,
short  p2 
)
static

Definiert in Zeile 1788 der Datei ubasic.c.

1789 {
1790  accept(token);
1791  func(expr(),p2);
1792  accept_cr();
1793 }
static void one_short_param_function ( int  token,
void(*)(short)  func 
)
static

Definiert in Zeile 1780 der Datei ubasic.c.

1781 {
1782  accept(token);
1783  func(expr());
1784  accept_cr();
1785 }
static void one_short_param_plus_const_function ( int  token,
void(*)(short, short)  func,
short  p2 
)
static

Definiert in Zeile 1796 der Datei ubasic.c.

1797 {
1798  accept(token);
1799  func(expr(),p2);
1800  accept_cr();
1801 }
static void press_statement ( void  )
static

Definiert in Zeile 1610 der Datei ubasic.c.

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

Definiert in Zeile 943 der Datei ubasic.c.

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

Definiert in Zeile 1914 der Datei ubasic.c.

1914  {
1917  tokenizer_string(string, sizeof(string));
1918  tokenizer_next();
1919  reboot(string);
1920  } else {
1921  reboot(NULL);
1922  }
1923 }
static int relation ( void  )
static

Definiert in Zeile 841 der Datei ubasic.c.

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

Definiert in Zeile 1624 der Datei ubasic.c.

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

Definiert in Zeile 1375 der Datei ubasic.c.

1376 {
1378  DEBUG_PRINTF("rem_statement\n");
1380 }
static void return_statement ( void  )
static

Definiert in Zeile 1419 der Datei ubasic.c.

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

Definiert in Zeile 1328 der Datei ubasic.c.

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

Definiert in Zeile 1890 der Datei ubasic.c.

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

Definiert in Zeile 1902 der Datei ubasic.c.

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

Definiert in Zeile 1925 der Datei ubasic.c.

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

Definiert in Zeile 1707 der Datei ubasic.c.

1708 {
1711  accept_cr();
1712 }
static void set_console_layout ( void  )
static

Definiert in Zeile 1695 der Datei ubasic.c.

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

Definiert in Zeile 1806 der Datei ubasic.c.

1807  {
1808  int to;
1810  to = expr();
1813  accept_cr();
1814  }
static void set_exit_key_statement ( )
static

Definiert in Zeile 2004 der Datei ubasic.c.

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

Definiert in Zeile 1840 der Datei ubasic.c.

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

Definiert in Zeile 1864 der Datei ubasic.c.

1865 {
1866  int to, to1, to2;
1868  to = expr();
1869  to1 = expr();
1870  to2 = 200;
1872  to2 = expr();
1873  }
1874  camera_set_led(to, to1, to2);
1875  accept_cr();
1876 }
static void set_mf_statement ( )
static

Definiert in Zeile 1832 der Datei ubasic.c.

1833 {
1835  if (expr() > 0) DoMFLock();
1836  else UnlockMF();
1837  accept_cr();
1838 }
static void set_movie_status_statement ( )
static

Definiert in Zeile 1816 der Datei ubasic.c.

1817 {
1820  accept_cr();
1821 }
static void set_prop_statement ( )
static

Definiert in Zeile 1878 der Datei ubasic.c.

1879 {
1880  int to, to1;
1882  to = expr();
1883  to1 = expr();
1884  shooting_set_prop(to, to1);
1885  accept_cr();
1886 }
static void set_propcase_statement ( int  token,
int  prop 
)
static

Definiert in Zeile 1824 der Datei ubasic.c.

1825 {
1826  accept(token);
1827  shooting_set_prop(prop, expr());
1828  accept_cr();
1829 }
static void set_yield_statement ( )
static

Definiert in Zeile 1721 der Datei ubasic.c.

1722 {
1724  int val = expr();
1726  val = expr();
1728  accept_cr();
1729 }
static void shoot_statement ( void  )
static

Definiert in Zeile 1679 der Datei ubasic.c.

1680 {
1682  ubasic_as_ret_var_num = -1;
1683  if (tokenizer_token() != TOKENIZER_CR)
1684  {
1687  }
1688  action_push_shoot(1);
1689  flag_yield=1;
1690  DEBUG_PRINTF("End of shoot\n");
1691  accept_cr();
1692 }
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 2057 der Datei ubasic.c.

2057  {
2060  accept_cr();
2061 }
static int sleep_delay ( int  delay)
static

Definiert in Zeile 1649 der Datei ubasic.c.

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

Definiert in Zeile 1662 der Datei ubasic.c.

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

Definiert in Zeile 2231 der Datei ubasic.c.

2232 {
2234 
2235  token = tokenizer_token();
2236 
2237  switch(token) {
2238  // aelock
2239  case TOKENIZER_SET_AELOCK:
2241  break;
2242  // aflock
2243  case TOKENIZER_SET_AFLOCK:
2245  break;
2246 
2249  break;
2250  case TOKENIZER_PRINT:
2251  print_statement();
2252  break;
2253 
2254  case TOKENIZER_SLEEP:
2255  sleep_statement();
2256  break;
2257  case TOKENIZER_CLICK:
2258  click_statement();
2259  break;
2260  case TOKENIZER_PRESS:
2261  press_statement();
2262  break;
2263  case TOKENIZER_RELEASE:
2265  break;
2266  case TOKENIZER_SHOOT:
2267  shoot_statement();
2268  break;
2271  break;
2274  break;
2277  break;
2278 #ifdef INCLUDE_OLD_GET__SYNTAX
2279  case TOKENIZER_GET_TV96:
2281  break;
2284  break;
2287  break;
2288  case TOKENIZER_GET_AV96:
2290  break;
2293  break;
2296  break;
2297  case TOKENIZER_GET_ZOOM:
2299  break;
2300  case TOKENIZER_GET_FOCUS:
2302  break;
2305  break;
2308  break;
2309  case TOKENIZER_GET_DOF:
2311  break;
2314  break;
2317  break;
2320  break;
2321  case TOKENIZER_GET_BV96:
2323  break;
2324  case TOKENIZER_GET_SV96:
2326  break;
2329  break;
2330  case TOKENIZER_GET_VBATT:
2331  get_int_var_statement(token, (int (*)(void))stat_get_vbatt);
2332  break;
2334  get_int_var_statement(token, (int (*)(void))GetTotalCardSpaceKb);
2335  break;
2337  get_int_var_statement(token, (int (*)(void))GetFreeCardSpaceKb);
2338  break;
2340  get_int_var_statement(token, (int (*)(void))GetJpgCount);
2341  break;
2343  get_int_var_statement(token, (int (*)(void))GetRawCount);
2344  break;
2345  case TOKENIZER_GET_PROP:
2347  break;
2348 #endif
2351  break;
2352  case TOKENIZER_SET_TV96:
2354  break;
2355  case TOKENIZER_PLAY_SOUND:
2356  one_int_param_function(token, (void (*)(int))play_sound);
2357  break;
2360  break;
2363  break;
2366  break;
2369  break;
2370  case TOKENIZER_SET_AV96:
2372  break;
2373 
2376  break;
2379  break;
2382  break;
2383 
2386  break;
2387 
2388  case TOKENIZER_SET_ZOOM:
2390  break;
2393  break;
2396  break;
2397  case TOKENIZER_SET_FOCUS:
2399  break;
2400  case TOKENIZER_SET_MF:
2401  set_mf_statement();
2402  break;
2403 
2404 /*
2405  case TOKENIZER_SET_ISO_MARKET:
2406  one_int_param_function(token, shooting_set_iso_market);
2407  break;
2408  case TOKENIZER_SET_ISO_DL_F_B:
2409  one_int_param_function(token, shooting_set_iso_real_delta_from_base);
2410  break;
2411 */
2412  //ARM End
2413 
2416  break;
2417  case TOKENIZER_SET_SV96:
2419  break;
2420 
2423  break;
2424 
2425  case TOKENIZER_SET_PROP:
2427  break;
2428  case TOKENIZER_SET_LED:
2430  break;
2431 
2432  case TOKENIZER_SET_EV:
2433  set_ev_statement();
2434  break;
2435 
2438  break;
2441  break;
2442  case TOKENIZER_SET_QUALITY:
2444  break;
2445 
2446  case TOKENIZER_WAIT_CLICK:
2448  break;
2449  case TOKENIZER_IS_KEY:
2450  is_key_statement();
2451  break;
2454  break;
2455 
2456  case TOKENIZER_WHEEL_LEFT:
2457  accept(token);
2458  JogDial_CCW();
2459  accept_cr();
2460  break;
2461  case TOKENIZER_WHEEL_RIGHT:
2462  accept(token);
2463  JogDial_CW();
2464  accept_cr();
2465  break;
2466 
2467  case TOKENIZER_IF:
2468  if_statement();
2469  break;
2470  case TOKENIZER_ELSE:
2471  else_statement();
2472  break;
2473  case TOKENIZER_ENDIF:
2474  endif_statement();
2475  break;
2476  case TOKENIZER_SELECT:
2477  select_statement();
2478  break;
2479  case TOKENIZER_CASE:
2480  case_statement();
2481  break;
2482  case TOKENIZER_CASE_ELSE:
2484  break;
2485  case TOKENIZER_GOTO:
2486  goto_statement();
2487  break;
2488  case TOKENIZER_GOSUB:
2489  gosub_statement();
2490  break;
2491  case TOKENIZER_RETURN:
2492  return_statement();
2493  break;
2494  case TOKENIZER_FOR:
2495  for_statement();
2496  break;
2497  case TOKENIZER_NEXT:
2498  next_statement();
2499  break;
2500  case TOKENIZER_DO:
2501  do_statement();
2502  break;
2503  case TOKENIZER_UNTIL:
2504  until_statement();
2505  break;
2506  case TOKENIZER_WHILE:
2507  while_statement();
2508  break;
2509  case TOKENIZER_WEND:
2510  wend_statement();
2511  break;
2512  case TOKENIZER_END:
2513  end_statement();
2514  break;
2515  case TOKENIZER_LET:
2517  /* Fall through. */
2518  case TOKENIZER_VARIABLE:
2519  let_statement();
2520  break;
2521  case TOKENIZER_REM:
2522  rem_statement();
2523  break;
2524  case TOKENIZER_CLS:
2525  cls_statement();
2526  break;
2527  case TOKENIZER_SET_RAW:
2528  accept(token);
2529  conf.save_raw = expr();
2530  accept_cr();
2531  break;
2532  case TOKENIZER_SET_RAW_NR:
2533  accept(token);
2534  conf.raw_nr = expr();
2535  accept_cr();
2536  break;
2539  break;
2540  case TOKENIZER_EXIT_ALT:
2542  break;
2543  case TOKENIZER_ENTER_ALT:
2545  break;
2546  case TOKENIZER_SHUT_DOWN:
2550  break;
2553  break;
2555  accept(token);
2557  accept_cr();
2558  break;
2559 
2560  // >> mx3 . motion detector
2563  break;
2566  break;
2569  break;
2570  // << mx3 . motion_detector
2571 
2573  accept(token);
2576  if ((camera_info.perf.md_af_on_time > 0) && (camera_info.cam_af_led >= 0)) {
2577  camera_info.perf.md_af_tuning = 1; // Enable MD testing with AF LED
2578  // clear previous values
2580  camera_info.perf.af_led.min = 0xFFFFFFFF;
2581  } else {
2582  camera_info.perf.md_af_tuning = 0; // Disable MD testing
2583  }
2584  accept_cr();
2585  break;
2586 
2588  one_int_param_function(token, (void (*)(int))_shot_histogram_set);
2589  break;
2590 
2591  case TOKENIZER_SET_RECORD:
2593  break;
2594 
2596  one_int_param_function(token, (void (*)(int))shooting_set_mode_chdk);
2597  break;
2598 
2601  break;
2602 
2603  case TOKENIZER_REBOOT:
2604  reboot_statement();
2605  break;
2606 
2609  break;
2610 
2613  break;
2614  case TOKENIZER_SET_YIELD:
2616  break;
2617 
2620  if (expr()) usb_sync_wait_flag = 1;
2621  else usb_sync_wait_flag = 0;
2622  accept_cr();
2623  break;
2624 
2627  int hpenable= expr();
2628  if ( hpenable > 0) start_usb_HPtimer(hpenable);
2629  else stop_usb_HPtimer();
2630  accept_cr();
2631  break;
2632 
2633  default:
2634  DEBUG_PRINTF("ubasic.c: statement(): not implemented %d\n", token);
2635  ended = 1;
2637  }
2638 }
static int term ( void  )
static

Definiert in Zeile 740 der Datei ubasic.c.

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

Definiert in Zeile 2063 der Datei ubasic.c.

2063  {
2065  return ;
2066 }
static void uB_set_av96_direct ( int  param)
static

Definiert in Zeile 2068 der Datei ubasic.c.

2068  {
2070  return ;
2071 }
static void uB_set_iso_real ( int  param)
static

Definiert in Zeile 2093 der Datei ubasic.c.

2093  {
2095  return ;
2096 }
static void uB_set_nd_filter_state ( int  param)
static

Definiert in Zeile 2088 der Datei ubasic.c.

2088  {
2090  return ;
2091 }
static void uB_set_sv96 ( int  param)
static

Definiert in Zeile 2083 der Datei ubasic.c.

2083  {
2085  return ;
2086 }
static void uB_set_tv96 ( int  param)
static

Definiert in Zeile 2073 der Datei ubasic.c.

2073  {
2075  return ;
2076 }
static void uB_set_tv96_direct ( int  param)
static

Definiert in Zeile 2078 der Datei ubasic.c.

2078  {
2080  return ;
2081 }
void ubasic_end ( void  )

Definiert in Zeile 2749 der Datei ubasic.c.

2749  {
2750 }
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 2740 der Datei ubasic.c.

2741 {
2742  if(varnum >= 0 && varnum < MAX_VARNUM) {
2743  return variables[varnum];
2744  }
2745  return 0;
2746 }
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 2684 der Datei ubasic.c.

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

Definiert in Zeile 2754 der Datei ubasic.c.

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

Definiert in Zeile 2732 der Datei ubasic.c.

2733 {
2734  if(varnum >= 0 && varnum < MAX_VARNUM) {
2735  variables[varnum] = value;
2736  }
2737 }
static void until_statement ( void  )
static

Definiert in Zeile 1512 der Datei ubasic.c.

1513 {
1514  int r;
1515 
1517  r = relation();
1518  if(do_stack_ptr > 0) {
1519  if(!r) {
1521  } else {
1522  do_stack_ptr--;
1523  accept_cr();
1524  }
1525  } else {
1526  DEBUG_PRINTF("until_statement: unmatched until\n");
1527  ended = 1;
1529  }
1530 }
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 1962 der Datei ubasic.c.

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

Definiert in Zeile 1575 der Datei ubasic.c.

1576 {
1578  if(while_stack_ptr > 0) {
1580  } else {
1581  DEBUG_PRINTF("wend_statement: unmatched wend\n");
1582  ended = 1;
1584  }
1585 }
static void while_statement ( void  )
static

Definiert in Zeile 1533 der Datei ubasic.c.

1534 {
1535  int r, while_cntr;
1536 
1541  while_stack_ptr++;
1542  }
1543  } else {
1544  DEBUG_PRINTF("while_statement: while stack depth exceeded\n");
1545  ended = 1;
1547  return;
1548  }
1549 
1550  r = relation();
1551  if(while_stack_ptr > 0) {
1552  if(!r) {
1553  while_cntr=0;
1554  while((tokenizer_token() != TOKENIZER_WEND || while_cntr ) &&
1556  if (tokenizer_token() == TOKENIZER_WHILE) while_cntr+=1;
1557  if (tokenizer_token() == TOKENIZER_WEND) while_cntr-=1;
1558  tokenizer_next();
1559  }
1560  while_stack_ptr--;
1561 
1563  accept(TOKENIZER_CR);
1564  } else {
1565  accept_cr();
1566  }
1567  } else {
1568  DEBUG_PRINTF("while_statement: unmatched wend\n");
1569  ended = 1;
1571  }
1572 }

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.