int main(int argc, char** argv) { UNUSED(argc); UNUSED(argv); FileHash_Init(); Mouse_Init(); if (A5_InitOptions() == false) exit(1); char filename[1024]; snprintf(filename, sizeof(filename), "%s/error.log", g_dune_data_dir); FILE* err = fopen(filename, "w"); snprintf(filename, sizeof(filename), "%s/output.log", g_dune_data_dir); FILE* out = fopen(filename, "w"); _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); if (err != NULL) _dup2(_fileno(err), _fileno(stderr)); if (out != NULL) _dup2(_fileno(out), _fileno(stdout)); FreeConsole(); if (!Unknown_25C4_000E()) exit(1); if (A5_Init() == false) exit(1); Scenario_InitTables(); Input_Init(); Audio_LoadSampleSet(SAMPLESET_INVALID); String_Init(); Sprites_Init(); Sprites_LoadTiles(); VideoA5_InitSprites(); GameLoop_TweakWidgetDimensions(); Audio_PlayVoice(VOICE_STOP); GameLoop_GameIntroAnimationMenu(); printf("%s\n", String_Get_ByIndex(STR_THANK_YOU_FOR_PLAYING_DUNE_II)); PrepareEnd(); exit(0); }
static bool Unknown_25C4_000E(void) { Timer_Init(); if (!Video_Init()) return false; Mouse_Init(); /* Add the general tickers */ Timer_Add(Video_Tick, 1000000 / 60); Timer_Add(Timer_Tick, 1000000 / 60); g_var_7097 = -1; GFX_Init(); GFX_ClearScreen(); if (!Font_Init()) { Error( "--------------------------\n" "ERROR LOADING DATA FILE\n" "\n" "Did you copy the Dune2 1.07eu data files into the data directory ?\n" "\n" ); return false; } Font_Select(g_fontNew8p); g_palette_998A = calloc(256 * 3, sizeof(uint8)); memset(&g_palette_998A[45], 63, 3); GFX_SetPalette(g_palette_998A); Tools_RandomLCG_Seed((unsigned)time(NULL)); Widget_SetCurrentWidget(0); return true; }
/** * Initialize Timer, Video, Mouse, GFX, Fonts, Random number generator * and current Widget */ static bool OpenDune_Init(int screen_magnification, VideoScaleFilter filter) { if (!Font_Init()) { Error( "--------------------------\n" "ERROR LOADING DATA FILE\n" "\n" "Did you copy the Dune2 1.07eu data files into the data directory ?\n" "\n" ); return false; } Timer_Init(); if (!Video_Init(screen_magnification, filter)) return false; Mouse_Init(); /* Add the general tickers */ Timer_Add(Timer_Tick, 1000000 / 60, false); Timer_Add(Video_Tick, 1000000 / 60, true); g_mouseDisabled = -1; GFX_Init(); GFX_ClearScreen(); Font_Select(g_fontNew8p); g_palette_998A = calloc(256 * 3, sizeof(uint8)); memset(&g_palette_998A[45], 63, 3); GFX_SetPalette(g_palette_998A); Tools_RandomLCG_Seed((unsigned)time(NULL)); Widget_SetCurrentWidget(0); return true; }
boolean I_Init(void) { if(initOk) return true; // Already initialized. #ifdef __CLIENT__ // Select drivers. iMouse = &qtMouse; #ifdef WIN32 iMouse = &win32Mouse; DirectInput_Init(); #endif Mouse_Init(); Joystick_Init(); #endif // __CLIENT__ initOk = true; return true; }
/** * @brief main routine for USB mouse example * @return Function should not exit. */ int main(void) { USBD_API_INIT_PARAM_T usb_param; USB_CORE_DESCS_T desc; ErrorCode_t ret = LPC_OK; USB_CORE_CTRL_T *pCtrl; /* Initialize board and chip */ SystemCoreClockUpdate(); Board_Init(); /* enable clocks and pinmux */ USB_init_pin_clk(); /* Init USB API structure */ g_pUsbApi = (const USBD_API_T *) LPC_ROM_API->usbdApiBase; /* initialize call back structures */ memset((void *) &usb_param, 0, sizeof(USBD_API_INIT_PARAM_T)); usb_param.usb_reg_base = LPC_USB_BASE; usb_param.mem_base = USB_STACK_MEM_BASE; usb_param.mem_size = USB_STACK_MEM_SIZE; usb_param.max_num_ep = 2; /* Set the USB descriptors */ desc.device_desc = (uint8_t *) USB_DeviceDescriptor; desc.string_desc = (uint8_t *) USB_StringDescriptor; #ifdef USE_USB0 desc.high_speed_desc = USB_HsConfigDescriptor; desc.full_speed_desc = USB_FsConfigDescriptor; desc.device_qualifier = (uint8_t *) USB_DeviceQualifier; #else /* Note, to pass USBCV test full-speed only devices should have both * descriptor arrays point to same location and device_qualifier set * to 0. */ desc.high_speed_desc = USB_FsConfigDescriptor; desc.full_speed_desc = USB_FsConfigDescriptor; desc.device_qualifier = 0; #endif /* USB Initialization */ ret = USBD_API->hw->Init(&g_hUsb, &desc, &usb_param); if (ret == LPC_OK) { /* WORKAROUND for artf45032 ROM driver BUG: Due to a race condition there is the chance that a second NAK event will occur before the default endpoint0 handler has completed its preparation of the DMA engine for the first NAK event. This can cause certain fields in the DMA descriptors to be in an invalid state when the USB controller reads them, thereby causing a hang. */ pCtrl = (USB_CORE_CTRL_T *) g_hUsb; /* convert the handle to control structure */ g_Ep0BaseHdlr = pCtrl->ep_event_hdlr[0];/* retrieve the default EP0_OUT handler */ pCtrl->ep_event_hdlr[0] = EP0_patch;/* set our patch routine as EP0_OUT handler */ ret = Mouse_Init(g_hUsb, (USB_INTERFACE_DESCRIPTOR *) &USB_FsConfigDescriptor[sizeof(USB_CONFIGURATION_DESCRIPTOR)], &usb_param.mem_base, &usb_param.mem_size); if (ret == LPC_OK) { /* enable USB interrrupts */ NVIC_EnableIRQ(LPC_USB_IRQ); /* now connect */ USBD_API->hw->Connect(g_hUsb, 1); } } while (1) { /* Do Mouse tasks */ Mouse_Tasks(); /* Sleep until next IRQ happens */ __WFI(); } }
/** * @brief main routine for USBD keyboard example * @return Function should not exit. */ int main(void) { USBD_API_INIT_PARAM_T usb_param; USB_CORE_DESCS_T desc; ErrorCode_t ret = LPC_OK; USB_CORE_CTRL_T *pCtrl; /* Initialize board and chip */ SystemCoreClockUpdate(); Board_Init(); /* enable clocks and pinmux */ USB_init_pin_clk(); /* Init EDU-CIAA GPIOs */ ciaaIOInit(); /* Init USB API structure */ g_pUsbApi = (const USBD_API_T *) LPC_ROM_API->usbdApiBase; /* initialize call back structures */ memset((void *) &usb_param, 0, sizeof(USBD_API_INIT_PARAM_T)); usb_param.usb_reg_base = LPC_USB_BASE; usb_param.mem_base = USB_STACK_MEM_BASE; usb_param.mem_size = USB_STACK_MEM_SIZE; usb_param.max_num_ep = 2; /* Set the USB descriptors */ desc.device_desc = (uint8_t *) USB_DeviceDescriptor; desc.string_desc = (uint8_t *) USB_StringDescriptor; #ifdef USE_USB0 desc.high_speed_desc = USB_HsConfigDescriptor; desc.full_speed_desc = USB_FsConfigDescriptor; desc.device_qualifier = (uint8_t *) USB_DeviceQualifier; #else /* Note, to pass USBCV test full-speed only devices should have both * descriptor arrays point to same location and device_qualifier set * to 0. */ desc.high_speed_desc = USB_FsConfigDescriptor; desc.full_speed_desc = USB_FsConfigDescriptor; desc.device_qualifier = 0; #endif /* USB Initialization */ ret = USBD_API->hw->Init(&g_hUsb, &desc, &usb_param); if (ret == LPC_OK) { /* WORKAROUND for artf45032 ROM driver BUG: Due to a race condition there is the chance that a second NAK event will occur before the default endpoint0 handler has completed its preparation of the DMA engine for the first NAK event. This can cause certain fields in the DMA descriptors to be in an invalid state when the USB controller reads them, thereby causing a hang. */ pCtrl = (USB_CORE_CTRL_T *) g_hUsb; /* convert the handle to control structure */ g_Ep0BaseHdlr = pCtrl->ep_event_hdlr[0];/* retrieve the default EP0_OUT handler */ pCtrl->ep_event_hdlr[0] = EP0_patch;/* set our patch routine as EP0_OUT handler */ ret = Mouse_Init(g_hUsb, (USB_INTERFACE_DESCRIPTOR *) &USB_FsConfigDescriptor[sizeof(USB_CONFIGURATION_DESCRIPTOR)], &usb_param.mem_base, &usb_param.mem_size); if (ret == LPC_OK) { /* enable USB interrrupts */ NVIC_EnableIRQ(LPC_USB_IRQ); /* now connect */ USBD_API->hw->Connect(g_hUsb, 1); } } /* * vvvvvvvvvvvvv ENCODER vvvvvvvvvvvvvvvv * */ STATES state; STATES nextState; int leftCount = 0; int rightCount = 0; int skipCount = 0; int errorCount = 0; digitalConfig( 0, ENABLE_DIGITAL_IO ); digitalConfig( DIO3, INPUT ); digitalConfig( DIO4, INPUT ); state = ZERO_ZERO; while (1) { uint8_t dt = digitalRead(DIO3); uint8_t clk = digitalRead(DIO4); if (clk && dt ) { nextState = ONE_ONE; } else if ( clk && ! dt ) { nextState = ZERO_ONE; } else if ( ! clk && dt ) { nextState = ONE_ZERO; } else if ( !clk && ! dt ) { nextState = ZERO_ZERO; } if (nextState == state) continue; switch (state) { case ZERO_ZERO: switch (nextState) { case ZERO_ONE: leftCount++; break; case ONE_ZERO: rightCount++; break; case ONE_ONE: skipCount++; break; default: errorCount++; break; } break; case ZERO_ONE: switch (nextState) { case ZERO_ZERO: rightCount++; break; case ONE_ZERO: skipCount++; break; case ONE_ONE: leftCount++; break; default: errorCount++; break; } break; case ONE_ZERO: switch (nextState) { case ZERO_ZERO: leftCount++; break; case ZERO_ONE: skipCount++; break; case ONE_ONE: rightCount++; break; default: errorCount++; break; } break; case ONE_ONE: switch (nextState) { case ZERO_ZERO: skipCount++; break; case ZERO_ONE: rightCount++; break; case ONE_ZERO: leftCount++; break; default: errorCount++; break; } break; default: errorCount++; break; } state = nextState; /* Do Keyboard tasks */ Mouse_Tasks(leftCount * 6, rightCount * 6); leftCount = 0; rightCount = 0; /* Sleep until next IRQ happens */ __WFI(); } }