Example #1
0
int DisplayWindow::OnCommand(WPARAM wParam,LPARAM lParam) {
  if (HIWORD(wParam)==0) {
    
    if (LOWORD(wParam)==ID_VIDEO_STD256X240) {
      CheckMenuItem(menu_,ID_VIDEO_STD256X240,MF_CHECKED);
      CheckMenuItem(menu_,ID_VIDEO_EAGLE512X480,MF_UNCHECKED);
      SetClientSize(256,240);
      gfx.SetDisplaySize(256,240);
      display_mode = ID_VIDEO_STD256X240;
    }

    if (LOWORD(wParam)==ID_VIDEO_EAGLE512X480) {
      CheckMenuItem(menu_,ID_VIDEO_EAGLE512X480,MF_CHECKED);
      CheckMenuItem(menu_,ID_VIDEO_STD256X240,MF_UNCHECKED);
      SetClientSize(512,480);
      gfx.SetDisplaySize(512,480);
      display_mode = ID_VIDEO_EAGLE512X480;
    }

    if (LOWORD(wParam)==ID_MODE_NTSC) {
      CheckMenuItem(menu_,ID_MODE_NTSC,MF_CHECKED);
      CheckMenuItem(menu_,ID_MODE_PAL,MF_UNCHECKED);
      nes.settings.machine_mode = NTSC;
      nes.set_mode(nes.settings.machine_mode);
      machine_mode = ID_MODE_NTSC;
    }

    if (LOWORD(wParam)==ID_MODE_PAL) {
      CheckMenuItem(menu_,ID_MODE_PAL,MF_CHECKED);
      CheckMenuItem(menu_,ID_MODE_NTSC,MF_UNCHECKED);
      nes.settings.machine_mode = PAL;
      nes.set_mode(nes.settings.machine_mode);
      machine_mode = ID_MODE_PAL;
    }
    

    if (LOWORD(wParam)==ID_FILE_EXIT) {
      PostQuitMessage(0);
    }

    if (LOWORD(wParam)==ID_MACHINE_RESET) {
      nes.Reset();
      ResetTiming();
    }
     
    if (LOWORD(wParam)==ID_EDIT_OPTIONS) {
      options.Show(this);
    }
  
  }
  return 0;
}
Example #2
0
int kalman_roll_pitch(float *final_roll,float *final_pitch){
  int a=0;
  float accel_roll,accel_pitch,gyro_roll_rate,gyro_pitch_rate;
 
  a=accel_rollpitch(accel_object,&accel_roll,&accel_pitch);
  if(a<0){
    usart_printf(USARTx,"Issue with reading the accel sensor value in kalman\n\r");
    return -1;
   }
  if(accel_roll > 180 || accel_roll < -180 || accel_pitch > 180 || accel_pitch < -180 ){
    usart_printf(USARTx,"Accel's roll and pitch is not proper.\n\r");
    return -1;
  }
  //usart_printf(USARTx,"a.roll=%f a.pitch=%f",accel_roll,accel_pitch);
   unsigned int time=((*DWT_CYCCNT)-start)/10000000;
   //usart_printf(USARTx,"DWT_CYCCNT=%lu\n\r",*DWT_CYCCNT);
   ResetTiming();
   start=*DWT_CYCCNT;
   a=gyro_rollpitch(gyro_object,&gyro_pitch_rate,&gyro_roll_rate);
   if(a<0){
    usart_printf(USARTx,"Issue with reading the gyro sensor value in kalman\n\r");
    return -1;
  }
  if(gyro_roll_rate > 2000 || gyro_roll_rate < -2000 || gyro_pitch_rate > 2000 || gyro_pitch_rate < -2000 ){
    usart_printf(USARTx,"Gyro's roll and pitch is not proper.\n\r");
    return -1;
  }
   time=1;
   gyro_roll_rate=-gyro_roll_rate;
   gyro_roll+=gyro_roll_rate*0.01*90/14.0;
   gyro_pitch+=gyro_pitch_rate*0.01*90/14.0;
   //usart_printf(USARTx,"g.roll=%f g.pitch=%f\n\r",gyro_roll,gyro_pitch);
   
  *final_roll=kalman_getAngle(kalman_roll,accel_roll, gyro_roll_rate,time);
  *final_pitch=kalman_getAngle(kalman_pitch,accel_pitch,gyro_pitch_rate,time);
  return 0;
}
Example #3
0
void DisplayWindow::Init() {
  exit_signal_ = false;
  PrepareClass("NesEmu");
  window_class.hIcon = static_cast<HICON>(LoadImage(instance, MAKEINTRESOURCE(IDI_ICON1),IMAGE_ICON,32,32,LR_DEFAULTSIZE));
  window_class.hIconSm = static_cast<HICON>(LoadImage(instance, MAKEINTRESOURCE(IDI_ICON1),IMAGE_ICON,16,16,LR_DEFAULTSIZE));
  Create();
  SetMenu(LoadMenu(instance, MAKEINTRESOURCE(IDR_MENU1)));
  DragAcceptFiles(handle(),true);

  gfx.Initialize(handle(),0,0);
  nes.set_on_render([this]() {
    //InvalidateRect(handle(),nullptr,true);
    PostMessage(handle(),WM_PAINT,0,0);
  });

  nes.set_on_vertical_blank([this]() {
    MSG msg;
    while (PeekMessage(&msg,NULL,0,0,PM_REMOVE)!=0) {//while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
      TranslateMessage(&msg);
      DispatchMessage(&msg);
    }
  });

  //auto a = glGetError();
  //glPixelZoom(1, -1);
  //a = glGetError();
  //glRasterPos2i(0,0);
  //a = glGetError();
  glEnable( GL_TEXTURE_2D );
  auto a = glGetError();
  glGenTextures( 1, &texture );
  a = glGetError();
  glBindTexture( GL_TEXTURE_2D, texture );
  glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
  glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
  //wglMakeCurrent(NULL, NULL);

  //settings setup
  options.nes = &nes;
  IO::window_handle = handle();
  IO::Init();
  ResetTiming();
  
  OnCommand(ID_VIDEO_STD256X240,0);
  Center();
  ShowWindow(handle(), SW_SHOW); 
  UpdateWindow(handle()); 
  
  

  nes.Open("D:\\Personal\\Projects\\NesEmu\\mario.nes");

  //CPU Tests
  //nes.Open("D:\\Personal\\Projects\\NesEmu\\testroms\\cpu_reset\\ram_after_reset.nes");
  //nes.Open("D:\\Personal\\Projects\\NesEmu\\testroms\\cpu_timing_test6\\cpu_timing_test.nes");
  //nes.Open("D:\\Personal\\Projects\\NesEmu\\testroms\\cpu_interrupts_v2\\rom_singles\\1-cli_latency.nes");
  //nes.Open("D:\\Personal\\Projects\\NesEmu\\testroms\\cpu_interrupts_v2\\rom_singles\\2-nmi_and_brk.nes");
  //nes.Open("D:\\Personal\\Projects\\NesEmu\\testroms\\cpu_interrupts_v2\\cpu_interrupts.nes");
  //nes.Open("D:\\Personal\\Projects\\NesEmu\\testroms\\nestest.nes");
  //nes.Open("D:\\Personal\\Projects\\NesEmu\\testroms\\instr_timing\\instr_timing.nes");
  //nes.Open("D:\\Personal\\Projects\\NesEmu\\testroms\\instr_timing\\instr_timing.nes");
  //nes.Open("D:\\Personal\\Projects\\NesEmu\\testroms\\NEStress\\NEStress.NES");
  //nes.Open("D:\\Personal\\Projects\\NesEmu\\testroms\\cpu_dummy_writes\\cpu_dummy_writes_ppumem.nes");
  //nes.Open("D:\\Personal\\Projects\\NesEmu\\testroms\\cpu_flag_concurrency\\test_cpu_flag_concurrency.nes");
  //nes.Open("D:\\Personal\\Projects\\NesEmu\\testroms\\cpu_exec_space\\test_cpu_exec_space_apu.nes");
  


  //APU Tests
  //nes.Open("D:\\Personal\\Projects\\NesEmu\\testroms\\apu_reset\\4015_cleared.nes");
  //nes.Open("D:\\Personal\\Projects\\NesEmu\\testroms\\apu_reset\\4017_timing.nes");
  //nes.Open("D:\\Personal\\Projects\\NesEmu\\testroms\\apu_reset\\4017_written.nes");
  //nes.Open("D:\\Personal\\Projects\\NesEmu\\testroms\\blargg_apu\\01.len_ctr.nes");
  //nes.Open("D:\\Personal\\Projects\\NesEmu\\testroms\\blargg_apu\\09.reset_timing.nes");
  
  //nes.Open("D:\\Personal\\Projects\\NesEmu\\testroms\\nes_saw\\square_scale.nes");

  //MMC3
  //nes.Open("D:\\Personal\\Projects\\NesEmu\\testroms\\mmc3_irq_tests\\1.Clocking.nes");
  //nes.Open("D:\\Personal\\Projects\\NesEmu\\testroms\\mmc3_test_2\\rom_singles\\1-clocking.nes");
  //nes.Open("D:\\Personal\\Projects\\NesEmu\\testroms\\mmc3_test_2\\rom_singles\\2-details.nes");
  //nes.Open("F:\\NESRen\\Pirate\\Captain Tsubasa Vol 2 - Super Striker (J) [p1].nes");

  //PPU
  //nes.Open("D:\\Personal\\Projects\\NesEmu\\testroms\\blargg_ppu_tests\\vram_access.nes");
  //nes.Open("D:\\Personal\\Projects\\NesEmu\\testroms\\sprite_hit_tests_2005.10.05\\10.timing_order.nes");
  
  //MMC1
  //nes.Open("F:\\NESRen\\USA\\Legend of Zelda, The (U) (PRG 0).nes");
  //nes.Open("F:\\NESRen\\Translated\\Captain Tsubasa (J) [T-Eng].nes");
  OnCommand(ID_MODE_NTSC,0);

  //emu_th = new std::thread(&app::DisplayWindow::Step,this);
  //emu_th->join();
}