// File: 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
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
xorl %edi, %edi
movl $0x179, %esi            # imm = 0x179
movl $0x90, %edx
movl $0x8, %ecx
movl $0x13000801, %r8d       # imm = 0x13000801
callq 0x70b0
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x7330
movq -0x8(%rbp), %rdi
movl $0x1, %esi
movl $0xf9, %edx
callq 0x7560
movq 0x828e25(%rip), %rdi    # 0x8313e8
callq 0x75a0
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x7330
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x120(%rbp)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x11c(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movzbl 0x10(%rax), %eax
movl %eax, -0x118(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movzbl 0x10(%rax), %edi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x14(%rax), %esi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x18(%rax), %edx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x1c(%rax), %ecx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x20(%rax), %r8d
callq 0x7690
movl -0x120(%rbp), %esi
movl -0x11c(%rbp), %edx
movl -0x118(%rbp), %ecx
movl %eax, %r8d
xorl %edi, %edi
callq 0x70b0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x866f
cmpq $0x0, -0x18(%rbp)
jne 0x868a
callq 0x7370
movq %rax, %rsi
leaq 0x1adc2(%rip), %rdi     # 0x23440
movb $0x0, %al
callq 0x75c0
jmp 0x8a52
movq -0x18(%rbp), %rdi
xorl %esi, %esi
callq 0x7330
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x1c(%rbp)
movq 0x828d38(%rip), %rdi    # 0x8313e8
leaq -0x28(%rbp), %rsi
leaq -0x28(%rbp), %rdx
addq $0x4, %rdx
callq 0x7170
movl -0x20(%rbp), %ecx
movl -0x28(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x28(%rbp)
movl -0x1c(%rbp), %ecx
movl -0x24(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x24(%rbp)
movl -0x28(%rbp), %eax
sarl %eax
movl %eax, -0x28(%rbp)
imull $0x3, -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
sarl $0x2, %eax
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdi
callq 0x8a60
movq 0x828ce1(%rip), %rdi    # 0x8313e8
callq 0x74f0
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq -0x28(%rbp), %rsi
xorl %eax, %eax
movl %eax, %ecx
callq 0x73b0
movq -0x8(%rbp), %rdi
movl $0xff, %r8d
movl $0x4d, %edx
leaq 0x1b016(%rip), %rcx     # 0x2374d
movl %r8d, %esi
callq 0x8b90
movl -0x1c(%rbp), %eax
addl $0x14, %eax
subl $0x6c, %eax
sarl %eax
movl %eax, -0x30(%rbp)
leaq -0x60(%rbp), %rdi
leaq 0x23578(%rip), %rsi     # 0x2bcd0
movl $0x30, %edx
callq 0x73c0
movl $0x11b, -0x64(%rbp)     # imm = 0x11B
movl $0x0, -0x68(%rbp)
cmpl $0x6, -0x68(%rbp)
jge 0x87a2
movslq -0x68(%rbp), %rax
movq -0x60(%rbp,%rax,8), %rdi
callq 0x8ec0
movl %eax, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
cmpl -0x64(%rbp), %eax
jle 0x8795
movl -0x6c(%rbp), %eax
movl %eax, -0x64(%rbp)
jmp 0x8797
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x8770
movl -0x20(%rbp), %eax
subl -0x64(%rbp), %eax
sarl %eax
movl %eax, -0x2c(%rbp)
movl $0x0, -0x70(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x74(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x78(%rbp)
cmpl $0x6, -0x70(%rbp)
jge 0x8801
movslq -0x70(%rbp), %rax
movq -0x60(%rbp,%rax,8), %rdi
movl -0x78(%rbp), %edx
movq -0x8(%rbp), %r9
leaq -0x74(%rbp), %rsi
xorl %ecx, %ecx
movl $0xff, %r8d
callq 0x8f10
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x74(%rbp)
movl -0x78(%rbp), %eax
addl $0x12, %eax
movl %eax, -0x78(%rbp)
jmp 0x87c0
movl -0x20(%rbp), %edi
subl -0x2c(%rbp), %edi
subl $0x1e, %edi
movl -0x30(%rbp), %esi
addl $0x3, %esi
movq -0x8(%rbp), %rdx
callq 0x9140
movq -0x28(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x80(%rbp)
movl $0x0, -0x98(%rbp)
movl $0x0, -0x94(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x90(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x8c(%rbp)
movl $0x1, -0x9c(%rbp)
cmpl $0x8, -0x9c(%rbp)
jg 0x8906
movq -0x8(%rbp), %rdi
imull $0x1f, -0x9c(%rbp), %eax
movzbl %al, %esi
callq 0x7780
movl -0x20(%rbp), %eax
imull -0x9c(%rbp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
movl %eax, -0x80(%rbp)
movl -0x80(%rbp), %eax
movl %eax, -0x90(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
subl -0x80(%rbp), %eax
sarl %eax
movl %eax, -0x88(%rbp)
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rdx
xorl %eax, %eax
movl %eax, %esi
leaq -0x28(%rbp), %rcx
callq 0x73b0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq -0x98(%rbp), %rsi
leaq -0x88(%rbp), %rcx
callq 0x73b0
movq 0x828b05(%rip), %rdi    # 0x8313e8
callq 0x74f0
movl $0x10, %edi
callq 0x7350
movl -0x9c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x9c(%rbp)
jmp 0x885c
jmp 0x8908
jmp 0x890a
leaq -0xd8(%rbp), %rdi
callq 0x72b0
cmpl $0x0, %eax
je 0x895b
movl -0xd8(%rbp), %eax
movl %eax, -0x124(%rbp)
subl $0x100, %eax            # imm = 0x100
je 0x8941
jmp 0x8930
movl -0x124(%rbp), %eax
subl $0x300, %eax            # imm = 0x300
jne 0x8959
jmp 0x893f
jmp 0x8967
movl $0x100, -0x110(%rbp)    # imm = 0x100
leaq -0x110(%rbp), %rdi
callq 0x7700
jmp 0x8967
jmp 0x890a
movl $0x10, %edi
callq 0x7350
jmp 0x8908
movl $0x7, -0x114(%rbp)
cmpl $0x0, -0x114(%rbp)
jle 0x8a2b
movq -0x8(%rbp), %rdi
imull $0x1f, -0x114(%rbp), %eax
movzbl %al, %esi
callq 0x7780
movl -0x1c(%rbp), %eax
imull -0x114(%rbp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
movl %eax, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
movl %eax, -0x8c(%rbp)
movl -0x1c(%rbp), %eax
subl -0x7c(%rbp), %eax
movl %eax, -0x94(%rbp)
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
subl -0x7c(%rbp), %eax
imull $0x3, %eax, %eax
sarl $0x2, %eax
movl %eax, -0x84(%rbp)
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rdx
xorl %eax, %eax
movl %eax, %esi
leaq -0x28(%rbp), %rcx
callq 0x73b0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq -0x98(%rbp), %rsi
leaq -0x88(%rbp), %rcx
callq 0x73b0
movq 0x8289e0(%rip), %rdi    # 0x8313e8
callq 0x74f0
movl $0x10, %edi
callq 0x7350
movl -0x114(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x114(%rbp)
jmp 0x8971
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rdx
xorl %eax, %eax
movl %eax, %esi
leaq -0x28(%rbp), %rcx
callq 0x73b0
movq -0x18(%rbp), %rdi
callq 0x7400
movq -0x8(%rbp), %rdi
callq 0x7400
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
nopl (%rax,%rax)