309 lines
6.5 KiB
C++
309 lines
6.5 KiB
C++
#ifndef _DEBUG
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
#define WIN32_EXTRA_LEAN
|
|
#define USE_SOUND_THREAD
|
|
|
|
#ifndef ASPECT
|
|
#define ASPECT 1.77
|
|
#define SCREENWIDTH 640
|
|
#define SCREENHEIGHT 360
|
|
#endif
|
|
|
|
#include <windows.h>
|
|
#include <GL/gl.h>
|
|
#include <GL/glu.h>
|
|
#include "glext.h"
|
|
#include "small.h"
|
|
#include "mmsystem.h"
|
|
#include "mmreg.h"
|
|
#include "4klang.h"
|
|
#include "mark_small.h"
|
|
|
|
#pragma bss_seg(".bss")
|
|
unsigned int shaders[4];
|
|
SAMPLE_TYPE lpSoundBuffer[MAX_SAMPLES*2];
|
|
HWAVEOUT hWaveOut;
|
|
HDC hDC;
|
|
|
|
#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, // MAX_SAMPLES*sizeof(float)*2(stereo)
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0
|
|
};
|
|
|
|
#pragma data_seg(".mmtime")
|
|
MMTIME MMTime =
|
|
{
|
|
TIME_SAMPLES,
|
|
0
|
|
};
|
|
|
|
#define STR2(x) #x
|
|
#define STR(x) STR2(x)
|
|
|
|
#pragma data_seg(".vertexshader")
|
|
static char* vsh = "varying vec2 "I_Y","I_Z";void main(){"I_Y"=gl_Color.xy;"I_Z"=(gl_Vertex.xy*vec2("STR( ASPECT )",1))*.5+.5;gl_Position=gl_Vertex;}";
|
|
|
|
#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
|
|
};
|
|
|
|
#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
|
|
};
|
|
|
|
#pragma data_seg(".glLinkProgram")
|
|
static const char* glLinkProgram = "glLinkProgram";
|
|
#pragma data_seg(".glAttachShader")
|
|
static const char* glAttachShader = "glAttachShader";
|
|
#pragma data_seg(".glCompileShader")
|
|
static const char* glCompileShader = "glCompileShader";
|
|
#pragma data_seg(".glShaderSource")
|
|
static const char* glShaderSource = "glShaderSource";
|
|
#pragma data_seg(".glCreateShader")
|
|
static const char* glCreateShader = "glCreateShader";
|
|
#pragma data_seg(".glCreateProgram")
|
|
static const char* glCreateProgram = "glCreateProgram";
|
|
#pragma data_seg(".glUseProgram")
|
|
static const char* glUseProgram = "glUseProgram";
|
|
#pragma data_seg(".edit")
|
|
static const char* windowClass = "edit";
|
|
|
|
#pragma data_seg(".magicInt")
|
|
static const int g_MagicConstant = 313600 * 4;
|
|
#pragma data_seg(".magicFloat")
|
|
static const float magicFloat = 313600.0f;
|
|
|
|
#pragma code_seg(".main")
|
|
void _cdecl main()
|
|
{
|
|
unsigned int p,f,v,fsh;
|
|
__asm
|
|
{
|
|
xor esi, esi
|
|
|
|
// CreateWindowEx:
|
|
push esi
|
|
push esi
|
|
push esi
|
|
push esi
|
|
push esi
|
|
push esi
|
|
push SCREENHEIGHT
|
|
push SCREENWIDTH
|
|
push esi
|
|
push esi
|
|
push WS_OVERLAPPEDWINDOW | WS_VISIBLE
|
|
push esi
|
|
push windowClass;
|
|
push esi
|
|
|
|
// ChangeDisplaySettings:
|
|
//push CDS_FULLSCREEN
|
|
//push offset dmScreenSettings
|
|
|
|
//call dword ptr [ChangeDisplaySettings]
|
|
call dword ptr [CreateWindowExA]
|
|
push eax
|
|
call dword ptr [GetDC]
|
|
mov dword ptr [hDC], eax
|
|
|
|
// waveOutOpen
|
|
push esi
|
|
push esi
|
|
push esi
|
|
push offset WaveFMT
|
|
push 0FFFFFFFFh
|
|
push offset hWaveOut
|
|
|
|
// Sleep
|
|
push 4096
|
|
|
|
// CreateThread
|
|
push esi
|
|
push esi
|
|
push offset lpSoundBuffer
|
|
push _4klang_render
|
|
push esi
|
|
push esi
|
|
|
|
// PixelFormat
|
|
push dword ptr [hDC]
|
|
push offset pfd
|
|
push offset pfd
|
|
push dword ptr [hDC]
|
|
call dword ptr [ChoosePixelFormat]
|
|
push eax
|
|
push dword ptr [hDC]
|
|
call dword ptr [SetPixelFormat]
|
|
call dword ptr [wglCreateContext]
|
|
push eax
|
|
push dword ptr [hDC]
|
|
call dword ptr [wglMakeCurrent]
|
|
push dword ptr [hDC]
|
|
call dword ptr [SwapBuffers]
|
|
|
|
mov ebx, offset shaders
|
|
mov eax, offset ShaderSources
|
|
mov fsh, eax
|
|
call dword ptr [compileShader]
|
|
call dword ptr [compileShader]
|
|
call dword ptr [compileShader]
|
|
call dword ptr [compileShader]
|
|
|
|
call dword ptr [CreateThread]
|
|
call dword ptr [Sleep]
|
|
call dword ptr [waveOutOpen]
|
|
|
|
push 20h
|
|
push offset WaveHDR
|
|
push dword ptr [hWaveOut]
|
|
push 20h
|
|
push offset WaveHDR
|
|
push dword ptr [hWaveOut]
|
|
call dword ptr [waveOutPrepareHeader]
|
|
call dword ptr [waveOutWrite]
|
|
|
|
schleife:
|
|
|
|
push 12
|
|
push offset MMTime
|
|
push hWaveOut
|
|
call dword ptr [waveOutGetPosition]
|
|
|
|
xor edx, edx
|
|
mov eax, dword ptr [MMTime+4]
|
|
div g_MagicConstant
|
|
push dword ptr shaders[eax * 4]
|
|
shr eax, 2
|
|
test ax,ax
|
|
jne exit
|
|
push dword ptr [glUseProgram]
|
|
call dword ptr [wglGetProcAddress]
|
|
call eax
|
|
|
|
fild dword ptr [MMTime+4]
|
|
|
|
sub esp, 0Ch
|
|
fdiv dword ptr [magicFloat]
|
|
fstp dword ptr [esp]
|
|
call dword ptr [glColor3f]
|
|
|
|
push dword ptr [hDC]
|
|
push 1
|
|
push esi
|
|
push esi
|
|
push esi
|
|
push esi
|
|
push 1
|
|
push 1
|
|
push -1
|
|
push -1
|
|
call dword ptr [glRects]
|
|
call dword ptr [PeekMessageA]
|
|
call dword ptr [SwapBuffers]
|
|
|
|
push VK_ESCAPE
|
|
call dword ptr [GetAsyncKeyState]
|
|
test ax,ax
|
|
jne exit
|
|
|
|
jmp schleife
|
|
|
|
exit:
|
|
call dword ptr [ExitProcess]
|
|
|
|
compileShader:
|
|
push GL_FRAGMENT_SHADER
|
|
push glCreateShader
|
|
push GL_VERTEX_SHADER
|
|
push glCreateShader
|
|
push glCreateProgram
|
|
call dword ptr [wglGetProcAddress]
|
|
call eax
|
|
mov p, eax
|
|
mov dword ptr[ebx], eax
|
|
call dword ptr [wglGetProcAddress]
|
|
call eax
|
|
mov v, eax
|
|
call dword ptr [wglGetProcAddress]
|
|
call eax
|
|
mov f, eax
|
|
|
|
push p
|
|
push glLinkProgram
|
|
|
|
push f
|
|
push p
|
|
push glAttachShader
|
|
|
|
push v
|
|
push p
|
|
push glAttachShader
|
|
|
|
push f
|
|
push glCompileShader
|
|
|
|
push v
|
|
push glCompileShader
|
|
|
|
push esi
|
|
push fsh
|
|
push 7
|
|
push f
|
|
push glShaderSource
|
|
|
|
push esi
|
|
push offset vsh
|
|
push 1
|
|
push v
|
|
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
|
|
call dword ptr [wglGetProcAddress]
|
|
call eax
|
|
call dword ptr [wglGetProcAddress]
|
|
call eax
|
|
call dword ptr [wglGetProcAddress]
|
|
call eax
|
|
|
|
add ebx, 4
|
|
add dword ptr [fsh], 28
|
|
ret
|
|
}
|
|
}
|
|
#endif |