// File: /workspace/github_cpp_makefile_star2_O3/mdpkh[P]retro6k/src/main.cpp
// Function: DoAbout()
void DoAbout() {
	SDL_Surface* winbuffer = SDL_CreateRGBSurfaceWithFormat(
		0,
		377,
		144,
		8,
		SDL_PIXELFORMAT_INDEX8);
	SDL_SetSurfaceBlendMode(winbuffer, SDL_BLENDMODE_BLEND);
	SDL_SetColorKey(winbuffer, true, 0xf9);
	SDL_Surface* mwsurface = SDL_GetWindowSurface(mainwindow);
	SDL_SetSurfaceBlendMode(mwsurface, SDL_BLENDMODE_NONE);
	SDL_Surface* restorescreen = SDL_CreateRGBSurfaceWithFormat(
		0,
		winbuffer->w,
		winbuffer->h,
		mwsurface->format->BitsPerPixel,
		SDL_MasksToPixelFormatEnum(
			mwsurface->format->BitsPerPixel,
			mwsurface->format->Rmask,
			mwsurface->format->Gmask,
			mwsurface->format->Bmask,
			mwsurface->format->Amask));
	if (!winbuffer || !restorescreen)
	{
		SDL_Log("Could not create menu display buffers: %s", SDL_GetError());
		return;
	}
	SDL_SetSurfaceBlendMode(restorescreen, SDL_BLENDMODE_NONE);
	SDL_Rect winpos;
	winpos.w = winbuffer->w;
	winpos.h = winbuffer->h;
	SDL_GetWindowSize(mainwindow, &winpos.x, &winpos.y);
	winpos.x -= winpos.w;
	winpos.y -= winpos.h;
	winpos.x >>= 1;
	winpos.y *= 3;
	winpos.y >>= 2;
	SetHWPalette(winbuffer->format->palette);
	SDL_UpdateWindowSurface(mainwindow);
	SDL_BlitSurface(mwsurface, &winpos, restorescreen, NULL);
	PaintWindow(winbuffer, 0xff, 0x4d, "About Retro 6k", 0xff);
	int tx0;
	int y0 = (winpos.h + 20 - 18 * 6) >> 1;
	{
		// hey, if you're not me, don't change this #ifdef/#else/#endif block
		// and don't define OFFICIAL_BUILD. ---MDPKH
#ifdef OFFICIAL_BUILD
		char* abouttext[6] = {
			(char*)"Retro 6k designed by Maggie\220David",         //points to cstring in program data
			(char*)"P.\220K. Haynes in 2019\22620.",               //points to cstring in program data
			(char*)"",                                             //points to cstring in program data
			nullptr,                                               //will point to cstring in stack
			(char*)"Haynes. Includes public domain 6502 emulator", //points to cstring in program data
			(char*)"core written by Mike Chambers in 2011."        //points to cstring in program data
		};
		const char* vertempl = "Emulator v------- \2512019\22620 Maggie\220David P.\220K."; //program data
		char verline[46];                                                                   //stack
		strcpy_s((char*)&verline, 46, vertempl); //copy cstring from program data into stack
		extern const char* verstring; //points to cstring in program data in a separately-compiled obj file
		verline[10] = verstring[0];   //copy 7 bytes from separate program data to middle of cstring in stack
		verline[11] = verstring[1];   //verstring is assumed to point to at least 7 non-null bytes (see ver.cpp)
		verline[12] = verstring[2];
		verline[13] = verstring[3];
		verline[14] = verstring[4];
		verline[15] = verstring[5];
		verline[16] = verstring[6];
		abouttext[3] = verline;       //now the abouttext array is complete
#else
		char* abouttext[6] = {
			(char*)"Retro 6k designed by Maggie\220David",         
			(char*)"P.\220K. Haynes in 2019\22620.",               
			(char*)"",                                             
			(char*)CUSTOM_BUILD_CREDIT,                                               
			(char*)"Includes public domain 6502 emulator", 
			(char*)"core written by Mike Chambers in 2011."        
		};
#endif
		int mlw = 283;
		for (int i = 0; i < 6; ++i)
		{
			int lw = TextWidth(abouttext[i]);
			if (lw > mlw)
				mlw = lw;
		}
		tx0 = (winpos.w - mlw) >> 1;
		for (int i = 0, x = tx0, y = y0; i < 6; ++i, x = tx0, y += 18)
		{
			DrawText(abouttext[i], x, y, 0x00, 0xff, winbuffer);
		}
	}
	DrawLogo(winpos.w - tx0 - 30, y0 + 3, winbuffer);
	SDL_Rect animrect = winpos;
	SDL_Rect menurect = { 0, 0, winpos.w, winpos.h };
	for (int t = 1; t <= 8; ++t)
	{
		SDL_SetSurfaceAlphaMod(winbuffer, t * 31);
		animrect.w = winpos.w * t / 8;
		menurect.w = animrect.w;
		animrect.x = (mwsurface->w - animrect.w) >> 1;
		SDL_BlitSurface(restorescreen, NULL, mwsurface, &winpos);
		SDL_BlitSurface(winbuffer, &menurect, mwsurface, &animrect);
		SDL_UpdateWindowSurface(mainwindow);
		SDL_Delay(16);
	}
	while (true)
	{
		SDL_Event event;
		while (SDL_PollEvent(&event))
		{
			SDL_Event newevent;
			switch (event.type)
			{
			case SDL_KEYDOWN:
				goto exitabout;
				break;
			case SDL_QUIT:
				newevent.type = SDL_QUIT;
				SDL_PushEvent(&newevent);
				goto exitabout;
			}
		}
		SDL_Delay(16);
	}
exitabout:
	for (int t = 7; t > 0; --t)
	{
		SDL_SetSurfaceAlphaMod(winbuffer, t * 31);
		animrect.h = winpos.h * t / 8;
		menurect.h = animrect.h;
		menurect.y = winpos.h - animrect.h;
		animrect.y = ((mwsurface->h - animrect.h) * 3) >> 2;
		SDL_BlitSurface(restorescreen, NULL, mwsurface, &winpos);
		SDL_BlitSurface(winbuffer, &menurect, mwsurface, &animrect);
		SDL_UpdateWindowSurface(mainwindow);
		SDL_Delay(16);
	}
	SDL_BlitSurface(restorescreen, NULL, mwsurface, &winpos);
	SDL_FreeSurface(restorescreen);
	SDL_FreeSurface(winbuffer);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
xorl %edi, %edi
movl $0x179, %esi            # imm = 0x179
movl $0x90, %edx
movl $0x8, %ecx
movl $0x13000801, %r8d       # imm = 0x13000801
callq 0x6090
movq %rax, %rbx
movq %rax, %rdi
movl $0x1, %esi
callq 0x6270
movq %rbx, %rdi
movl $0x1, %esi
movl $0xf9, %edx
callq 0x6420
movq 0x8193a4(%rip), %rdi    # 0x8202e8
callq 0x6460
movq %rax, %r14
movq %rax, %rdi
xorl %esi, %esi
callq 0x6270
movl 0x10(%rbx), %ebp
movl 0x14(%rbx), %r15d
movq 0x8(%r14), %rax
movzbl 0x10(%rax), %r12d
movl 0x14(%rax), %esi
movl 0x18(%rax), %edx
movl 0x1c(%rax), %ecx
movl 0x20(%rax), %r8d
movl %r12d, %edi
callq 0x64f0
xorl %edi, %edi
movl %ebp, %esi
movl %r15d, %edx
movl %r12d, %ecx
movl %eax, %r8d
callq 0x6090
testq %rax, %rax
je 0x7210
movq %rax, %r13
xorl %r12d, %r12d
movq %rax, %rdi
xorl %esi, %esi
callq 0x6270
movq 0x10(%rbx), %rax
leaq 0x10(%rsp), %rdx
movq %rax, 0x4(%rdx)
movq 0x81932e(%rip), %rdi    # 0x8202e8
leaq 0xc(%rsp), %r15
movq %r15, %rsi
callq 0x6150
movl (%r15), %eax
movl 0x4(%r15), %ecx
subl 0x8(%r15), %eax
subl 0xc(%r15), %ecx
sarl %eax
movl %eax, (%r15)
leal (%rcx,%rcx,2), %eax
sarl $0x2, %eax
movl %eax, 0x4(%r15)
movq 0x8(%rbx), %rax
movq 0x8(%rax), %rdi
callq 0x731e
movq 0x8192ef(%rip), %rdi    # 0x8202e8
callq 0x63d0
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0x62e0
leaq 0xf940(%rip), %rcx      # 0x16955
movq %rbx, %rdi
movl $0xff, %esi
movl $0x4d, %edx
movl $0xff, %r8d
callq 0x7ae5
movl 0xc(%r15), %ebp
addl $-0x58, %ebp
movl $0x11b, %eax            # imm = 0x11B
leaq 0x13cd0(%rip), %r15     # 0x1ad10
leaq 0xd1b9(%rip), %rcx      # 0x14200
movq (%r15,%r12,8), %rdx
movb (%rdx), %dil
movl $0x0, %esi
testb %dil, %dil
je 0x707d
incq %rdx
xorl %esi, %esi
movzbl %dil, %edi
movl %edi, %r8d
shll $0x5, %r8d
leaq (%r8,%rdi,2), %rdi
movzbl (%rcx,%rdi), %edi
addl %edi, %esi
movb (%rdx), %dil
incq %rdx
testb %dil, %dil
jne 0x705d
cmpl %eax, %esi
cmovgl %esi, %eax
incq %r12
cmpq $0x6, %r12
jne 0x7047
movq %r13, 0x30(%rsp)
sarl %ebp
movl 0x14(%rsp), %r12d
subl %eax, %r12d
sarl %r12d
leaq 0x48(%rsp), %rax
movl %r12d, (%rax)
xorl %r13d, %r13d
movl %ebp, 0x1c(%rsp)
movq (%r13,%r15), %rdi
leaq 0x48(%rsp), %rsi
movl %ebp, %edx
xorl %ecx, %ecx
movl $0xff, %r8d
movq %rbx, %r9
callq 0x7d9f
movl %r12d, 0x48(%rsp)
addl $0x12, %ebp
addq $0x8, %r13
cmpq $0x30, %r13
jne 0x70ac
movl 0x1c(%rsp), %eax
addl $0x3, %eax
cltq
movslq 0x18(%rbx), %rcx
imulq %rax, %rcx
movslq 0x14(%rsp), %rax
movslq %r12d, %rdx
addq 0x20(%rbx), %rcx
subq %rdx, %rax
addq %rcx, %rax
addq $-0x1e, %rax
leaq 0xc488(%rip), %rcx      # 0x13590
xorl %edx, %edx
xorl %esi, %esi
movb (%rcx,%rsi), %dil
movb %dil, (%rax,%rsi)
incq %rsi
cmpq $0x1d, %rsi
jne 0x710c
movslq 0x18(%rbx), %rdi
addq %rdi, %rax
incl %edx
addq %rsi, %rcx
cmpl $0x1b, %edx
jne 0x710a
leaq 0xc(%rsp), %rax
movups (%rax), %xmm0
leaq 0x20(%rsp), %rcx
movaps %xmm0, (%rcx)
leaq 0x38(%rsp), %rbp
movq $0x0, (%rbp)
movq 0x8(%rax), %rax
movq %rax, 0x8(%rbp)
movl $0x1, %r13d
movb $0x1f, %r15b
movq 0x30(%rsp), %r12
movzbl %r15b, %r15d
movq %rbx, %rdi
movl %r15d, %esi
callq 0x65b0
movl 0x14(%rsp), %eax
imull %r13d, %eax
leal 0x7(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
sarl $0x3, %ecx
movl %ecx, 0x28(%rsp)
movl %ecx, 0x40(%rsp)
movl 0x10(%r14), %eax
subl %ecx, %eax
sarl %eax
movl %eax, 0x20(%rsp)
movq %r12, %rdi
xorl %esi, %esi
movq %r14, %rdx
leaq 0xc(%rsp), %rcx
callq 0x62e0
movq %rbx, %rdi
movq %rbp, %rsi
movq %r14, %rdx
leaq 0x20(%rsp), %rcx
callq 0x62e0
movq 0x819125(%rip), %rdi    # 0x8202e8
callq 0x63d0
movl $0x10, %edi
callq 0x6290
incl %r13d
addb $0x1f, %r15b
cmpl $0x9, %r13d
jne 0x7161
leaq 0x48(%rsp), %r15
movq %r15, %rdi
callq 0x6220
testl %eax, %eax
je 0x7204
movl 0x48(%rsp), %eax
cmpl $0x300, %eax            # imm = 0x300
je 0x724a
cmpl $0x100, %eax            # imm = 0x100
jne 0x71e4
jmp 0x7237
movl $0x10, %edi
callq 0x6290
jmp 0x71e4
callq 0x62b0
leaq 0xf42c(%rip), %rdi      # 0x16648
movq %rax, %rsi
xorl %eax, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6470
leaq 0x80(%rsp), %rdi
movl $0x100, (%rdi)          # imm = 0x100
callq 0x6540
movl $0x8, %r12d
movb $-0x27, %bpl
leaq 0x20(%rsp), %r15
movq 0x30(%rsp), %r13
decl %r12d
movzbl %bpl, %ebp
movq %rbx, %rdi
movl %ebp, %esi
callq 0x65b0
movl 0x18(%rsp), %eax
movl %eax, %ecx
imull %r12d, %ecx
leal 0x7(%rcx), %edx
testl %ecx, %ecx
cmovnsl %ecx, %edx
sarl $0x3, %edx
movl %edx, 0x2c(%rsp)
movl %edx, 0x44(%rsp)
subl %edx, %eax
movl %eax, 0x3c(%rsp)
movl 0x14(%r14), %eax
subl %edx, %eax
leal (%rax,%rax,2), %eax
sarl $0x2, %eax
movl %eax, 0x24(%rsp)
movq %r13, %rdi
xorl %esi, %esi
movq %r14, %rdx
leaq 0xc(%rsp), %rcx
callq 0x62e0
movq %rbx, %rdi
leaq 0x38(%rsp), %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x62e0
movq 0x81901b(%rip), %rdi    # 0x8202e8
callq 0x63d0
movl $0x10, %edi
callq 0x6290
addb $-0x1f, %bpl
cmpl $0x1, %r12d
ja 0x725d
leaq 0xc(%rsp), %rcx
movq %r13, %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x62e0
movq %r13, %rdi
callq 0x6320
movq %rbx, %rdi
callq 0x6320
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq