Revert "testing threads"

This reverts commit f5b7f19ebb.
This commit is contained in:
Jorj Bauer 2020-07-04 16:28:07 -04:00
parent e0b0072b73
commit cf484cf302

View File

@ -1,8 +1,7 @@
#include <Arduino.h> #include <Arduino.h>
#include <SPI.h> #include <SPI.h>
#include <TimeLib.h> #include <TimeLib.h>
#include <TeensyThreads.h> #include <TimerOne.h>
#include "bios.h" #include "bios.h"
#include "cpu.h" #include "cpu.h"
#include "applevm.h" #include "applevm.h"
@ -27,8 +26,6 @@ uint32_t startMicros;
BIOS bios; BIOS bios;
int cpuThreadId = 0;
// How many microseconds per cycle // How many microseconds per cycle
#define SPEEDCTL ((float)1000000/(float)g_speed) #define SPEEDCTL ((float)1000000/(float)g_speed)
@ -137,9 +134,9 @@ void setup()
println("free-running"); println("free-running");
threads.setDefaultTimeSlice(1); Timer1.initialize(3);
threads.setSliceMicros(500); Timer1.attachInterrupt(runCPU);
cpuThreadId = threads.addThread(runCPU); Timer1.start();
} }
// FIXME: move these memory-related functions elsewhere... // FIXME: move these memory-related functions elsewhere...
@ -170,7 +167,7 @@ int heapSize(){
void biosInterrupt() void biosInterrupt()
{ {
threads.suspend(cpuThreadId); Timer1.stop();
// wait for the interrupt button to be released // wait for the interrupt button to be released
while (digitalRead(RESETPIN) == LOW) while (digitalRead(RESETPIN) == LOW)
@ -201,7 +198,7 @@ void biosInterrupt()
// Poll the keyboard before we start, so we can do selftest on startup // Poll the keyboard before we start, so we can do selftest on startup
g_keyboard->maintainKeyboard(); g_keyboard->maintainKeyboard();
threads.restart(cpuThreadId); Timer1.start();
} }
//bool debugState = false; //bool debugState = false;
@ -210,7 +207,7 @@ void biosInterrupt()
void runCPU() void runCPU()
{ {
while (1) { g_inInterrupt = true;
// Debugging: to watch when the speaker is triggered... // Debugging: to watch when the speaker is triggered...
// static bool debugState = false; // static bool debugState = false;
// debugState = !debugState; // debugState = !debugState;
@ -235,7 +232,8 @@ void runCPU()
((AppleVM *)g_vm)->cpuMaintenance(g_cpu->cycles); ((AppleVM *)g_vm)->cpuMaintenance(g_cpu->cycles);
} }
}
g_inInterrupt = false;
} }
void loop() void loop()
@ -262,7 +260,14 @@ void loop()
// display update, OR // display update, OR
// - lock display updates so the CPU can update the memory, but we // - lock display updates so the CPU can update the memory, but we
// keep drawing what was going to be displayed // keep drawing what was going to be displayed
//
// The Timer1.stop()/start() is bad. Using it, the display doesn't
// tear; but the audio is also broken. Taking it out, audio is good
// but the display tears. So there's a global - g_prioritizeDisplay -
// which lets the user pick which they want.
if (g_prioritizeDisplay)
Timer1.stop();
g_ui->blit(); g_ui->blit();
g_vm->vmdisplay->lockDisplay(); g_vm->vmdisplay->lockDisplay();
if (g_vm->vmdisplay->needsRedraw()) { if (g_vm->vmdisplay->needsRedraw()) {
@ -271,6 +276,8 @@ void loop()
g_display->blit(what); g_display->blit(what);
} }
g_vm->vmdisplay->unlockDisplay(); g_vm->vmdisplay->unlockDisplay();
if (g_prioritizeDisplay)
Timer1.start();
static unsigned long nextBattCheck = millis() + 30;// debugging static unsigned long nextBattCheck = millis() + 30;// debugging
static int batteryLevel = 0; // static for debugging code! When done static int batteryLevel = 0; // static for debugging code! When done
@ -377,6 +384,7 @@ void readPrefs()
g_volume = p.volume; g_volume = p.volume;
g_displayType = p.displayType; g_displayType = p.displayType;
g_debugMode = p.debug; g_debugMode = p.debug;
g_prioritizeDisplay = p.priorityMode;
g_speed = (p.speed * (1023000/2)); // steps of half normal speed g_speed = (p.speed * (1023000/2)); // steps of half normal speed
if (g_speed < (1023000/2)) if (g_speed < (1023000/2))
g_speed = (1023000/2); g_speed = (1023000/2);
@ -413,13 +421,14 @@ void writePrefs()
p.volume = g_volume; p.volume = g_volume;
p.displayType = g_displayType; p.displayType = g_displayType;
p.debug = g_debugMode; p.debug = g_debugMode;
p.priorityMode = g_prioritizeDisplay;
p.speed = g_speed / (1023000/2); p.speed = g_speed / (1023000/2);
strcpy(p.disk1, ((AppleVM *)g_vm)->DiskName(0)); strcpy(p.disk1, ((AppleVM *)g_vm)->DiskName(0));
strcpy(p.disk2, ((AppleVM *)g_vm)->DiskName(1)); strcpy(p.disk2, ((AppleVM *)g_vm)->DiskName(1));
strcpy(p.hd1, ((AppleVM *)g_vm)->HDName(0)); strcpy(p.hd1, ((AppleVM *)g_vm)->HDName(0));
strcpy(p.hd2, ((AppleVM *)g_vm)->HDName(1)); strcpy(p.hd2, ((AppleVM *)g_vm)->HDName(1));
threads.suspend(cpuThreadId); Timer1.stop();
bool ret = np.writePrefs(&p); bool ret = np.writePrefs(&p);
threads.restart(cpuThreadId); Timer1.start();
} }