a tiny bit of reorganization, doing things more like the documentation (bink playback) and preparing to merge with thread repo
This commit is contained in:
1 parent
1523b581bb
commit
fc0b9c2fed
6 files changed
+95
-65
No files matched your search
Binary file not shown.
Binary file not shown.
Binary file not shown.
+90
-61
@@ -191,13 +191,27 @@ BOOL HeapFree(HANDLE, DWORD, LPVOID ptr) {
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void *memcpy(void *dest, const void *src, size_t n) {
|
||||||
|
// Cast the void pointers to char pointers so we can perform byte-wise arithmetic
|
||||||
|
unsigned char *d = (unsigned char *)dest;
|
||||||
|
const unsigned char *s = (const unsigned char *)src;
|
||||||
|
|
||||||
|
// Copy each byte from src to dest
|
||||||
|
for (size_t i = 0; i < n; i++) {
|
||||||
|
d[i] = s[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the original destination pointer
|
||||||
|
return dest;
|
||||||
|
}
|
||||||
|
|
||||||
LPVOID HeapReAlloc(HANDLE, DWORD, LPVOID ptr, SIZE_T size) {
|
LPVOID HeapReAlloc(HANDLE, DWORD, LPVOID ptr, SIZE_T size) {
|
||||||
PRINT("Called: HeapReAlloc with size: %ull and ptr: %p\n", size, ptr);
|
PRINT("Called: HeapReAlloc with size: %ull and ptr: %p\n", size, ptr);
|
||||||
if (!ptr) return Malloc(size);
|
if (!ptr) return Malloc(size);
|
||||||
LPVOID newPtr = Malloc(size);
|
LPVOID newPtr = Malloc(size);
|
||||||
if (!newPtr) return nullptr;
|
if (!newPtr) return nullptr;
|
||||||
// No original size info; can't fully emulate, user must handle
|
// No original size info; can't fully emulate, user must handle
|
||||||
CopyMem(newPtr, ptr, size);
|
memcpy(newPtr, ptr, size);
|
||||||
Free(ptr);
|
Free(ptr);
|
||||||
return newPtr;
|
return newPtr;
|
||||||
}
|
}
|
||||||
@@ -223,6 +237,58 @@ DWORD WaitForSingleObject(HANDLE, DWORD) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DWORD ResumeThread(HANDLE hThread) {
|
||||||
|
PRINT("Called: ResumeThread\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL SetThreadPriority(HANDLE hThread, int nPriority) {
|
||||||
|
PRINT("Called: SetThreadPriority\n");
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void InitializeCriticalSection(LPCRITICAL_SECTION lpCriticalSection) {
|
||||||
|
PRINT("Called: InitializeCriticalSection\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeleteCriticalSection(LPCRITICAL_SECTION lpCriticalSection) {
|
||||||
|
PRINT("Called: DeleteCriticalSection\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void EnterCriticalSection(LPCRITICAL_SECTION lpCriticalSection) {
|
||||||
|
PRINT("Called: EnterCriticalSection\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void LeaveCriticalSection(LPCRITICAL_SECTION lpCriticalSection) {
|
||||||
|
PRINT("Called: LeaveCriticalSection\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
DWORD GetCurrentThreadId() {
|
||||||
|
PRINT("Called: GetCurrentThreadId\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
HANDLE CreateMutexA(LPSECURITY_ATTRIBUTES lpMutexAttributes, BOOL bInitialOwner, LPCTSTR lpName) {
|
||||||
|
PRINT("Called: CreateMutexA with name: lpName: %s\n", lpName);
|
||||||
|
return reinterpret_cast<HANDLE>(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL ReleaseMutex(HANDLE hMutex) {
|
||||||
|
PRINT("Called: ReleaseMutex\n");
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
HANDLE CreateSemaphoreA(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, LONG lInitialCount, LONG lMaximumCount, LPCTSTR lpName) {
|
||||||
|
PRINT("Called: CreateSemaphoreA with name: lpName: %s\n", lpName);
|
||||||
|
return reinterpret_cast<HANDLE>(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL ReleaseSemaphore(HANDLE hSemaphore, LONG lReleaseCount, LPLONG lpPreviousCount) {
|
||||||
|
PRINT("Called: ReleaseSemaphore\n");
|
||||||
|
if (lpPreviousCount) *lpPreviousCount = 0;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
// --- Timing ---
|
// --- Timing ---
|
||||||
static inline unsigned long long read_tsc() {
|
static inline unsigned long long read_tsc() {
|
||||||
_mm_lfence();
|
_mm_lfence();
|
||||||
@@ -282,7 +348,28 @@ BOOL QueryPerformanceCounter(LARGE_INTEGER* lpPerformanceCount)
|
|||||||
DWORD GetTickCount() {
|
DWORD GetTickCount() {
|
||||||
LARGE_INTEGER counter;
|
LARGE_INTEGER counter;
|
||||||
QueryPerformanceCounter(&counter);
|
QueryPerformanceCounter(&counter);
|
||||||
return (DWORD)(counter.QuadPart / 1000ULL); // ms
|
return (DWORD)counter.QuadPart;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Sleep(DWORD dwMilliseconds) {
|
||||||
|
if (dwMilliseconds == 0) return;
|
||||||
|
|
||||||
|
// Ensure calibration has happened
|
||||||
|
if (!g_QpcInitialized) {
|
||||||
|
LARGE_INTEGER freq;
|
||||||
|
QueryPerformanceFrequency(&freq);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long long start = read_tsc();
|
||||||
|
|
||||||
|
// Calculate how many total TSC ticks we need to wait
|
||||||
|
unsigned long long ticksToWait = (unsigned long long)dwMilliseconds * g_TicksPerMs;
|
||||||
|
|
||||||
|
// Busy-wait until the TSC difference reaches the target
|
||||||
|
// We use _mm_pause() to be friendly to the CPU pipeline during the loop
|
||||||
|
while ((read_tsc() - start) < ticksToWait) {
|
||||||
|
_mm_pause();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Module / File ---
|
// --- Module / File ---
|
||||||
@@ -448,12 +535,6 @@ DWORD GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sleep(DWORD dwMilliseconds) {
|
|
||||||
PRINT("Called: Sleep\n");
|
|
||||||
UINTN microseconds = (UINTN)dwMilliseconds * 1000;
|
|
||||||
BS->Stall(microseconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
DWORD SetErrorMode(DWORD uMode) {
|
DWORD SetErrorMode(DWORD uMode) {
|
||||||
PRINT("Called: SetErrorMode\n");
|
PRINT("Called: SetErrorMode\n");
|
||||||
return 0;
|
return 0;
|
||||||
@@ -527,60 +608,8 @@ DWORD_PTR SetThreadAffinityMask(HANDLE hThread, DWORD_PTR dwThreadAffinityMask)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
DWORD ResumeThread(HANDLE hThread) {
|
|
||||||
PRINT("Called: ResumeThread\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL SetThreadPriority(HANDLE hThread, int nPriority) {
|
|
||||||
PRINT("Called: SetThreadPriority\n");
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void InitializeCriticalSection(LPCRITICAL_SECTION lpCriticalSection) {
|
|
||||||
PRINT("Called: InitializeCriticalSection\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeleteCriticalSection(LPCRITICAL_SECTION lpCriticalSection) {
|
|
||||||
PRINT("Called: DeleteCriticalSection\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
void EnterCriticalSection(LPCRITICAL_SECTION lpCriticalSection) {
|
|
||||||
PRINT("Called: EnterCriticalSection\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
void LeaveCriticalSection(LPCRITICAL_SECTION lpCriticalSection) {
|
|
||||||
PRINT("Called: LeaveCriticalSection\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
DWORD GetCurrentThreadId() {
|
|
||||||
PRINT("Called: GetCurrentThreadId\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
HANDLE CreateMutexA(LPSECURITY_ATTRIBUTES lpMutexAttributes, BOOL bInitialOwner, LPCTSTR lpName) {
|
|
||||||
PRINT("Called: CreateMutexA with name: lpName: %s\n", lpName);
|
|
||||||
return reinterpret_cast<HANDLE>(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL ReleaseMutex(HANDLE hMutex) {
|
|
||||||
PRINT("Called: ReleaseMutex\n");
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
HANDLE CreateSemaphoreA(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, LONG lInitialCount, LONG lMaximumCount, LPCTSTR lpName) {
|
|
||||||
PRINT("Called: CreateSemaphoreA with name: lpName: %s\n", lpName);
|
|
||||||
return reinterpret_cast<HANDLE>(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL ReleaseSemaphore(HANDLE hSemaphore, LONG lReleaseCount, LPLONG lpPreviousCount) {
|
|
||||||
PRINT("Called: ReleaseSemaphore\n");
|
|
||||||
if (lpPreviousCount) *lpPreviousCount = 0;
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL TerminateProcess(HANDLE hProcess, UINT uExitCode) {
|
BOOL TerminateProcess(HANDLE hProcess, UINT uExitCode) {
|
||||||
PRINT("Called: TerminateProcess\n");
|
PRINT("!! Called: TerminateProcess\n");
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -467,16 +467,15 @@ EFI_STATUS efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE* SystemTable) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Wait for the next frame
|
// Wait for the next frame
|
||||||
if (pBinkWait(bink)) {
|
while (pBinkWait(bink)) {
|
||||||
_mm_pause(); // don't burn CPU cycles
|
_mm_pause(); // don't burn CPU cycles
|
||||||
continue; // wait for the next frame
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if we should skip the frame
|
// Check if we should skip the frame
|
||||||
if (pBinkShouldSkip(bink)) {
|
while (pBinkShouldSkip(bink)) {
|
||||||
pBinkNextFrame(bink);
|
pBinkNextFrame(bink);
|
||||||
|
pBinkDoFrame(bink);
|
||||||
skipped++;
|
skipped++;
|
||||||
continue; // skip this frame
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int code = pBinkDoFrame(bink);
|
int code = pBinkDoFrame(bink);
|
||||||
@@ -484,6 +483,7 @@ EFI_STATUS efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE* SystemTable) {
|
|||||||
printf("BinkDoFrame failed!\n");
|
printf("BinkDoFrame failed!\n");
|
||||||
pBinkClose(bink);
|
pBinkClose(bink);
|
||||||
Free(video_file);
|
Free(video_file);
|
||||||
|
Free(framebuffer);
|
||||||
gBS->Stall(5 * 1000 * 1000);
|
gBS->Stall(5 * 1000 * 1000);
|
||||||
gST->RuntimeServices->ResetSystem(EfiResetShutdown, EFI_SUCCESS, 0, NULL);
|
gST->RuntimeServices->ResetSystem(EfiResetShutdown, EFI_SUCCESS, 0, NULL);
|
||||||
return 1;
|
return 1;
|
||||||
@@ -503,6 +503,7 @@ EFI_STATUS efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE* SystemTable) {
|
|||||||
printf("BinkCopyToBuffer failed!\n");
|
printf("BinkCopyToBuffer failed!\n");
|
||||||
pBinkClose(bink);
|
pBinkClose(bink);
|
||||||
Free(video_file);
|
Free(video_file);
|
||||||
|
Free(framebuffer);
|
||||||
gBS->Stall(5 * 1000 * 1000);
|
gBS->Stall(5 * 1000 * 1000);
|
||||||
gST->RuntimeServices->ResetSystem(EfiResetShutdown, EFI_SUCCESS, 0, NULL);
|
gST->RuntimeServices->ResetSystem(EfiResetShutdown, EFI_SUCCESS, 0, NULL);
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
Reference in new issue
Block a user