示例#1
0
int main(void)
{
    // Hardware Init
    delay_init();	    	 //ÑÓʱº¯Êý³õʼ»¯
    pwr_init();
    #ifdef YANMING3
    charger_init();
    if (check_standby_flag() == SUCCESS && check_charging() != CHARGING) {
        Key_GPIO_Config();
        exti_key_init();
        #ifdef DEBUG_POWER_OFF_WAKE_UP
        Screen_Init();
        OLED_Clear();
        OLED_Display_On();
        draw_about_mesage();
        #endif
        check_standby_wakeup_button_press();
        // If we boot up from standby by pressing 5 times, the system will reboot again without
        // this code block.
    }
    #endif

    // OLED Init
    Screen_Init();
    OLED_Clear();
    
    //
    low_switch_power_init();

    TIMx_Int_DeInit();
    EXTIX_DeInit();
    
    // Key
    Key_GPIO_Config();
    
    // PID related code
    ADC1_Configuration();
    PWM_Configuration();
    VoltagePID_Init();

    TIMx_Int_Init();
    rtc_init();

    // Our Init
    system_init();
    #ifndef YANMING3
    //iwdg_init();
    #endif

    while(1) {
        #ifndef YANMING3
        //iwdg_feed();
        #endif
        task_schedule();
    }
}
示例#2
0
文件: main.c 项目: Lewis-Liu-1/os_diy
int
main(void)
{
   Intr_Init();
   Intr_SetFaultHandlers(SVGA_DefaultFaultHandler);
   SVGA_Init();
   GMR_Init();
   Heap_Reset();
   SVGA_SetMode(0, 0, 32);
   Screen_Init();

   SVGAScreenObject myScreen = {
      .structSize = sizeof(SVGAScreenObject),
      .id = 0,
      .flags = SVGA_SCREEN_HAS_ROOT | SVGA_SCREEN_IS_PRIMARY,
      .size = { 1600, 1200 },
      .root = { -1234, 5678 },
   };
   Screen_Define(&myScreen);

   const uint32 gmrId = 0;
   uint32 numPages = 1 + (myScreen.size.width * myScreen.size.height *
                          sizeof(uint32)) / PAGE_SIZE;

   PPN pages = GMR_DefineEvenPages(gmrId, numPages);

   const uint32 bitsPerPixel = 32;
   const uint32 colorDepth = 24;
   const uint32 bytesPerLine = myScreen.size.width * sizeof(uint32);

   const SVGAGMRImageFormat format = {{{
      .bitsPerPixel = bitsPerPixel,
      .colorDepth = colorDepth,
   }}};
示例#3
0
void	Hardware_Init( void )
{
	System_Init();
	Vbl_Init();
	Video_Init();
	IKBD_Init();
	Graphic_Init();
	Screen_Init();
}
示例#4
0
void	Test_Loop( void )
{
	Screen_Init();

	Box_Render();

	while( !IKBD_GetKeyStatus(eIKBDSCAN_SPACE) )
	{
	}

	Screen_DeInit();
}
示例#5
0
文件: main.c 项目: Lewis-Liu-1/os_diy
int
main(void)
{
   static FPSCounterState fps;
   uint32 frameFence = 0;
   uint32 nextFence;

   Intr_Init();
   Intr_SetFaultHandlers(SVGA_DefaultFaultHandler);
   SVGA_Init();
   GMR_Init();
   Heap_Reset();
   SVGA_SetMode(0, 0, 32);
   SVGA3D_Init();
   Screen_Init();
   ScreenDraw_Init(0);

   initScreens();
   setup3D();

   /*
    * One big circle, and a smaller one that overlaps the top-right
    * corner.  (This tests positive and negative clipping extremes.)
    */
   prepareCircle(&circles[0], 650, 400, 300);
   prepareCircle(&circles[1], 1000, 50, 250);

   while (1) {
      if (SVGA3DUtil_UpdateFPSCounter(&fps)) {
         Console_MoveTo(900, 730);
         Console_Format("%s    ", fps.text);
      }

      drawCube();

      /*
       * Flow control- one frame in the FIFO at a time.
       */
      nextFence = SVGA_InsertFence();
      SVGA_SyncToFence(frameFence);
      frameFence = nextFence;

      present();
   }

   return 0;
}
示例#6
0
int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);

 	// TODO: Place code here.
	MSG msg;
	HACCEL hAccelTable;

	// Handle XP stupidity
	InitCommonControls();

	// Initialize global strings
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	LoadString(hInstance, IDC_PROJCONTROL, szWindowClass, MAX_LOADSTRING);
	MyRegisterClass(hInstance);

	// Init the screen mirror controller
	Screen_Init(hInstance);

	// Perform application initialization:
	if (!InitInstance (hInstance, nCmdShow))
	{
		return FALSE;
	}

	hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_PROJCONTROL));

	// Main message loop:
	while (GetMessage(&msg, NULL, 0, 0))
	{
		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

	return (int) msg.wParam;
}
示例#7
0
void	Test_Loop( void )
{
	Screen_Init();

	gpPicture = File_Load( "RGLOGO.PI1" );

	if( gpPicture )
	{
		Memory_Copy( 32000L, &gpPicture->Pixels[ 0 ], gpPhysic );
		Video_SetNextPalST( &gpPicture->Header.Palette[ 0 ] );

		while( !IKBD_GetKeyStatus(eIKBDSCAN_SPACE) )
		{
		}
	}

	File_UnLoad( gpPicture );

	Screen_DeInit();
}
示例#8
0
int NDS_Init( struct armcpu_memory_iface *arm9_mem_if,
struct armcpu_ctrl_iface **arm9_ctrl_iface,
struct armcpu_memory_iface *arm7_mem_if,
struct armcpu_ctrl_iface **arm7_ctrl_iface) {
#else
int NDS_Init( void) {
#endif
	nds.ARM9Cycle = 0;
	nds.ARM7Cycle = 0;
	nds.cycles = 0;
	nds.idleFrameCounter = 0;
	memset(nds.runCycleCollector,0,sizeof(nds.runCycleCollector));
	MMU_Init();
	nds.nextHBlank = 3168;
	nds.VCount = 0;
	nds.lignerendu = FALSE;

	if (Screen_Init(GFXCORE_DUMMY) != 0)
		return -1;

	gfx3d_init();

#ifdef GDB_STUB
	armcpu_new(&NDS_ARM7,1, arm7_mem_if, arm7_ctrl_iface);
	armcpu_new(&NDS_ARM9,0, arm9_mem_if, arm9_ctrl_iface);
#else
	armcpu_new(&NDS_ARM7,1);
	armcpu_new(&NDS_ARM9,0);
#endif

	if (SPU_Init(SNDCORE_DUMMY, 740) != 0)
		return -1;

#ifdef EXPERIMENTAL_WIFI
	WIFI_Init(&wifiMac) ;
#endif

	return 0;
}
示例#9
0
LOCALFUNC blnr InitOSGLU(void)
{
	DS_SysInit();

	if (AllocMyMemory())
#if dbglog_HAVE
	if (dbglog_open())
#endif
	if (LoadMacRom())
	if (LoadInitialImages())
	if (InitLocationDat())
#if MySoundEnabled
	if (MySound_Init())
#endif
	if (Screen_Init())
	if (KC2MKCInit())
	if (WaitForRom())
	{
		return trueblnr;
	}

	return falseblnr;
}
示例#10
0
void	Test_Loop( void )
{
	sGraphicPos	lPos;
	S16			lAddX,lAddY;
	sSprite *	lpSprite;

	Screen_Init();

	gpPicture = File_Load( "SPRITE.PI1" );

	if( gpPicture )
	{
		Video_SetPalST( &gpPicture->Header.Palette[ 0 ] );

		lPos.X = 0;
		lPos.Y = 0;

		lAddX  = 1;
		lAddY  = 1;

		lpSprite = Sprite_Create(
			&gpPicture->Pixels[ 0 ],
			&gpPicture->Pixels[ 0 ],
			16,
			16,
			4,
			0 );

		while( !IKBD_GetKeyStatus(eIKBDSCAN_SPACE) )
		{
			Screen_Swap();

			gGraphic.pVRAM = gpLogic;
			gGraphic.pFuncs->ClearScreen( &gGraphic );

			gGraphic.pClipFuncs->DrawSprite(
				&gGraphic,
				&lPos,
				lpSprite );

			if( lAddX > 0 )
			{
				lPos.X++;
				if( lPos.X > (320-16) )
				{
					lPos.X = 320-16;
					lAddX  = -1;
				}
			}
			else
			{
				lPos.X--;
				if( lPos.X < 0 )
				{
					lPos.X = 0;
					lAddX  = 1;
				}
			}

			if( lAddY > 0 )
			{
				lPos.Y++;
				if( lPos.Y > (200-16) )
				{
					lPos.Y = 200-16;
					lAddY  = -1;
				}
			}
			else
			{
				lPos.Y--;
				if( lPos.Y < 0 )
				{
					lPos.Y = 0;
					lAddY  = 1;
				}
			}


		}
	}

	File_UnLoad( gpPicture );

	Screen_DeInit();
}
示例#11
0
文件: main.c 项目: Lewis-Liu-1/os_diy
int
main(void)
{
   uint32 frame = 0;
   uint32 lastTick = 0;

   Intr_Init();
   Intr_SetFaultHandlers(SVGA_DefaultFaultHandler);

   Timer_InitPIT(PIT_HZ / FRAME_RATE);
   Intr_SetMask(PIT_IRQ, TRUE);
   Intr_SetHandler(IRQ_VECTOR(PIT_IRQ), timerISR);

   SVGA_Init();
   GMR_Init();
   Heap_Reset();
   SVGA_SetMode(0, 0, 32);
   Screen_Init();
   ScreenDraw_Init(GMRID_SCREEN_DRAW);

   allocNoise();

   /*
    * Define a screen.
     */

   SVGAScreenObject myScreen = {
      .structSize = sizeof(SVGAScreenObject),
      .id = SCREEN_ID,
      .flags = SVGA_SCREEN_HAS_ROOT | SVGA_SCREEN_IS_PRIMARY,
      .size = { 800, 600 },
      .root = { 0, 0 },
   };
   Screen_Define(&myScreen);

   /*
    * Draw some explanatory text.
    */

   char docString[] =
      "Annotated Blit Sample:"
      "\n\n"
      "You should see two moving rectangles. The left one is animated "
      "using a fill-annotated blit. The blit itself contains random "
      "noise, but the annotation is a blue fill. If your host is "
      "using the annotation, you will see the blue. If not, you'll "
      "see noise. Either one is correct, but it is often more efficient "
      "to use the fill."
      "\n\n"
      "The right one is a copy-annotated blit. The blit data is again "
      "random noise, and the copy is a screen-to-screen copy which "
      "moves the rectangle from its old position to the new position. "
      "We drew a checkerboard pattern to the screen once, and that "
      "pattern should be preserved indefinitely if the annotation is "
      "being executed correctly."
      "\n\n"
      "Both rectangles should have a 1-pixel solid white border, and "
      "in both cases we use a fill-annotated blit to clear the screen "
      "behind each rectangle. This annotation doesn't lie, its blit data "
      "matches the advertised fill color.";

   ScreenDraw_SetScreen(myScreen.id, myScreen.size.width, myScreen.size.height);
   Console_Clear();
   ScreenDraw_WrapText(docString, 770);
   Console_WriteString(docString);

   /*
    * Animate the two rectangles indefinitely, sleeping between frames.
    */

   while (1) {
      SVGASignedRect oldRect1, oldRect2;
      SVGASignedRect newRect1, newRect2;

      /*
       * Move them around in a circle.
       */

      float theta = frame * 0.01;

      newRect1.left = 190 + cosf(theta) * 60;
      newRect1.top = 350 + sinf(theta) * 60;
      newRect1.right = newRect1.left + 80;
      newRect1.bottom = newRect1.top + 120;

      newRect2.left = 530 + sinf(theta) * 60;
      newRect2.top = 350 + cosf(theta) * 60;
      newRect2.right = newRect2.left + 80;
      newRect2.bottom = newRect2.top + 120;

      /*
       * Update the position of each.
       */

      updateFillRect(frame ? &oldRect1 : NULL, &newRect1);
      updateCopyRect(frame ? &oldRect2 : NULL, &newRect2);

      oldRect1 = newRect1;
      oldRect2 = newRect2;

      /*
       * Wait for the next timer tick.
       */

      while (timerTick == lastTick) {
         Intr_Halt();
      }
      lastTick = timerTick;
      frame++;
   }

   return 0;
}
示例#12
0
文件: main.c 项目: kfreezen/kos
int kmain(UInt32 initial_stack, MultibootHeader* mboot, UInt32 mboot_magic) {
	initial_esp = initial_stack;
	
	CLI_Init();
	Cls();
	
	UInt32 initrd_end = *(UInt32*)(mboot->mods_addr+4);
	
	placement_address = (Pointer) initrd_end;
	
	// Set up our new stack here.
	//UInt32 stack = (UInt32) kmalloc_a(8192, TRUE);
	MultibootHeader* mboot_hdr = mboot; //kmalloc(sizeof(MultibootHeader));
	//memcpy(mboot_hdr, mboot, sizeof(MultibootHeader));
	
	kprintf("Starting init...\n");

	//new_start(stack, mboot_hdr);
	GDT_Init();
	IDT_Init();
	ISR_Init();
	asm volatile("sti");
	
	kprintf("Basics\t\t\t[OK]\n");

	PIT_Init(PIT_MSTIME);

	kprintf("PIT\t\t\t[OK]\n");

	init_kheap();
	InitPaging((mboot_hdr->mem_lower+mboot_hdr->mem_upper)&~3);
	InitKernelHeap();

	kprintf("Heap\t\t\t[OK]\n");

	VFS_Init();
	DevFS_Init();
	
	kprintf("VFS\t\t\t[OK]\n");

	DriversInit();

	kprintf("Drivers\t\t\t[OK]\n");

	Screen_Init();

	FloppyInit();

	checkAllBuses();
	DumpPCIDeviceData();
	kprintf("PCI\t\t\t[OK]\n");

	/*kprintf("Keyboard Init... ");
	KB_Init(0);
	kprintf("[ok]\n");*/

	FAT12_Init(FAT12_GetContext(FloppyGetDevice()), "/", "sys");
	
	InitTasking();

	KernelSymbolsLoad();

	//Cls();

	kprintf("kOS v0.6.13\n");

	VFS_Node* rd = GetNodeFromFile(GetFileFromPath("/sys"));
	kprintf("rd = %x\n", rd);
	
	ArrayList* list = ListFiles(rd);
	ALIterator* itr = ALGetItr(list);

	while(ALItrHasNext(itr)) {
		VFS_Node* node = ALItrNext(itr);
		kprintf("file: %s\n", node->name);
	}

	ALFreeItr(itr);
	
	ALFreeList(list);

	//kprintf("kprintf symbol = %x\n", getKernelSymbol("kprintf"));
	File* initScript = GetFileFromPath("/sys/init.script");
	FileSeek(0, initScript); // Due to these being global objects, we have to do such ugly things as this.

	#ifdef INIT_DEBUG
	kprintf("initScript=%x\n", initScript);
	#endif

	char* lineBuf = kalloc(256);
	int doBreak = 0;
	while(!doBreak) {
		if(fgetline(initScript, lineBuf, 256, '\n')==-1) {
			if(strlen(lineBuf) > 0) {
				doBreak = 1;
			} else {
				break; // We've processed everything that needs to be processed.
			}
		}

		// Now parse it.
		char* tok = strtok(lineBuf, " ");
		kprintf("%s, %x\n", tok,tok);
		if(!strcmp(tok, "load_driver")) {
			#ifdef INIT_DEBUG
			kprintf("load_driver ");
			#endif

			tok = strtok(NULL, " ");

			// Load the driver specified.
			File* drv = GetFileFromPath(tok);
			if(drv != NULL) {
				int drvLength = FileSeek(SEEK_EOF, drv);
				FileSeek(0, drv);
				void* drvBuf = kalloc(drvLength);

				#ifdef INIT_DEBUG
				kprintf("%s\n", GetNodeFromFile(drv)->name);
				#endif

				ReadFile(drvBuf, drvLength, drv);
				ELF* elf = LoadKernelDriver(drvBuf);

				#ifdef INIT_DEBUG
				kprintf("elf->start=%x\n", elf->start);
				#endif

				if(elf->error == 0) {
					void (*driverInit)() = (void (*)()) elf->start;
					driverInit();
				}

				kfree(drvBuf);
				drvBuf = NULL;

				CloseFile(drv);
			}
		}
	}

	CloseFile(initScript);
	kfree(lineBuf);

	kprintf("Kernel init done...\n");

	File* elf = GetFileFromPath("/sys/helloworld");
	
	FileSeek(SEEK_EOF, elf);
	int length = FileTell(elf);
	FileSeek(0, elf);
	UInt8* elfBuf = kalloc(length);
	ReadFile(elfBuf, length, elf);
	ELF* elfExe = Parse_ELF(elfBuf);
	CreateTaskFromELF(elfExe);

	// Kernel main logic loop
	while(1) {
		asm volatile("hlt");
	}

	return 0;
}
示例#13
0
// ---------------------------------------------------------------------------
int main(int argc, char* argv[]) {
 signal(SIGINT, (sig_t)cleanup);

 // load settings file
 char* settings_file = NULL;
 int settings = 0;
 if(argc == 2) {
   settings_file = argv[1];
   settings = Settings_Load(argv[1]);
 } 
 if(!settings) {
   settings_file = "default.conf";
   if(!Settings_Load("default.conf")) {
      printf("%s\r\n", _lng(ERROR_LOADING_SETTINGS));
      return 0;
   }
 }

 // load settings
 FW_VERSION = Settings_Get("gui", "version");
 SONG_FILE = Settings_Get("files", "song");
 CURRENT_STATION_FILE = Settings_Get("files", "current_station");
 STATIONS_FILE = Settings_Get("files", "stations");
 USB_PATH = Settings_Get("files", "usb");
 
 // check for running instance
 char* single_instance_cmd = Settings_Get("programs", "check_running");
 ignore_result(system(single_instance_cmd));
 FILE *running = fopen("fw.running", "r");
 if(running == NULL) {
   printf("Cannot check if firmware is running, aborting.\r\n");
   exit(0);
 }
 if(fgetc(running) >= '2') {
   fclose(running);
   printf("Firmware is already running!\r\nExiting...\r\n");
   exit(0);
 } else {
   fclose(running);
 }
 

 if(strcmp(Settings_Get("hardware", "io"), "sim") == 0) IO_SetSimulate(1);
 if(strcmp(Settings_Get("hardware", "lcd"), "sim") == 0) GLCDD_SetSimulate(1);
 else if(strcmp(Settings_Get("hardware", "lcd"), "bmp") == 0) GLCDD_SetSimulate(2);
  
 GLCDD_Init();
 IO_Init();

 Language_Init(Settings_Get("gui", "language"));
 Screen_Init(silkscreen_8);
 
 Screen screen = SCREEN_MAIN;
 
 // create fonts
 fnt_dejavu_9 = createFont(dejavu_9);
 fnt_dejavu_9b = createFont(dejavu_9_b);
 fnt_silkscreen_8 = createFont(silkscreen_8);
 
 // register screens
 Screen_Add(SCREEN_MAIN, init_Main, draw_Main, exit_Main);
 Screen_Add(SCREEN_NOW_PLAYING, init_NowPlaying, draw_NowPlaying, exit_NowPlaying);
 Screen_Add(SCREEN_STATIONS, init_Stations, draw_Stations, exit_Stations);
 Screen_Add(SCREEN_INFO, NULL, draw_Info, NULL);
 Screen_Add(SCREEN_USB, init_USB, draw_USB, NULL);
 Screen_Add(SCREEN_SHUTDOWN, init_Shutdown, draw_Shutdown, NULL);
 Screen_Add(SCREEN_SETTINGS, init_Settings, draw_Settings, exit_Settings);
 Screen_Add(SCREEN_WIFI_SCAN, init_WifiScan, draw_WifiScan, exit_WifiScan);
 Screen_Add(SCREEN_WIFI_AUTH, init_WifiAuth, draw_WifiAuth, NULL);
 Screen_Add(SCREEN_WIFI_CONNECT, init_WifiConnect, draw_WifiConnect, NULL);
 Screen_Add(SCREEN_LANGUAGE, init_Language, draw_Language, exit_Language);
 Screen_Add(SCREEN_VOLUME, init_Volume, draw_Volume, NULL);
 Screen_Add(SCREEN_SHOUTCAST, init_Shoutcast, draw_Shoutcast, exit_Shoutcast);
 Screen_Add(SCREEN_SHOUTCAST_LIST, init_ShoutcastList, draw_ShoutcastList, exit_ShoutcastList);
 Screen_Add(SCREEN_SHOUTCAST_GENRE, init_ShoutcastGenre, draw_ShoutcastGenre, exit_ShoutcastGenre);
 Screen_Add(SCREEN_SHOUTCAST_SEARCH, init_ShoutcastSearch, draw_ShoutcastSearch, NULL);
 Screen_Add(SCREEN_MANAGE_STATION, init_ManageStation, draw_ManageStation, exit_ManageStation);
 Screen_Add(SCREEN_SNOOZE, init_Snooze, draw_Snooze, exit_Snooze);
 Screen_Add(SCREEN_TIMEOUT, init_Timeout, draw_Timeout, NULL);
 Screen_SetRefreshTimeout(SCREEN_INFO, 2);
 Screen_SetRefreshTimeout(SCREEN_MAIN, 10);
 Screen_SetRefreshTimeout(SCREEN_NOW_PLAYING, 1);
 Screen_SetRefreshTimeout(SCREEN_STATIONS, 10);
 Screen_SetRefreshTimeout(SCREEN_USB, 1);
 Screen_SetRefreshTimeout(SCREEN_SHUTDOWN, 10);
 Screen_SetRefreshTimeout(SCREEN_WIFI_SCAN, 1); 
 Screen_SetRefreshTimeout(SCREEN_WIFI_AUTH, 10);
 Screen_SetRefreshTimeout(SCREEN_WIFI_CONNECT, 1);
 Screen_SetRefreshTimeout(SCREEN_LANGUAGE, 10);
 Screen_SetRefreshTimeout(SCREEN_VOLUME, 10);
 Screen_SetRefreshTimeout(SCREEN_SHOUTCAST, 10);
 Screen_SetRefreshTimeout(SCREEN_SHOUTCAST_LIST, 10);
 Screen_SetRefreshTimeout(SCREEN_SHOUTCAST_GENRE, 10);
 Screen_SetRefreshTimeout(SCREEN_SHOUTCAST_SEARCH, 10);
 Screen_SetRefreshTimeout(SCREEN_MANAGE_STATION, 10);
 Screen_SetRefreshTimeout(SCREEN_SNOOZE, 10);
 Screen_SetRefreshTimeout(SCREEN_TIMEOUT, 10);
 Screen_ShowLoadingScreen(SCREEN_USB, 1);
 Screen_ShowLoadingScreen(SCREEN_VOLUME, 1);
 Screen_ShowLoadingScreen(SCREEN_SHOUTCAST_LIST, 1);
 Screen_ShowLoadingScreen(SCREEN_SHOUTCAST_GENRE, 1);
 
  
 // reset song info
 resetMetaInfo();
 
 // start ui
 Screen_Goto(SCREEN_MAIN);
 
 // background light
 GLCDD_BacklightTimeout(atoi(Settings_Get("hardware", "timeout")));
 int keep_light_when_playing = 0;
 if(strcmp(Settings_Get("gui", "keep_light_when_playing"), "true") == 0) keep_light_when_playing = 1;
 GLCDD_BacklightReset();
 
 uint64_t last_io = 0;
 
 while(1) {

#ifndef SIMULATE
  if(getTimeMillisecond() - last_io >= 25) {
    IO_Get();
    last_io = getTimeMillisecond();
  }
#else
  IO_Get();
#endif
  if(IO_HasChanged()) {
    Screen_ForceRedraw();
    GLCDD_BacklightReset();
  }
  
  screen = Screen_GetActive();
  
  // ---------------------------------------------------------------------------
  if(screen == SCREEN_MAIN) {
    int selection = Menu_IsChosen(menu_main);
    if(selection == 0) {
      // goto now playing screen
      Screen_Goto(SCREEN_NOW_PLAYING);
    } else if(selection == 1) {
      // goto stations screen
      Screen_Goto(SCREEN_STATIONS);	
    } else if(selection == 2) {
      // goto shoutcast browser
      Screen_Goto(SCREEN_SHOUTCAST);
    } else if(selection == 3) {
      // goto usb screen
      Screen_Goto(SCREEN_USB);
    } else if(selection == 4) {
      // goto info screen
      Screen_Goto(SCREEN_SETTINGS);
    }
  }
  // ---------------------------------------------------------------------------
  else if(screen == SCREEN_INFO) {
    if(IO_GetButton(0)) {
      Screen_Goto(SCREEN_SETTINGS);
    }
  }
  // ---------------------------------------------------------------------------
  else if(screen == SCREEN_STATIONS) {
    int selection = Menu_IsChosen(menu_stations);
    if(selection != -1) {
      // start station
      playStation(Menu_GetItemTag(menu_stations, selection));
    }
    
    // add station as favorite
    if(IO_GetButtonLong(3)) asFavorite(1);
    if(IO_GetButtonLong(4)) asFavorite(2);
    if(IO_GetButtonLong(5)) asFavorite(3);
    if(IO_GetButtonLong(6)) asFavorite(4);
  }
  // ---------------------------------------------------------------------------
  else if(screen == SCREEN_NOW_PLAYING) {
    // if at now playing screen, backlight is always on
    if(keep_light_when_playing) GLCDD_BacklightReset(); 
  }
  // ---------------------------------------------------------------------------
  else if(screen == SCREEN_SETTINGS) {
      int selection = Menu_IsChosen(menu_settings);
      if(selection == 0) {
	// goto info screen
	Screen_Goto(SCREEN_INFO);
      } else if(selection == 1) {
	// goto wifi scanning screen
	Screen_Goto(SCREEN_WIFI_SCAN);
      } else if(selection == 2) {
	// goto language selection
	Screen_Goto(SCREEN_LANGUAGE);
      } else if(selection == 3) {
	// goto volume adjustment
	Screen_Goto(SCREEN_VOLUME);
      } else if(selection == 4) {
	// goto backlight timeout
	Screen_Goto(SCREEN_TIMEOUT);
      } else if(selection == 5) {
	// goto station manager
	Screen_Goto(SCREEN_MANAGE_STATION);
      } else if(selection == 6) {
	// restart firmware
	// stop all music
	stopMusic();
	// kill all streams
	ignore_result(system(Settings_Get("programs", "killall")));
	// restart self
	execv(argv[0], argv);
      } else if(selection == 7) {
	// shutdown
	Screen_Goto(SCREEN_SHUTDOWN); 
      }
  }
  // ---------------------------------------------------------------------------
  else if(screen == SCREEN_WIFI_SCAN) {
      int selection = Menu_IsChosen(menu_wifi_scan);
      if(selection != -1) {
	// save ssid
	Settings_Add("wifi", "ssid", Menu_GetItemText(menu_wifi_scan, selection));
	// go to authentification
	Screen_Goto(SCREEN_WIFI_AUTH);
      }
  }
  // ---------------------------------------------------------------------------
  else if(screen == SCREEN_WIFI_AUTH) {
      if(Keyboard_IsConfirmed()) {
	// connect to wifi network
	Settings_Add("wifi", "pwd", Keyboard_GetText());
	printf("Connecting to '%s' with key '%s'\r\n", Settings_Get("wifi", "ssid"), Settings_Get("wifi", "pwd"));
	Screen_Goto(SCREEN_WIFI_CONNECT);
      }
  }
  // ---------------------------------------------------------------------------
  else if(screen == SCREEN_LANGUAGE) {
      // change language
      int selection = Menu_IsChosen(menu_language);
      if(selection != -1) {
	char disp[64];
	int i;
	strcpy(disp, Menu_GetItemText(menu_language, selection));
	for(i = strlen(disp) - 1; i >= 0; i--) {
	  if(disp[i] == ')') disp[i] = 0;
	  if(disp[i] == '(') {
	   i++;
	   break;
	  }
	}
	Settings_Add("gui", "language", &disp[i]);
	Language_Cleanup();
	Language_Init(&disp[i]);
	Settings_Save(settings_file);
	Screen_Goto(SCREEN_SETTINGS);
      }
  }
  // ---------------------------------------------------------------------------
  else if(screen == SCREEN_VOLUME) {
      if(IO_GetButton(0)) {
	// go back to settings
	Screen_Goto(SCREEN_SETTINGS);
      }
  }
  // ---------------------------------------------------------------------------
  else if(screen == SCREEN_SHOUTCAST) {
      int selection = Menu_IsChosen(menu_shoutcast);
      if(selection == 0) {
	// go to shoutcast top stations
	setShoutcastListUrl(Settings_Get("shoutcast", "list_url"));
	printf("'%s'\r\n", Settings_Get("shoutcast", "list_url"));
	setStationsParentGenre("X");
	setCurrentGenre(" ");
	Screen_Goto(SCREEN_SHOUTCAST_LIST);
      } 
      else if(selection == 1) { 
	// random station
	setShoutcastListUrl(Settings_Get("shoutcast", "random_url"));
	setStationsParentGenre("X");
	setCurrentGenre(" ");
	Screen_Goto(SCREEN_SHOUTCAST_LIST);
      }
      else if(selection == 2) {
	// go to genre list
	setShoutcastGenreParent("0");
	Screen_Goto(SCREEN_SHOUTCAST_GENRE);
      }
      else if(selection == 3) {
	// go to station search
	Screen_Goto(SCREEN_SHOUTCAST_SEARCH);
      }
  }
  // ---------------------------------------------------------------------------
  else if(screen == SCREEN_SHOUTCAST_GENRE) {
      int selection = Menu_IsChosen(menu_genres);
      if(selection != -1) {
	if(selection == 0) { // back
	  if(strcmp(getShoutcastGenreParent(), "0") == 0) { // main genres
	    Screen_Goto(SCREEN_SHOUTCAST);
	  } else { // sub genre -> go back to main genres
	    setShoutcastGenreParent("0");
	    Screen_Goto(SCREEN_SHOUTCAST_GENRE);
	  }
	} else { // list stations or sub genre
	  ShoutcastGenre* info = getChosenGenre((int)Menu_GetItemTag(menu_genres, selection));
	  // show sub genres
	  if(info->has_children) {
	    setStationsParentGenre(info->id);
	    setShoutcastGenreParent(info->id);
	    Screen_Goto(SCREEN_SHOUTCAST_GENRE);
	  } else { // show stations
	    char buffer[128];
	    sprintf(buffer, Settings_Get("shoutcast", "stations_by_genre_url"), info->name);
	    setShoutcastListUrl(buffer);
	    setCurrentGenre(info->name);
	    Screen_Goto(SCREEN_SHOUTCAST_LIST);
	  }
	}
      }
  }
  // ---------------------------------------------------------------------------
  else if(screen == SCREEN_SHOUTCAST_LIST) {
      if(Menu_GetAutoIO(menu_station_list)) {
	int selection = Menu_IsChosen(menu_station_list);
	if(selection != -1) {
	  if(selection == 0) { // back
	      if(strcmp(getStationsParentGenre(), "X") == 0) { // go to shoutcast menu
		Screen_Goto(SCREEN_SHOUTCAST); 
	      } else { // go to genre list
		setShoutcastGenreParent(getStationsParentGenre());
		Screen_Goto(SCREEN_SHOUTCAST_GENRE);
	      }
	  } else { // show play/as_favorite/cancel menu
	      Menu_SetAutoIO(menu_station_list, 0);
	      Screen_ForceRedraw();
	  }
	}
      } else {
	int selection = Menu_IsChosen(menu_play_fav);
	if(selection != -1) {
	  Menu_SetAutoIO(menu_station_list, 1);
	  Screen_ForceRedraw();
	  
	  if(selection == 0) { // play
	      ShoutcastStation* info = getChosenStation((int)Menu_GetItemTag(menu_station_list, Menu_GetSelectedItem(menu_station_list)));
	      StationInfo* station = parseShoutcastList(info);
	      station->genre = getCurrentGenre();
	      playStation(station);
	      free(station->url);
	      free(station);
	  }
	  else if(selection == 1) { // add to station list
	      ShoutcastStation* sc_stat = getChosenStation((int)Menu_GetItemTag(menu_station_list, Menu_GetSelectedItem(menu_station_list)));
	      StationInfo* stat = parseShoutcastList(sc_stat);
	      
	      StationInfo* info = (StationInfo*)malloc(sizeof(StationInfo));
	      info->tag = '\0';
	      info->name = stat->name;
	      info->url = stat->url;
	      info->genre = getCurrentGenre();
	      
	      ArrayList* stations = readStations();
	      AList_Add(stations, info);
	      writeStations(stations);
	      AList_Delete(stations, AList_Length(stations) - 1);
	      freeStations(stations);
	      AList_Destroy(stations);
	      free(stat->url);
	      free(stat);
	      free(info);
	  }
	  else if(selection == 2) { // cancel
	    // do nothing
	  } 
	}
      }
  }
  // ---------------------------------------------------------------------------
  else if(screen == SCREEN_SHOUTCAST_SEARCH) {
    if(Keyboard_IsConfirmed()) {
      char buffer[256];
      sprintf(buffer, Settings_Get("shoutcast", "search_url"), Keyboard_GetText());
      setShoutcastListUrl(buffer);
      setStationsParentGenre("X");
      setCurrentGenre(" ");
      Screen_Goto(SCREEN_SHOUTCAST_LIST);
    }
  }
  // ---------------------------------------------------------------------------
  else if(screen == SCREEN_MANAGE_STATION) {
      if(Menu_GetAutoIO(menu_m_station)) { // handle station list menu
	int selection = Menu_IsChosen(menu_m_station);
	if(selection != -1) { // show menu
	  Menu_SetAutoIO(menu_m_station, 0);
	  Menu_ScrollTo(menu_m_menu, 0);
	  Screen_ForceRedraw();
	}
      } else {
	if(Menu_GetAutoIO(menu_m_menu)) { // handle station menu
	    int selection = Menu_IsChosen(menu_m_menu);
	    
	    if(selection == 0) {
	      // do nothing (cancel)
	    }
	    else if(selection == 1) {
	      // move -> handled below
	    }
	    else if(selection == 2) {
	      deleteStation(Menu_GetSelectedItem(menu_m_station));
	      Screen_Goto(SCREEN_MANAGE_STATION);
	    }
	    
	    // close menu
	    if(selection != -1) {
	      if(selection == 1) { // move -> disable all menus
		Menu_SetAutoIO(menu_m_menu, 0);
		Menu_SetTitleTag(menu_m_station, Menu_GetSelectedItem(menu_m_station), '*');
		Screen_ForceRedraw();
	      } else {
		Menu_SetAutoIO(menu_m_station, 1);
		Screen_ForceRedraw();
	      }
	    }
	}
	
	else { // moving stations
	  if(IO_GetButton(0)) { // we are done
	    Menu_SetTitleTag(menu_m_station, Menu_GetSelectedItem(menu_m_station), 0);
	    ArrayList* new_stations = AList_Create();
	    int i;
	    for(i = 0; i < Menu_GetItems(menu_m_station); i++) {
	      StationInfo* info = Menu_GetItemTag(menu_m_station, i);
	      AList_Add(new_stations, info);
	    }
	    writeStations(new_stations);
	    AList_Destroy(new_stations);
	    
	    Menu_SetAutoIO(menu_m_menu, 1);
	    Menu_SetAutoIO(menu_m_station, 1);
	    Screen_ForceRedraw();
	  }
	  else {
	   int8_t rotary = IO_GetRotaryValue();
	   if(rotary != 0) {
	      int index = Menu_GetSelectedItem(menu_m_station);
	      int new_index = index + ((rotary > 0) ? 1 : -1);
	      Menu_SwapItems(menu_m_station, index, new_index); 
	      Menu_Scroll(menu_m_station, (rotary > 0) ? 1 : -1);
	   }
	  }
	  
	}
	
      }
  }
  // ---------------------------------------------------------------------------
  else if(screen == SCREEN_TIMEOUT) {
     if(IO_GetButton(0)) {
      // go back to settings
      char buffer[8];
      sprintf(buffer, "%d", Timeout_Get());
      Settings_Add("hardware", "timeout", buffer);
      Settings_Save(settings_file);
      GLCDD_BacklightTimeout(Timeout_Get());      
      Screen_Goto(SCREEN_SETTINGS); 
    }     
  }
  // ---------------------------------------------------------------------------

  // home button
  if(IO_GetButton(1)) Screen_Goto(SCREEN_MAIN);
  
  // play/stop button
  if(IO_GetButton(2)) {
    if(screen != SCREEN_USB) {
      // stop music
      stopMusic();
    } else {
      // play folder
      int i;
      FILE* f = fopen("/tmp/playlist1.m3u", "w");
      for(i = 0; i < Menu_GetItems(menu_usb); i++) {
	// a file, add it to the list
	if((int)Menu_GetItemTag(menu_usb, i) == 0) {
	  fprintf(f, "%s/%s\r\n", usb_root, Menu_GetItemText(menu_usb, i));
	}
      }
      fclose(f);
      char cmd[128];
      sprintf(cmd, "%s /tmp/playlist1.m3u > /tmp/playlist.m3u", Settings_Get("programs", "shuffle"));
      ignore_result(system(cmd));
      
      playUSB("/tmp/playlist.m3u");
    }
  }
  
  // end of snooze time
  if(checkSnoozeStop()) {
   // stop the music
   stopMusic();
   // go to main screen
   Screen_Goto(SCREEN_MAIN);
  }
  
  // (1) button
  if(IO_GetButton(3)) playFavorite(1);
  // (2) button
  if(IO_GetButton(4)) playFavorite(2);
  // (3) button
  if(IO_GetButton(5)) playFavorite(3);
  // (4) button
  if(IO_GetButton(6)) playFavorite(4);
  
  Screen_Draw();

  GLCDD_BacklightUpdate();
  
  usleep(100);
//sleep(1);
 
 }
 
 // really no need to cleanup, as firmware runs as long as device is powered
 // plus, the operating system frees all resources anyway
 
}
示例#14
0
文件: main.c 项目: jsdf/previous
/**
 * Initialise emulation
 */
static void Main_Init(void)
{
	/* Open debug log file */
	if (!Log_Init())
	{
		fprintf(stderr, "Logging/tracing initialization failed\n");
		exit(-1);
	}
	Log_Printf(LOG_INFO, PROG_NAME ", compiled on:  " __DATE__ ", " __TIME__ "\n");

	/* Init SDL's video subsystem. Note: Audio and joystick subsystems
	   will be initialized later (failures there are not fatal). */
	if (SDL_Init(SDL_INIT_VIDEO | Opt_GetNoParachuteFlag()) < 0)
	{
		fprintf(stderr, "Could not initialize the SDL library:\n %s\n", SDL_GetError() );
		exit(-1);
	}
	ClocksTimings_InitMachine ( ConfigureParams.System.nMachineType );
	Resolution_Init();
	SDLGui_Init();
	Screen_Init();
	Main_SetTitle(NULL);
//	HostScreen_Init();
	DSP_Init();
//	Floppy_Init();
	M68000_Init();                /* Init CPU emulation */
//	Audio_Init();
//	DmaSnd_Init();
	Keymap_Init();


    /* call menu at startup */
    if (!File_Exists(sConfigFileName) || ConfigureParams.ConfigDialog.bShowConfigDialogAtStartup)
        Dialog_DoProperty();
    else
        Dialog_CheckFiles();
    
    if (bQuitProgram)
    {
        SDL_Quit();
        exit(-2);
    }
    
    
//    const char *err_msg;
//    
//    while ((err_msg=Reset_Cold())!=NULL)
//    {
//        DlgMissing_Rom();
//        if (bQuitProgram) {
//            Main_RequestQuit();
//            break;
//        }
//    }

    Reset_Cold();
    
//    if (bQuitProgram) {
//        SDL_Quit();
//        exit(-2);
//    }
	IoMem_Init();
	
	/* done as last, needs CPU & DSP running... */
	DebugUI_Init();
}
示例#15
0
/* 
 * Run a command from the menus.
 */
void RunCommand (Menu_Item_Type *i) {
  char *command;
  int must_redraw=0;
  Conditional_String *cs=NULL;
  Window_List_Type *this_window=CurrentWindow;

  if (i->command[0] != '\0') { /* don't try to run a null command */

    if (i->edit_flag) { /* edit command on fly */
      cs=EditTags(i->command);
      if (cs->ignore) { /* user hit escape */
	free(cs->value);
	free(cs);
	return;
      }
      else { /* user hit enter */
	command=malloc(strlen(cs->value)+1);
	strcpy(command,cs->value);
	free(cs->value);
	free(cs);
      }
    }
    else { /* don't edit command on fly */
      command=malloc(strlen(i->command)+1);
      strcpy(command,i->command);
    }

#ifdef SETENV_FLAG_OK
    if (i->setenv_flag) { /* a setenv command */
      RunSetenv(command);
    }
    else
#endif
      if (i->makemenu_flag) { /* process command output as rc file */
	ReadRc(command,RC_PREPROC);
	SanityCheckMenus();
	/*
	 * make sure that all modified menus currently on screen
	 * get recalced.
	 */
	while (this_window) {
	  if (this_window->menu->recalc) {
	    CalcMenu(this_window->menu);
	    must_redraw=1;
	  }
	  this_window=this_window->last;
	}
	if (must_redraw)
	  DrawAll();
      }
      else if (i->truncate_flag) { /* display in a window and truncate */
	RunShow(i->text,command,1);
      }
      else if (i->display_flag) {	/* display in a window and wrap. */
	RunShow(i->text,command,0);
      }
      else { /* normal display */
	if (! i->noclear_flag) {
				/* clear screen */
	  SLsmg_cls();
	  SLsmg_normal_video();
	  Screen_Reset();
#ifdef GPM_SUPPORT
	  EndMouse(); /* return to normal GPM/selection mode */
#endif
	}

	/* 
	 * This is what the whole pdmenu program comes down to.
	 * The rest is fluff. ;-) 
	 */

	/*
	 * start: Steve Blott ([email protected])
	 *
	 * add capability to exec() (rather than system()) a command, thereby
	 * replacing the current process;  if the first word of command is
	 * "exec", then exec() it, otherwise system() it
	 */

	char *cp = command;

        while (isspace(cp[0]))
	   cp++;

	if ( strncmp(cp, "exec", 4) == 0 && isspace(cp[4]) )
	{
	   char *cv[4]; /* command vector */
	   cv[0] = "sh";
	   cv[1] = "-c";
	   cv[2] = cp;
	   cv[3] = 0;
	   execvp(cv[0],cv);
	   /* should not reach here; if the execvp fails, then pdmenu will
	    * continue to run, silently ignoring the failure; if the execvp
	    * succeeds but the subsequent exec fails, then pdmenu will silently
	    * disappear (its process no longer exists), and no feedback will be
	    * received */
	}
	else
	   system(command);

	if (! i->noclear_flag) { /* redraw screen */
	  Screen_Init();
			
	  if (i->pause_flag) { /* pause 1st */
	    printf("\n%s",_("Press Enter to return to Pdmenu."));
	    fflush(stdout); /* make sure above is displayed. */
	    /* Now wait for the keypress. */
	    while (1) {
		    int k;
		    k = SLang_getkey();
		    if (k == '\n' || k == '\r') {
			    break;
		    }
	    }
	    SLang_flush_input(); /* kill any buffered input */
	    printf("\n");
	  }

#ifdef GPM_SUPPORT
	  gpm_ok=InitMouse(); /* grab mouse pointer again. */
#endif

	  /* 
	   * we need to account for the screen size changing behind our backs
	   * while the program was running.
	   */
	  SetScreensize();
	  Resize_Screen();
	  DrawAll();
	}
      }
    free(command);
  }
}