/*---------------------------------------------------------------------------*/ static void next_statement(void) { int var; struct for_state *fs; struct typevalue t; /* FIXME: support 'NEXT' on its own, also loop down the stack so if you GOTO out of a layer of NEXT the right thing occurs */ var = tokenizer_variable_num(); accept_tok(TOKENIZER_INTVAR); /* FIXME: make the for stack just use pointers so it compiles better */ fs = &for_stack[for_stack_ptr - 1]; if(for_stack_ptr > 0 && var == fs->for_variable) { ubasic_get_variable(var, &t, 0, NULL); t.d.i += fs->step; ubasic_set_variable(var, &t, 0,NULL); /* NEXT end depends upon sign of STEP */ if ((fs->step >= 0 && t.d.i <= fs->to) || (fs->step < 0 && t.d.i >= fs->to)) tokenizer_goto(fs->resume_token); else for_stack_ptr--; } else ubasic_error("Mismatched NEXT"); }
//static int varfactor(void) int varfactor(void) { long r; r = ubasic_get_variable(tokenizer_variable_num()); accept(TOKENIZER_VARIABLE); return r; }
//static void next_statement(void) void next_statement(void) { long var; accept(TOKENIZER_NEXT); var = tokenizer_variable_num(); accept(TOKENIZER_VARIABLE); if(for_stack_ptr > 0 && var == for_stack[for_stack_ptr - 1].for_variable) { ubasic_set_variable(var, ubasic_get_variable(var) + 1); if(ubasic_get_variable(var) <= for_stack[for_stack_ptr - 1].to) { jump_linenum(for_stack[for_stack_ptr - 1].line_after_for); }else{ for_stack_ptr--; accept(TOKENIZER_CR); } }else{ accept(TOKENIZER_CR); } }
/*---------------------------------------------------------------------------*/ static int varfactor(void) { int r; DEBUG_PRINTF("varfactor: obtaining %d from variable %d\n", variables[tokenizer_variable_num()], tokenizer_variable_num()); r = ubasic_get_variable(tokenizer_variable_num()); accept(TOKENIZER_VARIABLE); return r; }
/*---------------------------------------------------------------------------*/ static void varfactor(struct typevalue *v) { var_t var = tokenizer_variable_num(); struct typevalue s[MAX_SUBSCRIPT]; int n = 0; /* Sinclair style A$(2 TO 5) would also need to be parsed here if added */ accept_either(TOKENIZER_INTVAR, TOKENIZER_STRINGVAR); if (current_token == TOKENIZER_LEFTPAREN) n = parse_subscripts(s); ubasic_get_variable(var, v, n, s); DEBUG_PRINTF("varfactor: obtaining %d from variable %d\n", v->d.i, tokenizer_variable_num()); }
/*---------------------------------------------------------------------------*/ int main(void) { struct typevalue v; run(program_let); ubasic_get_variable(0, &v, 0, NULL); assert(v.d.i == 42 && v.type == TYPE_INTEGER); run(program_goto); ubasic_get_variable(2, &v, 0, NULL); assert(v.d.i == 108 && v.type == TYPE_INTEGER); run(program_loop); ubasic_get_variable(0, &v, 0, NULL); assert(v.d.i == ((value_t)(126 * 126 * 10)) && v.type == TYPE_INTEGER); run(program_fibs); ubasic_get_variable(1, &v, 0, NULL); assert(v.d.i == 89 && v.type == TYPE_INTEGER); run(program_peek_poke); ubasic_get_variable(0, &v, 0, NULL); assert(v.d.i == 123 && v.type == TYPE_INTEGER); ubasic_get_variable(25, &v, 0, NULL); assert(v.d.i == 123 && v.type == TYPE_INTEGER); return 0; }
/*---------------------------------------------------------------------------*/ static void next_statement(void) { int var; accept(TOKENIZER_NEXT); var = tokenizer_variable_num(); accept(TOKENIZER_VARIABLE); if(for_stack_ptr > 0 && var == for_stack[for_stack_ptr - 1].for_variable) { ubasic_set_variable(var, ubasic_get_variable(var) + 1); if(ubasic_get_variable(var) <= for_stack[for_stack_ptr - 1].to) { jump_linenum(for_stack[for_stack_ptr - 1].line_after_for); } else { for_stack_ptr--; accept(TOKENIZER_CR); } } else { DEBUG_PRINTF("next_statement: non-matching next (expected %d, found %d)\n", for_stack[for_stack_ptr - 1].for_variable, var); accept(TOKENIZER_CR); } }
void process_script() { long t; int Lres; // process stack operations if (kbd_int_stack_ptr){ switch (KBD_STACK_PREV(1)){ case SCRIPT_MOTION_DETECTOR: if(md_detect_motion()==0){ kbd_int_stack_ptr-=1; if (L) { // We need to recover the motion detector's // result from ubasic variable 0 and push // it onto the thread's stack. -- AUJ lua_pushnumber( Lt, ubasic_get_variable(0) ); } } return; case SCRIPT_PRESS: kbd_key_press(KBD_STACK_PREV(2)); kbd_int_stack_ptr-=2; // pop op. return; case SCRIPT_RELEASE: kbd_key_release(KBD_STACK_PREV(2)); kbd_int_stack_ptr-=2; // pop op. return; case SCRIPT_SLEEP: t = get_tick_count(); // FIXME take care if overflow occurs if (delay_target_ticks == 0){ /* setup timer */ delay_target_ticks = t+KBD_STACK_PREV(2); } else { if (delay_target_ticks <= t){ delay_target_ticks = 0; kbd_int_stack_ptr-=2; // pop sleep op. } } return; case SCRIPT_PR_WAIT_SAVE: state_shooting_progress = SHOOTING_PROGRESS_NONE; state_expos_recalculated = 0; histogram_stop(); kbd_int_stack_ptr-=1; // pop op. return; case SCRIPT_WAIT_SAVE:{ if (state_shooting_progress == SHOOTING_PROGRESS_DONE) kbd_int_stack_ptr-=1; // pop op. return; } case SCRIPT_WAIT_FLASH:{ if (shooting_is_flash_ready()) kbd_int_stack_ptr-=1; // pop op. return; } case SCRIPT_WAIT_EXPHIST:{ if (state_expos_recalculated) { kbd_int_stack_ptr-=1; // pop op. state_expos_under = under_exposed; state_expos_over = over_exposed; } return; } case SCRIPT_PR_WAIT_EXPHIST: { if (shooting_in_progress() || mvideo) { state_expos_recalculated = 0; histogram_restart(); kbd_int_stack_ptr-=1; // pop op. } return; } case SCRIPT_WAIT_CLICK: { t = get_tick_count(); if (delay_target_ticks == 0){ /* setup timer */ delay_target_ticks = t+((KBD_STACK_PREV(2))?KBD_STACK_PREV(2):86400000); } else { kbd_last_clicked = kbd_get_clicked_key(); if (kbd_last_clicked || delay_target_ticks <= t) { if (!kbd_last_clicked) kbd_last_clicked=0xFFFF; delay_target_ticks = 0; kbd_int_stack_ptr-=2; // pop op. } } return; } default: /*finished();*/ script_end(); } } if (state_kbd_script_run != 3) { if( L ) { int top; if (state_lua_kbd_first_call_to_resume) { state_lua_kbd_first_call_to_resume = 0; top = 0; } else { top = lua_gettop(Lt); } Lres = lua_resume( Lt, top ); if (Lres != LUA_YIELD && Lres != 0) { script_console_add_line( lua_tostring( Lt, -1 ) ); wait_and_end(); return; } if (Lres != LUA_YIELD) { script_console_add_line(lang_str(LANG_CONSOLE_TEXT_FINISHED)); script_end(); } } else { ubasic_run(); if (ubasic_finished()) { script_console_add_line(lang_str(LANG_CONSOLE_TEXT_FINISHED)); script_end(); } } } }