2 // Apple 2 SDL Portable Apple Emulator
5 // © 2014 Underground Software
7 // Loosely based on AppleWin by Tom Charlesworth which was based on AppleWin by
8 // Oliver Schmidt which was based on AppleWin by Michael O'Brien. :-) Parts are
9 // also derived from ApplePC. Too bad it was closed source--it could have been
10 // *the* premier Apple II emulator out there.
12 // JLH = James Hammons <jlhamm@acm.org>
15 // --- ---------- ------------------------------------------------------------
16 // JLH 11/12/2005 Initial port to SDL
17 // JLH 11/18/2005 Wired up graphic soft switches
18 // JLH 12/02/2005 Setup timer subsystem for more accurate time keeping
19 // JLH 12/12/2005 Added preliminary state saving support
20 // JLH 09/24/2013 Added //e support
25 // - Port to SDL [DONE]
27 // - Weed out unneeded functions [DONE]
29 // - 128K IIe related stuff [DONE]
30 // - State loading/saving
48 #include "applevideo.h"
56 // Debug and misc. defines
58 #define THREADED_65C02
59 #define CPU_THREAD_OVERFLOW_COMPENSATION
61 //#define CPU_CLOCK_CHECKING
62 //#define THREAD_DEBUGGING
63 #define SOFT_SWITCH_DEBUGGING
67 uint8_t ram[0x10000], rom[0x10000]; // RAM & ROM spaces
68 uint8_t ram2[0x10000]; // Auxillary RAM
69 //uint8_t diskRom[0x100]; // Disk ROM space
70 V65C02REGS mainCPU; // v65C02 execution context
71 uint8_t appleType = APPLE_TYPE_IIE;
72 FloppyDrive floppyDrive;
76 uint8_t lastKeyPressed = 0;
78 bool openAppleDown = false;
79 bool closedAppleDown = false;
80 bool store80Mode = false;
82 bool slotCXROM = false;
83 bool slotC3ROM = false;
90 static bool running = true; // Machine running state flag...
91 static uint32_t startTicks;
92 static bool pauseMode = false;
93 static bool fullscreenDebounce = false;
94 static bool capsLock = false;
95 static bool capsLockDebounce = false;
96 //static GUI * gui = NULL;
98 // Local functions (technically, they're global...)
100 bool LoadImg(char * filename, uint8_t * ram, int size);
101 uint8_t RdMem(uint16_t addr);
102 void WrMem(uint16_t addr, uint8_t b);
103 static void SaveApple2State(const char * filename);
104 static bool LoadApple2State(const char * filename);
106 // Local timer callback functions
108 static void FrameCallback(void);
109 static void BlinkTimer(void);
111 #ifdef THREADED_65C02
112 // Test of threaded execution of 6502
113 static SDL_Thread * cpuThread = NULL;
114 //static SDL_mutex * cpuMutex = NULL;
115 static SDL_cond * cpuCond = NULL;
116 static SDL_sem * mainSem = NULL;
117 static bool cpuFinished = false;
118 static bool cpuSleep = false;
120 // NB: Apple //e Manual sez 6502 is running @ 1,022,727 Hz
122 // Let's try a thread...
124 Here's how it works: Execute 1 frame's worth, then sleep.
125 Other stuff wakes it up
127 int CPUThreadFunc(void * data)
129 // Mutex must be locked for conditional to work...
130 // Also, must be created in the thread that uses it...
131 SDL_mutex * cpuMutex = SDL_CreateMutex();
133 // decrement mainSem...
134 //SDL_SemWait(mainSem);
135 #ifdef CPU_THREAD_OVERFLOW_COMPENSATION
136 float overflow = 0.0;
142 SDL_CondWait(cpuCond, cpuMutex);
144 // decrement mainSem...
145 #ifdef THREAD_DEBUGGING
146 WriteLog("CPU: SDL_SemWait(mainSem);\n");
148 SDL_SemWait(mainSem);
150 // There are exactly 800 slices of 21.333 cycles per frame, so it works out
153 uint32_t cycles = 17066;
154 #ifdef CPU_THREAD_OVERFLOW_COMPENSATION
155 // ODD! It's closer *without* this overflow compensation. ??? WHY ???
156 overflow += 0.666666667;
165 #ifdef THREAD_DEBUGGING
166 WriteLog("CPU: Execute65C02(&mainCPU, cycles);\n");
168 Execute65C02(&mainCPU, cycles); // how much? 1 frame (after 1 s, off by 40 cycles) not any more--it's off by as much as 240 now!
170 // Adjust the sound routine's last cycle toggled time base
171 // Also, since we're finished executing, .clock is now valid
172 #ifdef THREAD_DEBUGGING
173 WriteLog("CPU: AdjustLastToggleCycles(mainCPU.clock);\n");
175 AdjustLastToggleCycles(mainCPU.clock);
177 #ifdef THREAD_DEBUGGING
178 WriteLog("CPU: Execute65C02(&mainCPU, cycles);\n");
180 for(int i=0; i<800; i++)
182 uint32_t cycles = 21;
183 overflow += 0.333333334;
191 Execute65C02(&mainCPU, cycles);
192 WriteSampleToBuffer();
194 // Dunno if this is correct (seems to be close enough)...
195 vbl = (i < 670 ? true : false);
199 #ifdef THREAD_DEBUGGING
200 WriteLog("CPU: SDL_mutexP(cpuMutex);\n");
202 SDL_mutexP(cpuMutex);
203 // increment mainSem...
204 #ifdef THREAD_DEBUGGING
205 WriteLog("CPU: SDL_SemPost(mainSem);\n");
207 SDL_SemPost(mainSem);
208 #ifdef THREAD_DEBUGGING
209 WriteLog("CPU: SDL_CondWait(cpuCond, cpuMutex);\n");
211 SDL_CondWait(cpuCond, cpuMutex);
213 #ifdef THREAD_DEBUGGING
214 WriteLog("CPU: SDL_mutexV(cpuMutex);\n");
216 SDL_mutexV(cpuMutex);
218 while (!cpuFinished);
220 SDL_DestroyMutex(cpuMutex);
230 Element * TestWindow(void)
232 Element * win = new DraggableWindow2(10, 10, 128, 128);
233 // ((DraggableWindow *)win)->AddElement(new TextEdit(4, 16, 92, 0, "u2prog.dsk", win));
239 Element * QuitEmulator(void)
250 // Load a file into RAM/ROM image space
252 bool LoadImg(char * filename, uint8_t * ram, int size)
254 FILE * fp = fopen(filename, "rb");
259 fread(ram, 1, size, fp);
266 static void SaveApple2State(const char * filename)
271 static bool LoadApple2State(const char * filename)
277 #ifdef CPU_CLOCK_CHECKING
279 uint32_t totalCPU = 0;
280 uint64_t lastClock = 0;
285 int main(int /*argc*/, char * /*argv*/[])
287 InitLog("./apple2.log");
289 srand(time(NULL)); // Initialize RNG
292 memset(ram, 0, 0x10000);
293 memset(rom, 0, 0x10000);
294 memset(ram2, 0, 0x10000);
300 // Set up V65C02 execution context
301 memset(&mainCPU, 0, sizeof(V65C02REGS));
302 mainCPU.RdMem = AppleReadMem;
303 mainCPU.WrMem = AppleWriteMem;
305 mainCPU.RdMem = RdMem;
306 mainCPU.WrMem = WrMem;
308 mainCPU.cpuFlags |= V65C02_ASSERT_LINE_RESET;
310 // alternateCharset = true;
311 // if (!LoadImg(settings.BIOSPath, rom + 0xD000, 0x3000))
312 if (!LoadImg(settings.BIOSPath, rom + 0xC000, 0x4000))
314 WriteLog("Could not open file '%s'!\n", settings.BIOSPath);
318 //Load up disk image from config file (for now)...
319 floppyDrive.LoadImage(settings.diskImagePath1, 0);
320 floppyDrive.LoadImage(settings.diskImagePath2, 1);
321 // floppyDrive.LoadImage("./disks/temp.nib", 1); // Load temp .nib file into second drive...
323 WriteLog("About to initialize video...\n");
327 std::cout << "Aborting!" << std::endl;
331 GUI::Init(sdlRenderer);
333 // Have to do this *after* video init but *before* sound init...!
334 //Shouldn't be necessary since we're not doing emulation in the ISR...
335 if (settings.autoStateSaving)
337 // Load last state from file...
338 if (!LoadApple2State(settings.autoStatePath))
339 WriteLog("Unable to use Apple2 state file \"%s\"!\n", settings.autoStatePath);
345 if (!LoadImg("./BT1_6502_RAM_SPACE.bin", ram, 0x10000))
347 cout << "Couldn't load state file!" << endl;
348 cout << "Aborting!!" << endl;
353 //-- -- -- -- ----- -----
354 //00 75 3B 53 FD 01 41 44
356 mainCPU.cpuFlags = 0;
366 displayPage2 = false;
373 memcpy(ram + 0xD000, ram + 0xC000, 0x1000);
376 WriteLog("About to initialize audio...\n");
378 //nope SDL_EnableUNICODE(1); // Needed to do key translation shit
380 // gui = new GUI(surface); // Set up the GUI system object...
381 // gui = new GUI(mainSurface); // Set up the GUI system object...
382 // SDL 2... this will likely cause Apple 2 to crash
383 // gui = new GUI(NULL); // Set up the GUI system object...
385 gui->AddMenuTitle("Apple2");
386 gui->AddMenuItem("Test!", TestWindow/*, hotkey*/);
387 gui->AddMenuItem("");
388 gui->AddMenuItem("Quit", QuitEmulator, SDLK_q);
389 gui->CommitItemsToMenu();
392 SetupBlurTable(); // Set up the color TV emulation blur table
393 running = true; // Set running status...
395 InitializeEventList(); // Clear the event list before we use it...
396 SetCallbackTime(FrameCallback, 16666.66666667); // Set frame to fire at 1/60 s interval
397 SetCallbackTime(BlinkTimer, 250000); // Set up blinking at 1/4 s intervals
398 startTicks = SDL_GetTicks();
400 #ifdef THREADED_65C02
401 cpuCond = SDL_CreateCond();
402 mainSem = SDL_CreateSemaphore(1);
403 cpuThread = SDL_CreateThread(CPUThreadFunc, NULL, NULL);
404 //Hmm... CPU does POST (+1), wait, then WAIT (-1)
405 // SDL_sem * mainMutex = SDL_CreateMutex();
408 WriteLog("Entering main loop...\n");
412 double timeToNextEvent = GetTimeToNextEvent();
413 #ifndef THREADED_65C02
414 Execute65C02(&mainCPU, USEC_TO_M6502_CYCLES(timeToNextEvent));
416 //We MUST remove a frame's worth of time in order for the CPU to function... !!! FIX !!!
417 //(Fix so that this is not a requirement!)
418 //Fixed, but mainCPU.clock is destroyed in the bargain. Oh well.
419 // mainCPU.clock -= USEC_TO_M6502_CYCLES(timeToNextEvent);
421 #ifdef CPU_CLOCK_CHECKING
422 #ifndef THREADED_65C02
423 totalCPU += USEC_TO_M6502_CYCLES(timeToNextEvent);
429 #ifdef THREADED_65C02
430 WriteLog("Main: cpuFinished = true;\n");
432 //#warning "If sound thread is behind, CPU thread will never wake up... !!! FIX !!!" [DONE]
433 //What to do? How do you know when the CPU is sleeping???
434 //USE A CONDITIONAL!!! OF COURSE!!!!!!11!11!11!!!1!
436 SDL_mutexP(mainMutex);
437 SDL_CondWait(mainCond, mainMutex); // Wait for CPU thread to get to signal point...
438 SDL_mutexV(mainMutex);
440 //Nope, use a semaphore...
441 WriteLog("Main: SDL_SemWait(mainSem);\n");
442 SDL_SemWait(mainSem);//should lock until CPU thread is waiting...
445 WriteLog("Main: SDL_CondSignal(cpuCond);//thread is probably asleep, wake it up\n");
446 SDL_CondSignal(cpuCond);//thread is probably asleep, wake it up
447 WriteLog("Main: SDL_WaitThread(cpuThread, NULL);\n");
448 SDL_WaitThread(cpuThread, NULL);
449 //nowok:SDL_WaitThread(CPUThreadFunc, NULL);
450 WriteLog("Main: SDL_DestroyCond(cpuCond);\n");
451 SDL_DestroyCond(cpuCond);
453 //SDL_DestroyMutex(mainMutex);
454 SDL_DestroySemaphore(mainSem);
457 if (settings.autoStateSaving)
459 // Save state here...
460 SaveApple2State(settings.autoStatePath);
462 floppyDrive.SaveImage(0);
463 floppyDrive.SaveImage(1);
479 -----------------------
480 space $A0 $A0 $A0 $A0 No xlation
481 RETURN $8D $8D $8D $8D No xlation
482 0 $B0 $B0 $B0 $B0 Need to screen shift+0 (?)
483 1! $B1 $B1 $A1 $A1 No xlation
484 2" $B2 $B2 $A2 $A2 No xlation
485 3# $B3 $B3 $A3 $A3 No xlation
486 4$ $B4 $B4 $A4 $A4 No xlation
487 5% $B5 $B5 $A5 $A5 No xlation
488 6& $B6 $B6 $A6 $A6 No xlation
489 7' $B7 $B7 $A7 $A7 No xlation
490 8( $B8 $B8 $A8 $A8 No xlation
491 9) $B9 $B9 $A9 $A9 No xlation
492 :* $BA $BA $AA $AA No xlation
493 ;+ $BB $BB $AB $AB No xlation
494 ,< $AC $AC $BC $BC No xlation
495 -= $AD $AD $BD $BD No xlation
496 .> $AE $AE $BE $BE No xlation
497 /? $AF $AF $BF $BF No xlation
510 M $CD $8D $DD $9D -> ODD
511 N^ $CE $8E $DE $9E -> ODD
513 P@ $D0 $90 $C0 $80 Need to xlate CTL+SHFT+P & SHFT+P (?)
526 ESC $9B $9B $9B $9B No xlation
529 //static uint64_t lastCPUCycles = 0;
530 static uint32_t frameCount = 0;
531 static void FrameCallback(void)
535 while (SDL_PollEvent(&event))
539 // Problem with using SDL_TEXTINPUT is that it causes key delay. :-/
542 //Need to do some key translation here, and screen out non-apple keys as well...
543 //(really, could do it all in SDL_KEYDOWN, would just have to get symbols &
544 // everything else done separately. this is slightly easier. :-P)
545 // if (event.key.keysym.sym == SDLK_TAB) // Prelim key screening...
546 if (event.edit.text[0] == '\t') // Prelim key screening...
549 lastKeyPressed = event.edit.text[0];
552 //kludge: should have a caps lock thingy here...
553 //or all uppercase for ][+...
554 // if (lastKeyPressed >= 'a' && lastKeyPressed <='z')
555 // lastKeyPressed &= 0xDF; // Convert to upper case...
560 // Use ALT+Q to exit, as well as the usual window decoration method
561 if (event.key.keysym.sym == SDLK_q && (event.key.keysym.mod & KMOD_ALT))
564 // CTRL+RESET key emulation (mapped to CTRL+`)
565 // This doesn't work...
566 // if (event.key.keysym.sym == SDLK_BREAK && (event.key.keysym.mod & KMOD_CTRL))
567 // if (event.key.keysym.sym == SDLK_PAUSE && (event.key.keysym.mod & KMOD_CTRL))
568 if (event.key.keysym.sym == SDLK_BACKQUOTE && (event.key.keysym.mod & KMOD_CTRL))
570 //NOTE that this shouldn't take place until the key is lifted... !!! FIX !!!
571 //ALSO it seems to leave the machine in an inconsistent state vis-a-vis the language card...
572 mainCPU.cpuFlags |= V65C02_ASSERT_LINE_RESET;
576 if (event.key.keysym.sym == SDLK_RIGHT)
577 lastKeyPressed = 0x15, keyDown = true;
578 else if (event.key.keysym.sym == SDLK_LEFT)
579 lastKeyPressed = 0x08, keyDown = true;
580 else if (event.key.keysym.sym == SDLK_UP)
581 lastKeyPressed = 0x0B, keyDown = true;
582 else if (event.key.keysym.sym == SDLK_DOWN)
583 lastKeyPressed = 0x0A, keyDown = true;
584 else if (event.key.keysym.sym == SDLK_RETURN)
585 lastKeyPressed = 0x0D, keyDown = true;
586 else if (event.key.keysym.sym == SDLK_ESCAPE)
587 lastKeyPressed = 0x1B, keyDown = true;
588 else if (event.key.keysym.sym == SDLK_BACKSPACE)
589 lastKeyPressed = 0x7F, keyDown = true;
591 // Fix CTRL+key combo...
592 if (event.key.keysym.mod & KMOD_CTRL)
594 if (event.key.keysym.sym >= SDLK_a && event.key.keysym.sym <= SDLK_z)
596 lastKeyPressed = (event.key.keysym.sym - SDLK_a) + 1;
598 //printf("Key combo pressed: CTRL+%c\n", lastKeyPressed + 0x40);
604 // Fix SHIFT+key combo...
605 if (event.key.keysym.mod & KMOD_SHIFT)
607 if (event.key.keysym.sym >= SDLK_a && event.key.keysym.sym <= SDLK_z)
609 lastKeyPressed = (event.key.keysym.sym - SDLK_a) + 0x41;
611 //printf("Key combo pressed: CTRL+%c\n", lastKeyPressed + 0x40);
614 else if (event.key.keysym.sym == SDLK_1)
616 lastKeyPressed = '!';
620 else if (event.key.keysym.sym == SDLK_2)
622 lastKeyPressed = '@';
626 else if (event.key.keysym.sym == SDLK_3)
628 lastKeyPressed = '#';
632 else if (event.key.keysym.sym == SDLK_3)
634 lastKeyPressed = '#';
638 else if (event.key.keysym.sym == SDLK_4)
640 lastKeyPressed = '$';
644 else if (event.key.keysym.sym == SDLK_5)
646 lastKeyPressed = '%';
650 else if (event.key.keysym.sym == SDLK_6)
652 lastKeyPressed = '^';
656 else if (event.key.keysym.sym == SDLK_7)
658 lastKeyPressed = '&';
662 else if (event.key.keysym.sym == SDLK_8)
664 lastKeyPressed = '*';
668 else if (event.key.keysym.sym == SDLK_9)
670 lastKeyPressed = '(';
674 else if (event.key.keysym.sym == SDLK_0)
676 lastKeyPressed = ')';
680 else if (event.key.keysym.sym == SDLK_MINUS)
682 lastKeyPressed = '_';
686 else if (event.key.keysym.sym == SDLK_EQUALS)
688 lastKeyPressed = '+';
692 else if (event.key.keysym.sym == SDLK_LEFTBRACKET)
694 lastKeyPressed = '{';
698 else if (event.key.keysym.sym == SDLK_RIGHTBRACKET)
700 lastKeyPressed = '}';
704 else if (event.key.keysym.sym == SDLK_BACKSLASH)
706 lastKeyPressed = '|';
710 else if (event.key.keysym.sym == SDLK_SEMICOLON)
712 lastKeyPressed = ':';
716 else if (event.key.keysym.sym == SDLK_QUOTE)
718 lastKeyPressed = '"';
722 else if (event.key.keysym.sym == SDLK_COMMA)
724 lastKeyPressed = '<';
728 else if (event.key.keysym.sym == SDLK_PERIOD)
730 lastKeyPressed = '>';
734 else if (event.key.keysym.sym == SDLK_SLASH)
736 lastKeyPressed = '?';
740 else if (event.key.keysym.sym == SDLK_BACKQUOTE)
742 lastKeyPressed = '~';
750 if (event.key.keysym.sym >= SDLK_SPACE && event.key.keysym.sym <= SDLK_z)
752 lastKeyPressed = event.key.keysym.sym;
755 // Check for Caps Lock key...
756 if (event.key.keysym.sym >= SDLK_a && event.key.keysym.sym <= SDLK_z && capsLock)
757 lastKeyPressed -= 0x20;
762 if (event.key.keysym.sym == SDLK_PAUSE)
764 pauseMode = !pauseMode;
769 SpawnMessage("*** PAUSED ***");
774 SpawnMessage("*** RESUME ***");
778 // Paddle buttons 0 & 1
779 if (event.key.keysym.sym == SDLK_INSERT)
780 openAppleDown = true;
781 if (event.key.keysym.sym == SDLK_PAGEUP)
782 closedAppleDown = true;
784 if (event.key.keysym.sym == SDLK_F11)
785 dumpDis = !dumpDis; // Toggle the disassembly process
786 // else if (event.key.keysym.sym == SDLK_F11)
787 // floppyDrive.LoadImage("./disks/bt1_char.dsk");//Kludge to load char disk...
788 else if (event.key.keysym.sym == SDLK_F9)
790 floppyDrive.CreateBlankImage(0);
791 // SpawnMessage("Image cleared...");
793 else if (event.key.keysym.sym == SDLK_F10)
795 floppyDrive.SwapImages();
796 // SpawnMessage("Image swapped...");
799 if (event.key.keysym.sym == SDLK_F2)// Toggle the palette
801 else if (event.key.keysym.sym == SDLK_F3)// Cycle through screen types
804 // GUI is no longer launched this way...
806 // if (event.key.keysym.sym == SDLK_F5) // Temp GUI launch key
807 if (event.key.keysym.sym == SDLK_F1) // GUI launch key
808 //NOTE: Should parse the output to determine whether or not the user requested
809 // to quit completely... !!! FIX !!!
813 if (event.key.keysym.sym == SDLK_F5)
816 char volStr[19] = "[****************]";
817 // volStr[GetVolume()] = 0;
818 for(int i=GetVolume(); i<16; i++)
820 SpawnMessage("Volume: %s", volStr);
822 else if (event.key.keysym.sym == SDLK_F6)
825 char volStr[19] = "[****************]";
826 // volStr[GetVolume()] = 0;
827 for(int i=GetVolume(); i<16; i++)
829 SpawnMessage("Volume: %s", volStr);
832 if (event.key.keysym.sym == SDLK_F12)
834 if (!fullscreenDebounce)
837 fullscreenDebounce = true;
841 if (event.key.keysym.sym == SDLK_CAPSLOCK)
843 if (!capsLockDebounce)
845 capsLock = !capsLock;
846 capsLockDebounce = true;
852 if (event.key.keysym.sym == SDLK_F12)
853 fullscreenDebounce = false;
854 if (event.key.keysym.sym == SDLK_CAPSLOCK)
855 capsLockDebounce = false;
857 // Paddle buttons 0 & 1
858 if (event.key.keysym.sym == SDLK_INSERT)
859 openAppleDown = false;
860 if (event.key.keysym.sym == SDLK_PAGEUP)
861 closedAppleDown = false;
863 // if (event.key.keysym.sym >= SDLK_a && event.key.keysym.sym <= SDLK_z)
867 case SDL_MOUSEBUTTONDOWN:
868 GUI::MouseDown(event.motion.x, event.motion.y, event.motion.state);
870 case SDL_MOUSEBUTTONUP:
871 GUI::MouseUp(event.motion.x, event.motion.y, event.motion.state);
873 case SDL_MOUSEMOTION:
874 GUI::MouseMove(event.motion.x, event.motion.y, event.motion.state);
876 case SDL_WINDOWEVENT:
877 if (event.window.event == SDL_WINDOWEVENT_LEAVE)
878 GUI::MouseMove(0, 0, 0);
886 //#warning "!!! Taking MAJOR time hit with the video frame rendering !!!"
888 RenderScreenBuffer();
889 GUI::Render(sdlRenderer);
890 SDL_RenderPresent(sdlRenderer);
891 SetCallbackTime(FrameCallback, 16666.66666667);
893 #ifdef CPU_CLOCK_CHECKING
894 //We know it's stopped, so we can get away with this...
898 uint64_t clock = GetCurrentV65C02Clock();
899 //totalCPU += (uint32_t)(clock - lastClock);
901 printf("Executed %u cycles...\n", (uint32_t)(clock - lastClock));
907 //Instead of this, we should yield remaining time to other processes... !!! FIX !!! [DONE]
910 //Actually, slows things down too much...
912 // while (SDL_GetTicks() - startTicks < 16); // Wait for next frame...
914 // This is the problem: If you set the interval to 16, it runs faster than
915 // 1/60s per frame. If you set it to 17, it runs slower. What we need is to
916 // have it do 16 for one frame, then 17 for two others. Then it should average
917 // out to 1/60s per frame every 3 frames.
918 frameCount = (frameCount + 1) % 3;
919 uint32_t waitFrameTime = 17 - (frameCount == 0 ? 1 : 0);
921 while (SDL_GetTicks() - startTicks < waitFrameTime)
922 SDL_Delay(1); // Wait for next frame...
924 startTicks = SDL_GetTicks();
926 uint64_t cpuCycles = GetCurrentV65C02Clock();
927 uint32_t cyclesBurned = (uint32_t)(cpuCycles - lastCPUCycles);
928 WriteLog("FrameCallback: used %i cycles\n", cyclesBurned);
929 lastCPUCycles = cpuCycles;
932 //let's wait, then signal...
933 //works longer, but then still falls behind...
934 #ifdef THREADED_65C02
936 SDL_CondSignal(cpuCond);//OK, let the CPU go another frame...
941 static void BlinkTimer(void)
944 SetCallbackTime(BlinkTimer, 250000); // Set up blinking at 1/4 sec intervals
949 Next problem is this: How to have events occur and synchronize with the rest
952 o Have the CPU thread manage the timer mechanism? (need to have a method of carrying
953 remainder CPU cycles over...)
955 One way would be to use a fractional accumulator, then subtract 1 every
956 time it overflows. Like so:
962 Execute6808(&soundCPU, time);
963 overflow += 0.289115646;