// File: /workspace/github_c_makefile_star2_O2/jonof[P]jftekwar/jfbuild/src/build.c
// Function: menuselect
int menuselect(int newpathmode)
{
	int listsize;
	int i;
	char ch, buffer[90];
	CACHE1D_FIND_REC *dir;

	int bakpathsearchmode = pathsearchmode;

	listsize = (ydim16-32)/8;

	if (newpathmode != pathsearchmode) {
		strcpy(selectedboardfilename, "");
		pathsearchmode = newpathmode;
	}
	if (pathsearchmode == PATHSEARCH_SYSTEM) {
		Bcanonicalisefilename(selectedboardfilename, 1);		// clips off the last token and compresses relative path
	} else {
		Bcorrectfilename(selectedboardfilename, 1);
	}

	getfilenames(selectedboardfilename, "*.map");

	printmessage16("Select .MAP file with arrows&enter.");

	do {
		clearbuf((unsigned char *)frameplace, (bytesperline*ydim16) >> 2, 0l);

		if (pathsearchmode == PATHSEARCH_SYSTEM) {
			strcpy(buffer,"Local filesystem mode. Press F for game filesystem.");
		} else {
			strcpy(buffer,"Game filesystem");
			if (grponlymode) strcat(buffer, " GRP-only");
			strcat(buffer, " mode. Press F for local filesystem, G for ");
			if (grponlymode) strcat(buffer, "all files.");
			else strcat(buffer, "GRP files only.");
		}
		printext16(halfxdim16-(8*(int)strlen(buffer)/2), 4, 14,0,buffer,0);

		snprintf(buffer,sizeof(buffer),"(%d dirs, %d files) %s",numdirs,numfiles,selectedboardfilename);
		printext16(1,ydim16-8-1,8,0,buffer,0);

		if (finddirshigh) {
			dir = finddirshigh;
			for(i=listsize/2-1; i>=0; i--) if (!dir->prev) break; else dir=dir->prev;
			for(i=0; i<listsize && dir; i++, dir=dir->next) {
				int c = dir->type == CACHE1D_FIND_DIR ? 4 : 3;
				memset(buffer,0,sizeof(buffer));
				strncpy(buffer,dir->name,25);
				if (strlen(buffer) == 25)
					buffer[21] = buffer[22] = buffer[23] = '.', buffer[24] = 0;
				if (dir == finddirshigh) {
					if (currentlist == 0) printext16(8,16+8*i,c|8,0,"->",0);
					printext16(32,16+8*i,c|8,0,buffer,0);
				} else {
					printext16(32,16+8*i,c,0,buffer,0);
				}
			}
		}

		if (findfileshigh) {
			dir = findfileshigh;
			for(i=listsize/2-1; i>=0; i--) if (!dir->prev) break; else dir=dir->prev;
			for(i=0; i<listsize && dir; i++, dir=dir->next) {
				if (dir == findfileshigh) {
					if (currentlist == 1) printext16(240,16+8*i,7|8,0,"->",0);
					printext16(240+24,16+8*i,7|8,0,dir->name,0);
				} else {
					printext16(240+24,16+8*i,7,0,dir->name,0);
				}
			}
		}
		showframe();

		keystatus[0xcb] = 0;
		keystatus[0xcd] = 0;
		keystatus[0xc8] = 0;
		keystatus[0xd0] = 0;
		keystatus[0x1c] = 0;	//enter
		keystatus[0xf] = 0;		//tab
		keystatus[1] = 0;		//esc
		ch = 0;                      //Interesting fakery of ch = getch()
		while (ch == 0)
		{
			if (handleevents()) {
				if (quitevent) {
					keystatus[1] = 1;
					quitevent = 0;
				}
			}
			ch = bgetchar();
			if (keystatus[0xcb] > 0) ch = 9;		// left arr
			if (keystatus[0xcd] > 0) ch = 9;		// right arr
			if (keystatus[0xc8] > 0) ch = 72;		// up arr
			if (keystatus[0xd0] > 0) ch = 80;		// down arr

		}

		if (ch == 'f' || ch == 'F') {
			currentlist = 0;
			pathsearchmode = 1-pathsearchmode;
			if (pathsearchmode == PATHSEARCH_SYSTEM) {
				strcpy(selectedboardfilename, "");
				Bcanonicalisefilename(selectedboardfilename, 1);
			} else strcpy(selectedboardfilename, "/");
			getfilenames(selectedboardfilename, "*.map");
		} else if (ch == 'g' || ch == 'G') {
			if (pathsearchmode == PATHSEARCH_GAME) {
				grponlymode = 1-grponlymode;
				getfilenames(selectedboardfilename, "*.map");
			}
		} else if (ch == 9) {
			if ((currentlist == 0 && findfiles) || (currentlist == 1 && finddirs))
				currentlist = 1-currentlist;
		} else if ((ch == 75) || (ch == 72)) {
			if (currentlist == 0) {
				if (finddirshigh && finddirshigh->prev) finddirshigh = finddirshigh->prev;
			} else {
				if (findfileshigh && findfileshigh->prev) findfileshigh = findfileshigh->prev;
			}
		} else if ((ch == 77) || (ch == 80)) {
			if (currentlist == 0) {
				if (finddirshigh && finddirshigh->next) finddirshigh = finddirshigh->next;
			} else {
				if (findfileshigh && findfileshigh->next) findfileshigh = findfileshigh->next;
			}
		} else if ((ch == 13) && (currentlist == 0) && finddirshigh) {
			if (finddirshigh->type == CACHE1D_FIND_DRIVE) {
				strcpy(selectedboardfilename, finddirshigh->name);
			} else {
				strcat(selectedboardfilename, finddirshigh->name);
			}
			strcat(selectedboardfilename, "/");
			if (pathsearchmode == PATHSEARCH_SYSTEM)
				Bcanonicalisefilename(selectedboardfilename, 1);
			else
				Bcorrectfilename(selectedboardfilename, 1);

			//printf("Changing directories to: %s\n", selectedboardfilename);

			getfilenames(selectedboardfilename, "*.map");
			ch = 0;

			clearbuf((unsigned char *)frameplace, (bytesperline*ydim16) >> 2, 0l);
			showframe();
		}
		if (ch == 13 && !findfileshigh) ch = 0;
	}
	while ((ch != 13) && (ch != 27));
	if (ch == 13)
	{
		Bstrcat(selectedboardfilename, findfileshigh->name);
		//printf("Selected file: %s\n", selectedboardfilename);

		return(0);
	}
	pathsearchmode = bakpathsearchmode;
	return(-1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
leaq 0x192c8f(%rip), %rax    # 0x1ad700
movl (%rax), %esi
movl 0x10c2ef(%rip), %ebp    # 0x126d68
addl $-0x20, %ebp
pushq $0x8
popq %rcx
movl %ebp, %eax
cltd
idivl %ecx
movl %eax, %ebx
movl %esi, 0xc(%rsp)
cmpl %edi, %esi
je 0x1aa9e
movb $0x0, 0x15873b(%rip)    # 0x1731d0
leaq 0x192c64(%rip), %rax    # 0x1ad700
movl %edi, (%rax)
cmpl $0x1, %edi
jne 0x1aab4
leaq 0x158726(%rip), %rdi    # 0x1731d0
pushq $0x1
popq %rsi
callq 0x1f86a
jmp 0x1aac3
leaq 0x158715(%rip), %rdi    # 0x1731d0
pushq $0x1
popq %rsi
callq 0x1f656
pushq $0x1
popq %r12
leaq 0x158702(%rip), %r13    # 0x1731d0
leaq 0x4ef7c(%rip), %rsi     # 0x69a51
movq %r13, %rdi
callq 0x1b2ce
leaq 0x4ef73(%rip), %rdi     # 0x69a57
callq 0x177d3
pushq $0x10
popq %rcx
movl %ebp, %eax
cltd
idivl %ecx
incl %eax
movl %eax, 0x8(%rsp)
leaq 0x10(%rsp), %r15
movl %ebx, 0x4(%rsp)
leaq 0x15c5a9(%rip), %rax    # 0x1770b0
movq (%rax), %rdi
movl 0x10c258(%rip), %esi    # 0x126d68
leaq 0x15c76d(%rip), %rax    # 0x177284
imull (%rax), %esi
sarl $0x2, %esi
xorl %edx, %edx
callq 0x444af
leaq 0x192bd5(%rip), %rax    # 0x1ad700
cmpl $0x1, (%rax)
jne 0x1ab61
movups 0x4ef64(%rip), %xmm0    # 0x69a9b
movaps %xmm0, 0x30(%rsp)
movups 0x4ef48(%rip), %xmm0    # 0x69a8b
movaps %xmm0, 0x20(%rsp)
movups 0x4ef2c(%rip), %xmm0    # 0x69a7b
movaps %xmm0, 0x10(%rsp)
movl $0x2e6d65, 0x40(%rsp)   # imm = 0x2E6D65
jmp 0x1ac1e
movups 0x4ef47(%rip), %xmm0    # 0x69aaf
movaps %xmm0, 0x10(%rsp)
movl 0x10bda5(%rip), %ebx    # 0x126918
movq %r15, %rdi
callq 0x6420
addq %rsp, %rax
addq $0x10, %rax
testl %ebx, %ebx
je 0x1abe6
movabsq $0x6c6e6f2d50524720, %rcx # imm = 0x6C6E6F2D50524720
movq %rcx, (%rax)
movw $0x79, 0x8(%rax)
movq %r15, %rdi
callq 0x6420
movups 0x4ef21(%rip), %xmm0    # 0x69ac9
movups %xmm0, 0x10(%rsp,%rax)
movups 0x4ef25(%rip), %xmm0    # 0x69ad9
movups %xmm0, 0x20(%rsp,%rax)
movups 0x4ef25(%rip), %xmm0    # 0x69ae5
movups %xmm0, 0x2c(%rsp,%rax)
movq %r15, %rdi
callq 0x6420
movabsq $0x656c6966206c6c61, %rcx # imm = 0x656C6966206C6C61
movq %rcx, 0x10(%rsp,%rax)
movl $0x2e7365, 0x17(%rsp,%rax) # imm = 0x2E7365
jmp 0x1ac1a
movups 0x4eef8(%rip), %xmm0    # 0x69ae5
movups %xmm0, 0x1c(%rax)
movups 0x4eee1(%rip), %xmm0    # 0x69ad9
movups %xmm0, 0x10(%rax)
movups 0x4eec6(%rip), %xmm0    # 0x69ac9
movups %xmm0, (%rax)
movq %r15, %rdi
callq 0x6420
movups 0x4eeeb(%rip), %xmm0    # 0x69b00
movups %xmm0, 0x10(%rsp,%rax)
movl 0x4(%rsp), %ebx
movl 0x15859f(%rip), %r14d   # 0x1731c4
movq %r15, %rdi
callq 0x6420
shll $0x2, %eax
subl %eax, %r14d
movl %r14d, %edi
pushq $0x4
popq %rsi
pushq $0xe
popq %rdx
xorl %ecx, %ecx
movq %r15, %r8
xorl %r9d, %r9d
callq 0x176c0
movl 0x158991(%rip), %ecx    # 0x1735e0
movl 0x15898e(%rip), %r8d    # 0x1735e4
movq %r15, %rdi
pushq $0x5a
popq %rsi
leaq 0x4eead(%rip), %rdx     # 0x69b10
movq %r13, %r9
xorl %eax, %eax
callq 0x64f0
movl 0x10c0f5(%rip), %esi    # 0x126d68
addl $-0x9, %esi
movl %r12d, %edi
pushq $0x8
popq %rdx
xorl %ecx, %ecx
movq %r15, %r8
xorl %r9d, %r9d
callq 0x176c0
movq 0x158958(%rip), %rcx    # 0x1735e8
testq %rcx, %rcx
je 0x1ada0
movl 0x8(%rsp), %eax
movq %rcx, %rbp
decl %eax
jle 0x1acad
movq 0x18(%rbp), %rcx
testq %rcx, %rcx
jne 0x1ac9d
xorl %r13d, %r13d
pushq $0x10
popq %r14
cmpl %ebx, %r13d
jge 0x1ada0
testq %rbp, %rbp
je 0x1ada0
xorl %r12d, %r12d
cmpl $0x2, 0x8(%rbp)
sete %bl
xorps %xmm0, %xmm0
movups %xmm0, 0x5a(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movq (%rbp), %rsi
leaq 0x10(%rsp), %r15
movq %r15, %rdi
pushq $0x19
popq %rdx
callq 0x6190
movq %r15, %rdi
callq 0x6420
cmpq $0x19, %rax
jne 0x1ad1b
movl $0x2e2e2e, 0x25(%rsp)   # imm = 0x2E2E2E
movb %bl, %r12b
addl $0x3, %r12d
cmpq 0x1588bf(%rip), %rbp    # 0x1735e8
je 0x1ad49
pushq $0x20
popq %rdi
movl %r14d, %esi
movl %r12d, %edx
xorl %ecx, %ecx
leaq 0x10(%rsp), %r8
xorl %r9d, %r9d
callq 0x176c0
movl 0x4(%rsp), %ebx
jmp 0x1ad90
orl $0x8, %r12d
cmpl $0x0, 0x1588a4(%rip)    # 0x1735f8
movzwl %r12w, %r12d
movl 0x4(%rsp), %ebx
jne 0x1ad78
pushq $0x8
popq %rdi
movl %r14d, %esi
movl %r12d, %edx
xorl %ecx, %ecx
leaq 0x4edb7(%rip), %r8      # 0x69b27
xorl %r9d, %r9d
callq 0x176c0
pushq $0x20
popq %rdi
movl %r14d, %esi
movl %r12d, %edx
xorl %ecx, %ecx
leaq 0x10(%rsp), %r8
xorl %r9d, %r9d
callq 0x176c0
incl %r13d
movq 0x10(%rbp), %rbp
addl $0x8, %r14d
jmp 0x1acb4
movq 0x158849(%rip), %rcx    # 0x1735f0
testq %rcx, %rcx
pushq $0xf
popq %r15
pushq $0x7
popq %r13
je 0x1ae41
movl 0x8(%rsp), %eax
movq %rcx, %r12
decl %eax
jle 0x1adcd
movq 0x18(%r12), %rcx
testq %rcx, %rcx
jne 0x1adbc
xorl %ebp, %ebp
pushq $0x10
popq %r14
cmpl %ebx, %ebp
jge 0x1ae41
testq %r12, %r12
je 0x1ae41
cmpq 0x15880d(%rip), %r12    # 0x1735f0
je 0x1adf6
movq (%r12), %r8
movl $0x108, %edi            # imm = 0x108
movl %r14d, %esi
movl %r13d, %edx
jmp 0x1ae2a
cmpl $0x1, 0x1587fb(%rip)    # 0x1735f8
jne 0x1ae1b
movl $0xf0, %edi
movl %r14d, %esi
movl %r15d, %edx
xorl %ecx, %ecx
leaq 0x4ed14(%rip), %r8      # 0x69b27
xorl %r9d, %r9d
callq 0x176c0
movq (%r12), %r8
movl $0x108, %edi            # imm = 0x108
movl %r14d, %esi
movl %r15d, %edx
xorl %ecx, %ecx
xorl %r9d, %r9d
callq 0x176c0
incl %ebp
movq 0x10(%r12), %r12
addl $0x8, %r14d
jmp 0x1add3
callq 0x63720
xorl %r14d, %r14d
leaq 0x15c440(%rip), %r12    # 0x177290
movb %r14b, 0xcb(%r12)
movb %r14b, 0xcd(%r12)
movb %r14b, 0xc8(%r12)
movb %r14b, 0xd0(%r12)
movb %r14b, 0x1c(%r12)
movb %r14b, 0xf(%r12)
movb %r14b, 0x1(%r12)
leaq 0x10(%rsp), %r15
leaq 0x15c215(%rip), %r13    # 0x1770a0
pushq $0x9
popq %rbp
testb %r14b, %r14b
jne 0x1aef4
callq 0x63a71
testl %eax, %eax
je 0x1aeae
cmpb $0x0, (%r13)
je 0x1aeae
movb $0x1, 0x1(%r12)
movb $0x0, (%r13)
callq 0x1ca8f
cmpb $0x0, 0xcb(%r12)
movl %ebp, %r14d
jg 0x1aec5
movzbl %al, %r14d
cmpb $0x0, 0xcd(%r12)
cmovgl %ebp, %r14d
cmpb $0x0, 0xc8(%r12)
pushq $0x48
popq %rax
cmovgl %eax, %r14d
cmpb $0x0, 0xd0(%r12)
pushq $0x50
popq %rax
cmovgl %eax, %r14d
jmp 0x1ae8e
movl %r14d, %eax
andb $-0x21, %al
cmpb $0x47, %al
pushq $0x1
popq %r12
leaq 0x1582ca(%rip), %r13    # 0x1731d0
je 0x1af36
movzbl %al, %eax
cmpl $0x46, %eax
jne 0x1af53
andl $0x0, 0x1586e1(%rip)    # 0x1735f8
leaq 0x1927e2(%rip), %rdx    # 0x1ad700
movl (%rdx), %eax
movl %r12d, %ecx
subl %eax, %ecx
movl %ecx, (%rdx)
testl %eax, %eax
je 0x1af92
movw $0x2f, 0x15829c(%rip)   # 0x1731d0
jmp 0x1afa4
leaq 0x1927c3(%rip), %rax    # 0x1ad700
cmpl $0x0, (%rax)
jne 0x1afb3
movl %r12d, %eax
subl 0x10b9cd(%rip), %eax    # 0x126918
movl %eax, 0x10b9c7(%rip)    # 0x126918
jmp 0x1afa4
movzbl %r14b, %eax
leal -0x48(%rax), %ecx
cmpl $0x8, %ecx
ja 0x1b011
leaq 0x4e212(%rip), %rdx     # 0x6917c
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
cmpl $0x0, 0x15867e(%rip)    # 0x1735f8
je 0x1b0a7
movq 0x158669(%rip), %rax    # 0x1735f0
testq %rax, %rax
je 0x1afb3
movq 0x18(%rax), %rax
jmp 0x1b003
movb $0x0, 0x158237(%rip)    # 0x1731d0
movq %r13, %rdi
movl %r12d, %esi
callq 0x1f86a
movq %r13, %rdi
leaq 0x4eaa3(%rip), %rsi     # 0x69a51
callq 0x1b2ce
movq 0x158636(%rip), %rax    # 0x1735f0
testq %rax, %rax
movsbl %r14b, %edx
movl $0x0, %ecx
cmovnel %edx, %ecx
cmpb $0xd, %dl
cmovnel %edx, %ecx
cmpl $0x1b, %ecx
je 0x1b15b
cmpl $0xd, %ecx
jne 0x1ab00
jmp 0x1b148
cmpl $0x0, 0x15860b(%rip)    # 0x1735f8
je 0x1b091
movq 0x1585f6(%rip), %rax    # 0x1735f0
testq %rax, %rax
je 0x1afb3
movq 0x10(%rax), %rax
testq %rax, %rax
je 0x1afb3
movq %rax, 0x1585e1(%rip)    # 0x1735f0
jmp 0x1afb3
cmpl $0x9, %eax
jne 0x1b053
movl 0x1585dc(%rip), %eax    # 0x1735f8
testl %eax, %eax
jne 0x1b02a
cmpq $0x0, 0x1585b0(%rip)    # 0x1735d8
jne 0x1b040
movb $0x9, %r14b
cmpl $0x1, %eax
jne 0x1afb3
cmpq $0x0, 0x158596(%rip)    # 0x1735d0
je 0x1afb3
movl %r12d, %ecx
subl %eax, %ecx
movl %ecx, 0x1585ad(%rip)    # 0x1735f8
movb $0x9, %r14b
jmp 0x1afb3
cmpb $0xd, %r14b
sete %al
cmpl $0x0, 0x158597(%rip)    # 0x1735f8
sete %cl
andb %al, %cl
movq 0x15857b(%rip), %rax    # 0x1735e8
testq %rax, %rax
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x1afb3
cmpl $0x4, 0x8(%rax)
movq (%rax), %rsi
movq %r13, %rdi
jne 0x1b0d0
callq 0x6430
jmp 0x1b0d5
movq 0x158550(%rip), %rax    # 0x1735e8
testq %rax, %rax
je 0x1afb3
movq 0x10(%rax), %rax
jmp 0x1b0bb
movq 0x15853a(%rip), %rax    # 0x1735e8
testq %rax, %rax
je 0x1afb3
movq 0x18(%rax), %rax
testq %rax, %rax
je 0x1afb3
movq %rax, 0x15851d(%rip)    # 0x1735e8
jmp 0x1afb3
callq 0x6710
movq %r13, %rdi
callq 0x6420
movw $0x2f, (%rax,%r13)
leaq 0x192615(%rip), %rax    # 0x1ad700
cmpl $0x1, (%rax)
jne 0x1b0fd
movq %r13, %rdi
movl %r12d, %esi
callq 0x1f86a
jmp 0x1b108
movq %r13, %rdi
movl %r12d, %esi
callq 0x1f656
movq %r13, %rdi
leaq 0x4e93f(%rip), %rsi     # 0x69a51
callq 0x1b2ce
leaq 0x15bf92(%rip), %rax    # 0x1770b0
movq (%rax), %rdi
movl 0x10bc41(%rip), %esi    # 0x126d68
leaq 0x15c156(%rip), %rax    # 0x177284
imull (%rax), %esi
sarl $0x2, %esi
xorl %r14d, %r14d
xorl %edx, %edx
callq 0x444af
callq 0x63720
jmp 0x1afb3
movq (%rax), %rsi
leaq 0x15807e(%rip), %rdi    # 0x1731d0
callq 0x6710
xorl %eax, %eax
jmp 0x1b16b
leaq 0x19259e(%rip), %rax    # 0x1ad700
movl 0xc(%rsp), %ecx
movl %ecx, (%rax)
pushq $-0x1
popq %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq