void main(void) { RCC_HSECLKInit(); WatchDogOn(); SysInit(); BootProc(); }
// 3. Subroutines Section // MAIN: Mandatory for a C Program to be executable int main(void){ PLL_Init(); // 80 MHz // initialize output and interrupts SysInit(); Port_Init(); // EnableInterrupts(); /*Initialize ports and timers*/ while(1) { for(j=80000;j<=160000;j=j+8000) { for(k=0;k<=3;k++) { GPIO_PORTA_DATA_R|=0x20; SysLoad(j); GPIO_PORTA_DATA_R&=~(0x20); SysLoad(1600000-j); } } } }
ADC_ContinuousScan (void) { /* Init System, IP clock and multi-function I/O In the end of SYS_Init() will issue SYS_LockReg() to lock protected register. If user want to write protected register, please issue SYS_UnlockReg() to unlock protected register if necessary */ SysInit(); /* Init UART0 for printf */ UART0_Init(); printf("\nThis sample code demonstrate ADC continuous scan conversion\n"); printf("It convert channel 0,1,2 continuously and print conversion result\n"); // Enable channel 0,1,2 ADC_Open(ADC, ADC_INPUT_MODE_SINGLE_END, ADC_OPERATION_MODE_CONTINUOUS, (ADC_CH_0_MASK | ADC_CH_1_MASK | ADC_CH_2_MASK)); // Power on ADC ADC_POWER_ON(ADC); // Enable ADC ADC_IF interrupt ADC_EnableInt(ADC, ADC_ADF_INT); NVIC_EnableIRQ(ADC_IRQn); ADC_START_CONV(ADC); while(1); }
int main(void) { //Initial Set-up of: SPI, USB, TIM2, and ADC SysInit(); SysTickInit(); LMP_SPI_Init(); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); InitTIM2(); startUSBOTG(); ADC1_Config(); TIM_ITConfig(TIM4, TIM_IT_Update, ENABLE); TIM_ITConfig(TIM4, TIM_IT_CC1, ENABLE); //Main Loop: Transmit ADC result to PC while (1) { //Read in from DMA buffer to output array while(!ADCBuffer[399]); //Wait until last element of buffer is non-zero(testing) for(int i = 0; i<400; i++) adc_16[i] = ADCBuffer[i]; //Convert 16b array elements in 4000 element array to 8 bit words and store in //8000 element array for (int i=0; i<800; i++) { if (i%2 == 0) adc_8[i] = (adc_16[i/2] >> 8); else adc_8[i] = (adc_16[i/2]); } //Output 2000 element array of ADC results over USB VCP Data line APP_Rx_ptr_out = 0; APP_Rx_length = 0; APP_Rx_ptr_in = 0; //for (int i=0; i < 8; i++) VCP_DataTx(&adc_8[i], 1); VCP_DataTx(&adc_8[55], 1); }
int main(void) { //Initial Set-up of: SPI, USB, TIM2, and ADC SysInit(); LMP_SPI_Init(); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); InitTIM2(); startUSBOTG(); ADC3_CH2_DMA_Config(); TIM_ITConfig(TIM4, TIM_IT_Update, ENABLE); TIM_ITConfig(TIM4, TIM_IT_CC1, ENABLE); ADC_DMACmd(ADC3, ENABLE); //Main Loop: Transmit ADC result to PC while (1) { //Convert array elements in 1000 element array to 8 bit words and store in //2000 element array for (int i=0; i<2000; i++) { if (i%2 == 0) adc3ch2_16bit[i] = (adc3ch2[i/2] >> 8); else adc3ch2_16bit[i] = (adc3ch2[i/2]); } //Output 2000 element array of ADC results over USB VCP Data line for (int i=0; i < 2000; i++) VCP_DataTx (&adc3ch2_16bit[i],0); }
int main(void) { // Must include this line in all programs using "cm530.h/.c" SysInit(); while(1) { // Reset the LEDs SetLED(TXD, 0); SetLED(RXD, 0); SetLED(AUX, 0); SetLED(MANAGE, 0); SetLED(PROGRAM, 0); SetLED(PLAY, 0); mDelay(1000); SetLED(TXD, 1); SetLED(RXD, 1); SetLED(AUX, 1); SetLED(MANAGE, 1); SetLED(PROGRAM, 1); SetLED(PLAY, 1); mDelay(1000); } return 0; }
int main(void) { PLL_Init(); PortA_Init(); SysInit(); SysLoad(40000); while(1){} }
/** @brief メインルーチン ここではアプリケーションメイン処理、ドライバメイン処理を呼び出す時間管理と メイン処理の呼び出しを行います。 また、デバッグ用に書き換え専用、テスト関数の呼び出しを行う関数を呼びます。 @note mainを呼ぶのはアセンブラからなので、mainにたどり着く前に不具合がある場合はそちらを疑うこと。 see -> sect30.inc */ void main(void) { BOOL onError = FALSE; SysInit(); //ペリフェラルの初期化や設定、インターフェースデータの初期化もここでやる // DebugCall(); //デバッグ、単体テスト用呼び出しなど //メインループ while(TRUE){ //タスクについて //|アプリ処理 |ドライバ処理 |アプリ処理・・・・・・ //|----------------|-------------------|----------・・・・・・ // 5ms 5ms // //|------------------------------------| // 適時割り込み処理 //というようにアプリ5ms、ドライバ5msでループします。 //割り込み処理はアプリ処理中、ドライバ処理中関係なく動作します。 //割り込みは主にタイマ管理、UART送受信で行われます。 while(IF_taskASWait); //タイマ割り込みがg_taskASWaitの上書きを行います onError = ASMain(); //アプリケーション処理 DebugASOverWrite(); //アプリケーション処理のデバッグ用に強制上書きを行う(デバッグ時のみ動作) if(onError){ //エラーが発生しているかのチェック ErrorTask(); } while(IF_taskDriverwait); //タイマ割り込みがg_taskDriverwaitの上書きを行います onError = DrvMain(); //ドライバ、ハードウェアメイン処理 DebugDriverOverWrite(); //ドライバ処理のデバッグ、又はアプリケーションにダミーを if(onError){ //エラーが発生しているかのチェック ErrorTask(); } }//Main LOOP END }
int main() { // Chip and peripheral initialization SysInit(); Setup(); // Program loop while(1) { Loop(); } }
/** * \brief Start the RIP. * * \return @c TRUE if RIP started, @c FALSE otherwise. */ int OIL_StartRIP() { /* check if system already started, start up as required */ if(!SysInit(OIL_Sys_Active)) { if(g_SystemState.eCurrentState == OIL_Sys_Active) { SysExit(OIL_Sys_Inactive); } return FALSE; } return TRUE; }
int main(void){ PLL_Init(); PortA_Init(); SysInit(); SysLoad(40000); while(1){ } // initialize output and interrupts //EnableInterrupts(); /*Initialize necessary ports and timers here*/ }
BOOL WINAPI xlAutoOpen(void) { XLOPER12 xlName; if (!Excel12(xlGetName, &xlName, 0)) { int i, len = xlName.val.str[0]; for (i = 0; i < len; i++) dllpath += ( xlName.val.str[i + 1] & 0xff ); Excel12(xlFree, 0, 1, &xlName); } SysInit(); return true; }
//int _tmain(int argc, _TCHAR* argv[]) int win32_main() { //return TestAvi(); DEBUG_INFO("Media server start...\n"); SysInit(); CNetServer Srv; Srv.SetTask(10, 1024 *1024); Srv.Start("55555:9527:9088:12345:65432"); while(1){ sleep(1); }; SysUnInit(); return MW_SUCC; }
void main(void) { SysInit(); AD9954Init(); IrInit(); ADCInit(); UIInit(); UIRefresh(); //InitManchester(); //Set the timer A1 TA1CCTL0 = CCIE; // CCR0 interrupt enabled TA1CCR0 = 3277; TA1CTL = TASSEL_1 + MC_1 + TACLR; // SMCLK, up mode, clear TAR //AD9954_OSK_H; // OSK UP SingleTone(); // 1MHz for default g_ulFrequence = 5000000; // 必须和SetFreqToHz绑定使用 SetFreqToHz(g_ulFrequence); // n Hz _EINT(); while(1){ //ADSend(0xff); _nop();_nop();_nop();_nop();_nop(); delay_ms(100); if(g_ucGetNumFlag){ //g_ulFrequence = g_ulGetNum; //SetFreqToHz(g_ulFrequence); g_dC = GetCValueByVRate(g_ulGetNum / 1000.0); UIRefresh(); //AD9954SetReg8(ASF, 1000*g_ulGetNum); //g_ulGetNum = 16415; g_ucGetNumFlag = 0; // Clear g_ulGetNum = 0; // Reset //g_dQ = GetCValueByVRate(g_fVRate); } // 进入低功耗模式 __bis_SR_register(LPM0_bits + GIE); // Enter LPM0, Enable interrupts __no_operation(); // For debugger } }
int Timer_InterTimerTriggerMode(void) { int volatile i; /* Init System, IP clock and multi-function I/O In the end of SYS_Init() will issue SYS_LockReg() to lock protected register. If user want to write protected register, please issue SYS_UnlockReg() to unlock protected register if necessary */ SysInit(); /* Init UART to 115200-8n1 for print message */ UART_Open(UART0, 115200); /* This sample code demonstrate inter timer trigger mode using Timer0 and Timer1 * In this mode, Timer0 is working as counter, and triggers Timer1. Using Timer1 * to calculate the amount of time used by Timer0 to count specified amount of events. * By dividing the time period recorded in Timer1 by the event counts, we get * the event frequency. */ printf("Inter timer trigger mode demo code\n"); printf("Please connect input source with Timer 0 counter pin PB.8, press any key to continue\n"); UART_GetChar(); // Give a dummy target frequency here. Will over write prescale and compare value with macro TIMER_Open(TIMER0, TIMER_ONESHOT_MODE, 100); // Update prescale and compare value. Calculate average frequency every 1000 events TIMER_SET_PRESCALE_VALUE(TIMER0, 0); TIMER_SET_CMP_VALUE(TIMER0, 1000); // Update Timer 1 prescale value. So Timer 1 clock is 1MHz TIMER_SET_PRESCALE_VALUE(TIMER1, 11); // We need capture interrupt NVIC_EnableIRQ(TMR1_IRQn); while(1) { complete = 0; // Count event by timer 0, disable drop count (set to 0), disable timeout (set to 0). Enable interrupt after complete TIMER_EnableFreqCounter(TIMER0, 0, 0, TRUE); while(complete == 0); } }
void task_app(void *arg) { (void)arg; __GlobalLock(); watchdog_feed(); if(SysInit()) { DebugPrint(0,"system init failed!! quit\n"); return; } watchdog_feed(); if(ParamInit()) { DebugPrint(0,"param init failed!! quit\n"); return; } watchdog_feed(); // MonitorInit(); RunTimeThread(); InitCenmet(); //´®¿Ú³±í #ifndef TEST_PLC SysCreateTask(SvrCommTask,0,"Svr Comm Task",-1,TASK_GPRS_STK_SIZE,TASK_GPRS_PRIO);//uplink 300 8 #endif #ifdef BIG_CONCENT InitUp485(); #endif // MonitorTask(); #ifdef DEFINE_PLCOMM PlcCommInit(); #endif #ifdef TEST_PLC SysCreateTask(RunTestTask,0,"Test Task",0,200,25);//test 200 25 #endif // SysCreateTask(RunStackCheck,0,"Stack Check Task",0,200,26);//check 200 26 TtyShellStart(); //while(1)Sleep(2000);; }
void Example_WebClient(void) { int status = WL_IDLE_STATUS; //uint32_t ip = *(uint32_t *)Addr; SysInit(); DebugPortInit(); WiFi_Init(); //status = WiFi_Begin(WEP,"Embest", 0, "0123456789"); status = WiFi_Begin(NET_TYPE, NET_SSID NET_KEY_INDEX NET_KEY); if(status != WL_CONNECTED) { printf("\r\nFailure to join network\r\n"); while(1); } //wait network connection stable. DelayMs(200); if(!WiFiClient_Connect("www.google.com.hk", 80)) { printf("\r\nFailure to connect to webserver\r\n"); while(1); } WebPrint( "GET /search?q=CooCox HTTP/1.1\r\n" "Host:www.google.com.hk\r\n" "Connection: close\r\n" "\r\n"); DelayMs(2000); // if there are incoming bytes available // from the server, read them and print them: while (WiFiClient_Available()) { char c = WiFiClient_ReadByte(); putchar(c); } printf("\r\nExample End\r\n"); while(1); }
int main(void) { SysInit(); CPUInit(); while(1) { //flag change in timer interrupt //change LED output base on flag if(LEDOnOff&0x01) { LEDOutput(0); } else { LEDOutput(1); } } }
int UART_TxRx_Function(void) { /* Init System, IP clock and multi-function I/O */ SysInit(); /* Init UART0 for printf */ UART0_Init(); /*---------------------------------------------------------------------------------------------------------*/ /* SAMPLE CODE */ /*---------------------------------------------------------------------------------------------------------*/ printf("\n\nCPU @ %dHz\n", SystemCoreClock); printf("+---------------------+\n"); printf("| UART function test |\n"); printf("+---------------------+\n"); UART_FunctionTest(); }
int Timer_FreeCountingMode(void) { int volatile i; /* Init System, IP clock and multi-function I/O In the end of SYS_Init() will issue SYS_LockReg() to lock protected register. If user want to write protected register, please issue SYS_UnlockReg() to unlock protected register if necessary */ SysInit(); /* Init UART to 115200-8n1 for print message */ UART_Open(UART0, 115200); printf("\nThis sample code demonstrate timer free counting mode.\n"); printf("Please connect input source with Timer 0 capture pin PD.11, press any key to continue\n"); UART_GeyChar(); // Give a dummy target frequency here. Will over write capture resolution with macro TIMER_Open(TIMER0, TIMER_PERIODIC_MODE, 1000000); // Update prescale to set proper resolution. // Timer 0 clock source is 12MHz, to set resolution to 1us, we need to // set clock divider to 12. e.g. set prescale to 12 - 1 = 11 TIMER_SET_PRESCALE_VALUE(TIMER0, 11); // Set compare value as large as possible, so don't need to worry about counter overrun too frequently. TIMER_SET_CMP_VALUE(TIMER0, 0xFFFFFF); // Configure Timer 0 free counting mode, capture TDR value on rising edge TIMER_EnableCapture(TIMER0, TIMER_CAPTURE_FREE_COUNTING_MODE, TIMER_CAPTURE_RISING_EDGE); // Start Timer 0 TIMER_Start(TIMER0); // Enable timer interrupt TIMER_EnableCaptureInt(TIMER0); NVIC_EnableIRQ(TMR0_IRQn); while(1); }
int main(void) { SysInit(); sys_init(); mem_init(); memp_init(); pbuf_init(); tcpip_init( NULL, NULL ); /* Start the tasks defined within this file/specific to this demo. */ xTaskCreate( vGSM_GPRS_Task, "GSM_GPRS_TASK", 256 , NULL,tskIDLE_PRIORITY + 1 , NULL ); xTaskCreate( vAmpmNetTestTask, "ampm net test", 128 , "\r\nThienhaiblue->",tskIDLE_PRIORITY + 1 , NULL ); xTaskCreate( vAmpmNetTestTask1, "ampm net test1", 128 , "\r\nTony->",tskIDLE_PRIORITY + 1 , NULL ); /* Start the scheduler. */ vTaskStartScheduler(); while(1) { } return 0; }
PWM_DeadZone (void) { /* Init System, IP clock and multi-function I/O In the end of SYS_Init() will issue SYS_LockReg() to lock protected register. If user want to write protected register, please issue SYS_UnlockReg() to unlock protected register if necessary */ SysInit(); /* Init UART to 115200-8n1 for print message */ UART0_Init(); printf("\nThis sample code will output PWM0 channel 0 to with different\n"); printf("frequency and duty, enable dead zone function of all PWM0 pairs.\n"); printf("And also enable/disable PWM0 output every 1 second.\n"); // PWM0 frequency is 100Hz, duty 30%, PWM_ConfigOutputChannel(PWM0, 0, 100, 30); PWM_EnableDeadZone(PWM0, 0, 400); // PWM2 frequency is 300Hz, duty 50% PWM_ConfigOutputChannel(PWM0, 2, 300, 50); PWM_EnableDeadZone(PWM0, 2, 200); // Enable output of all PWM channels PWM_EnableOutput(PWM0, 0xF); // Enable PWM channel 0 period interrupt, use channel 0 to measure time. PWM_EnablePeriodInt(PWM0, 0, 0); NVIC_EnableIRQ(PWM0_IRQn); // Start PWM_Start(PWM0, 0xF); while(1); }
int main(void) { unsigned long T=1600000 ; int i,j; PLL_Init(); SysHandler(); PortA_Init(); SysInit(); SysLoad(T); while(1) { for(j=80000; j <160000 ; j=j+8000){ for(i=0;i<4;i++){ GPIO_PORTA_DATA_R|=0x20; SysLoad(j); GPIO_PORTA_DATA_R&=~0x20 ; SysLoad(T-j); } } } }
// // Constructor // EventHandler::EventHandler(image *screen, palette *pal) { CHECK(screen && pal); m_pending = 0; m_screen = screen; // Mouse stuff uint8_t mouse_sprite[]= { 0, 2, 0, 0, 0, 0, 0, 0, 2, 1, 2, 0, 0, 0, 0, 0, 2, 1, 1, 2, 0, 0, 0, 0, 2, 1, 1, 1, 2, 0, 0, 0, 2, 1, 1, 1, 1, 2, 0, 0, 2, 1, 1, 1, 1, 1, 2, 0, 0, 2, 1, 1, 2, 2, 0, 0, 0, 0, 2, 1, 1, 2, 0, 0, 0, 0, 2, 1, 1, 2, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0 }; Filter f; f.Set(1, pal->brightest(1)); f.Set(2, pal->darkest(1)); image *im = new image(ivec2(8, 10), mouse_sprite); f.Apply(im); m_sprite = new Sprite(screen, im, ivec2(100, 100)); m_pos = screen->Size() / 2; m_center = ivec2(0, 0); m_button = 0; // Platform-specific stuff SysInit(); }
int main(int argc, char **argv) { char str[256]; int16 i16; HANDLE rom_fh; const char *rom_path; uint32 rom_size; DWORD actual; uint8 *rom_tmp; // Initialize variables RAMBase = 0; // Print some info printf(GetString(STR_ABOUT_TEXT1), VERSION_MAJOR, VERSION_MINOR); printf(" %s\n", GetString(STR_ABOUT_TEXT2)); // Read preferences PrefsInit(NULL, argc, argv); // Parse command line arguments for (int i=1; i<argc; i++) { if (strcmp(argv[i], "--help") == 0) { usage(argv[0]); } else if (argv[i][0] == '-') { fprintf(stderr, "Unrecognized option '%s'\n", argv[i]); usage(argv[0]); } } // Check we are using a Windows NT kernel >= 4.0 OSVERSIONINFO osvi; ZeroMemory(&osvi, sizeof(OSVERSIONINFO)); osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); if (!GetVersionEx(&osvi)) { ErrorAlert("Could not determine OS type"); QuitEmulator(); } win_os = osvi.dwPlatformId; win_os_major = osvi.dwMajorVersion; if (win_os != VER_PLATFORM_WIN32_NT || win_os_major < 4) { ErrorAlert(GetString(STR_NO_WIN32_NT_4)); QuitEmulator(); } // Check that drivers are installed if (!check_drivers()) QuitEmulator(); // Load win32 libraries KernelInit(); // FIXME: default to DIB driver if (getenv("SDL_VIDEODRIVER") == NULL) putenv("SDL_VIDEODRIVER=windib"); // Initialize SDL system int sdl_flags = 0; #ifdef USE_SDL_VIDEO sdl_flags |= SDL_INIT_VIDEO; #endif #ifdef USE_SDL_AUDIO sdl_flags |= SDL_INIT_AUDIO; #endif assert(sdl_flags != 0); if (SDL_Init(sdl_flags) == -1) { char str[256]; sprintf(str, "Could not initialize SDL: %s.\n", SDL_GetError()); ErrorAlert(str); goto quit; } atexit(SDL_Quit); #ifdef ENABLE_MON // Initialize mon mon_init(); #endif // Install SIGSEGV handler for CPU emulator if (!sigsegv_install_handler(sigsegv_handler)) { sprintf(str, GetString(STR_SIGSEGV_INSTALL_ERR), strerror(errno)); ErrorAlert(str); goto quit; } // Initialize VM system vm_init(); // Get system info PVR = 0x00040000; // Default: 604 CPUClockSpeed = 100000000; // Default: 100MHz BusClockSpeed = 100000000; // Default: 100MHz TimebaseSpeed = 25000000; // Default: 25MHz PVR = 0x000c0000; // Default: 7400 (with AltiVec) D(bug("PVR: %08x (assumed)\n", PVR)); // Init system routines SysInit(); // Show preferences editor if (!PrefsFindBool("nogui")) if (!PrefsEditor()) goto quit; // Create areas for Kernel Data if (!kernel_data_init()) goto quit; kernel_data = (KernelData *)Mac2HostAddr(KERNEL_DATA_BASE); emulator_data = &kernel_data->ed; KernelDataAddr = KERNEL_DATA_BASE; D(bug("Kernel Data at %p (%08x)\n", kernel_data, KERNEL_DATA_BASE)); D(bug("Emulator Data at %p (%08x)\n", emulator_data, KERNEL_DATA_BASE + offsetof(KernelData, ed))); // Create area for DR Cache if (vm_mac_acquire(DR_EMULATOR_BASE, DR_EMULATOR_SIZE) < 0) { sprintf(str, GetString(STR_DR_EMULATOR_MMAP_ERR), strerror(errno)); ErrorAlert(str); goto quit; } dr_emulator_area_mapped = true; if (vm_mac_acquire(DR_CACHE_BASE, DR_CACHE_SIZE) < 0) { sprintf(str, GetString(STR_DR_CACHE_MMAP_ERR), strerror(errno)); ErrorAlert(str); goto quit; } dr_cache_area_mapped = true; DRCacheAddr = (uint32)Mac2HostAddr(DR_CACHE_BASE); D(bug("DR Cache at %p (%08x)\n", DRCacheAddr, DR_CACHE_BASE)); // Create area for SheepShaver data if (!SheepMem::Init()) { sprintf(str, GetString(STR_SHEEP_MEM_MMAP_ERR), strerror(errno)); ErrorAlert(str); goto quit; } // Create area for Mac ROM if (vm_mac_acquire(ROM_BASE, ROM_AREA_SIZE) < 0) { sprintf(str, GetString(STR_ROM_MMAP_ERR), strerror(errno)); ErrorAlert(str); goto quit; } ROMBase = ROM_BASE; ROMBaseHost = Mac2HostAddr(ROMBase); rom_area_mapped = true; D(bug("ROM area at %p (%08x)\n", ROMBaseHost, ROMBase)); // Create area for Mac RAM RAMSize = PrefsFindInt32("ramsize"); if (RAMSize < 8*1024*1024) { WarningAlert(GetString(STR_SMALL_RAM_WARN)); RAMSize = 8*1024*1024; } RAMBase = 0; if (vm_mac_acquire(RAMBase, RAMSize) < 0) { sprintf(str, GetString(STR_RAM_MMAP_ERR), strerror(errno)); ErrorAlert(str); goto quit; } RAMBaseHost = Mac2HostAddr(RAMBase); ram_area_mapped = true; D(bug("RAM area at %p (%08x)\n", RAMBaseHost, RAMBase)); if (RAMBase > ROMBase) { ErrorAlert(GetString(STR_RAM_HIGHER_THAN_ROM_ERR)); goto quit; } // Load Mac ROM rom_path = PrefsFindString("rom"); rom_fh = CreateFile(rom_path && *rom_path ? rom_path : ROM_FILE_NAME, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (rom_fh == INVALID_HANDLE_VALUE) { rom_fh = CreateFile(ROM_FILE_NAME2, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (rom_fh == INVALID_HANDLE_VALUE) { ErrorAlert(GetString(STR_NO_ROM_FILE_ERR)); goto quit; } } printf(GetString(STR_READING_ROM_FILE)); rom_size = GetFileSize(rom_fh, NULL); rom_tmp = new uint8[ROM_SIZE]; ReadFile(rom_fh, (void *)rom_tmp, ROM_SIZE, &actual, NULL); CloseHandle(rom_fh); // Decode Mac ROM if (!DecodeROM(rom_tmp, actual)) { if (rom_size != 4*1024*1024) { ErrorAlert(GetString(STR_ROM_SIZE_ERR)); goto quit; } else { ErrorAlert(GetString(STR_ROM_FILE_READ_ERR)); goto quit; } } delete[] rom_tmp; // Initialize native timers timer_init(); // Initialize everything if (!InitAll(NULL)) goto quit; D(bug("Initialization complete\n")); // Write protect ROM vm_protect(ROMBaseHost, ROM_AREA_SIZE, VM_PAGE_READ); // Start 60Hz thread tick_thread_cancel = false; tick_thread_active = ((tick_thread = create_thread(tick_func)) != NULL); SetThreadPriority(tick_thread, THREAD_PRIORITY_ABOVE_NORMAL); D(bug("Tick thread installed (%ld)\n", tick_thread)); // Start NVRAM watchdog thread memcpy(last_xpram, XPRAM, XPRAM_SIZE); nvram_thread_cancel = false; nvram_thread_active = ((nvram_thread = create_thread(nvram_func, NULL)) != NULL); SetThreadPriority(nvram_thread, THREAD_PRIORITY_BELOW_NORMAL); D(bug("NVRAM thread installed (%ld)\n", nvram_thread)); // Get my thread ID and jump to ROM boot routine emul_thread = GetCurrentThread(); D(bug("Jumping to ROM\n")); #ifdef _MSC_VER __try { #endif jump_to_rom(ROMBase + 0x310000); #ifdef _MSC_VER } __except (main_exception_filter(GetExceptionInformation())) {} #endif D(bug("Returned from ROM\n")); quit: Quit(); return 0; }
int main(int argc, char *argv[]) { char file[MAXPATHLEN] = ""; char path[MAXPATHLEN]; int runcd = RUN; int loadst = 0; int i; #ifdef ENABLE_NLS setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, LOCALE_DIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #endif memset(&Config, 0, sizeof(PcsxConfig)); // what is the name of the config file? // it may be redefined by -cfg on the command line strcpy(cfgfile_basename, "pcsxr.cfg"); // read command line options for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-runcd")) runcd = RUN_CD; else if (!strcmp(argv[i], "-nogui")) UseGui = FALSE; else if (!strcmp(argv[i], "-psxout")) Config.PsxOut = TRUE; else if (!strcmp(argv[i], "-slowboot")) Config.SlowBoot = TRUE; else if (!strcmp(argv[i], "-load")) loadst = atol(argv[++i]); else if (!strcmp(argv[i], "-cfg")) { if (i+1 >= argc) break; strncpy(cfgfile_basename, argv[++i], MAXPATHLEN-100); /* TODO buffer overruns */ printf("Using config file %s.\n", cfgfile_basename); } else if (!strcmp(argv[i], "-cdfile")) { char isofilename[MAXPATHLEN]; if (i+1 >= argc) break; strncpy(isofilename, argv[++i], MAXPATHLEN); if (isofilename[0] != '/') { getcwd(path, MAXPATHLEN); if (strlen(path) + strlen(isofilename) + 1 < MAXPATHLEN) { strcat(path, "/"); strcat(path, isofilename); strcpy(isofilename, path); } else isofilename[0] = 0; } SetIsoFile(isofilename); runcd = RUN_CD; } else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "-help") || !strcmp(argv[i], "--help")) { printf(PACKAGE_STRING "\n"); printf("%s\n", _( " pcsxr [options] [file]\n" "\toptions:\n" "\t-runcd\t\tRuns CD-ROM\n" "\t-cdfile FILE\tRuns a CD image file\n" "\t-nogui\t\tDon't open the GTK GUI\n" "\t-cfg FILE\tLoads desired configuration file (default: ~/.pcsxr/pcsxr.cfg)\n" "\t-psxout\t\tEnable PSX output\n" "\t-slowboot\tEnable BIOS Logo\n" "\t-load STATENUM\tLoads savestate STATENUM (1-9)\n" "\t-h -help\tDisplay this message\n" "\tfile\t\tLoads file\n")); return 0; } else { strncpy(file, argv[i], MAXPATHLEN); if (file[0] != '/') { getcwd(path, MAXPATHLEN); if (strlen(path) + strlen(file) + 1 < MAXPATHLEN) { strcat(path, "/"); strcat(path, file); strcpy(file, path); } else file[0] = 0; } } } strcpy(Config.Net, "Disabled"); if (UseGui) gtk_init(NULL, NULL); CheckSubDir(); ScanAllPlugins(); // try to load config // if the config file doesn't exist if (LoadConfig() == -1) { if (!UseGui) { printf(_("PCSXR cannot be configured without using the GUI -- you should restart without -nogui.\n")); return 1; } // Uh oh, no config file found, use some defaults Config.PsxAuto = 1; gchar *str_bios_dir = g_strconcat(getenv("HOME"), BIOS_DIR, NULL); strcpy(Config.BiosDir, str_bios_dir); g_free(str_bios_dir); gchar *str_plugin_dir = g_strconcat(getenv("HOME"), PLUGINS_DIR, NULL); strcpy(Config.PluginsDir, str_plugin_dir); g_free(str_plugin_dir); gtk_init(NULL, NULL); // Update available plugins, but not GUI UpdatePluginsBIOS(); // Pick some defaults, if they're available set_default_plugin(GpuConfS.plist[0], Config.Gpu); set_default_plugin(SpuConfS.plist[0], Config.Spu); set_default_plugin(CdrConfS.plist[0], Config.Cdr); set_default_plugin(Pad1ConfS.plist[0], Config.Pad1); set_default_plugin(Pad2ConfS.plist[0], Config.Pad2); set_default_plugin(BiosConfS.plist[0], Config.Bios); // create & load default memcards if they don't exist CreateMemcard("card1.mcd", Config.Mcd1); CreateMemcard("card2.mcd", Config.Mcd2); LoadMcds(Config.Mcd1, Config.Mcd2); SaveConfig(); } gchar *str_patches_dir = g_strconcat(getenv("HOME"), PATCHES_DIR, NULL); strcpy(Config.PatchesDir, str_patches_dir); g_free(str_patches_dir); // switch to plugin dotdir // this lets plugins work without modification! gchar *plugin_default_dir = g_build_filename(getenv("HOME"), PLUGINS_DIR, NULL); chdir(plugin_default_dir); g_free(plugin_default_dir); if (UseGui && runcd != RUN_CD) SetIsoFile(NULL); if (SysInit() == -1) return 1; if (UseGui && runcd != RUN_CD) { StartGui(); } else { // the following only occurs if the gui isn't started if (LoadPlugins() == -1) { SysErrorMessage(_("Error"), _("Failed loading plugins!")); return 1; } if (OpenPlugins() == -1 || plugins_configured() == FALSE) { return 1; } CheckCdrom(); // Auto-detect: get region first, then rcnt-bios reset SysReset(); if (file[0] != '\0') { Load(file); } else { if (runcd == RUN_CD) { if (LoadCdrom() == -1) { ClosePlugins(); printf(_("Could not load CD-ROM!\n")); return -1; } } } // If a state has been specified, then load that if (loadst) { StatesC = loadst - 1; gchar *state_filename = get_state_filename(StatesC); LoadState(state_filename); g_free(state_filename); } psxCpu->Execute(); } return 0; }
s32 SelectGame() { u32 keys; s32 loadst = 0; s32 menu_state = 0; s32 menu_pos = 0; s8* newpackfile = NULL; gp2x_video_RGB_clearscreen16(); gp2x_video_flip(); #if 1 for(;;) { gp2x_video_RGB_clearscreen16(); backg(); //exems(); //gp2x_timer_delay(500000); keys = gp2x_joystick_read(); gp2x_printf(NULL, 10, (menu_pos * 10) + PSX4ALL_MENU_START_POS, PSX4ALL_ROW2); if( keys & GP2X_UP ) { if( menu_pos > 0 ) menu_pos--; } switch(menu_state) { case PSX4ALL_MENU_DEFAULT_STATE: if( keys & GP2X_DOWN ) { if (psx4all_emulating) { if( menu_pos < 4 ) menu_pos++; }else{ if( menu_pos < 3 ) menu_pos++; } } break; case PSX4ALL_MENU_OPTIONS_STATE: if( keys & GP2X_DOWN ) { if( menu_pos < 2 ) menu_pos++; } break; case PSX4ALL_MENU_GPU_STATE: if( keys & GP2X_DOWN ) { if( menu_pos < 15 ) menu_pos++; } break; case PSX4ALL_MENU_SPU_STATE: if( keys & GP2X_DOWN ) { if( menu_pos < 1 ) menu_pos++; } break; /*case PSX4ALL_MENU_ABOUT_STATE: if( keys & GP2X_B ) { if( menu_pos < 0 ) menu_pos++; } break;*/ case PSX4ALL_MENU_GAMESTATE_STATE: if( keys & GP2X_DOWN ) { if( menu_pos < 4 ) menu_pos++; } break; } switch(menu_state) { case PSX4ALL_MENU_DEFAULT_STATE: gp2x_printf(NULL, 100, PSX4ALL_MENU_START_POS + 0, PSX4ALL_OPT); gp2x_printf(NULL, 100, PSX4ALL_MENU_START_POS + 10, PSX4ALL_FO); gp2x_printf(NULL, 100, PSX4ALL_MENU_START_POS + 20, PSX4ALL_ABOUT); if (psx4all_emulating) { gp2x_printf(NULL, 100, PSX4ALL_MENU_START_POS + 30, PSX4ALL_RES); if(psx4all_emulating){ gp2x_printf(NULL, 100, PSX4ALL_MENU_START_POS + 40, PSX4ALL_QT); break; } }else { gp2x_printf(NULL, 100, PSX4ALL_MENU_START_POS + 30, PSX4ALL_QT); } break; case PSX4ALL_MENU_OPTIONS_STATE: gp2x_printf(NULL, 100, PSX4ALL_MENU_START_POS + 0, PSX4ALL_GS); gp2x_printf(NULL, 100, PSX4ALL_MENU_START_POS + 10, PSX4ALL_SS); gp2x_printf(NULL, 100, PSX4ALL_MENU_START_POS + 20, PSX4ALL_BK); break; case PSX4ALL_MENU_GPU_STATE: gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 0, PSX4ALL_FPS, (displayFrameInfo == false ? "OFF" : "ON")); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 10, PSX4ALL_GPU, (displayGpuStats == false ? "OFF" : "ON")); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 20, PSX4ALL_MEM, (displayVideoMemory == false ? "OFF" : "ON")); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 30, PSX4ALL_GPUS, (activeNullGPU == false ? "OFF" : "ON")); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 40, PSX4ALL_IC, linesInterlace_user ); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 50, PSX4ALL_FL, (enableFrameLimit == false ? "OFF" : "ON")); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 60, PSX4ALL_SKIP, skipCount, skipRate); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 70, PSX4ALL_HACK, (enableAbbeyHack == false ? "OFF" : "ON")); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 80, PSX4ALL_CM, PsxCycleMult); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 90, PSX4ALL_FRL, hardframeskip_line ? "ON" : "OFF"); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 100, PSX4ALL_FPL, hardframeskip_poly ? "ON" : "OFF"); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 110, PSX4ALL_FST, hardframeskip_sprite ? "ON" : "OFF"); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 120, PSX4ALL_FIM, hardframeskip_image ? "ON" : "OFF"); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 130, PSX4ALL_FBT, hardframeskip_blit ? "ON" : "OFF"); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 140, PSX4ALL_WTM, use_wall_clock_time ? "ON" : "OFF"); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 150, PSX4ALL_BK); break; case PSX4ALL_MENU_SPU_STATE: gp2x_printf(NULL, 100, PSX4ALL_MENU_START_POS + 0, PSX4ALL_SND, (iSoundMuted == 0 ? "ON" : "OFF")); gp2x_printf(NULL, 100, PSX4ALL_MENU_START_POS + 10, PSX4ALL_BK); break; case PSX4ALL_MENU_GAMESTATE_STATE: gp2x_printf(NULL, 100, PSX4ALL_MENU_START_POS + 0, PSX4ALL_SST); gp2x_printf(NULL, 100, PSX4ALL_MENU_START_POS + 10, PSX4ALL_LST); gp2x_printf(NULL, 100, PSX4ALL_MENU_START_POS + 20, PSX4ALL_LG); gp2x_printf(NULL, 100, PSX4ALL_MENU_START_POS + 30, PSX4ALL_LGW); gp2x_printf(NULL, 100, PSX4ALL_MENU_START_POS + 40, PSX4ALL_BK); break; case PSX4ALL_MENU_ABOUT_STATE: gp2x_printf(NULL, 0, 50, PSX4ALL_NAME " V " PSX4ALL_VERSION "." PSX4ALL_BUILD " By " PSX4ALL_BY); gp2x_printf(NULL, 0, 60, PSX4ALL_CREDITS); gp2x_printf(NULL, 0, 70, PSX4ALL_PORT); gp2x_printf(NULL, 0, 80, PSX4ALL_PTI " " PSX4ALL_PLAT); gp2x_printf(NULL, 0, 100, PSX4ALL_PRM); break; } switch(menu_state) { case PSX4ALL_MENU_DEFAULT_STATE: if (psx4all_emulating) { if( keys & GP2X_B ) { switch(menu_pos) { case 0: menu_state = PSX4ALL_MENU_OPTIONS_STATE; menu_pos = 0; break; case 1: menu_state = PSX4ALL_MENU_GAMESTATE_STATE; menu_pos = 0; break; case 2: menu_state = PSX4ALL_MENU_ABOUT_STATE; menu_pos = 0; break; case 3: gp2x_video_RGB_clearscreen16(); return 0; case 4: SDL_Quit(); default: break; } } }else{ if( keys & GP2X_B ) { switch(menu_pos) { case 0: menu_state = PSX4ALL_MENU_OPTIONS_STATE; menu_pos = 0; break; case 1: menu_state = PSX4ALL_MENU_GAMESTATE_STATE; menu_pos = 0; break; case 2: menu_state = PSX4ALL_MENU_ABOUT_STATE; menu_pos = 0; break; case 3: gp2x_video_RGB_clearscreen16(); return 0; default: break; } } } if (keys & GP2X_L && psx4all_emulating) { gp2x_video_RGB_clearscreen16(); return 0; } break; case PSX4ALL_MENU_OPTIONS_STATE: switch(menu_pos) { case 0: if (keys & GP2X_B){ menu_state = PSX4ALL_MENU_GPU_STATE; menu_pos = 0; }break; case 1: if( keys & GP2X_B){ menu_state = PSX4ALL_MENU_SPU_STATE; menu_pos = 0; } break; case 2: if( keys & GP2X_B ) { menu_state = PSX4ALL_MENU_DEFAULT_STATE; menu_pos = 0; } break; default: break; } if (keys & GP2X_L) { menu_state = PSX4ALL_MENU_DEFAULT_STATE; menu_pos = 0; } break; case PSX4ALL_MENU_GPU_STATE: switch(menu_pos) { case 0: if( keys & GP2X_B || keys & GP2X_LEFT || keys & GP2X_RIGHT ) { displayFrameInfo = !displayFrameInfo; } break; case 1: if( keys & GP2X_B || keys & GP2X_LEFT || keys & GP2X_RIGHT ) { displayGpuStats = !displayGpuStats; } break; case 2: if( keys & GP2X_B ) { displayVideoMemory = !displayVideoMemory; } break; case 3: if( keys & GP2X_B || keys & GP2X_LEFT || keys & GP2X_RIGHT ) { activeNullGPU = !activeNullGPU; } break; case 4: if ( keys & GP2X_LEFT && linesInterlace_user > 0) linesInterlace_user--; if ( keys & GP2X_RIGHT && linesInterlace_user < 7) linesInterlace_user++; break; case 5: if( keys & GP2X_B ) { enableFrameLimit = !enableFrameLimit; } break; case 6: if( keys & GP2X_LEFT ) { if( skipValue > 0 ) { skipValue--; skipCount = skipCountTable[skipValue]; skipRate = skipRateTable[skipValue]; } } if( keys & GP2X_RIGHT ) { if( skipValue < 8 ) { skipValue++; skipCount = skipCountTable[skipValue]; skipRate = skipRateTable[skipValue]; } } break; case 7: if( keys & GP2X_B || keys & GP2X_LEFT || keys & GP2X_RIGHT ) { enableAbbeyHack = !enableAbbeyHack; } break; case 8: if ( keys & GP2X_LEFT && PsxCycleMult > 1) PsxCycleMult--; if ( keys & GP2X_RIGHT && PsxCycleMult < 10) PsxCycleMult++; break; case 9: if( keys & GP2X_B || keys & GP2X_LEFT || keys & GP2X_RIGHT ) { hardframeskip_line = !hardframeskip_line; } break; case 10: if( keys & GP2X_B || keys & GP2X_LEFT || keys & GP2X_RIGHT ) { hardframeskip_poly = !hardframeskip_poly; } break; case 11: if( keys & GP2X_B || keys & GP2X_LEFT || keys & GP2X_RIGHT ) { hardframeskip_sprite = !hardframeskip_sprite; } break; case 12: if( keys & GP2X_B || keys & GP2X_LEFT || keys & GP2X_RIGHT ) { hardframeskip_image = !hardframeskip_image; } break; case 13: if( keys & GP2X_B || keys & GP2X_LEFT || keys & GP2X_RIGHT ) { hardframeskip_blit = !hardframeskip_blit; } break; case 14: if( keys & GP2X_B || keys & GP2X_LEFT || keys & GP2X_RIGHT ) { use_wall_clock_time = !use_wall_clock_time; } break; case 15: if( keys & GP2X_B ) { menu_state = PSX4ALL_MENU_OPTIONS_STATE; menu_pos = 0; } break; default: break; } if (keys & GP2X_L) { menu_state = PSX4ALL_MENU_OPTIONS_STATE; menu_pos = 0; } break; case PSX4ALL_MENU_SPU_STATE: switch(menu_pos) { case 0: if( keys & GP2X_B || keys & GP2X_LEFT || keys & GP2X_RIGHT ) { #ifndef NOSOUND iSoundMuted = !iSoundMuted; #endif } break; case 1: if( keys & GP2X_B ) { menu_state = PSX4ALL_MENU_OPTIONS_STATE; menu_pos = 0; } break; default: break; } if (keys & GP2X_L) { menu_state = PSX4ALL_MENU_OPTIONS_STATE; menu_pos = 0; } break; case PSX4ALL_MENU_GAMESTATE_STATE: switch(menu_pos) { case 0: if( keys & GP2X_B ) { #ifndef IPHONE if( 1 == psx4all_emulating ) { s32 ret; char buffer[360]; char filename[260]; struct stat s; for(int count = 1;; count++) { sprintf(filename, "%s-%04d.svs", packfile, count); if (stat(filename, &s)) break; } gp2x_printf(NULL, 100, 130, PSX4ALL_SV); gp2x_video_flip(); GPU_freeze(2, NULL); ret = SaveState(filename); if (ret == 0) sprintf(buffer, PSX4ALL_SVD); else sprintf(buffer, PSX4ALL_ESV); gp2x_printf(NULL, 100, 140, PSX4ALL_STR, buffer); gp2x_video_flip(); gp2x_timer_delay(900); } #endif } break; case 1: if( keys & GP2X_B ) { #ifndef IPHONE gp2x_timer_delay(500); newpackfile = FileReq(NULL, FORMAT_SV); #endif } break; case 2: if( keys & GP2X_B ) { #ifndef IPHONE Config.HLE = 0; gp2x_timer_delay(500); newpackfile = FileReq(NULL, NULL); #endif } break; case 3: if( keys & GP2X_B ) { #ifndef IPHONE Config.HLE = 1; gp2x_timer_delay(500); newpackfile = FileReq(NULL, NULL); #endif } break; case 4: if( keys & GP2X_B ) { menu_state = PSX4ALL_MENU_DEFAULT_STATE; menu_pos = 0; } break; default: break; } if (keys & GP2X_L) { menu_state = PSX4ALL_MENU_DEFAULT_STATE; menu_pos = 0; } break; case PSX4ALL_MENU_ABOUT_STATE: switch(menu_pos) { case 0: if( keys & GP2X_B ) { menu_state = PSX4ALL_MENU_DEFAULT_STATE; menu_pos = 0; } break; default: break; } if (keys & GP2X_L) { menu_state = PSX4ALL_MENU_DEFAULT_STATE; menu_pos = 0; } break; } if( newpackfile != NULL ) { break; } gp2x_video_flip(); gp2x_timer_delay(90); if(keys & (GP2X_A|GP2X_B|GP2X_X|GP2X_Y|GP2X_L|GP2X_R|GP2X_PUSH| GP2X_LEFT|GP2X_RIGHT|GP2X_UP|GP2X_DOWN) ) { gp2x_timer_delay(50); } } #else Config.HLE = 1; //newpackfile = "Cotton Jap.cbn"; #endif DEBUGF("loaded "PSX4ALL_STR, newpackfile); packfile = newpackfile; gp2x_video_RGB_clearscreen16(); keys = gp2x_joystick_read(); backg(); LoadCdBios = 0; if( (!strcasecmp(packfile + (strlen(packfile)-4), FORMAT_SV)) ) { char *pos; loadst = 1; sprintf(svsfilename, PSX4ALL_STR, packfile); pos = strrchr(packfile, '-'); if (pos) *pos = '\0'; } else { loadst = 0; } if( loadst > 0 ) { gp2x_printf(NULL, 120, 90, PSX4ALL_LDG); } else { gp2x_printf(NULL, 120, 90, PSX4ALL_LDB); } gp2x_video_flip(); if( 1 == psx4all_emulating ) { psxShutdown(); CloseComponents(); } if (SysInit() == -1) { gp2x_deinit(); return 0; } if (InitComponents() == -1) { gp2x_deinit(); return 0; } SysReset(); CheckCdrom(); if( Config.HLE ) { LoadCdBios = 0; if( LoadCdrom() == -1 ) { gp2x_printf(NULL, 120, 120, PSX4ALL_LDD); gp2x_video_flip(); gp2x_timer_delay(2000); gp2x_video_RGB_clearscreen16(); backg(); return 0; } } else { gp2x_printf(NULL, 120, 120, PSX4ALL_LDY); gp2x_video_flip(); gp2x_timer_delay(90); backg(); } if (loadst) { if( LoadState(svsfilename) == -1 ) { gp2x_printf(NULL, 120, 120, PSX4ALL_LSF); gp2x_video_flip(); gp2x_timer_delay(2000); gp2x_video_RGB_clearscreen16(); return 0; } } return 1; }
int main(int argc, char *argv[]) #endif { #ifndef IPHONE #if defined(ARM_ARCH) ChangeWorkingDirectory(argv[0]); getcwd(gamepath, 256); #else #if defined(__WIN32__) if(argc == 1) strncpy(gamepath,"E:\\ps1",256); else strncpy(gamepath,argv[1],256); #else strncpy(gamepath,ROM_PREFIX,256); #endif #endif #endif #ifdef PSP sprintf(gamepath,""); #endif #ifdef IPHONE sprintf(gamepath,""); #endif memset(&Config, 0, sizeof(PsxConfig)); Config.PsxAuto = 1; Config.Cdda = 1; Config.Xa = 0; #ifdef DYNAREC Config.Cpu = 0; #else Config.Cpu = 1; #endif #ifdef WITH_HLE Config.HLE = 1; #else Config.HLE = 0; #endif Config.Mdec = 0; Config.PsxOut = 0; Config.PsxType = 0; Config.QKeys = 0; Config.RCntFix = 0; Config.Sio = 0; Config.SpuIrq = 1; Config.VSyncWA = 0; #if defined(PSP) || defined(SDL) || defined(IPHONE) sprintf(Config.BiosDir, "%s/Media/ROMs/PSX/", appworkdir); sprintf(Config.Bios, "scph1001.bin"); sprintf(Config.Mcd1, "mcd001.mcr"); sprintf(Config.Mcd2, "mcd002.mcr"); #else sprintf(Config.BiosDir, PSX4ALL_STR, gamepath); sprintf(Config.Bios, "/bios/scph1000.bin"); sprintf(Config.Mcd1, "%s/memory_card/mcd001.mcr", gamepath); sprintf(Config.Mcd2, "%s/memory_card/mcd002.mcr", gamepath); #endif gp2x_init(900, 16, 11025, 16, 1, 60, 1); #ifndef GP2X gp2x_video_flip_single(); #endif #ifdef IPHONE u32 loadsvs = 0; linesInterlace_user = preferences.interlace; skipCount = skipCountTablePhone[preferences.frameSkip]; skipRate = skipRateTablePhone[preferences.frameSkip]; iSoundMuted = preferences.muted; Config.Cdda = preferences.muted; Config.Xa = preferences.muted; #ifdef WITH_HLE Config.HLE = !preferences.bios; #else Config.HLE = 0; #endif if( (!strcasecmp(filename + (strlen(filename)-4), FORMAT_SV )) ) { u32 pos; loadsvs = 1; sprintf(svsfilename, PSX4ALL_STR, filename); sprintf(iphonefile, PSX4ALL_STR, filename); pos = strlen(iphonefile)-18; iphonefile[pos] = '\0'; packfile = iphonefile; } else { loadsvs = 0; sprintf(iphonefile, PSX4ALL_STR, filename); packfile = iphonefile; } gp2x_video_RGB_clearscreen16(); LoadCdBios = 0; if (SysInit() == -1) { gp2x_deinit(); return 0; } if (InitComponents() == -1) { gp2x_deinit(); return 0; } SysReset(); CheckCdrom(); if( Config.HLE ) { LoadCdBios = 0; if( LoadCdrom() == -1 ) { gp2x_printf(NULL, 120, 120, PSX4ALL_LDD); gp2x_video_flip(); gp2x_timer_delay(2000); gp2x_video_RGB_clearscreen16(); return 0; } } if (loadsvs) { if( LoadState(svsfilename) == -1 ) { gp2x_printf(NULL, 120, 120, PSX4ALL_LSF); gp2x_video_flip(); gp2x_timer_delay(2000); gp2x_video_RGB_clearscreen16(); psxShutdown(); CloseComponents(); gp2x_deinit(); pthread_exit(NULL); } } psx4all_emulating=1; psx4all_prof_start(PROFILER_TOTAL); psxCpu->Execute(); psx4all_prof_end(PROFILER_TOTAL); psx4all_emulating=0; psx4all_prof_show(); #else if( 0 != SelectGame() ) { psx4all_emulating=1; psx4all_prof_start(PROFILER_TOTAL); psxCpu->Execute(); psx4all_prof_end(PROFILER_TOTAL); psx4all_emulating=0; psx4all_prof_show(); } #endif gp2x_deinit(); return 0; }
int main( void ) { SysInit(); LedInit(); BatteryInit(); ComInit(); TimerInit(); INTEN while(1) { if(TimerGetTimeFlag() > 10) { TimerClearTimeFlag(); BattertSleep(); } if(TimerGetBatteryFlag() > 0x01) { TimerClearBatteryFlag(); if(BatterGetFlag() == 0) { BatterSetFlag(1); BattertGet(); ComWatchSendCmd(dce_powe,BattertGetLevel(),0x00,0x00); } } LedTimeService(); if(ComWatchGetFlag() == 0x80) { ComWatchClearFlag(); TimerClearTimeFlag(); BattertOpen(); BatterSetFlag(0);//可以获取电量 if(ComWatchGetData(0) != 0x00) { BattertOpen(); } LedSetModeFlicker(1); if(BattertGetLevel() > 0) { switch(ComWatchGetData(0)) {//电量不足 case front: switch(ComWatchGetData(1)) { case add_stal:ComRearSendCmd(add_stal,0x00,0x00,0x00);break; case sub_stal:ComRearSendCmd(sub_stal,0x00,0x00,0x00);break; case add_setp:ComRearSendCmd(add_setp,0x00,0x00,0x00);break; case sub_setp:ComRearSendCmd(sub_setp,0x00,0x00,0x00);break; case set_inti:ComRearSendCmd(set_inti,0x00,0x00,0x00);break; } break; case behind: switch(ComWatchGetData(1)) { case exchange_stal: ComBehindSendCmd(exchange_stal,0x00,0x00,0x00);break; case add_setp:ComBehindSendCmd(add_setp,0x00,0x00,0x00);break; case sub_setp:ComBehindSendCmd(sub_setp,0x00,0x00,0x00);break; case set_inti:ComBehindSendCmd(set_inti,0x00,0x00,0x00);break; } break; default:break; } } else { } } if(ComRearGetFlag() == 0x80) { ComRearClearFlag(); switch(ComRearGetData(0)) { case dce_gear: ComBehindSendCmd(ask_rear,ComRearGetData(1),0x00,0x00); ComWatchSendCmd(behind,dce_gear,ComRearGetData(1),BattertGetLevel()); break; case stuck: ComWatchSendCmd(stuck,dce_gear,ComRearGetData(1),BattertGetLevel()); break; default:break; } } if(ComBehindGetFlag() == 0x80) { ComBehindClearFlag(); switch(ComBehindGetData(0)) { case dce_gear: ComWatchSendCmd(front,dce_gear,ComBehindGetData(1),BattertGetLevel()); break; case stuck: ComWatchSendCmd(stuck,dce_gear,ComBehindGetData(1),BattertGetLevel()); break; default:break; } } } }
/*---------------------------------------------------------------------------------------------------------*/ I2C_Loopback (void) { uint32_t i; /* Init System, IP clock and multi-function I/O */ SysInit(); /* Init UART to 115200-8n1 for print message */ UART_Open(UART0, 115200); printf("+-------------------------------------------------------+\n"); printf("| Nano1x2 Series I2C Cross Test Sample Code |\n"); printf("+-------------------------------------------------------+\n"); printf(" I/O Configuration:\n"); printf(" SCK: GPC0 <--> GPC2\n"); printf(" SDA: GPC1 <--> GPC3\n"); printf("\n\n"); printf("..... Press a key to continue ...\n"); UART_GetChar(); /* Configure I2C0 as master and I2C1 as slave */ I2C0_Init(); I2C1_Init(); for (i = 0; i < 0x100; i++) { g_u8SlvData[i] = 0; } /* I2C function to Slave receive/transmit data */ s_I2C1HandlerFn = (I2C_FUNC)I2C_SlaveTRx; g_u8DeviceAddr = SLAVE_ADDRESS; printf("Test Loop =>"); for (i = 0; i < 0x100; i++) { printf("%d..", i); g_au8MasterTxData[0] = (uint8_t)((i & 0xFF00) >> 8); g_au8MasterTxData[1] = (uint8_t)(i & 0x00FF); g_au8MasterTxData[2] = (uint8_t)(g_au8MasterTxData[1] + 3); g_u8MasterDataLen = 0; g_u8EndFlag = 0; /* I2C function to write data to slave */ s_I2C0HandlerFn = (I2C_FUNC)I2C_MasterTx; /* I2C as master sends START signal */ I2C_SET_CONTROL_REG(I2C0, I2C_STA); /* Wait I2C Tx Finish */ while (g_u8EndFlag == 0); g_u8EndFlag = 0; /* I2C function to read data from slave */ s_I2C0HandlerFn = (I2C_FUNC)I2C_MasterRx; g_u8MasterDataLen = 0; g_u8DeviceAddr = SLAVE_ADDRESS; /* I2C as master sends START signal */ I2C_SET_CONTROL_REG(I2C0, I2C_STA); /* Wait I2C Rx Finish */ while (g_u8EndFlag == 0); /* Compare Tx and Rx data */ if (g_u8MasterRxData != g_au8MasterTxData[2]) { printf("I2C Byte Write/Read Failed, Data 0x%x\n", g_u8MasterRxData); return -1; } printf("[OK]\n"); } printf("\nTest Completely !!\n"); while(1); }