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 V65C02REGS mainCPU; // v65C02 execution context
70 uint8_t appleType = APPLE_TYPE_IIE;
71 FloppyDrive floppyDrive;
72 bool powerStateChangeRequested = false;
74 // Local variables (actually, they're global since they're not static)
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;
89 // Language card state (ROM read, no write)
90 uint8_t lcState = 0x02;
92 static bool running = true; // Machine running state flag...
93 static uint32_t startTicks;
94 static bool pauseMode = false;
95 static bool fullscreenDebounce = false;
96 static bool capsLock = false;
97 static bool capsLockDebounce = false;
101 static void SaveApple2State(const char * filename);
102 static bool LoadApple2State(const char * filename);
103 static void ResetApple2State(void);
105 // Local timer callback functions
107 static void FrameCallback(void);
108 static void BlinkTimer(void);
110 #ifdef THREADED_65C02
111 // Test of threaded execution of 6502
112 static SDL_Thread * cpuThread = NULL;
113 //static SDL_mutex * cpuMutex = NULL;
114 static SDL_cond * cpuCond = NULL;
115 static SDL_sem * mainSem = NULL;
116 static bool cpuFinished = false;
117 //static bool cpuSleep = false;
119 // NB: Apple //e Manual sez 6502 is running @ 1,022,727 Hz
121 // Let's try a thread...
123 // Here's how it works: Execute 1 frame's worth, then sleep. Other stuff wakes
126 int CPUThreadFunc(void * data)
128 // Mutex must be locked for conditional to work...
129 // Also, must be created in the thread that uses it...
130 SDL_mutex * cpuMutex = SDL_CreateMutex();
132 // decrement mainSem...
133 //SDL_SemWait(mainSem);
134 #ifdef CPU_THREAD_OVERFLOW_COMPENSATION
135 float overflow = 0.0;
140 // This is never set to true anywhere...
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
152 #ifdef THREAD_DEBUGGING
153 WriteLog("CPU: Execute65C02(&mainCPU, cycles);\n");
155 for(int i=0; i<800; i++)
157 uint32_t cycles = 21;
158 overflow += 0.333333334;
166 Execute65C02(&mainCPU, cycles);
167 WriteSampleToBuffer();
169 // Dunno if this is correct (seems to be close enough)...
170 vbl = (i < 670 ? true : false);
173 #ifdef THREAD_DEBUGGING
174 WriteLog("CPU: SDL_mutexP(cpuMutex);\n");
176 SDL_mutexP(cpuMutex);
177 // increment mainSem...
178 #ifdef THREAD_DEBUGGING
179 WriteLog("CPU: SDL_SemPost(mainSem);\n");
181 SDL_SemPost(mainSem);
182 #ifdef THREAD_DEBUGGING
183 WriteLog("CPU: SDL_CondWait(cpuCond, cpuMutex);\n");
185 SDL_CondWait(cpuCond, cpuMutex);
187 #ifdef THREAD_DEBUGGING
188 WriteLog("CPU: SDL_mutexV(cpuMutex);\n");
190 SDL_mutexV(cpuMutex);
192 while (!cpuFinished);
194 SDL_DestroyMutex(cpuMutex);
202 // Request a change in the power state of the emulated Apple
204 void SetPowerState(void)
206 powerStateChangeRequested = true;
211 // Load a file into RAM/ROM image space
213 bool LoadImg(char * filename, uint8_t * ram, int size)
215 FILE * fp = fopen(filename, "rb");
220 fread(ram, 1, size, fp);
227 const uint8_t stateHeader[19] = "APPLE2SAVESTATE1.0";
228 static void SaveApple2State(const char * filename)
230 WriteLog("Main: Saving Apple2 state...\n");
231 FILE * file = fopen(filename, "wb");
235 WriteLog("Could not open file \"%s\" for writing!\n", filename);
240 fwrite(stateHeader, 1, 18, file);
242 // Write out CPU state
243 fwrite(&mainCPU, 1, sizeof(mainCPU), file);
245 // Write out main memory
246 fwrite(ram, 1, 0x10000, file);
247 fwrite(ram2, 1, 0x10000, file);
249 // Write out state variables
250 fputc((uint8_t)keyDown, file);
251 fputc((uint8_t)openAppleDown, file);
252 fputc((uint8_t)closedAppleDown, file);
253 fputc((uint8_t)store80Mode, file);
254 fputc((uint8_t)vbl, file);
255 fputc((uint8_t)slotCXROM, file);
256 fputc((uint8_t)slotC3ROM, file);
257 fputc((uint8_t)ramrd, file);
258 fputc((uint8_t)ramwrt, file);
259 fputc((uint8_t)altzp, file);
260 fputc((uint8_t)ioudis, file);
261 fputc((uint8_t)dhires, file);
262 fputc((uint8_t)flash, file);
263 fputc((uint8_t)textMode, file);
264 fputc((uint8_t)mixedMode, file);
265 fputc((uint8_t)displayPage2, file);
266 fputc((uint8_t)hiRes, file);
267 fputc((uint8_t)alternateCharset, file);
268 fputc((uint8_t)col80Mode, file);
269 fputc(lcState, file);
271 // Write out floppy state
272 floppyDrive.SaveState(file);
277 static bool LoadApple2State(const char * filename)
279 WriteLog("Main: Loading Apple2 state...\n");
280 FILE * file = fopen(filename, "rb");
284 WriteLog("Could not open file \"%s\" for reading!\n", filename);
289 fread(buffer, 1, 18, file);
292 if (memcmp(buffer, stateHeader, 18) != 0)
295 WriteLog("File \"%s\" is not a valid Apple2 save state file!\n", filename);
300 fread(&mainCPU, 1, sizeof(mainCPU), file);
303 fread(ram, 1, 0x10000, file);
304 fread(ram2, 1, 0x10000, file);
306 // Read in state variables
307 keyDown = (bool)fgetc(file);
308 openAppleDown = (bool)fgetc(file);
309 closedAppleDown = (bool)fgetc(file);
310 store80Mode = (bool)fgetc(file);
311 vbl = (bool)fgetc(file);
312 slotCXROM = (bool)fgetc(file);
313 slotC3ROM = (bool)fgetc(file);
314 ramrd = (bool)fgetc(file);
315 ramwrt = (bool)fgetc(file);
316 altzp = (bool)fgetc(file);
317 ioudis = (bool)fgetc(file);
318 dhires = (bool)fgetc(file);
319 flash = (bool)fgetc(file);
320 textMode = (bool)fgetc(file);
321 mixedMode = (bool)fgetc(file);
322 displayPage2 = (bool)fgetc(file);
323 hiRes = (bool)fgetc(file);
324 alternateCharset = (bool)fgetc(file);
325 col80Mode = (bool)fgetc(file);
326 lcState = fgetc(file);
328 // Read in floppy state
329 floppyDrive.LoadState(file);
333 // Make sure things are in a sane state before execution :-P
334 mainCPU.RdMem = AppleReadMem;
335 mainCPU.WrMem = AppleWriteMem;
342 static void ResetApple2State(void)
345 openAppleDown = false;
346 closedAppleDown = false;
359 // Without this, you can wedge the system :-/
360 memset(ram, 0, 0x10000);
361 mainCPU.cpuFlags |= V65C02_ASSERT_LINE_RESET;
365 #ifdef CPU_CLOCK_CHECKING
367 uint32_t totalCPU = 0;
368 uint64_t lastClock = 0;
373 int main(int /*argc*/, char * /*argv*/[])
375 InitLog("./apple2.log");
377 srand(time(NULL)); // Initialize RNG
380 memset(ram, 0, 0x10000);
381 memset(rom, 0, 0x10000);
382 memset(ram2, 0, 0x10000);
388 // Set up V65C02 execution context
389 memset(&mainCPU, 0, sizeof(V65C02REGS));
390 mainCPU.RdMem = AppleReadMem;
391 mainCPU.WrMem = AppleWriteMem;
392 mainCPU.cpuFlags |= V65C02_ASSERT_LINE_RESET;
394 if (!LoadImg(settings.BIOSPath, rom + 0xC000, 0x4000))
396 WriteLog("Could not open file '%s'!\n", settings.BIOSPath);
400 WriteLog("About to initialize video...\n");
404 std::cout << "Aborting!" << std::endl;
408 GUI::Init(sdlRenderer);
410 // Have to do this *after* video init but *before* sound init...!
411 //Shouldn't be necessary since we're not doing emulation in the ISR...
412 if (settings.autoStateSaving)
414 // Load last state from file...
415 if (!LoadApple2State(settings.autoStatePath))
416 WriteLog("Unable to use Apple2 state file \"%s\"!\n", settings.autoStatePath);
419 WriteLog("About to initialize audio...\n");
421 SetupBlurTable(); // Set up the color TV emulation blur table
422 running = true; // Set running status...
423 InitializeEventList(); // Clear the event list before we use it...
424 SetCallbackTime(FrameCallback, 16666.66666667); // Set frame to fire at 1/60 s interval
425 SetCallbackTime(BlinkTimer, 250000); // Set up blinking at 1/4 s intervals
426 startTicks = SDL_GetTicks();
428 #ifdef THREADED_65C02
429 cpuCond = SDL_CreateCond();
430 mainSem = SDL_CreateSemaphore(1);
431 cpuThread = SDL_CreateThread(CPUThreadFunc, NULL, NULL);
432 //Hmm... CPU does POST (+1), wait, then WAIT (-1)
433 // SDL_sem * mainMutex = SDL_CreateMutex();
436 WriteLog("Entering main loop...\n");
440 double timeToNextEvent = GetTimeToNextEvent();
441 #ifndef THREADED_65C02
442 Execute65C02(&mainCPU, USEC_TO_M6502_CYCLES(timeToNextEvent));
444 #ifdef CPU_CLOCK_CHECKING
445 totalCPU += USEC_TO_M6502_CYCLES(timeToNextEvent);
451 #ifdef THREADED_65C02
452 WriteLog("Main: cpuFinished = true;\n");
455 WriteLog("Main: SDL_SemWait(mainSem);\n");
456 // Only do this if NOT in power off/emulation paused mode!
458 // Should lock until CPU thread is waiting...
459 SDL_SemWait(mainSem);
462 WriteLog("Main: SDL_CondSignal(cpuCond);\n");
463 SDL_CondSignal(cpuCond);//thread is probably asleep, so wake it up
464 WriteLog("Main: SDL_WaitThread(cpuThread, NULL);\n");
465 SDL_WaitThread(cpuThread, NULL);
466 WriteLog("Main: SDL_DestroyCond(cpuCond);\n");
467 SDL_DestroyCond(cpuCond);
468 SDL_DestroySemaphore(mainSem);
470 // Autosave state here, if requested...
471 if (settings.autoStateSaving)
472 SaveApple2State(settings.autoStatePath);
474 floppyDrive.SaveImage(0);
475 floppyDrive.SaveImage(1);
491 -----------------------
492 space $A0 $A0 $A0 $A0 No xlation
493 RETURN $8D $8D $8D $8D No xlation
494 0 $B0 $B0 $B0 $B0 Need to screen shift+0 (?)
495 1! $B1 $B1 $A1 $A1 No xlation
496 2" $B2 $B2 $A2 $A2 No xlation
497 3# $B3 $B3 $A3 $A3 No xlation
498 4$ $B4 $B4 $A4 $A4 No xlation
499 5% $B5 $B5 $A5 $A5 No xlation
500 6& $B6 $B6 $A6 $A6 No xlation
501 7' $B7 $B7 $A7 $A7 No xlation
502 8( $B8 $B8 $A8 $A8 No xlation
503 9) $B9 $B9 $A9 $A9 No xlation
504 :* $BA $BA $AA $AA No xlation
505 ;+ $BB $BB $AB $AB No xlation
506 ,< $AC $AC $BC $BC No xlation
507 -= $AD $AD $BD $BD No xlation
508 .> $AE $AE $BE $BE No xlation
509 /? $AF $AF $BF $BF No xlation
522 M $CD $8D $DD $9D -> ODD
523 N^ $CE $8E $DE $9E -> ODD
525 P@ $D0 $90 $C0 $80 Need to xlate CTL+SHFT+P & SHFT+P (?)
538 ESC $9B $9B $9B $9B No xlation
541 static uint32_t frameCount = 0;
542 static void FrameCallback(void)
546 while (SDL_PollEvent(&event))
550 // Problem with using SDL_TEXTINPUT is that it causes key delay. :-/
553 //Need to do some key translation here, and screen out non-apple keys as well...
554 //(really, could do it all in SDL_KEYDOWN, would just have to get symbols &
555 // everything else done separately. this is slightly easier. :-P)
556 // if (event.key.keysym.sym == SDLK_TAB) // Prelim key screening...
557 if (event.edit.text[0] == '\t') // Prelim key screening...
560 lastKeyPressed = event.edit.text[0];
563 //kludge: should have a caps lock thingy here...
564 //or all uppercase for ][+...
565 // if (lastKeyPressed >= 'a' && lastKeyPressed <='z')
566 // lastKeyPressed &= 0xDF; // Convert to upper case...
571 // Use CTRL+SHIFT+Q to exit, as well as the usual window decoration
573 if ((event.key.keysym.mod & KMOD_CTRL)
574 && (event.key.keysym.mod & KMOD_SHIFT)
575 && (event.key.keysym.sym == SDLK_q))
578 // We return here, because we don't want to pick up any
579 // spurious keypresses with our exit sequence.
583 // CTRL+RESET key emulation (mapped to CTRL+`)
584 // This doesn't work...
585 // if (event.key.keysym.sym == SDLK_BREAK && (event.key.keysym.mod & KMOD_CTRL))
586 // if (event.key.keysym.sym == SDLK_PAUSE && (event.key.keysym.mod & KMOD_CTRL))
587 if ((event.key.keysym.mod & KMOD_CTRL)
588 && (event.key.keysym.sym == SDLK_BACKQUOTE))
590 //NOTE that this shouldn't take place until the key is lifted... !!! FIX !!!
591 //ALSO it seems to leave the machine in an inconsistent state vis-a-vis the language card...
592 mainCPU.cpuFlags |= V65C02_ASSERT_LINE_RESET;
596 if (event.key.keysym.sym == SDLK_RIGHT)
597 lastKeyPressed = 0x15, keyDown = true;
598 else if (event.key.keysym.sym == SDLK_LEFT)
599 lastKeyPressed = 0x08, keyDown = true;
600 else if (event.key.keysym.sym == SDLK_UP)
601 lastKeyPressed = 0x0B, keyDown = true;
602 else if (event.key.keysym.sym == SDLK_DOWN)
603 lastKeyPressed = 0x0A, keyDown = true;
604 else if (event.key.keysym.sym == SDLK_RETURN)
605 lastKeyPressed = 0x0D, keyDown = true;
606 else if (event.key.keysym.sym == SDLK_ESCAPE)
607 lastKeyPressed = 0x1B, keyDown = true;
608 else if (event.key.keysym.sym == SDLK_BACKSPACE)
609 lastKeyPressed = 0x7F, keyDown = true;
611 // Fix CTRL+key combo...
612 if (event.key.keysym.mod & KMOD_CTRL)
614 if (event.key.keysym.sym >= SDLK_a && event.key.keysym.sym <= SDLK_z)
616 lastKeyPressed = (event.key.keysym.sym - SDLK_a) + 1;
618 //printf("Key combo pressed: CTRL+%c\n", lastKeyPressed + 0x40);
624 // Fix SHIFT+key combo...
625 if (event.key.keysym.mod & KMOD_SHIFT)
627 if (event.key.keysym.sym >= SDLK_a && event.key.keysym.sym <= SDLK_z)
629 lastKeyPressed = (event.key.keysym.sym - SDLK_a) + 0x41;
631 //printf("Key combo pressed: CTRL+%c\n", lastKeyPressed + 0x40);
634 else if (event.key.keysym.sym == SDLK_1)
636 lastKeyPressed = '!';
640 else if (event.key.keysym.sym == SDLK_2)
642 lastKeyPressed = '@';
646 else if (event.key.keysym.sym == SDLK_3)
648 lastKeyPressed = '#';
652 else if (event.key.keysym.sym == SDLK_4)
654 lastKeyPressed = '$';
658 else if (event.key.keysym.sym == SDLK_5)
660 lastKeyPressed = '%';
664 else if (event.key.keysym.sym == SDLK_6)
666 lastKeyPressed = '^';
670 else if (event.key.keysym.sym == SDLK_7)
672 lastKeyPressed = '&';
676 else if (event.key.keysym.sym == SDLK_8)
678 lastKeyPressed = '*';
682 else if (event.key.keysym.sym == SDLK_9)
684 lastKeyPressed = '(';
688 else if (event.key.keysym.sym == SDLK_0)
690 lastKeyPressed = ')';
694 else if (event.key.keysym.sym == SDLK_MINUS)
696 lastKeyPressed = '_';
700 else if (event.key.keysym.sym == SDLK_EQUALS)
702 lastKeyPressed = '+';
706 else if (event.key.keysym.sym == SDLK_LEFTBRACKET)
708 lastKeyPressed = '{';
712 else if (event.key.keysym.sym == SDLK_RIGHTBRACKET)
714 lastKeyPressed = '}';
718 else if (event.key.keysym.sym == SDLK_BACKSLASH)
720 lastKeyPressed = '|';
724 else if (event.key.keysym.sym == SDLK_SEMICOLON)
726 lastKeyPressed = ':';
730 else if (event.key.keysym.sym == SDLK_QUOTE)
732 lastKeyPressed = '"';
736 else if (event.key.keysym.sym == SDLK_COMMA)
738 lastKeyPressed = '<';
742 else if (event.key.keysym.sym == SDLK_PERIOD)
744 lastKeyPressed = '>';
748 else if (event.key.keysym.sym == SDLK_SLASH)
750 lastKeyPressed = '?';
754 else if (event.key.keysym.sym == SDLK_BACKQUOTE)
756 lastKeyPressed = '~';
764 if (event.key.keysym.sym >= SDLK_SPACE && event.key.keysym.sym <= SDLK_z)
766 lastKeyPressed = event.key.keysym.sym;
769 // Check for Caps Lock key...
770 if (event.key.keysym.sym >= SDLK_a && event.key.keysym.sym <= SDLK_z && capsLock)
771 lastKeyPressed -= 0x20;
776 if (event.key.keysym.sym == SDLK_PAUSE)
778 pauseMode = !pauseMode;
783 SpawnMessage("*** PAUSED ***");
788 SpawnMessage("*** RESUME ***");
792 // Paddle buttons 0 & 1
793 if (event.key.keysym.sym == SDLK_LALT)
794 openAppleDown = true;
795 if (event.key.keysym.sym == SDLK_RALT)
796 closedAppleDown = true;
798 if (event.key.keysym.sym == SDLK_F11)
799 dumpDis = !dumpDis; // Toggle the disassembly process
801 /*else if (event.key.keysym.sym == SDLK_F9)
803 floppyDrive.CreateBlankImage(0);
804 // SpawnMessage("Image cleared...");
806 /*else if (event.key.keysym.sym == SDLK_F10)
808 floppyDrive.SwapImages();
809 // SpawnMessage("Image swapped...");
812 if (event.key.keysym.sym == SDLK_F2)
814 else if (event.key.keysym.sym == SDLK_F3)
816 else if (event.key.keysym.sym == SDLK_F5)
819 char volStr[19] = "[****************]";
821 for(int i=GetVolume(); i<16; i++)
824 SpawnMessage("Volume: %s", volStr);
826 else if (event.key.keysym.sym == SDLK_F6)
829 char volStr[19] = "[****************]";
831 for(int i=GetVolume(); i<16; i++)
834 SpawnMessage("Volume: %s", volStr);
836 else if (event.key.keysym.sym == SDLK_F12)
838 if (!fullscreenDebounce)
841 fullscreenDebounce = true;
845 if (event.key.keysym.sym == SDLK_CAPSLOCK)
847 if (!capsLockDebounce)
849 capsLock = !capsLock;
850 capsLockDebounce = true;
856 if (event.key.keysym.sym == SDLK_F12)
857 fullscreenDebounce = false;
858 if (event.key.keysym.sym == SDLK_CAPSLOCK)
859 capsLockDebounce = false;
861 // Paddle buttons 0 & 1
862 if (event.key.keysym.sym == SDLK_LALT)
863 openAppleDown = false;
864 if (event.key.keysym.sym == SDLK_RALT)
865 closedAppleDown = false;
868 case SDL_MOUSEBUTTONDOWN:
869 GUI::MouseDown(event.motion.x, event.motion.y, event.motion.state);
871 case SDL_MOUSEBUTTONUP:
872 GUI::MouseUp(event.motion.x, event.motion.y, event.motion.state);
874 case SDL_MOUSEMOTION:
875 GUI::MouseMove(event.motion.x, event.motion.y, event.motion.state);
877 case SDL_WINDOWEVENT:
878 if (event.window.event == SDL_WINDOWEVENT_LEAVE)
879 GUI::MouseMove(0, 0, 0);
887 // Handle power request from the GUI
888 if (powerStateChangeRequested)
890 if (GUI::powerOnState)
893 // Unlock the CPU thread...
894 SDL_SemPost(mainSem);
899 // Should lock until CPU thread is waiting...
900 SDL_SemWait(mainSem);
904 powerStateChangeRequested = false;
907 RenderVideoFrame(); // Render Apple screen to buffer
908 RenderScreenBuffer(); // Render buffer to host screen
909 GUI::Render(sdlRenderer);
910 SDL_RenderPresent(sdlRenderer);
911 SetCallbackTime(FrameCallback, 16666.66666667);
913 #ifdef CPU_CLOCK_CHECKING
914 //We know it's stopped, so we can get away with this...
918 uint64_t clock = GetCurrentV65C02Clock();
919 //totalCPU += (uint32_t)(clock - lastClock);
921 printf("Executed %u cycles...\n", (uint32_t)(clock - lastClock));
928 // This is the problem: If you set the interval to 16, it runs faster than
929 // 1/60s per frame. If you set it to 17, it runs slower. What we need is to
930 // have it do 16 for one frame, then 17 for two others. Then it should average
931 // out to 1/60s per frame every 3 frames.
932 frameCount = (frameCount + 1) % 3;
933 uint32_t waitFrameTime = 17 - (frameCount == 0 ? 1 : 0);
935 // Wait for next frame...
936 while (SDL_GetTicks() - startTicks < waitFrameTime)
939 startTicks = SDL_GetTicks();
941 uint64_t cpuCycles = GetCurrentV65C02Clock();
942 uint32_t cyclesBurned = (uint32_t)(cpuCycles - lastCPUCycles);
943 WriteLog("FrameCallback: used %i cycles\n", cyclesBurned);
944 lastCPUCycles = cpuCycles
947 //let's wait, then signal...
948 //works longer, but then still falls behind... [FIXED, see above]
949 #ifdef THREADED_65C02
951 SDL_CondSignal(cpuCond);//OK, let the CPU go another frame...
956 static void BlinkTimer(void)
958 // Set up blinking at 1/4 sec intervals
960 SetCallbackTime(BlinkTimer, 250000);
965 Next problem is this: How to have events occur and synchronize with the rest
968 o Have the CPU thread manage the timer mechanism? (need to have a method of carrying
969 remainder CPU cycles over...)
971 One way would be to use a fractional accumulator, then subtract 1 every
972 time it overflows. Like so:
978 Execute6808(&soundCPU, time);
979 overflow += 0.289115646;