int main() { int n; for(n=0;n<=MAX;n++) h_start(n); gbc_set_bk_color(0); sys_ginit(); srand(sys_get_tick_count()); while(kbhit()==0){ for(n=1;n<=MAX;n++){ if( tm[n]>tmb2[n] ){ h_parabola(n); }else if( tm[n]>0 ){ h_explosion(n); }else{ h_start(n); } } sys_sleep(30); } sys_set_color(0); return 0; }
void emu_run() { void *timer = sys_timer(); int delay; vid_begin(); lcd_begin(); for (;;) { cpu_emulate(2280); while (R_LY > 0 && R_LY < 144) emu_step(); vid_end(); rtc_tick(); sound_mix(); if (!pcm_submit()) { delay = framelen - sys_elapsed(timer); sys_sleep(delay); sys_elapsed(timer); } doevents(); vid_begin(); if (framecount) { if (!--framecount) die("finished\n"); } if (!(R_LCDC & 0x80)) cpu_emulate(32832); while (R_LY > 0) /* wait for next frame */ emu_step(); } }
/*FUNCTION*/ void hook_sleep(pExecuteObject pEo, long lSeconds ){ /*noverbatim CUT*/ sys_sleep(lSeconds); }
/* Time intervals throughout the code, unless otherwise noted, are specified in double-speed machine cycles (2MHz), each unit roughly corresponds to 0.477us. For CPU each cycle takes 2dsc (0.954us) in single-speed mode and 1dsc (0.477us) in double speed mode. Although hardware gbc LCDC would operate at completely different and fixed frequency, for emulation purposes timings for it are also specified in double-speed cycles. line = 228 dsc (109us) frame (154 lines) = 35112 dsc (16.7ms) of which visible lines x144 = 32832 dsc (15.66ms) vblank lines x10 = 2280 dsc (1.08ms) */ void emu_run() { void *timer = sys_timer(); int delay; vid_begin(); lcd_begin(); for (;;) { /* FRAME BEGIN */ /* FIXME: djudging by the time specified this was intended to emulate through vblank phase which is handled at the end of the loop. */ cpu_emulate(2280); /* FIXME: R_LY >= 0; comparsion to zero can also be removed altogether, R_LY is always 0 at this point */ while (R_LY > 0 && R_LY < 144) { /* Step through visible line scanning phase */ emu_step(); } /* VBLANK BEGIN */ vid_end(); rtc_tick(); sound_mix(); /* pcm_submit() introduces delay, if it fails we use sys_sleep() instead */ if (!pcm_submit()) { delay = framelen - sys_elapsed(timer); sys_sleep(delay); sys_elapsed(timer); } doevents(); vid_begin(); if (framecount) { if (!--framecount) die("finished\n"); } if (!(R_LCDC & 0x80)) { /* LCDC operation stopped */ /* FIXME: djudging by the time specified, this is intended to emulate through visible line scanning phase, even though we are already at vblank here */ cpu_emulate(32832); } while (R_LY > 0) { /* Step through vblank phase */ emu_step(); } /* VBLANK END */ /* FRAME END */ } }
int worker1_main(void* arg) { while(1) { while(!sys_lock(&printlock)); sys_sleep(1000); Serial_puts(Serial_module_debug, "Working on 1!\r\n"); sys_unlock(&printlock); } }
/*在新的进程里一直循环执行的函数,实现数据的接收和发送*/ static int echodemo_run() {/* int ret, send_len, recv_len = 0; char send_packet_buf[PACKET_BUF_SIZE]; char recv_packet_buf[PACKET_BUF_SIZE]; unsigned char send_flag , recv_flag; */ int count=0; while(1) { debug_printf("3G_GPRS %d\n",count); count++; sys_sleep(1000); /* if ((send_len =echodemo_build_send_packet(send_packet_buf, sizeof(send_packet_buf))) == 0) return SERIAL_STATUS_PKT_ERR; rtdb_set_data_value_by_name("test_parm", "send_buf", send_packet_buf); // debug_printf("!!!!!!!!!!!!!!!!!!!!\n"); ret = echodemo_transaction(send_packet_buf, send_len, recv_packet_buf, sizeof(recv_packet_buf), &recv_len, serial_id, 1000); if (ret == SERIAL_STATUS_OK) { echodemo_resp_packet_handle(recv_packet_buf, recv_len); } //rtdb_set_data_value_by_name("echodemo","status",&ret); sys_sleep(1000); rtdb_get_data_value_by_name("sys_set","send_pack_flag",&send_flag);//查询是否有数据发送 if(send_flag == 1) { rtdb_get_data_value_by_name("sys_set","send_pack",send_packet_buf);//复制数据 send_flag = 0; rtdb_set_data_value_by_name("sys_set","send_pack_flag",&send_flag); ret = send_pack(send_packet_buf);//数据发送 } ret = recv_pack(recv_packet_buf, sizeof(recv_packet_buf), &recv_len,100); if(SERIAL_STATUS_TIMEOUT != ret) rtdb_set_data_value_by_name("test_parm","ret",&ret); if(recv_len != 0) rtdb_set_data_value_by_name("test_parm","rec_len",&recv_len); serial_flush(serial_id, SERIAL_FLUSH_RX);//清空接收缓存 if(ret == SERIAL_STATUS_OK)//成功接收一帧消息 { rtdb_set_data_value_by_name("sys_set", "recv_pack", recv_packet_buf); recv_flag = 1; rtdb_set_data_value_by_name("sys_set", "recv_pack_flag", &recv_flag);//接收到一帧 debug_printf("recv 1 pack\n"); } memset(recv_packet_buf , 0 , PACKET_BUF_SIZE);*/ } return SERIAL_STATUS_OK; }
/// 等待所有任务处理完成 inline bool join_all(uint64_t milliseconds) { boost::timer bt; while ( unfinished() > 0 ) { if ((std::numeric_limits<uint64_t>::max)() != milliseconds && bt.elapsed() * CLOCKS_PER_SEC > milliseconds) return false; sys_sleep(1); } return true; }
/*** * * @TODO Could be handled by a lowlevel lookup-table, but this is probably a bit more readable * * Calling paramters: * param 1 : EBX * param 2 : ECX * param 3 : EDX * param 4 : ESI * param 5 : EDI * param 6 : time for using a structure instead of so many parameters... * * This parameter list is defined in the create_syscall_entryX macro's (service.h) * */ int service_interrupt (regs_t *r) { int retval = 0; int service = (r->eax & 0x0000FFFF); switch (service) { default : case SYS_NULL : retval = sys_null (); break; case SYS_CONSOLE : retval = sys_console (r->ebx, (console_t *)r->ecx, (char *)r->edx); break; case SYS_CONWRITE : retval = sys_conwrite ((char)r->ebx, r->ecx); break; case SYS_CONFLUSH : retval = sys_conflush (); break; case SYS_FORK : retval = sys_fork (r); break; case SYS_GETPID : retval = sys_getpid (); break; case SYS_GETPPID : retval = sys_getppid (); break; case SYS_SLEEP : retval = sys_sleep (r->ebx); break; case SYS_IDLE : retval = sys_idle (); break; case SYS_EXIT : retval = sys_exit (r->ebx); break; case SYS_EXECVE : retval = sys_execve (r, (char *)r->ebx, (char **)r->ecx, (char **)r->edx); break; } return retval; }
static int __ipc_connect_ip(u16 port, u32 addr, int quiet) { struct sockaddr_in sa; int fd = -1; while (1) { if ((fd = sock_socket(SOCK_STREAM, 0, 0)) < 0) return -1; MZERO(sa); sa.sin_family = AF_INET; sa.sin_addr.s_addr = addr; sa.sin_port = port; if (connect(fd, (struct sockaddr *)&sa, sizeof(sa)) < 0) { socket_close(fd); if (!quiet) rg_error(LERR, "failed ipc connect %m"); return -1; } /* Linux 2.4 kernel has a bug with localhost connections. * After the server calls listen(), then the client calls * connect() and returns with success immediately, before * the server calls accept()! * Therefore, a SYNC_STR command is used to make sure the connect * succeeded. * This has not been tested on Linux 2.2 whether it too has * this bug. It probably does not exist on VxWorks, since VxWorks * TCP/IP stack is completely different (its BSD based). */ if (!ipc_client_sync(fd)) break; socket_close(fd); if (!quiet) rg_error(LWARN, "failed ipc connect sync - retrying"); sys_sleep(1); } return fd; }
int pthread_cond_wait(pthread_cond_t * c, pthread_mutex_t * m) { // put ourselves in the queue _th_queue_t th; th.next = NULL; th.threadId = sys_thread_id(); anlock_lock(&c->fieldLock); if (c->last) { c->last->next = &th; c->last = &th; } else { c->last = (c->first = &th); } anlock_unlock(&c->fieldLock); pthread_mutex_unlock(m); while (1) { sys_sleep(UINT64_MAX); if (!_cond_contains(c)) break; } pthread_mutex_lock(m); return 0; }
static int ensure_adb_server_and_connect(void) { bool t_continue; t_continue = true; int t_socket; while(t_continue) { // Socket begins undefined t_socket = -1; // Acquire the global lock. sys_enter_lock(&s_global_lock); if (s_tracking_enabled) { // Make sure there is an adb server running sys_execute(s_adb_path, "start-server"); // Now attempt to connect t_socket = connect_to_adb_and_start_tracking(); } else t_continue = false; if (t_socket != -1) { s_tracking_socket = t_socket; t_continue = false; } sys_leave_lock(&s_global_lock); // If there is no socket yet, sleep for 5 seconds before trying again. if (t_continue && t_socket == -1) sys_sleep(5000); } return t_socket; }
/* * Main loop */ void game_run(void) { U32 tm, tmx; loaddata(); /* load cached data */ game_period = sysarg_args_period ? sysarg_args_period : GAME_PERIOD; tm = sys_gettime(); game_state = XRICK; /* main loop */ while (game_state != EXIT) { /* timer */ tmx = tm; tm = sys_gettime(); tmx = tm - tmx; if (tmx < game_period) sys_sleep(game_period - tmx); /* video */ /*DEBUG*//*game_rects=&draw_SCREENRECT;*//*DEBUG*/ sysvid_update(game_rects); draw_STATUSRECT.next = NULL; /* FIXME freerects should handle this */ /* sound */ /*snd_mix();*/ /* events */ if (game_waitevt) sysevt_wait(); /* wait for an event */ else sysevt_poll(); /* process events (non-blocking) */ /* frame */ frame(); } freedata(); /* free cached data */ }
vpicture_t* fbm_decoder_request_frame(Handle h) { u32 i; fbm_t* fbm; frame_info_t* frame_info; fbm = (fbm_t*)h; if(fbm == NULL) return NULL; frame_info = NULL; for(i=0; i<FBM_REQUEST_FRAME_WAIT_TIME/10; i++) { lock(fbm); frame_info = fbm_dequeue(&fbm->empty_queue); if(frame_info != NULL) { frame_info->status = FS_DECODER_USING; } unlock(fbm); if(frame_info != NULL) break; else sys_sleep(10); } if(frame_info != NULL) { return &frame_info->picture; } else return NULL; }
/// 任务处理函数(线程执行函数) void run() { while ( true ) { if ( m_taskQueue.empty() ) { sys_sleep(1); continue; } Task task; m_taskQueue.pop(task); if ( !task ) continue; task(); #if !defined(BEX_SUPPORT_CXX11) BOOST_INTERLOCKED_DECREMENT(&m_unfinished); #else --m_unfinished; #endif } }
void main() { setup(); PORTAbits.RA5 = 0; lcd_cursor(LCD_NOCURSOR); char timezone = EEPROM_READ(STORE_TZADDRESS); __delay_ms(20); sys_ready(); while(1) { if(PORTBbits.RB2 == 0) { timezone = EEPROM_READ(STORE_TZADDRESS); rtc_get_time_and_date(time,date); tz_get_date(screenbuf,date); lcd_write_at(0,0,screenbuf); tz_get_time(screenbuf,time,timezone); lcd_write_at(1,0,screenbuf); if(input_get_button_no_block() == b_menu) { menu_main(); } } else { lcd_blankscreen(); sys_sleep(); } } }
void ShowCredit() { uint8 *keyssnes = 0; int line=0,ypix=0,maxlines=26; char disptxt[100][256]={ "", "", " Thank you for using this Emulator! ", "", "", " Created by the Snes9x team.", "", " Port to libSDL by SiENcE", " crankgaming.blogspot.com", "", " regards to joyrider & g17", "", "", " Pandora port started by:", " skeezix", "", " Further work and maintenance:", " Ivanovic", "", " Special thanks to:", " EvilDragon (picklelauncher theme)", " john4p (cutting borders)", " Notaz (modified libSDL for Pandora)", " pickle (picklelauncher, Scale2x)", " WizardStan (smooth scaler)", "", }; do { SDL_Event event; SDL_PollEvent(&event); keyssnes = SDL_GetKeyState(NULL); //draw blue screen for(int y=0;y<240;y++){ for(int x=0;x<256*2;x+=2){ memset(GFX.Screen + 320*y*2+x,0x11,2); } } for(int i=0;i<=16;i++){ int j=i+line; if(j>=maxlines) j-=maxlines; S9xDisplayString (disptxt[j], GFX.Screen, 640,i*10+80-ypix); } ypix+=2; if(ypix==12) { line++; ypix=0; } if(line == maxlines) line = 0; S9xDeinitUpdate (320, 240); sys_sleep(3000); } while(keyssnes[sfc_key[B_1]] != SDL_PRESSED); return; }
void menu_loop(void) { bool8_32 exit_loop = false; char fname[256], ext[8]; char snapscreen_tmp[17120]; uint8 *keyssnes = 0; SaveSlotNum_old = -1; Scale_org = Scale; highres_current=Settings.SupportHiRes; capt_screenshot(); memcpy(snapscreen_tmp,snapscreen,17120); Scale = false; Settings.SupportHiRes=FALSE; S9xDeinitDisplay(); S9xInitDisplay(0, 0); menu_dispupdate(); sys_sleep(100000); SDL_Event event; do { while(SDL_PollEvent(&event)==1) { //PANDORA & DINGOO & WIN32 ----------------------------------------------------- keyssnes = SDL_GetKeyState(NULL); if(keyssnes[sfc_key[UP_1]] == SDL_PRESSED) cursor--; else if(keyssnes[sfc_key[DOWN_1]] == SDL_PRESSED) cursor++; else if( (keyssnes[sfc_key[A_1]] == SDL_PRESSED) || (keyssnes[sfc_key[LEFT_1]] == SDL_PRESSED) || (keyssnes[sfc_key[RIGHT_1]] == SDL_PRESSED) ) { switch(cursor) { case 2: //exit snes9x if (keyssnes[sfc_key[A_1]] == SDL_PRESSED) S9xExit(); break; case 3: //reset snes9x if ((keyssnes[sfc_key[A_1]] == SDL_PRESSED)) { //make sure the sram is stored before resetting the console //it should work without, but better safe than sorry... Memory.SaveSRAM (S9xGetFilename (".srm")); S9xReset(); exit_loop = TRUE; } break; case 4: if (keyssnes[sfc_key[A_1]] == SDL_PRESSED) ShowCredit(); break; case 6: //save state if (keyssnes[sfc_key[A_1]] == SDL_PRESSED) { memcpy(snapscreen,snapscreen_tmp,16050); show_screenshot(); strcpy(fname," Saving..."); S9xDisplayString (temp, GFX.Screen +320/*280*/, 640,80/*204*/); S9xDeinitUpdate (320, 240); sprintf(ext, ".s0%d", SaveSlotNum); strcpy(fname, S9xGetFilename (ext)); save_screenshot(fname); sprintf(ext, ".00%d", SaveSlotNum); strcpy(fname, S9xGetFilename (ext)); S9xFreezeGame (fname); sync(); exit_loop = TRUE; } break; case 7: //load state if (keyssnes[sfc_key[A_1]] == SDL_PRESSED) { sprintf(ext, ".00%d", SaveSlotNum); strcpy(fname, S9xGetFilename (ext)); S9xLoadSnapshot (fname); exit_loop = TRUE; } break; case 8: //select save state slot if (keyssnes[sfc_key[LEFT_1]] == SDL_PRESSED) { if ( SaveSlotNum == 0 ) SaveSlotNum = MAX_SAVE_SLOTS-1; // slots start at 0, so 10 slots means slot 0 to 9 else --SaveSlotNum; } else if (keyssnes[sfc_key[RIGHT_1]] == SDL_PRESSED) { if ( SaveSlotNum == MAX_SAVE_SLOTS-1 ) // slots start at 0, so 10 slots means slot 0 to 9 SaveSlotNum = 0; else ++SaveSlotNum; } break; case 10: // rotate through scalers if (keyssnes[sfc_key[RIGHT_1]] == SDL_PRESSED) { do { g_scale = (blit_scaler_e) ( ( g_scale + 1 ) % bs_max ); } while ( ( blit_scalers [ g_scale ].valid == bs_invalid ) || ( highres_current && !(blit_scalers [ g_scale ].support_hires) ) ); } else if (keyssnes[sfc_key[LEFT_1]] == SDL_PRESSED) { do { g_scale = (blit_scaler_e) ( g_scale - 1 ); if (g_scale < 1) g_scale = (blit_scaler_e)(bs_max-1); } while ( ( blit_scalers [ g_scale ].valid == bs_invalid ) || ( highres_current && !(blit_scalers [ g_scale ].support_hires) ) ); } // now force update the display, so that the new scaler is directly used (fixes some glitches) S9xDeinitDisplay(); S9xInitDisplay(0, 0); break; case 11: // set frameskip if (Settings.SkipFrames == AUTO_FRAMERATE) Settings.SkipFrames = 10; if (keyssnes[sfc_key[LEFT_1]] == SDL_PRESSED) Settings.SkipFrames--; else Settings.SkipFrames++; if(Settings.SkipFrames<=0 || Settings.SkipFrames==10) Settings.SkipFrames = AUTO_FRAMERATE; else if (Settings.SkipFrames>=11) Settings.SkipFrames = 1; break; case 12: // set vsync if (g_vsync) g_vsync = 0; else g_vsync = 1; break; case 13: // set display fps Settings.DisplayFrameRate = !Settings.DisplayFrameRate; break; case 14: // set transparency Settings.Transparency = !Settings.Transparency; break; case 15: // cut lines from top if (keyssnes[sfc_key[RIGHT_1]] == SDL_PRESSED) cut_top++; else if (keyssnes[sfc_key[LEFT_1]] == SDL_PRESSED && cut_top>0) cut_top--; // now force update the display, so that the new scaler is directly used (fixes some glitches) S9xDeinitDisplay(); S9xInitDisplay(0, 0); break; case 16: // cut lines from bottom if (keyssnes[sfc_key[RIGHT_1]] == SDL_PRESSED) cut_bottom++; else if (keyssnes[sfc_key[LEFT_1]] == SDL_PRESSED && cut_bottom>0) cut_bottom--; S9xDeinitDisplay(); S9xInitDisplay(0, 0); break; case 17: // cut from the left if (keyssnes[sfc_key[RIGHT_1]] == SDL_PRESSED) cut_left++; else if (keyssnes[sfc_key[LEFT_1]] == SDL_PRESSED && cut_left>0) cut_left--; S9xDeinitDisplay(); S9xInitDisplay(0, 0); break; case 18: // cut from the right if (keyssnes[sfc_key[RIGHT_1]] == SDL_PRESSED) cut_right++; else if (keyssnes[sfc_key[LEFT_1]] == SDL_PRESSED && cut_right>0) cut_right--; S9xDeinitDisplay(); S9xInitDisplay(0, 0); break; case 20: //offer an option to change to alternative sample decoding //cf. http://www.gp32x.com/board/index.php?/topic/55378-snes9x4d4p-another-new-build-now-with-hi-res-and-new-rom-picker/page__view__findpost__p__958860 if (Settings.AltSampleDecode) Settings.AltSampleDecode = 0; else Settings.AltSampleDecode = 1; break; } } if(cursor==1) cursor=20; else if(cursor==21) cursor=2; if(cursor==5 || cursor==9 || cursor==19) { if(keyssnes[sfc_key[UP_1]] == SDL_PRESSED) cursor--; else if(keyssnes[sfc_key[DOWN_1]] == SDL_PRESSED) cursor++; } menu_dispupdate(); sys_sleep(1000); break; } } while( exit_loop!=TRUE && keyssnes[sfc_key[B_1]] != SDL_PRESSED ); Scale = Scale_org; Settings.SupportHiRes=highres_current; S9xDeinitDisplay(); S9xInitDisplay(0, 0); }
char* menu_romselector() { char *rom_filename = NULL; int romcount = 0; bool8_32 exit_loop = false; uint8 *keyssnes = 0; //Read ROM-Directory romcount = FileDir("./roms", "sfc,smc"); Scale_org = Scale; highres_current=Settings.SupportHiRes; Scale = false; Settings.SupportHiRes=FALSE; S9xDeinitDisplay(); S9xInitDisplay(0, 0); loadmenu_dispupdate(romcount); sys_sleep(100000); SDL_Event event; do { loadmenu_dispupdate(romcount); sys_sleep(100); while(SDL_PollEvent(&event)==1) { //PANDORA & DINGOO & WIN32 ----------------------------------------------------- keyssnes = SDL_GetKeyState(NULL); switch(event.type) { case SDL_KEYDOWN: keyssnes = SDL_GetKeyState(NULL); //UP if(keyssnes[sfc_key[UP_1]] == SDL_PRESSED) loadcursor--; //DOWN else if(keyssnes[sfc_key[DOWN_1]] == SDL_PRESSED) loadcursor++; // //LS // else if(keyssnes[sfc_key[L_1]] == SDL_PRESSED) // loadcursor=loadcursor-10; // //RS // else if(keyssnes[sfc_key[R_1]] == SDL_PRESSED) // loadcursor=loadcursor+10; //QUIT Emulator : press ESCAPE KEY else if (keyssnes[sfc_key[SELECT_1]] == SDL_PRESSED) S9xExit(); else if( (keyssnes[sfc_key[B_1]] == SDL_PRESSED) ) { switch(loadcursor) { default: if ((keyssnes[sfc_key[B_1]] == SDL_PRESSED)) { if ((loadcursor>=0) && (loadcursor<(romcount))) { rom_filename=namelist[loadcursor]->d_name; exit_loop = TRUE; } } break; } } break; } if(loadcursor==-1) { loadcursor=romcount-1; } else if(loadcursor==romcount) { loadcursor=0; } break; } } while( exit_loop!=TRUE && keyssnes[sfc_key[B_1]] != SDL_PRESSED ); // TODO: ///free(). namelist Scale = Scale_org; Settings.SupportHiRes=highres_current; S9xDeinitDisplay(); S9xInitDisplay(0, 0); return (rom_filename); }
/* * Audio joining function, same as the routine above but a little bit * splited. * * actually into three parts: * o. start. (start the routine and join one file). * o. push. (add another file, somehow there's no 'pop' function :-) ). * o. end. (finish). */ int audiojoining_start(const string infile, string outfile, unsigned long eid, unsigned int bsize, int* cancelop, int* pauseop, double spos, double epos, audioconvert_file_pfunc cfunc) { int format_blocksize; unsigned int current_size; /* current file size */ unsigned int processed_size = 0; /* bytes encoded */ unsigned int rsize; int readreturn; void* ehandle; /* equalizer handle */ if(joining_started)return 0; /* already started */ /* set flag pointers */ joining_data.cancelop = cancelop; joining_data.pauseop = pauseop; joining_data.cfunc = cfunc; /* input selection */ joining_data.converter_playerhandle = audio_input_selectinput(infile); /* can we read the input file? */ if(joining_data.converter_playerhandle == (unsigned long)-1)return 0; audio_input_plugin_initialize(joining_data.converter_playerhandle); /* first, we gotta get some information */ if(!audio_input_plugin_loadfile(joining_data.converter_playerhandle, infile, &joining_data.converter_streamhandle))return 0; /* calculate padding (we need to allocate a buffer to store all samples, not halves) */ audio_input_plugin_getformat(joining_data.converter_playerhandle, joining_data.converter_streamhandle, &joining_data.format_freq, &joining_data.format_bps, &joining_data.format_chan); /* calculate block size for padding */ format_blocksize = (joining_data.format_bps / 8) * joining_data.format_chan; /* allocate the buffer */ if(bsize % format_blocksize) /* don't need to add padding */ joining_data.buffersize = bsize; else joining_data.buffersize = bsize + (format_blocksize - (bsize % format_blocksize)); joining_data.buffer = (char*) sys_mem_alloc(joining_data.buffersize); /* allright? */ if(!joining_data.buffer) { audio_input_plugin_unloadfile(joining_data.converter_playerhandle, joining_data.converter_streamhandle); return 0; } current_size = audio_input_plugin_getduration_ms(joining_data.converter_playerhandle, joining_data.converter_streamhandle) * /* bytes per ms */ ((joining_data.format_freq / 1000) * (joining_data.format_bps / 8) * joining_data.format_chan); audio_input_plugin_setposition(joining_data.converter_playerhandle, joining_data.converter_streamhandle, spos); current_size = (unsigned int)((((double)current_size) * epos) - (((double)current_size) * spos)); /* we need an encoder too */ if(!encoder_initialize()) { sys_mem_free(joining_data.buffer); audio_input_plugin_unloadfile(joining_data.converter_playerhandle, joining_data.converter_streamhandle); return 0; } /* which encoder? */ joining_data.encoder_playerhandle = eid; encoder_plugin_initialize(joining_data.encoder_playerhandle); /* create a file */ joining_data.encoder_streamhandle = encoder_plugin_file_create(joining_data.encoder_playerhandle, outfile); if(joining_data.encoder_streamhandle == -1) { sys_mem_free(joining_data.buffer); audio_input_plugin_unloadfile(joining_data.converter_playerhandle, joining_data.converter_streamhandle); encoder_uninitialize(); return 1; } /* we gotta clear out the equalizer history buffer */ ehandle = equalize_buffer_variable_init(&settings.conversion.equalizer_bands, joining_data.format_chan, joining_data.format_freq); /* start conversion */ for(;;) { /* first of all, we gotta check those pause/cancel flags */ if(*cancelop)goto point_end; if(*pauseop) goto point_continue; /* set buffer size to be read */ if(((int)current_size) - (int)(processed_size) > (int)joining_data.buffersize) rsize = joining_data.buffersize; else if(((int)current_size) - (int)(processed_size) > 0) rsize = (((int)current_size) - (int)(processed_size)); else rsize = 0; /* read data, on eof, error; 'read data' returns zero . and we can also determine it using 'rsize'. */ readreturn = audio_input_plugin_readdata(joining_data.converter_playerhandle, joining_data.converter_streamhandle, (unsigned long*)&rsize, joining_data.buffer); /* end of the file? */ if(!readreturn)goto point_end; /* set block volume, gain */ if(settings.conversion.volume < 0.98f) { convert_setblock_volume((fennec_sample*) joining_data.buffer, joining_data.format_freq, joining_data.format_chan, joining_data.format_bps, rsize, (float)settings.conversion.volume); }else if(settings.conversion.volume_gain > 0.02f){ convert_setblock_volume((fennec_sample*) joining_data.buffer, joining_data.format_freq, joining_data.format_chan, joining_data.format_bps, rsize, (float)settings.conversion.volume + 1.0f); } /* equalize block */ if(settings.joining.use_equalizer) { equalize_buffer_variable(joining_data.buffer, 0, joining_data.format_chan, joining_data.format_freq, joining_data.format_bps, rsize, ehandle); } /* copy data to the output file */ encoder_plugin_file_write(joining_data.encoder_playerhandle, joining_data.encoder_streamhandle, joining_data.buffer, joining_data.format_freq, joining_data.format_bps, joining_data.format_chan, rsize); /* call set position to dispaly some info */ processed_size += rsize; if(cfunc && current_size)cfunc((double)processed_size / (double)current_size); /* sleep awhile |-) */ sys_pass(); /* now check for eof */ if(rsize < joining_data.buffersize)goto point_end; /* continue if paused */ goto point_continue_fast; point_continue: sys_sleep(100); point_continue_fast:; } point_end: /* finish! */ if(cfunc)cfunc(1.0f); audio_input_plugin_unloadfile(joining_data.converter_playerhandle, joining_data.converter_streamhandle); joining_started = 1; return 1; }
/* * This function simply converts a file ('infile') to another file ('outfile'). * * read the input stream from 'audio' interface and send it to 'encoder-file' * interface. * * eid - encoder id. * bsize - buffer size (in bytes, will be padded if necessary). * cancelop - set to 1 to stop the operation and return 1 if it was sucessful. * pauseop - set to 1 to pause the operation (till you set it back to 0). * (uses the same system in 'internal output') * trans - transcoder settings (new!). * * use a thread to call this function, or just put this into a thread. */ int audioconvert_convertfile_ex(const string infile, string outfile, unsigned long eid, unsigned int bsize, int* cancelop, int* pauseop, audioconvert_file_pfunc cfunc, transcoder_settings *trans) { unsigned long converter_playerhandle; unsigned long converter_streamhandle; unsigned long encoder_playerhandle = eid; unsigned long encoder_streamhandle; unsigned long converter_format_freq; /* frequency */ unsigned long converter_format_bps; /* bits per sample, not bits per second */ unsigned long converter_format_chan; /* channels */ unsigned long converter_format_blocksize; /* (bits per sample / 8) * channels */ unsigned int rbuffsize; /* real buffer size (after padding) */ char* cbuffer; /* buffer (current buffer?) */ unsigned int rsize; /* return size */ int readreturn; unsigned long ssize = 0; /* data size (sum size?) */ unsigned long csize = 0; /* bytes converted (current size) */ void* ehandle; /* equalizer handle */ /* what kinda file we got?? */ converter_playerhandle = audio_input_selectinput(infile); if(converter_playerhandle == -1)return -1; /* not supported, -1? (maybe.. 'invalid player id') :) */ /* we've selected a player (decoder plugin), so initialize it first remember, we don't need to uninitialize it, cuz the 'internal input' would do it for us :) */ audio_input_plugin_initialize(converter_playerhandle); /* load the input file, anyhow, fennec ain't just designed to listen something and stop that, it can gather input from more than one streams at once (?), so we gotta use a handle to identify the file <- it can be any value between 0 and infinity. (ok, 0xffffffff... :) ). */ if(!audio_input_plugin_loadfile(converter_playerhandle, infile, &converter_streamhandle))return -2; /* get the ....... format first (we'll need some padding) */ audio_input_plugin_getformat(converter_playerhandle, converter_streamhandle, &converter_format_freq, &converter_format_bps, &converter_format_chan); /* calculate block size for padding */ converter_format_blocksize = (converter_format_bps / 8) * converter_format_chan; /* allocate the buffer */ if(bsize % converter_format_blocksize) /* add padding if necessary */ rbuffsize = bsize + (converter_format_blocksize - (bsize % converter_format_blocksize)); else rbuffsize = bsize; cbuffer = sys_mem_alloc(rbuffsize); if(!cbuffer) { /* not enough memory!, turn off the computer and add another core (>1MB) and restart the routine. :) 4 nw v unld d fy1 */ audio_input_plugin_unloadfile(converter_playerhandle, converter_streamhandle); return -3; } /* calc the raw size of the input stream (stream?... return -1 or 0?) we don't need a real 'ssize' value, it's just a progress notification. */ ssize = audio_input_plugin_getduration_ms(converter_playerhandle, converter_streamhandle) * /* bytes per ms */ ((converter_format_freq / 1000) * (converter_format_bps / 8) * converter_format_chan); /* we need an encoder too */ if(!encoder_initialize()) { sys_mem_free(cbuffer); audio_input_plugin_unloadfile(converter_playerhandle, converter_streamhandle); return -4; } encoder_plugin_initialize(encoder_playerhandle); /* create a file */ encoder_streamhandle = encoder_plugin_file_create(encoder_playerhandle, outfile); if(converter_streamhandle == -1) { sys_mem_free(cbuffer); audio_input_plugin_unloadfile(converter_playerhandle, converter_streamhandle); encoder_uninitialize(); return -5; } /* initialize the equalizer, all we need is an array of bands */ ehandle = equalize_buffer_variable_init(&trans->eq.eq, converter_format_chan, converter_format_freq); /* well... hummm..... start conversion */ for(;;) { /* first of all, we gotta check those pause/cancel flags */ if(*cancelop)goto point_end; if(*pauseop) goto point_continue; /* 'rsize' actually != just 'return size' */ rsize = rbuffsize; /* read data, on eof, error; 'read data' returns zero . and we can also determine it using 'rsize'. */ readreturn = audio_input_plugin_readdata(converter_playerhandle, converter_streamhandle, (unsigned long*)&rsize, cbuffer); if(!readreturn)goto point_end; /* set volume/gain */ if(trans->volume.enable_vol) { if(trans->volume.vol < 0.98f) { convert_setblock_volume((fennec_sample*) cbuffer, converter_format_freq, converter_format_chan, converter_format_bps, rsize, (float)trans->volume.vol); }else if(trans->volume.gain > 0.02f){ convert_setblock_volume((fennec_sample*)cbuffer, converter_format_freq, converter_format_chan, converter_format_bps, rsize, (float)(trans->volume.gain * 4.0) + 1.0f); } } /* set equalizer */ if(trans->eq.enable_eq) { equalize_buffer_variable(cbuffer, 0, converter_format_chan, converter_format_freq, converter_format_bps, rsize, ehandle); } sys_sleep(2); /* copy data to the output file */ encoder_plugin_file_write(encoder_playerhandle, encoder_streamhandle, cbuffer, converter_format_freq, converter_format_bps, converter_format_chan, rsize); /* call set position to dispaly some info */ csize += rsize; if(cfunc && ssize)cfunc((double)csize / (double)ssize); sys_pass(); /* now check for eof */ if(rsize < rbuffsize)goto point_end; /* continue if paused */ goto point_continue_fast; point_continue: sys_sleep(100); point_continue_fast:; } point_end: /* finish! */ if(cfunc)cfunc(1.0f); /* you should clean your ... by yourself :o) */ sys_mem_free(cbuffer); audio_input_plugin_unloadfile(converter_playerhandle, converter_streamhandle); encoder_plugin_file_close(encoder_playerhandle, encoder_streamhandle); equalize_buffer_variable_uninit(ehandle); /* encoder_plugin_uninitialize(encoder_playerhandle); encoder_uninitialize(); */ return 0; }
/* * Main loop */ void game_run(void) { U32 tm; #if 0 U32 tmx; #endif loaddata(); /* load cached data */ game_period = sysarg_args_period ? sysarg_args_period : GAME_PERIOD; tm = sys_gettime(); game_state = XRICK; /* main loop */ while (game_state != EXIT) { #if 0 /* This code doesn't make any sense to me at all. It waits until the desired amount of time has passed and then takes the time at which it started waiting (which is not synchronous with anything) as the reference point for the next frame. This sort of works if your system takes very little time to compute the frame, but fails horribly otherwise, e.g. if you use blocking I/O (sound, vblank). */ tmx = tm; tm = sys_gettime(); tmx = tm - tmx; if (tmx < game_period) sys_sleep(game_period - tmx); #endif /* video */ /*DEBUG*//*game_rects=&draw_SCREENRECT;*//*DEBUG*/ sysvid_update(game_rects); draw_STATUSRECT.next = NULL; /* FIXME freerects should handle this */ /* timer */ /* Reset the timing if it's way out of line, such as when the game thread has been paused. */ if (sys_gettime() - tm > game_period * 10) tm = sys_gettime() - game_period / 2; /* Update sound while waiting. */ do { syssnd_callback(); } while (sys_gettime() - tm < game_period / 2); /* Use the time at which the frame should have been complete as reference for the next frame. This makes it possible to "catch up" if a frame has taken longer for some reason. */ tm = tm + game_period / 2; /* sound */ /*snd_mix();*/ /* events */ if (game_waitevt) sysevt_wait(); /* wait for an event */ else sysevt_poll(); /* process events (non-blocking) */ /* frame */ frame(); } freedata(); /* free cached data */ }
int write_ogg_tag(const string fname, struct fennec_audiotag *wtag) { vcedit_state *state; vorbis_comment *vc; param_t *param; FILE *tfile; FILE *of; string outname; struct fennec_audiotag_item *ct; if(!fname || !wtag)return -3; setlocale(LC_ALL, ""); /* initialize the cmdline interface */ param = new_param(); tfile = _wfsopen(fname, uni("r+b"), _SH_DENYRW); if(!tfile) { MessageBox(0, uni("Access denied, please stop playback and try again (you don't need to close this window)."), uni("Tag Editing"), MB_ICONINFORMATION); return -1; } state = vcedit_new_state(); if(vcedit_open(state, tfile) < 0) { fclose(tfile); free_param(param); vcedit_clear(state); return -2; } vc = vcedit_comments(state); ct = &wtag->tag_title; if(ct->tsize)local_addcomment(vc, "TITLE", ct->tdata); else local_addcomment(vc, "TITLE", uni("") ); ct = &wtag->tag_album; if(ct->tsize)local_addcomment(vc, "ALBUM", ct->tdata); else local_addcomment(vc, "ALBUM", uni("") ); ct = &wtag->tag_artist; if(ct->tsize)local_addcomment(vc, "ARTIST", ct->tdata); else local_addcomment(vc, "ARTIST", uni("") ); ct = &wtag->tag_origartist; if(ct->tsize)local_addcomment(vc, "ORIGINALARTIST", ct->tdata); else local_addcomment(vc, "ORIGINALARTIST", uni("") ); ct = &wtag->tag_composer; if(ct->tsize)local_addcomment(vc, "COMPOSER", ct->tdata); else local_addcomment(vc, "COMPOSER", uni("") ); ct = &wtag->tag_lyricist; if(ct->tsize)local_addcomment(vc, "LYRICIST", ct->tdata); else local_addcomment(vc, "LYRICIST", uni("") ); ct = &wtag->tag_band; if(ct->tsize)local_addcomment(vc, "BANDNAME", ct->tdata); else local_addcomment(vc, "BANDNAME", uni("") ); ct = &wtag->tag_copyright; if(ct->tsize)local_addcomment(vc, "COPYRIGHT", ct->tdata); else local_addcomment(vc, "COPYRIGHT", uni("") ); ct = &wtag->tag_publish; if(ct->tsize)local_addcomment(vc, "PUBLISHER", ct->tdata); else local_addcomment(vc, "PUBLISHER", uni("") ); ct = &wtag->tag_encodedby; if(ct->tsize)local_addcomment(vc, "ENCODEDBY", ct->tdata); else local_addcomment(vc, "ENCODEDBY", uni("") ); ct = &wtag->tag_genre; if(ct->tsize)local_addcomment(vc, "GENRE", ct->tdata); else local_addcomment(vc, "GENRE", uni("") ); ct = &wtag->tag_year; if(ct->tsize)local_addcomment(vc, "YEAR", ct->tdata); else local_addcomment(vc, "YEAR", uni("") ); ct = &wtag->tag_url; if(ct->tsize)local_addcomment(vc, "URL", ct->tdata); else local_addcomment(vc, "URL", uni("") ); ct = &wtag->tag_offiartisturl; if(ct->tsize)local_addcomment(vc, "OFFICIALARTISTURL", ct->tdata); else local_addcomment(vc, "OFFICIALARTISTURL", uni("") ); ct = &wtag->tag_comments; if(ct->tsize)local_addcomment(vc, "COMMENT", ct->tdata); else local_addcomment(vc, "COMMENT", uni("") ); ct = &wtag->tag_lyric; if(ct->tsize)local_addcomment(vc, "LYRIC", ct->tdata); else local_addcomment(vc, "LYRIC", uni("") ); ct = &wtag->tag_bpm; if(ct->tsize)local_addcomment(vc, "BPM", ct->tdata); else local_addcomment(vc, "BPM", uni("") ); ct = &wtag->tag_tracknum; if(ct->tsize)local_addcomment(vc, "TRACKNUMBER", ct->tdata); else local_addcomment(vc, "TRACKNUMBER", uni("") ); outname = (string) malloc(str_size(fname) + (5 * sizeof(letter))); str_cpy(outname, fname); str_cat(outname, uni(".tmp")); of = _wfopen(outname, uni("wb")); if(vcedit_write(state, of) < 0) { fclose(of); fclose(tfile); free_param(param); vcedit_clear(state); free(outname); return 1; } fclose(of); /* done */ vcedit_clear(state); fclose(tfile); free_param(param); _wremove(fname); sys_sleep(0); _wrename(outname, fname); free(outname); return 0; }
/*----------------------------------------------------------------------------*/ void sys_adc_init() { GPIO_InitTypeDef GPIO_InitStructure; ADC_InitTypeDef ADC_InitStructure; DMA_InitTypeDef DMA_InitStructure; /* Enable DMA1 clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); #define DIV RCC_PCLK2_Div2 //#define DIV RCC_PCLK2_Div4 //#define DIV RCC_PCLK2_Div6 //#define DIV RCC_PCLK2_Div8 RCC_ADCCLKConfig(DIV); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); /* GPIO */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; //GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIO_InitStructure); /* DMA1 channel1 configuration ----------------------------------------------*/ DMA_DeInit(DMA1_Channel1); DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address; DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&adc_buffer; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; DMA_InitStructure.DMA_BufferSize = ADC_BUFFER_SIZE; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; DMA_InitStructure.DMA_Priority = DMA_Priority_High; DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; DMA_Init(DMA1_Channel1, &DMA_InitStructure); /* Enable DMA1 channel1 */ DMA_Cmd(DMA1_Channel1, ENABLE); /* ADC1 configuration ------------------------------------------------------*/ ADC_Cmd(ADC1, DISABLE); ADC_DeInit(ADC1); ADC_StructInit(&ADC_InitStructure); ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; ADC_InitStructure.ADC_ScanConvMode = ENABLE; ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel = 1; ADC_Init(ADC1, &ADC_InitStructure); /* ADC1 regular channel12 configuration */ //#define SAMPLE_TIME ADC_SampleTime_1Cycles5 //#define SAMPLE_TIME ADC_SampleTime_7Cycles5 //#define SAMPLE_TIME ADC_SampleTime_13Cycles5 #define SAMPLE_TIME ADC_SampleTime_28Cycles5 //#define SAMPLE_TIME ADC_SampleTime_41Cycles5 //#define SAMPLE_TIME ADC_SampleTime_55Cycles5 //#define SAMPLE_TIME ADC_SampleTime_71Cycles5 //#define SAMPLE_TIME ADC_SampleTime_239Cycles5 ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 1, SAMPLE_TIME); /* Enable ADC1 DMA */ ADC_DMACmd(ADC1, ENABLE); /* Enable ADC1 */ ADC_Cmd(ADC1, ENABLE); sys_sleep(2); /* Enable ADC1 reset calibration register */ ADC_ResetCalibration(ADC1); /* Check the end of ADC1 reset calibration register */ while(ADC_GetResetCalibrationStatus(ADC1)); /* Start ADC1 calibration */ ADC_StartCalibration(ADC1); /* Check the end of ADC1 calibration */ while(ADC_GetCalibrationStatus(ADC1)); /* Start ADC1 Software Conversion */ ADC_SoftwareStartConvCmd(ADC1, ENABLE); #ifdef USE_CONSOLE console_cmd_init(&adc_console1); adc_console1.cmd = "adc"; adc_console1.help = "adc - ADC read ADC DMA statistic"; adc_console1.handler = adc_cmd1; console_add_cmd(&adc_console1); #endif //USE_CONSOLE }
int audiojoining_push(int hjoin /* not used */, const string fpath, double spos, double epos) { unsigned int current_size; unsigned int processed_size = 0; void* ehandle; /* equalizer handle */ unsigned int rsize; int readreturn; unsigned long tmp_freq, tmp_chan, tmp_bps; if(!joining_started)return 0; /* select input */ joining_data.converter_playerhandle = audio_input_selectinput(fpath); /* can we read the file? */ if(joining_data.converter_playerhandle == -1)return 0; /* start reading */ audio_input_plugin_loadfile(joining_data.converter_playerhandle, fpath, &joining_data.converter_streamhandle); audio_input_plugin_getformat(joining_data.converter_playerhandle, joining_data.converter_streamhandle, &tmp_freq, &tmp_bps, &tmp_chan); /* check formats */ if(joining_data.format_bps != tmp_bps || joining_data.format_chan != tmp_chan || joining_data.format_freq != tmp_freq) { audio_input_plugin_unloadfile(joining_data.converter_playerhandle, joining_data.converter_streamhandle); return 0; } current_size = audio_input_plugin_getduration_ms(joining_data.converter_playerhandle, joining_data.converter_streamhandle) * /* bytes per ms */ ((joining_data.format_freq / 1000) * (joining_data.format_bps / 8) * joining_data.format_chan); /* set epos and spos */ audio_input_plugin_setposition(joining_data.converter_playerhandle, joining_data.converter_streamhandle, spos); current_size = (unsigned int)((((double)current_size) * epos) - (((double)current_size) * spos)); ehandle = equalize_buffer_variable_init(&settings.conversion.equalizer_bands, joining_data.format_chan, joining_data.format_freq); /* start conversion */ for(;;) { /* first of all, we gotta check those pause/cancel flags */ if(*joining_data.cancelop)goto point_end; if(*joining_data.pauseop) goto point_continue; /* set buffer size to be read */ if(((int)current_size) - (int)(processed_size) > (int)joining_data.buffersize) rsize = joining_data.buffersize; else if(((int)current_size) - (int)(processed_size) > 0) rsize = (((int)current_size) - (int)(processed_size)); else rsize = 0; /* read data, on eof, an error; 'read data' returns zero . and we can also determine it using 'rsize'. */ readreturn = audio_input_plugin_readdata(joining_data.converter_playerhandle, joining_data.converter_streamhandle, (unsigned long*)&rsize, joining_data.buffer); /* end of the file? */ if(!readreturn)goto point_end; /* set block volume, gain */ if(settings.conversion.volume < 0.98f) { convert_setblock_volume((fennec_sample*) joining_data.buffer, joining_data.format_freq, joining_data.format_chan, joining_data.format_bps, rsize, (float)settings.conversion.volume); }else if(settings.conversion.volume_gain > 0.02f){ convert_setblock_volume((fennec_sample*) joining_data.buffer, joining_data.format_freq, joining_data.format_chan, joining_data.format_bps, rsize, (float)settings.conversion.volume + 1.0f); } /* equalize block */ if(settings.joining.use_equalizer) { equalize_buffer_variable(joining_data.buffer, 0, joining_data.format_chan, joining_data.format_freq, joining_data.format_bps, rsize, &ehandle); } /* copy data to the output file */ encoder_plugin_file_write(joining_data.encoder_playerhandle, joining_data.encoder_streamhandle, joining_data.buffer, joining_data.format_freq, joining_data.format_bps, joining_data.format_chan, rsize); /* call set position to dispaly some info */ processed_size += rsize; if(joining_data.cfunc && current_size)joining_data.cfunc((double)processed_size / (double)current_size); /* sleep awhile |-) */ sys_pass(); /* now check for eof */ if(rsize < joining_data.buffersize)goto point_end; /* continue if paused */ goto point_continue_fast; point_continue: sys_sleep(100); point_continue_fast:; } point_end: /* finish! */ if(joining_data.cfunc)joining_data.cfunc(1.0f); audio_input_plugin_unloadfile(joining_data.converter_playerhandle, joining_data.converter_streamhandle); return 1; }
int sleep(unsigned int time) { return sys_sleep(time); }
/* * Map introduction * * ASM: 1948 * * return: SCREEN_RUNNING, SCREEN_DONE, SCREEN_EXIT */ U8 screen_introMap(void) { //char tutu[50]; //sprintf(tutu,"imap ctrl=%d seq=%d, %d %d ",control_status,seq, 0 , SCREEN_TIMEOUT); //slPrint(tutu,slLocate(3,14)); switch (seq) { case 0: // slPrint("befor sysvid_clear",slLocate(3,15)); sysvid_clear(); // slPrint("after sysvid_clear",slLocate(3,15)); #ifdef GFXPC draw_tilesBank = 1; draw_filter = 0xAAAA; #endif #ifdef GFXST draw_tilesBank = 0; #endif draw_tllst = screen_imaptext[game_map]; draw_setfb(32, 0); draw_tilesSubList(); draw_setfb(32, 96); #ifdef GFXPC draw_filter = 0x5555; #endif draw_tilesList(); game_rects = NULL; #ifdef GFXPC draw_filter = 0xFFFF; #endif // slPrint("befor init ",slLocate(3,15)); init(); // slPrint("after init ",slLocate(3,15)); nextstep(); // slPrint("after nextstep ",slLocate(3,15)); drawcenter(); // slPrint("after drawcenter ",slLocate(3,15)); drawtb(); // slPrint("after drawtb ",slLocate(3,15)); drawlr(); // slPrint("after drawlr ",slLocate(3,15)); drawsprite(); // slPrint("after drawsprite ",slLocate(3,15)); control_last = 0; game_rects = &draw_SCREENRECT; #ifdef ENABLE_SOUND game_setmusic(map_maps[game_map].tune, 1); #endif // slPrint("after game_setmusic ",slLocate(3,15)); seq = 1; break; case 1: /* top and bottom borders */ drawtb(); game_rects = &anim_rect; seq = 2; break; case 2: /* background and sprite */ anim(); drawcenter(); drawsprite(); game_rects = &anim_rect; seq = 3; break; case 3: /* all borders */ drawtb(); drawlr(); game_rects = &anim_rect; seq = 1; break; case 4: /* wait for key release */ if (!(control_status & CONTROL_FIRE)) seq = 5; else { //control_status =0; sys_sleep(50); /* .5s */ } break; } if (control_status & CONTROL_FIRE) { /* end as soon as key pressed */ seq = 4; } if (control_status & CONTROL_EXIT) /* check for exit request */ return SCREEN_EXIT; if (seq == 5) { /* end as soon as key pressed */ sysvid_clear(); seq = 0; return SCREEN_DONE; } else return SCREEN_RUNNING; }
int sleep(u32 milli) { return sys_sleep(milli); }
int main(void){ uint16_t curMotorL = 0x00; uint16_t curMotorR = 0x00; uint8_t speedMotorL = 0x00; uint8_t speedMotorR = 0x00; // initiate system sys_init(); // main loop while(1){ // suspend system sys_sleep(); // check for changed motor values if( ctrl_flag_motorL ){ motor_set_speed( MOTOR_ADDR_L, control_getMotorSpeed(MOTOR_ADDR_L), control_getMotorCommand(MOTOR_ADDR_L)); } if( ctrl_flag_motorR ){ motor_set_speed( MOTOR_ADDR_R, control_getMotorSpeed(MOTOR_ADDR_R), control_getMotorCommand(MOTOR_ADDR_R)); } // check for changed robot id if( ctrl_flag_id ){ sys_ee_set_robotID( control_getRobotID() ); #ifdef CFG_EXTERNAL_MARKER marker_set_id(sys_robotID); #endif } // read motor currents and speeds #if !defined(CFG_CODE_LEVEL_MIN) curMotorL = monitor_read_current(MONITOR_ADDR_1, MONITOR_I1); curMotorR = monitor_read_current(MONITOR_ADDR_1, MONITOR_I2); #endif speedMotorL = control_getMotorSpeed(MOTOR_ADDR_L); speedMotorR = control_getMotorSpeed(MOTOR_ADDR_R); // adjust motor speed // tries to decrease speed of faster motor, // or if that fails because motor is already speed minimum // increases the speed of the slower motor. // if( curMotorL > curMotorR ){ // // if( speedMotorL > MOTOR_SPEED_MIN ){ // motor_decrease_speed(MOTOR_ADDR_L, 1); // } else if( speedMotorR < MOTOR_SPEED_MAX ){ // motor_increase_speed(MOTOR_ADDR_R, 1); // } // // } else if( curMotorR > curMotorL ){ // // if( speedMotorR > MOTOR_SPEED_MIN ){ // motor_decrease_speed(MOTOR_ADDR_R, 1); // } else if( speedMotorL < MOTOR_SPEED_MAX ){ // motor_increase_speed(MOTOR_ADDR_L, 1); // } // // } #ifndef CFG_CODE_LEVEL_MIN // process debugging module debug_process(); #endif } }
LRESULT CALLBACK callback_vis_window(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { static int mdown = 0, dx, dy, lx, ly, maximized = 0; switch(msg) { case WM_TIMER: break; case WM_USER: /* overlay message: lparam = &hdc */ { HDC odc = *((HDC*)lParam); vis_lyrics_draw(odc); } break; case WM_MOUSEMOVE: { RECT rct; int x = (int)LOWORD(lParam), y = (int)HIWORD(lParam); GetClientRect(hwnd, &rct); if(x > rct.right - 20 && y > rct.bottom - 20 && x <= rct.right && y <= rct.bottom) { SetCursor(LoadCursor(0, IDC_SIZENWSE)); } if(mdown == 1) { POINT pt; GetCursorPos(&pt); move_docking_window(window_id_vis, pt.x - dx, pt.y - dy); }else if(mdown == 2){ /* resize */ POINT pt; GetCursorPos(&pt); skin_settings.vis_w = max(pt.x - lx + dx, 100); skin_settings.vis_h = max(pt.y - ly + dy, 50); if(skin_settings.vis_d) { if(skin_main_width > skin_settings.vis_w - 10 && skin_main_width < skin_settings.vis_w + 10) skin_settings.vis_w = skin_main_width; if(skin_main_height > skin_settings.vis_h - 10 && skin_main_height < skin_settings.vis_h + 10) skin_settings.vis_h = skin_main_height; } SetWindowPos(hwnd, 0, 0, 0, skin_settings.vis_w, skin_settings.vis_h, SWP_NOMOVE | SWP_NOZORDER); vis_draw_background(maximized); }else{ visualization_messages(2 /* mouse move */, x, y); } if(!maximized) { if(incoord_vpos_nozoom((int)LOWORD(lParam), (int)HIWORD(lParam), &coords.window_vis.button_close, coords.window_vis.button_close_align, skin_settings.vis_w, skin_settings.vis_h)) { show_tip(oooo_skins_close, 0); blt_coord_vpos_nozoom(hdc_vis, mdc_sheet, 1, &coords.window_vis.button_close, coords.window_vis.button_close_align, skin_settings.vis_w, skin_settings.vis_h); }else{ blt_coord_vpos_nozoom(hdc_vis, mdc_sheet, 0, &coords.window_vis.button_close, coords.window_vis.button_close_align, skin_settings.vis_w, skin_settings.vis_h); } if(incoord_vpos_nozoom((int)LOWORD(lParam), (int)HIWORD(lParam), &coords.window_vis.button_max, coords.window_vis.button_max_align, skin_settings.vis_w, skin_settings.vis_h)) { show_tip(oooo_skins_maximize, 0); blt_coord_vpos_nozoom(hdc_vis, mdc_sheet, 1, &coords.window_vis.button_max, coords.window_vis.button_max_align, skin_settings.vis_w, skin_settings.vis_h); }else{ blt_coord_vpos_nozoom(hdc_vis, mdc_sheet, 0, &coords.window_vis.button_max, coords.window_vis.button_max_align, skin_settings.vis_w, skin_settings.vis_h); } } } break; case WM_MOUSEWHEEL: SendMessage(skin.wnd, msg, wParam, lParam); break; case WM_KEYDOWN: if(visualization_messages(msg_keys, (int)wParam, (int)lParam))break; SendMessage(skin.wnd, msg, wParam, lParam); break; case WM_LBUTTONDBLCLK: offset_fullscreen: { WINDOWPLACEMENT wp; GetWindowPlacement(hwnd, &wp); if(wp.showCmd == SW_MAXIMIZE) { ShowWindow(hwnd, SW_RESTORE); maximized = 0; }else{ ShowWindow(hwnd, SW_MAXIMIZE); maximized = 1; } sys_sleep(30); vis_draw_background(maximized); } break; case WM_LBUTTONDOWN: { RECT rct; if(visualization_messages(msg_leftdown, (int)LOWORD(lParam), (int)HIWORD(lParam)))break; if(maximized)break; if(!maximized) { if(incoord_vpos_nozoom((int)LOWORD(lParam), (int)HIWORD(lParam), &coords.window_vis.button_close, coords.window_vis.button_close_align, skin_settings.vis_w, skin_settings.vis_h)) { if(skin_settings.skin_lock) { SendMessage(skin.wnd, WM_DESTROY, 0, 0); }else{ vis_close(); skin_settings.vis_show = 0; } break; } if(incoord_vpos_nozoom((int)LOWORD(lParam), (int)HIWORD(lParam), &coords.window_vis.button_max, coords.window_vis.button_max_align, skin_settings.vis_w, skin_settings.vis_h)) { goto offset_fullscreen; break; } } GetClientRect(hwnd, &rct); dx = (int)LOWORD(lParam); dy = (int)HIWORD(lParam); if(skin_settings.skin_lock) { RECT rctm; POINT pt; GetWindowRect(skin.wnd, &rctm); GetCursorPos(&pt); last_dx = pt.x - rctm.left; last_dy = pt.y - rctm.top; } if(dx > rct.right - 20 && dy > rct.bottom - 20 && dx <= rct.right && dy <= rct.bottom) { dx = rct.right - dx; dy = rct.bottom - dy; GetWindowRect(hwnd, &rct); lx = rct.left; ly = rct.top; mdown = 2; }else{ mdown = 1; } SetCapture(hwnd); } break; case WM_LBUTTONUP: mdown = 0; ReleaseCapture(); if(visualization_messages(msg_leftup, (int)LOWORD(lParam), (int)HIWORD(lParam)))break; break; case WM_RBUTTONDOWN: visualization_messages(msg_rightdown, (int)LOWORD(lParam), (int)HIWORD(lParam)); break; case WM_RBUTTONUP: if(!visualization_messages(msg_rightup, (int)LOWORD(lParam), (int)HIWORD(lParam))) { skin.shared->general.show_settings(0, 0, panel_visualizations); } break; case WM_CREATE: hdc_vis = GetDC(hwnd); vis_lyrics_font_size = MulDiv(20, GetDeviceCaps(hdc_vis, LOGPIXELSY), 72); vis_lyric_font = CreateFont(-vis_lyrics_font_size, 0, 0, 0, FW_NORMAL, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH, skin_settings.font_display); vis_lyric_font_b = CreateFont(-vis_lyrics_font_size, 0, 0, 0, FW_NORMAL, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, skin_settings.font_display); vis_lyric_timer = SetTimer(hwnd, 4000101, 10, 0); break; case WM_DESTROY: DeleteObject(vis_lyric_font); KillTimer(hwnd, vis_lyric_timer); break; case WM_PAINT: vis_draw_background(maximized); break; } return DefWindowProc(hwnd, msg, wParam, lParam); }
int main() { init_curses(); const char *exit_msg = ""; struct game_t game = { 0 }; int last_turn = game.turns; place_tile(&game); place_tile(&game); gotoxy(0, 7); printf("Press ENTER to quit."); int cur_key; while (1) { print_game(&game); if (lose_game(game)) { exit_msg = "lost"; goto lose; } last_turn = game.turns; switch (cur_key = keyb_getkey(1)) { case 22: move_left(&game); break; case 38: move_down(&game); break; case 6: move_up(&game); break; case 54: move_right(&game); break; case 96: exit_msg = "quit"; goto end; } if (last_turn != game.turns) place_tile(&game); } lose: gotoxy(0, 7); printf("You lose! Press ENTER to quit."); while (keyb_getkey(1) != 96); end: gotoxy(0, 7); printf("You %s after scoring %d points in %d turns, " "with largest tile %d\n", exit_msg, game.score, game.turns, 1 << max_tile((tile_t *)game.board)); sys_sleep(3000); return 0; }