// File: /workspace/github_cpp_makefile_star2_O2/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
pushq $0x8
popq %rcx
xorl %edi, %edi
movl $0x179, %esi            # imm = 0x179
movl $0x90, %edx
movl $0x13000801, %r8d       # imm = 0x13000801
callq 0x60a0
movq %rax, %rbx
pushq $0x1
popq %r12
movq %rax, %rdi
movl %r12d, %esi
callq 0x6290
movq %rbx, %rdi
movl %r12d, %esi
movl $0xf9, %edx
callq 0x6420
movq 0x818742(%rip), %rdi    # 0x81f2f8
callq 0x6470
movq %rax, %r14
movq %rax, %rdi
xorl %esi, %esi
callq 0x6290
movl 0x10(%rbx), %ebp
movl 0x14(%rbx), %r15d
movq 0x8(%r14), %rax
movzbl 0x10(%rax), %r13d
movl 0x14(%rax), %esi
movl 0x18(%rax), %edx
movl 0x1c(%rax), %ecx
movl 0x20(%rax), %r8d
movl %r13d, %edi
callq 0x6520
xorl %edi, %edi
movl %ebp, %esi
movl %r15d, %edx
movl %r13d, %ecx
movl %eax, %r8d
callq 0x60a0
testq %rax, %rax
je 0x6e1a
movq %rax, %r15
xorl %ebp, %ebp
movq %rax, %rdi
xorl %esi, %esi
callq 0x6290
movq 0x10(%rbx), %rax
leaq 0x4(%rsp), %rdx
movq %rax, 0x4(%rdx)
movq 0x8186cd(%rip), %rdi    # 0x81f2f8
movq %rsp, %r13
movq %r13, %rsi
callq 0x6150
movl (%r13), %eax
movl 0x4(%r13), %ecx
subl 0x8(%r13), %eax
subl 0xc(%r13), %ecx
sarl %eax
movl %eax, (%r13)
leal (%rcx,%rcx,2), %eax
sarl $0x2, %eax
movl %eax, 0x4(%r13)
movq 0x8(%rbx), %rax
movq 0x8(%rax), %rdi
callq 0x6f17
movq 0x81868e(%rip), %rdi    # 0x81f2f8
callq 0x63d0
movq %r14, %rdi
movq %r13, %rsi
movq %r15, 0x10(%rsp)
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x6300
leaq 0xdbfa(%rip), %rcx      # 0x14885
pushq $0x4d
popq %rdx
movq %rbx, %rdi
movl $0xff, %esi
movl $0xff, %r8d
callq 0x6fbf
movl 0xc(%r13), %r13d
addl $-0x58, %r13d
movl $0x11b, %r15d           # imm = 0x11B
cmpq $0x30, %rbp
je 0x6cd3
leaq 0x13054(%rip), %rax     # 0x19d10
movq (%rbp,%rax), %rdi
callq 0x7200
cmpl %r15d, %eax
cmovgl %eax, %r15d
addq $0x8, %rbp
jmp 0x6caf
sarl %r13d
movl %r13d, %ebp
movl 0x8(%rsp), %r13d
subl %r15d, %r13d
sarl %r13d
leaq 0x48(%rsp), %rax
movl %r13d, (%rax)
xorl %r15d, %r15d
movl %ebp, 0x1c(%rsp)
cmpq $0x30, %r15
je 0x6d29
leaq 0x13010(%rip), %rax     # 0x19d10
movq (%r15,%rax), %rdi
leaq 0x48(%rsp), %rsi
movl %ebp, %edx
xorl %ecx, %ecx
movl $0xff, %r8d
movq %rbx, %r9
callq 0x7221
movl %r13d, 0x48(%rsp)
addl $0x12, %ebp
addq $0x8, %r15
jmp 0x6cf3
movq %rsp, %r15
movl 0x8(%r15), %eax
negl %r13d
leal (%rax,%r13), %edi
addl $-0x1e, %edi
movl 0x1c(%rsp), %esi
addl $0x3, %esi
movq %rbx, %rdx
callq 0x7351
movups (%r15), %xmm0
leaq 0x20(%rsp), %rax
movaps %xmm0, (%rax)
leaq 0x38(%rsp), %rcx
andq $0x0, (%rcx)
movq 0x8(%r15), %rax
movq %rax, 0x8(%rcx)
movb $0x1f, %bpl
pushq $0x10
popq %r13
pushq $0x8
popq %r15
cmpl $0x9, %r12d
je 0x6de9
movzbl %bpl, %ebp
movq %rbx, %rdi
movl %ebp, %esi
callq 0x65d0
movl 0x8(%rsp), %eax
imull %r12d, %eax
cltd
idivl %r15d
movl %eax, 0x28(%rsp)
movl %eax, 0x40(%rsp)
movl 0x10(%r14), %ecx
subl %eax, %ecx
sarl %ecx
movl %ecx, 0x20(%rsp)
movq 0x10(%rsp), %rdi
xorl %esi, %esi
movq %r14, %rdx
movq %rsp, %rcx
callq 0x6300
movq %rbx, %rdi
leaq 0x38(%rsp), %rsi
movq %r14, %rdx
leaq 0x20(%rsp), %rcx
callq 0x6300
movq 0x818525(%rip), %rdi    # 0x81f2f8
callq 0x63d0
movl %r13d, %edi
callq 0x62b0
incl %r12d
addb $0x1f, %bpl
jmp 0x6d71
leaq 0x48(%rsp), %r12
pushq $0x10
popq %rbp
movq %r12, %rdi
callq 0x6240
testl %eax, %eax
je 0x6e11
movl 0x48(%rsp), %eax
cmpl $0x300, %eax            # imm = 0x300
je 0x6e54
cmpl $0x100, %eax            # imm = 0x100
jne 0x6df1
jmp 0x6e41
movl %ebp, %edi
callq 0x62b0
jmp 0x6df1
callq 0x62d0
leaq 0xd752(%rip), %rdi      # 0x14578
movq %rax, %rsi
xorl %eax, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6480
leaq 0x80(%rsp), %rdi
movl $0x100, (%rdi)          # imm = 0x100
callq 0x6570
pushq $0x7
popq %r13
movl $0xd9, %ebp
pushq $0x10
popq %r12
testl %ebp, %ebp
je 0x6ee0
movzbl %bpl, %esi
movq %rbx, %rdi
callq 0x65d0
movl 0xc(%rsp), %ecx
movl %ecx, %eax
imull %r13d, %eax
cltd
idivl %r15d
movl %eax, 0x2c(%rsp)
movl %eax, 0x44(%rsp)
subl %eax, %ecx
movl %ecx, 0x3c(%rsp)
movl 0x14(%r14), %ecx
subl %eax, %ecx
leal (%rcx,%rcx,2), %eax
sarl $0x2, %eax
movl %eax, 0x24(%rsp)
movq 0x10(%rsp), %rdi
xorl %esi, %esi
movq %r14, %rdx
movq %rsp, %rcx
callq 0x6300
movq %rbx, %rdi
leaq 0x38(%rsp), %rsi
movq %r14, %rdx
leaq 0x20(%rsp), %rcx
callq 0x6300
movq 0x81842d(%rip), %rdi    # 0x81f2f8
callq 0x63d0
movl %r12d, %edi
callq 0x62b0
decl %r13d
addl $-0x1f, %ebp
jmp 0x6e61
movq %rsp, %rcx
movq 0x10(%rsp), %r15
movq %r15, %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x6300
movq %r15, %rdi
callq 0x6340
movq %rbx, %rdi
callq 0x6340
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq