Compare commits

...

2 Commits

Author SHA1 Message Date
Ian Burgmyer 441ee50a44 Improved interrupt behavior. 4 years ago
Ian Burgmyer e85809995d Added turbo support to the frontend. 4 years ago
  1. 24
      libplip/Cpu/SharpLr35902/SharpLr35902.cpp
  2. 1
      libplip/Cpu/SharpLr35902/SharpLr35902.h
  3. 18
      plip-sdl/GameLoop.cpp
  4. 12
      plip-sdl/SDL/SdlEvent.cpp
  5. 3
      plip-sdl/SDL/SdlEvent.h
  6. 3
      plip-sdl/main.cpp

24
libplip/Cpu/SharpLr35902/SharpLr35902.cpp

@ -26,7 +26,7 @@ namespace Plip::Cpu {
// Handle interrupts here if (1) we're ready to fetch, (2) interrupts
// are enabled, and (3) an interrupt request has been made.
auto iFlag = m_memory->GetByte(m_interruptFlag) & 0b00011111;
if(m_allowFetch && m_ime == ScheduledState::Enabled && iFlag) {
if(m_allowFetch && m_ime == ScheduledState::Enabled && iFlag && !m_isr) {
auto ie = m_memory->GetByte(m_interruptEnabled);
// If no interrupts are enabled, and a HALT instruction has been
@ -37,9 +37,16 @@ namespace Plip::Cpu {
throw PlipEmulationException(ex.str().c_str());
}
// Check to see if the requested interrupt has been enabled.
iFlag &= ie;
if(iFlag) {
// Check for an enabled interrupt.
m_isr = false;
for(m_isrIdx = 0; m_isrIdx <= 4; m_isrIdx++) {
if(ie & (iFlag & (1 << m_isrIdx))) {
m_isr = true;
break;
}
}
if(m_isr) {
// Set up the CPU to jump to the interrupt handler.
m_allowFetch = false;
m_ime = ScheduledState::Disabled;
@ -51,15 +58,10 @@ namespace Plip::Cpu {
if(m_isr) {
STACK_PUSH_PC(3);
CYCLE(5) {
uint8_t idx = 0;
for(; idx > 4; idx++) {
if(iFlag & (1 << idx)) break;
}
m_halt = false;
m_isr = false;
m_reg.pc = 0x40 + (idx * 0x8);
m_memory->SetByte(m_interruptFlag, iFlag ^ (1 << idx));
m_reg.pc = 0x40 + (m_isrIdx * 0x8);
m_memory->SetByte(m_interruptFlag, iFlag ^ (1 << m_isrIdx));
}
NUM_MCYCLES(5);
}

1
libplip/Cpu/SharpLr35902/SharpLr35902.h

@ -156,6 +156,7 @@ namespace Plip::Cpu {
bool m_allowFetch = true;
bool m_isr = false;
uint8_t m_isrIdx = 0;
bool m_halt = false;
ScheduledState m_ime = ScheduledState::Disabled;
std::vector<uint8_t> m_instr;

18
plip-sdl/GameLoop.cpp

@ -106,6 +106,7 @@ namespace PlipSdl {
void GameLoop::Play() {
auto audio = m_plip->GetAudio();
auto core = m_plip->GetCore();
auto turbo = false;
m_running = true;
SdlUiEvent uiEvent;
@ -148,6 +149,14 @@ namespace PlipSdl {
m_console->ToggleConsole();
break;
case SdlUiEvent::TurboOff:
turbo = false;
break;
case SdlUiEvent::TurboOn:
turbo = true;
break;
case SdlUiEvent::Quit:
m_running = false;
break;
@ -157,10 +166,13 @@ namespace PlipSdl {
auto time = m_timer->StopwatchStop();
auto delay = m_updateTime - time;
while(delay < 0)
delay += m_updateTime;
m_timer->Nanosleep(delay);
if(!turbo) {
while(delay < 0)
delay += m_updateTime;
m_timer->Nanosleep(delay);
}
}
audio->DequeueAll();

12
plip-sdl/SDL/SdlEvent.cpp

@ -32,12 +32,17 @@ namespace PlipSdl {
uiEvent = SdlUiEvent::PlayPause;
else if(ev.key.keysym.scancode == m_stepKey)
uiEvent = SdlUiEvent::Step;
else if(ev.key.keysym.scancode == m_turboKey)
uiEvent = SdlUiEvent::TurboOn;
else
UpdateDigitalInput(ev.key.keysym.scancode, true);
break;
case SDL_KEYUP:
UpdateDigitalInput(ev.key.keysym.scancode, false);
if(ev.key.keysym.scancode == m_turboKey)
uiEvent = SdlUiEvent::TurboOff;
else
UpdateDigitalInput(ev.key.keysym.scancode, false);
break;
case SDL_QUIT:
@ -50,6 +55,7 @@ namespace PlipSdl {
}
void SdlEvent::SetKey(const std::string &action, SDL_Scancode scancode) {
// TODO: Oof, this is nasty. Kindly revamp this. :)
switch(Hash(action.c_str())) {
case Hash("console"):
m_consoleKey = scancode;
@ -66,6 +72,10 @@ namespace PlipSdl {
case Hash("step"):
m_stepKey = scancode;
break;
case Hash("turbo"):
m_turboKey = scancode;
break;
}
}

3
plip-sdl/SDL/SdlEvent.h

@ -16,6 +16,8 @@ namespace PlipSdl {
PlayPause,
Step,
ToggleConsole,
TurboOff,
TurboOn,
Quit
};
@ -40,6 +42,7 @@ namespace PlipSdl {
SDL_Scancode m_frameAdvanceKey {};
SDL_Scancode m_pauseKey {};
SDL_Scancode m_stepKey {};
SDL_Scancode m_turboKey {};
std::unordered_map<SDL_Scancode, int> m_digitalBinding;
Plip::PlipInput *m_input;
};

3
plip-sdl/main.cpp

@ -33,7 +33,8 @@ std::unordered_map<std::string, SDL_Scancode> defaultFrontendKeys = {
{ "console", SDL_SCANCODE_GRAVE },
{ "frameadvance", SDL_SCANCODE_RIGHTBRACKET },
{ "pause", SDL_SCANCODE_BACKSLASH },
{ "step", SDL_SCANCODE_LEFTBRACKET }
{ "step", SDL_SCANCODE_LEFTBRACKET },
{ "turbo", SDL_SCANCODE_TAB }
};
std::vector<std::vector<std::string>> intParamMapping = {

Loading…
Cancel
Save