-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
858 additions
and
715 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
jk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,62 @@ | ||
// | ||
// cpu_clock.c | ||
// plasm2_emu | ||
// | ||
// Created by Noah Wooten on 4/21/23. | ||
// | ||
#include "cpu.h" | ||
#include "mmu/mmu.h" | ||
#include "../decoder/decoder.h" | ||
#include "../psin2/psin2.h" | ||
#include "../emu.h" | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <time.h> | ||
|
||
void cpu_clock(void) { | ||
|
||
if ( | ||
!i->flags_s.HF // Do not clock if we are halted | ||
&& !i->flags_s.NF // Skip this cycle, due to no-execute | ||
) { | ||
time(&cpuctx->SystemSeconds); | ||
} else { | ||
if (i->flags_s.NF) { | ||
i->flags_s.NF = 0; | ||
int Psin2Id = Psin2iGetInstructionByOpcode(mmu_read1(i->ip)); | ||
BYTE TotalRead = (Psin2iGetTotalSize(Psin2Id) / 8); | ||
i->ip += TotalRead; | ||
} | ||
return; | ||
} | ||
|
||
if (i->flags_s.VF && | ||
i->flags_s.MF && | ||
i->ip >= i->pti.pml | ||
) { | ||
cpui_csm_msg(CSM_XPAGETOOSMALL, i->ip); | ||
} | ||
|
||
BYTE ThisInstruction = mmu_read1(i->ip++); | ||
if (EmuCtx->DebuggerEnabled) | ||
DecoderGo(ThisInstruction); | ||
|
||
if (ThisInstruction == 0x00) { | ||
if (mmu_read1(i->ip) == 0x00 && | ||
mmu_read1(i->ip) == 0x00 | ||
) { | ||
// we might be in a zero loop | ||
FILE* Memout = fopen("memout.bin", "wb"); | ||
fwrite(cpuctx->PhysicalMemory, cpuctx->PhysicalMemorySize, | ||
1, Memout); | ||
fclose(Memout); | ||
printf("[WARN]: CPU appears to be stuck.\n Continue?"); | ||
SDL_Delay(500); | ||
} | ||
} | ||
|
||
Instructions[ThisInstruction](); | ||
|
||
return; | ||
} | ||
// | ||
// cpu_clock.c | ||
// plasm2_emu | ||
// | ||
// Created by Noah Wooten on 4/21/23. | ||
// | ||
#include "cpu.h" | ||
#include "mmu/mmu.h" | ||
#include "../decoder/decoder.h" | ||
#include "../psin2/psin2.h" | ||
#include "../emu.h" | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <time.h> | ||
|
||
void CpuClock(void) { | ||
CpuCtx->LastTrackedNanoSecond = CpuTimerGetPreciseTimeNanoseconds(); | ||
// Sadly somewhat messy. - nw 11/27/23 | ||
#ifdef CLOCK_SYSTEM_ACTIVE | ||
if (!(EmuCtx->Flags & EMUFLAG_NOCLOCK)) { | ||
while (CpuCtx->NextTickNanoSecond > CpuCtx->LastTrackedNanoSecond) { | ||
#if defined(__unix__) || defined(__MACH__) | ||
#ifdef HAVE_NANOSLEEP | ||
struct timespec NextClockTime, ThisTime; | ||
NextClockTime.tv_sec = 0; | ||
NextClockTime.tv_nsec = CpuCtx->NextTickNanoSecond - CpuCtx->LastTrackedNanoSecond; | ||
nanosleep(&NextClockTime, &ThisTime); | ||
#endif | ||
#elif _WIN32 | ||
/* @TODO : NtDelayExecution for nanosleep =D | ||
This is a large CPU hole, that there doesn't seem to be a great solution to. | ||
When I'm on my Windows desktop, I'll attempt to divide the NextClockTime nanoseconds | ||
into 100ns chunks that a function such as NtDelayExecution can deal with. | ||
- nw 11/27/23 | ||
*/ | ||
#endif | ||
CpuCtx->LastTrackedNanoSecond = CpuTimerGetPreciseTimeNanoseconds(); | ||
} | ||
|
||
CpuCtx->NextTickNanoSecond = CpuCtx->LastTrackedNanoSecond + (NS_PER_S / (CpuCtx->ClocksPerSecond * 3)); | ||
} | ||
#endif | ||
|
||
CpuCtx->SystemTicks++; | ||
|
||
if (ECtx->flags_s.NF) { | ||
ECtx->flags_s.NF = 0; | ||
int Psin2Id = Psin2iGetInstructionByOpcode(MmuRead1(ECtx->ip)); | ||
BYTE TotalToRead = (Psin2iGetTotalSize(Psin2Id) / 8); | ||
ECtx->ip += TotalToRead; | ||
return; | ||
} | ||
|
||
|
||
BYTE ThisInstruction = MmuRead1(ECtx->ip++); | ||
if (EmuCtx->DebuggerEnabled) | ||
DecoderGo(ThisInstruction); | ||
|
||
Instructions[ThisInstruction](); | ||
|
||
return; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.