Files
bluflame/evoke-64k/evk13-4k/main_release.cpp
2026-04-18 22:31:51 +02:00

454 lines
9.5 KiB
C++

#define WIN32_LEAN_AND_MEAN
#define WIN32_EXTRA_LEAN
#include <windows.h>
#include <stdio.h>
#include <mmsystem.h>
#include <mmreg.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "glext.h"
#include "small.h"
#include "4klang.h"
#define ULTRA
#pragma data_seg(".Shader0")
#include "mark_small.h"
/*******************************************************/
/* config flags */
//#define DESKTOP_RESOLUTION
//#define WINDOWED
#define CHANGERES_DELAY
#define CLEAR_SCREEN_WHILE_LOADING
#define SHADER_WARMUP
/* end config flags */
/*******************************************************/
#ifndef DESKTOP_RESOLUTION
#ifndef ASPECT
#define ASPECT 1.77
#endif
#ifndef SCREENWIDTH
#define SCREENWIDTH 1920
#endif
#ifndef SCREENHEIGHT
#define SCREENHEIGHT 1080
#endif
#else
// default aspect ratio for when using the desktop resolution
#ifndef ASPECT
#define ASPECT 1.77
#endif
#endif
#define USE_SOUND_THREAD
#define STR2(x) #x
#define STR(x) STR2(x)
#pragma data_seg(".vertexshader")
static char* vertexShader = "varying vec4 "I_Y";varying vec2 "I_Z";void main(){"I_Y"=gl_Color;"I_Z"=(gl_Vertex.xy*vec2("STR(ASPECT)",1))*.5+.5;gl_Position=gl_Vertex;}";
static char** vsh = &vertexShader;
static char* pixelShader = (char*)mark_fs_0;
static char** fsh = &pixelShader;
#pragma data_seg(".pfd")
static const PIXELFORMATDESCRIPTOR pfd={
0, 1, PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, PFD_TYPE_RGBA, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8
};
#ifndef DESKTOP_RESOLUTION
#pragma data_seg(".dms")
static DEVMODE dmScreenSettings={
"",0,0,sizeof(dmScreenSettings),0,DM_PELSWIDTH|DM_PELSHEIGHT,0,0,0,0,0,0,0,0,0,0,0,0,0,"",0,0,SCREENWIDTH,SCREENHEIGHT
};
#endif
#pragma bss_seg(".mainbss")
static SAMPLE_TYPE lpSoundBuffer[MAX_SAMPLES*2];
static HWAVEOUT hWaveOut;
static unsigned int shaders[5];
#pragma data_seg(".wavefmt")
WAVEFORMATEX WaveFMT =
{
#ifdef FLOAT_32BIT
WAVE_FORMAT_IEEE_FLOAT,
#else
WAVE_FORMAT_PCM,
#endif
2, // channels
SAMPLE_RATE, // samples per sec
SAMPLE_RATE*sizeof(SAMPLE_TYPE)*2, // bytes per sec
sizeof(SAMPLE_TYPE)*2, // block alignment;
sizeof(SAMPLE_TYPE)*8, // bits per sample
0 // extension not needed
};
#pragma data_seg(".wavehdr")
WAVEHDR WaveHDR =
{
(LPSTR)lpSoundBuffer,
MAX_SAMPLES*sizeof(SAMPLE_TYPE)*2,
0, 0, 0, 0, 0, 0
};
#pragma data_seg(".mmtime")
MMTIME MMTime =
{
TIME_SAMPLES,
0
};
#pragma data_seg(".maindata")
const float sceneLength = 64 * SAMPLES_PER_TICK;
const int shaderLength = 4 * 64 * SAMPLES_PER_TICK;
#pragma data_seg(".windowClass")
const char* edit = "edit";
#pragma data_seg(".glFunctions")
const char* glUseProgram = "glUseProgram";
const char* glCreateProgram = "glCreateProgram";
const char* glCreateShader = "glCreateShader";
const char* glShaderSource = "glShaderSource";
const char* glCompileShader = "glCompileShader";
const char* glAttachShader = "glAttachShader";
const char* glLinkProgram = "glLinkProgram";
#pragma code_seg(".initsnd")
__forceinline void InitSound()
{
_asm
{
#ifdef USE_SOUND_THREAD
push ESI
push ESI
push offset [lpSoundBuffer]
push dword ptr [_4klang_render]
push ESI
push ESI
call dword ptr [CreateThread]
#else
push offset [lpSoundBuffer]
push dword ptr [_4klang_render]
#endif
push ESI
push ESI
push ESI
push offset [WaveFMT]
push -0x1
push offset [hWaveOut]
call dword ptr [waveOutOpen]
push 0x20
push offset [WaveHDR]
push dword ptr [hWaveOut]
push 0x20
push offset [WaveHDR]
push dword ptr [hWaveOut]
call dword ptr [waveOutPrepareHeader]
call dword ptr [waveOutWrite]
}
}
#pragma code_seg(".envelope")
float get_Envelope(int instrument)
{
return (&_4klang_envelope_buffer)[(((MMTime.u.sample) >> 8) << 5) + POLYPHONY*instrument]; // the last number is the instrument
}
#pragma code_seg(".sample")
int get_Sample()
{
waveOutGetPosition(hWaveOut, &MMTime, sizeof(MMTIME));
return MMTime.u.sample;
}
#pragma code_seg(".compile")
unsigned int compileShader()
{
_asm
{
push glCreateProgram
call dword ptr [wglGetProcAddress]
call eax
mov ebx, eax
push ebx
push glLinkProgram
push GL_FRAGMENT_SHADER
push glCreateShader
push GL_VERTEX_SHADER
push glCreateShader
call dword ptr [wglGetProcAddress]
call eax
push eax
push ebx
push glAttachShader
push eax
push glCompileShader
push esi
push vsh
push 1
push eax
push glShaderSource
call dword ptr [wglGetProcAddress]
call eax
call dword ptr [wglGetProcAddress]
call eax
call dword ptr [wglGetProcAddress]
call eax
call dword ptr [wglGetProcAddress]
call eax
push eax
push ebx
push glAttachShader
push eax
push glCompileShader
push esi
push fsh
push 1
push eax
push glShaderSource
call dword ptr [wglGetProcAddress]
call eax
call dword ptr [wglGetProcAddress]
call eax
call dword ptr [wglGetProcAddress]
call eax
call dword ptr [wglGetProcAddress]
call eax
mov eax, ebx
}
}
// Aufbau der musik:
// Teil / Dauer in Szenen
// ----------------------
// Intro / 2
// A-Teil / 4
// B-Teil / 4
// A-Teil / 4
// Outro / 3 (wobei die letzte Szene für fade-out dienen soll)
#pragma code_seg(".main")
void _cdecl main()
{
register HDC hDC;
_asm
{
xor esi,esi
push esi //ShowCursor
push esi //CreateWindowExA
push esi
push esi
push esi
#ifdef DESKTOP_RESOLUTION
push esi
push esi
#else
#ifdef WINDOWED
push SCREENHEIGHT
push SCREENWIDTH
#else
push esi
push esi
#endif
#endif
push esi
push esi
#ifdef DESKTOP_RESOLUTION
push WS_POPUP | WS_VISIBLE | WS_MAXIMIZE
#else
#ifdef WINDOWED
push WS_POPUP | WS_VISIBLE
#else
push WS_POPUP | WS_VISIBLE | WS_MAXIMIZE
#endif
#endif
push esi
push edit
push esi
#ifndef WINDOWED
#ifndef DESKTOP_RESOLUTION
push 4 //ChangeDisplaySettings
push offset [dmScreenSettings]
call dword ptr [ChangeDisplaySettings]
#endif
#endif
call dword ptr [CreateWindowExA]
push eax
call dword ptr [GetDC]
mov hDC, eax
mov eax, offset [pfd]
push eax
push eax
push hDC
call dword ptr [ChoosePixelFormat]
push eax
push hDC
call dword ptr [SetPixelFormat]
push hDC
call dword ptr [wglCreateContext]
push eax
push hDC
call dword ptr [wglMakeCurrent]
mov ebx, offset [shaders]
mov edi, offset [mark_fs_0] + 12
call dword ptr[compileShader]
mov dword ptr[ebx], eax
inc dword ptr[edi]
add ebx, 4
call dword ptr[compileShader]
mov dword ptr[ebx], eax
inc dword ptr[edi]
add ebx, 4
call dword ptr[compileShader]
mov dword ptr[ebx], eax
inc dword ptr[edi]
add ebx, 4
call dword ptr[compileShader]
mov dword ptr[ebx], eax
inc dword ptr[edi]
add ebx, 4
mov dword ptr[ebx], eax
call dword ptr[ShowCursor]
#ifdef CHANGERES_DELAY
push 2048 // delay time in milliseconds
#endif
#ifdef CLEAR_SCREEN_WHILE_LOADING
push hDC
push 1 // glRects
push 1
push -1
push -1
push esi
push esi
push esi
call dword ptr[glColor3f]
call dword ptr[glRects]
call dword ptr[SwapBuffers]
#endif
#ifdef CHANGERES_DELAY
call dword ptr [Sleep]
#endif
}
#ifdef SHADER_WARMUP
_asm
{
push 1 // glRects
push 1
push -1
push -1
push dword ptr [shaders+12] // glUseProgram
push dword ptr [glUseProgram] // wglGetProcAddress
push 1 // glRects
push 1
push -1
push -1
push dword ptr [shaders+8] // glUseProgram
push dword ptr [glUseProgram] // wglGetProcAddress
push 1 // glRects
push 1
push -1
push -1
push dword ptr [shaders+4] // glUseProgram
push dword ptr [glUseProgram] // wglGetProcAddress
push 1 // glRects
push 1
push -1
push -1
push dword ptr [shaders+0] // glUseProgram
push dword ptr [glUseProgram] // wglGetProcAddress
call dword ptr [wglGetProcAddress]
call eax
call dword ptr[glRects]
call dword ptr [wglGetProcAddress]
call eax
call dword ptr[glRects]
call dword ptr [wglGetProcAddress]
call eax
call dword ptr[glRects]
call dword ptr [wglGetProcAddress]
call eax
call dword ptr[glRects]
}
#endif
_asm call dword ptr[InitSound]
while (true)
{
_asm
{
push PM_REMOVE // PeekMessageA
push esi
push esi
push esi
push esi
push hDC // SwapBuffers
push 1 // glRects
push 1
push -1
push -1
push esi //glColor3f
push esi
push esi
}
if (get_Sample() >= MAX_TICKS * SAMPLES_PER_TICK)
break;
_asm
{
mov dword ptr [esp],eax
cdq
div dword ptr [shaderLength]
mov ebx, eax
fild dword ptr [esp]
fdiv dword ptr [sceneLength]
fstp dword ptr [esp]
push 2
call dword ptr [get_Envelope]
fstp dword ptr [esp+4]
push 6
call dword ptr [get_Envelope]
fstp dword ptr [esp+8]
call dword ptr [glColor3f]
push dword ptr [ebx*4+shaders]
push dword ptr [glUseProgram]
call dword ptr [wglGetProcAddress]
call eax
call dword ptr[glRects]
call dword ptr[SwapBuffers]
call dword ptr[PeekMessageA]
}
if (GetAsyncKeyState(VK_ESCAPE))
break;
}
ExitProcess(0);
}