go.cpp
1 #include "go.h" 2 3 extern "C" { 4 #include "emuapi.h" 5 #include "iopins.h" 6 } 7 8 #include "esp_event.h" 9 10 #include "keyboard_osd.h" 11 #include "ili9341_t3dma.h" 12 #ifdef HAS_SND 13 #include "AudioPlaySystem.h" 14 #endif 15 16 #include "sndplay.h" 17 18 19 ILI9341_t3DMA tft = ILI9341_t3DMA(PIN_NUM_CS, PIN_NUM_DC, -1, PIN_NUM_MOSI, PIN_NUM_CLK, PIN_NUM_MISO, TPIN_NUM_CS, TPIN_NUM_IRQ); 20 #ifdef HAS_SND 21 AudioPlaySystem audio; 22 #endif 23 24 25 static void spi_task(void *args) 26 { 27 while(true) { 28 tft.refresh(); 29 } 30 } 31 32 static void input_task(void *args) 33 { 34 while(true) { 35 if ( ((emu_ReadKeys() & (MASK_KEY_USER1+MASK_KEY_USER2)) == (MASK_KEY_USER1+MASK_KEY_USER2)) 36 || (emu_ReadKeys() & MASK_KEY_USER4 ) ) 37 { 38 printf("rebooting\n"); 39 esp_restart(); 40 } 41 42 uint16_t bClick = emu_DebounceLocalKeys(); 43 if (bClick & MASK_KEY_USER2) { 44 printf("%d\n",emu_SwapJoysticks(1)); 45 emu_SwapJoysticks(0); 46 } 47 else { 48 emu_Input(bClick); 49 } 50 #ifdef HAS_SND 51 audio.step(); 52 #endif 53 vTaskDelay(20 / portTICK_PERIOD_MS); 54 } 55 } 56 57 static void main_step() { 58 if (menuActive()) { 59 uint16_t bClick = emu_DebounceLocalKeys(); 60 int action = handleMenu(bClick); 61 char * filename = menuSelection(); 62 if (action == ACTION_RUNTFT) { 63 #ifdef HAS_SND 64 audio.begin(); 65 audio.start(); 66 #endif 67 toggleMenu(false); 68 tft.fillScreenNoDma( RGBVAL16(0x00,0x00,0x00) ); 69 xTaskCreatePinnedToCore(input_task, "inputthread", 4096, NULL, 2, NULL, 0); 70 emu_Init(filename); 71 } 72 //vTaskDelay(20 / portTICK_PERIOD_MS); 73 } 74 else { 75 emu_Step(); 76 } 77 } 78 79 80 void setup(void) 81 { 82 printf("Starting emulator\n"); 83 84 tft.begin(); 85 tft.flipscreen(true); 86 tft.start(); 87 tft.refresh(); 88 89 emu_init(); 90 91 xTaskCreatePinnedToCore(spi_task, "spithread", 4096, NULL, 1, NULL, 0); 92 //vTaskPrioritySet(NULL, tskIDLE_PRIORITY+1); 93 } 94 95 void loop(void) 96 { 97 unsigned long t = esp_timer_get_time(); 98 main_step(); 99 //printf("%d\n",(int)((esp_timer_get_time()-t)/1000)); 100 } 101 102 103 104