static void cmd_move_rel(svg_state_t *state, const float *p) { state->cur[0] += p[0]; state->cur[1] += p[1]; cmd_move(state); }
void cmd_exec(void) { switch(usb_in_buffer[0]) { case CMD_CAL: cmd_cali(); break; case CMD_MOV: cmd_move(); break; case CMD_TST: cmd_test(); break; case CMD_HLT: cmd_halt(); break; case CMD_QRY: cmd_query(); usb_send(); break; default: break; } }
static INT32 command_move (INT32 index, UINT32 offset, void (*callback)(INT32 type, INT32 process, UINT8 *str)) { INT32 result = (INT32)cmd_move(pslave_list[index].id, offset); if(result == SUCCESS) { INT32 progress = trans_size*100/slave_reorg_size; if(progress > prog) { prog = progress; callback(1,prog,NULL); if(prog<100) { #if (SYS_CHIP_MODULE != ALI_M3327C || SYS_SDRAM_SIZE != 2) sprintf(msg,"u%d ",prog); pan_display(LV_pPanDev, msg, 4); #endif } } } return result; }
// runs a script // returns -1 is esc was pressed, 0 o/w int run_script(char *script, DATAFILE *d) { char buf[512]; Ttoken *token; int i; // set datafile data = d; clear_keybuf(); // init sound memory for(i = 0; i < MAX_SCRIPT_SOUNDS; i ++) active_sounds[i] = -1; // create gfx buffers swap_buffer = create_bitmap(160, 120); buffer = create_bitmap(160, 120); script_done = FALSE; while(!script_done) { // get commands from script string script = get_line(buf, script); if (buf[0] != '#' && buf[0] != '\n' && buf[0] != '\r' && buf[0] != '-') { token = tokenize(buf); if (token != NULL) { if (!stricmp(token->word, "load_map")) cmd_loadmap(get_next_word(token)); else if (!stricmp(token->word, "draw_map")) cmd_drawmap(); else if (!stricmp(token->word, "set")) cmd_set((Ttoken *)token->next); else if (!stricmp(token->word, "move")) cmd_move((Ttoken *)token->next); else if (!stricmp(token->word, "delete")) cmd_del((Ttoken *)token->next); else if (!stricmp(token->word, "run")) cmd_run((Ttoken *)token->next); else if (!stricmp(token->word, "speak")) cmd_speak((Ttoken *)token->next, 1); else if (!stricmp(token->word, "text")) cmd_speak((Ttoken *)token->next, 0); else if (!stricmp(token->word, "save_buffer")) cmd_savebmp(); else if (!stricmp(token->word, "show_bmp")) cmd_showbmp(get_next_word(token)); else if (!stricmp(token->word, "blit")) cmd_blit(); else if (!stricmp(token->word, "fade_in")) cmd_fadein(); else if (!stricmp(token->word, "fade_out")) cmd_fadeout(); else if (!stricmp(token->word, "wait")) cmd_wait(atoi(get_next_word(token))); else if (!stricmp(token->word, "play_sample")) cmd_play_sample((Ttoken *)token->next); else if (!stricmp(token->word, "stop_sample")) cmd_stop_sample((Ttoken *)token->next); else if (!stricmp(token->word, "end_script")) cmd_end(); else { char msg[256]; sprintf(msg, "unknown: %s", token->word); msg_box(msg); } flush_tokens(token); } } } // destroy buffers delete_all_objects(); destroy_bitmap(buffer); destroy_bitmap(swap_buffer); // stop old sounds for(i = 0; i < MAX_SCRIPT_SOUNDS; i ++) { if (active_sounds[i] != -1) { stop_sound_id(active_sounds[i]); forget_sound(active_sounds[i]); } } return (script_done == -1 ? -1 : 0); }
int main(void) { uint8_t c; DATA_OUT // Шина данных (DDRD) DDRC = 0b00000000; // Шина адреса DDRB = 0b00101101; // Шина адреса, карта и светодиод PORTB = 0b00010001; // Подтягивающий резистор на MISO и светодиод // Пауза, пока не стабилизируется питание _delay_ms(100); // while(1) { // error(); // } // Запуск файловой системы if(fs_init()) error(); strcpy_P((char*)buf, PSTR("boot/boot.rk")); if(fs_open()) error(); if(fs_getfilesize()) error(); if(fs_tmp < 7) error(); if(fs_tmp > 128) error(); if(fs_read0(rom, (WORD)fs_tmp)) error(); // Гасим светодиод PORTB |= _BV(PB0); while(1) { // Эмуляция ПЗУ RomEmu(); // Зажигаем светодиод PORTB |= _BV(PB0); // Проверяем наличие карты sendStart(ERR_START); send(ERR_WAIT); if(fs_check()) { send(ERR_DISK_ERR); } else { send(ERR_OK_DISK); recvStart(); c = wrecv(); // Сбрасываем ошибку lastError = 0; // Принимаем аргументы switch(c) { case 0: cmd_boot(); break; case 1: cmd_ver(); break; case 2: cmd_exec(); break; case 3: cmd_find(); break; case 4: cmd_open(); break; case 5: cmd_lseek(); break; case 6: cmd_read(); break; case 7: cmd_write(); break; case 8: cmd_move(); break; default: lastError = ERR_INVALID_COMMAND; } // Вывод ошибки if(lastError) sendStart(lastError); } // Порт рабоатет на выход wait(); DATA_OUT // Гасим светодиод PORTB &=~_BV(PB0); _delay_ms(500); } }
int main ( int argc , char** argv ) { /* * Do initialization steps here. */ /* * Set up list of player id's. */ char* players [2] = { "r" , "b" }; /* * Attempt to initialize the game state to the default. * * Add more error checking? */ State* state = build_state ( ); FILE* init_file = fopen ( INIT_FILENAME , "r" ); bool initialized = init_file && state_load ( state , init_file ); fclose ( init_file ); if ( ! initialized ) return 1; /* * The top level of program logic resides nested within this loop, * which runs until one of the players sends the termination signal. * * Note that this is an infinite loop. The actual control logic for * this loop is a single goto statment in the verb interpreter, set * to jump outside the loop if and only if the VERB_TERM is * encountered. DO NOT BE ALARMED. THIS IS A LEGITIMATE USE OF THE * GOTO STATEMENT! */ while ( true ) { /* * The logic inside this loop effectively handles a single * round, from the starting position to reseting the game. */ /* * Initialize the player indexer and player. */ unsigned short indexer = 0; char* player = players[0]; /* * While a game is still in progress (i.e. while both players * have legal moves available), this loop alternates between * the red and black players, starting with the red player. * * The control statement for this loop determines whether the * player has any vaild moves. If the player does not have any * valid moves, the control logic of the interpreter loop is * modified to force the losing player to fix the situation. * This could change in the future, so with minor changes, * control could just be made to fall through to a reset * after this loop, it just depends on what happens during * development. */ while ( state_has_moves ( state , player ) ) { /* * The logic inside this loop effectively handles a single * turn, allowing an unlimited number of commands which are * not moves to be performed, followed by a single move. * * Notice that both players must be trusted for this system * to work as-is, otherwise any player could modify the * state of the game to their advantage. This is a standing * security issue, but one which can be ignored at the * moment for the academic purposes of the project. */ /* * Initialize the keep_turn flag. */ bool keep_turn = true; /* * While the player has not yet made a move, it is still * the player's turn. Thus, this loop terminates only after * a move has been made, processing any other commands * the player gives during the current turn. Control stays * with the player anyways if he has no moves, as he has * lost and the losing player is responsible for resetting * the board. */ while ( keep_turn || ( ! state_has_moves ( state , player ) ) ) { /* * This logic effectively handles a single command from * the current player. This involves reading the command * from the player's input pipe, interpreting and * executing the command, and returning the result of * the command to the player as appropriate. */ /* * Initialize the command buffer. */ //char* cmd = malloc ( sizeof ( char ) * CMD_BUFFER_SIZE ); char* cmd = NULL; size_t cmdlen = 0; /* * Read the next command from stdin. * * Might try and modify this to avoid the buffer. */ getline ( &cmd , &cmdlen , stdin ); /* * Extract the verb of the command, this is always the * first word of the command, in a HTTP-like format. */ char* verb = strtok ( cmd , " \n" ); /* * Use an if-else chain statement to select the proper * code to execute for each verb. */ if ( ! verb ) { /* * If the entry was just a newline, ignore it. */ } else if ( ! strcmp ( verb , VERB_TERM ) ) { /* * If the term signal is given, then jump to the * term_exit branch. */ goto term_exit; } else if ( ! strcmp ( verb , VERB_LOAD ) ) { cmd_load ( cmd , state ); } else if ( ! strcmp ( verb , VERB_SAVE ) ) { cmd_save ( cmd , state ); } else if ( ! strcmp ( verb , VERB_TGET ) ) { cmd_tget ( cmd , state ); } else if ( ! strcmp ( verb , VERB_TSET ) ) { cmd_tset ( cmd , state ); } else if ( ! strcmp ( verb , VERB_MOVE ) ) { /* * This code executes if the verb is the move command. * It then parses the remainder of the command to * determine its validity. If the command is well- * structured and the move is legal, the move is made * and the moved flag set to true. Otherwise, a 400 * BAD SYNTAX error will be returned. If the move * requested is well-formed but illegal, a 403 MOVE * FORBIDDEN error is returned. Assuming no errors * occur, a 200 OK message is returned. */ cmd_move ( cmd , state ); keep_turn = false; } else { /* * If we don't recognize the given verb, we do the * safe thing and return the verb nonexistant error. */ //puts ( "PCIP/1.0 404 NOTVERB" ); puts ( "NULL" ); } /* * Deallocate the command buffer. */ free ( cmd ); } /* * Increment the player indexer with wraparound. Set the * pipes pointing to the current player's input and * output. * * Trust me, I have a reason for putting it here. */ indexer = ( indexer + 1 ) % PLAYER_COUNT; player = players[indexer]; state->player = *player; /* * Announce the turn change. */ printf ( "PCIP/1.0 201 NEW TURN\n%c\n" , *player ); } /* * This is the interpreter loop's aforementioned implicit fall * through case for processing end of game conditions. * * Given the termination condition of the previous loop, the * player input and output pipes now point to the loosing * player, who is now responsible for resetting the game. */ } /* * If the term command is given, the program jumps to this point, * just before deallocation of top-level dynamic resources occurs. * Note that breaking out of a switch statement and a triple nested * do-while loop *is* a legitimate use of goto. */ term_exit: /* * Clean up. */ /* * Deallocate the game state. */ free_state ( state ); /* * If we got this far without an incident, the program should have * run successfully, so we return the corresponding status code. */ return EXIT_SUCCESS; };