1 #include <QtWidgets> 2 #include "emuworker.h" 3 #include "burner.h" 4 5 static int GetInput(bool bCopy); 6 static int RunFrame(int bDraw, int bPause); 7 static int RunGetNextSound(int bDraw); 8 EmuWorker(QObject * parent)9EmuWorker::EmuWorker(QObject *parent) : 10 QObject(parent) 11 { 12 m_isRunning = false; 13 } 14 init()15bool EmuWorker::init() 16 { 17 AudSoundStop(); 18 19 if (bDrvOkay) 20 DrvExit(); 21 22 // we need to initialize sound first 23 AudSoundInit(); 24 AudSetCallback(RunGetNextSound); 25 bAudOkay = 1; 26 27 DrvInit(m_game, false); 28 if (!bDrvOkay) 29 return false; 30 31 VidInit(); 32 33 return true; 34 } 35 resume()36void EmuWorker::resume() 37 { 38 AudSoundPlay(); 39 if (!bDrvOkay) { 40 m_isRunning = false; 41 return; 42 } 43 m_isRunning = true; 44 } 45 46 close()47void EmuWorker::close() 48 { 49 AudSoundStop(); 50 DrvExit(); 51 } 52 pause()53void EmuWorker::pause() 54 { 55 m_isRunning = false; 56 } 57 setGame(int no)58void EmuWorker::setGame(int no) 59 { 60 m_game = no; 61 } 62 run()63void EmuWorker::run() 64 { 65 if (m_isRunning && bDrvOkay) { 66 AudSoundCheck(); 67 } 68 } 69 GetInput(bool bCopy)70int GetInput(bool bCopy) 71 { 72 InputMake(bCopy); // get input 73 return 0; 74 } 75 RunFrame(int bDraw,int bPause)76int RunFrame(int bDraw, int bPause) 77 { 78 static int bPrevPause = 0; 79 static int bPrevDraw = 0; 80 81 if (bPrevDraw && !bPause) { 82 VidPaint(0); // paint the screen (no need to validate) 83 } 84 85 if (!bDrvOkay) { 86 return 1; 87 } 88 89 if (bPause) 90 { 91 GetInput(false); // Update burner inputs, but not game inputs 92 if (bPause != bPrevPause) 93 { 94 VidPaint(2); // Redraw the screen (to ensure mode indicators are updated) 95 } 96 } 97 else 98 { 99 nFramesEmulated++; 100 nCurrentFrame++; 101 GetInput(true); // Update inputs 102 } 103 if (bDraw) { 104 nFramesRendered++; 105 if (VidFrame()) { // Do one frame 106 AudBlankSound(); 107 } 108 } 109 else { // frame skipping 110 pBurnDraw = NULL; // Make sure no image is drawn 111 BurnDrvFrame(); 112 } 113 bPrevPause = bPause; 114 bPrevDraw = bDraw; 115 116 return 0; 117 } 118 RunGetNextSound(int bDraw)119int RunGetNextSound(int bDraw) 120 { 121 if (nAudNextSound == NULL) { 122 return 1; 123 } 124 // Render frame with sound 125 pBurnSoundOut = nAudNextSound; 126 RunFrame(bDraw, 0); 127 return 0; 128 } 129