113 lines
3.0 KiB
C
113 lines
3.0 KiB
C
#include <windows.h>
|
|
#include <stdint.h>
|
|
#include <stddef.h>
|
|
#include <string.h>
|
|
#include <intrin.h>
|
|
#include "bink.h"
|
|
|
|
int main(const char* cmdline) {
|
|
void* h = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
WriteConsoleA(h, "video: starting\n", 16, 0, 0);
|
|
|
|
WriteConsoleA(h, cmdline, (unsigned int)strlen(cmdline), 0, 0);
|
|
WriteConsoleA(h, "\n", 1, 0, 0);
|
|
|
|
void* f = CreateFileA("video.bk2", 0, 0, 0, 3, 0, 0);
|
|
if (!f || f == (void*)(unsigned long long)0xFFFFFFFF) { // fuckass
|
|
WriteConsoleA(h, "video: failed to open video.bk2\n", 32, 0, 0);
|
|
ExitProcess(1);
|
|
}
|
|
|
|
unsigned long s = GetFileSize(f, 0);
|
|
if (!s || s == 0xFFFFFFFF) {
|
|
WriteConsoleA(h, "video: GetFileSize failed!\n", 27, 0, 0);
|
|
ExitProcess(1);
|
|
}
|
|
void* buf = HeapAlloc(0, 0, s);
|
|
if (!buf) {
|
|
WriteConsoleA(h, "video: HeapAlloc failed\n", 24, 0, 0);
|
|
ExitProcess(1);
|
|
}
|
|
|
|
int r = ReadFile(f, buf, s, 0, 0);
|
|
if (!r) {
|
|
WriteConsoleA(h, "video: ReadFile failed\n", 23, 0, 0);
|
|
ExitProcess(1);
|
|
}
|
|
WriteConsoleA(h, "video: video.bk2 loaded\n", 24, 0, 0);
|
|
|
|
CloseHandle(h);
|
|
|
|
HBINK b = BinkOpen(buf, BINKFROMMEMORY);
|
|
if (!b) {
|
|
WriteConsoleA(h, "video: BinkOpen failed: ", 24, 0, 0);
|
|
const char* err = BinkGetError();
|
|
WriteConsoleA(h, err, (unsigned int)strlen(err), 0, 0);
|
|
WriteConsoleA(h, "\n", 1, 0, 0);
|
|
ExitProcess(1);
|
|
}
|
|
|
|
uint32_t width = b->Width;
|
|
uint32_t height = b->Height;
|
|
|
|
uint32_t* fb = HeapAlloc(0, 0, width * height * sizeof(uint32_t));
|
|
if (!fb) {
|
|
WriteConsoleA(h, "video: framebuffer alloc failed\n", 32, 0, 0);
|
|
ExitProcess(1);
|
|
}
|
|
|
|
// Prepare the Win32 BITMAPINFO structure
|
|
BITMAPINFO bmi;
|
|
memset(&bmi, 0, sizeof(bmi));
|
|
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
|
bmi.bmiHeader.biWidth = width;
|
|
bmi.bmiHeader.biHeight = -(LONG)height; // Negative means top-down drawing!
|
|
bmi.bmiHeader.biPlanes = 1;
|
|
bmi.bmiHeader.biBitCount = 32;
|
|
bmi.bmiHeader.biCompression = BI_RGB;
|
|
|
|
while (1) {
|
|
if (BinkWait(b)) {
|
|
_mm_pause();
|
|
continue;
|
|
}
|
|
|
|
BinkDoFrame(b);
|
|
|
|
if (BinkShouldSkip(b)) {
|
|
BinkNextFrame(b);
|
|
BinkDoFrame(b);
|
|
continue;
|
|
}
|
|
|
|
BinkCopyToBuffer(b, fb, width * 4, height, 0, 0,
|
|
BINKSURFACE32);
|
|
|
|
// Welcome to the GDI pipeline!
|
|
PAINTSTRUCT ps;
|
|
// Using NULL/0 as the HWND since we don't have a real window handle yet
|
|
HDC hdc = BeginPaint((HWND)0, &ps);
|
|
|
|
StretchDIBits(
|
|
hdc,
|
|
0, 0, width, height, // Destination rect
|
|
0, 0, width, height, // Source rect
|
|
fb,
|
|
&bmi,
|
|
DIB_RGB_COLORS,
|
|
SRCCOPY
|
|
);
|
|
|
|
EndPaint((HWND)0, &ps);
|
|
|
|
if (b->FrameNum == b->Frames)
|
|
break;
|
|
|
|
BinkNextFrame(b);
|
|
}
|
|
|
|
WriteConsoleA(h, "shell: goodbye\n", 15, 0, 0);
|
|
|
|
ExitProcess(0);
|
|
}
|