// File: /workspace/github_c_makefile_star2_O3/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 $0x88, %rsp
leaq 0x197770(%rip), %rax    # 0x1b4700
movl (%rax), %eax
movl 0x110dd0(%rip), %ecx    # 0x12dd68
leal -0x20(%rcx), %ebx
movq %rcx, 0x18(%rsp)
addl $-0x19, %ecx
testl %ebx, %ebx
cmovnsl %ebx, %ecx
movl %ecx, 0xc(%rsp)
movl %eax, 0x14(%rsp)
cmpl %edi, %eax
je 0x1cfc4
movb $0x0, 0x15d215(%rip)    # 0x17a1d0
leaq 0x19773e(%rip), %rax    # 0x1b4700
movl %edi, (%rax)
cmpl $0x1, %edi
jne 0x1cfdc
leaq 0x15d200(%rip), %rdi    # 0x17a1d0
movl $0x1, %esi
callq 0x2220a
jmp 0x1cfed
leaq 0x15d1ed(%rip), %rdi    # 0x17a1d0
movl $0x1, %esi
callq 0x21fdc
sarl $0x3, 0xc(%rsp)
leaq 0x15d1d7(%rip), %r14    # 0x17a1d0
leaq 0x57b11(%rip), %rsi     # 0x74b11
movq %r14, %rdi
callq 0x1d84c
leaq 0x57b08(%rip), %rdi     # 0x74b17
callq 0x192c8
leal 0xf(%rbx), %eax
testl %ebx, %ebx
cmovnsl %ebx, %eax
sarl $0x4, %eax
incl %eax
movl %eax, 0x10(%rsp)
leaq 0x20(%rsp), %r15
movl $0x50, %r13d
leaq 0x161079(%rip), %rax    # 0x17e0b0
movq (%rax), %rdi
movl 0x110d28(%rip), %esi    # 0x12dd68
leaq 0x16123d(%rip), %rax    # 0x17e284
imull (%rax), %esi
sarl $0x2, %esi
xorl %edx, %edx
callq 0x4d2d8
leaq 0x1976a5(%rip), %rax    # 0x1b4700
cmpl $0x1, (%rax)
jne 0x1d091
movups 0x57af4(%rip), %xmm0    # 0x74b5b
movaps %xmm0, 0x40(%rsp)
movups 0x57ad8(%rip), %xmm0    # 0x74b4b
movaps %xmm0, 0x30(%rsp)
movups 0x57abc(%rip), %xmm0    # 0x74b3b
movaps %xmm0, 0x20(%rsp)
movl $0x2e6d65, 0x50(%rsp)   # imm = 0x2E6D65
jmp 0x1d14a
movups 0x57ad7(%rip), %xmm0    # 0x74b6f
movaps %xmm0, 0x20(%rsp)
movl 0x110875(%rip), %ebx    # 0x12d918
movq %r15, %rdi
callq 0x6420
addq %rsp, %rax
addq $0x20, %rax
testl %ebx, %ebx
je 0x1d116
movabsq $0x6c6e6f2d50524720, %rcx # imm = 0x6C6E6F2D50524720
movq %rcx, (%rax)
movw $0x79, 0x8(%rax)
movq %r15, %rdi
callq 0x6420
movups 0x57ab1(%rip), %xmm0    # 0x74b89
movups %xmm0, 0x20(%rsp,%rax)
movups 0x57ab5(%rip), %xmm0    # 0x74b99
movups %xmm0, 0x30(%rsp,%rax)
movups 0x57ab5(%rip), %xmm0    # 0x74ba5
movups %xmm0, 0x3c(%rsp,%rax)
movq %r15, %rdi
callq 0x6420
movabsq $0x656c6966206c6c61, %rcx # imm = 0x656C6966206C6C61
movq %rcx, 0x20(%rsp,%rax)
movl $0x2e7365, 0x27(%rsp,%rax) # imm = 0x2E7365
jmp 0x1d14a
movups 0x57a88(%rip), %xmm0    # 0x74ba5
movups %xmm0, 0x1c(%rax)
movups 0x57a71(%rip), %xmm0    # 0x74b99
movups %xmm0, 0x10(%rax)
movups 0x57a56(%rip), %xmm0    # 0x74b89
movups %xmm0, (%rax)
movq %r15, %rdi
callq 0x6420
movups 0x57a7b(%rip), %xmm0    # 0x74bc0
movups %xmm0, 0x20(%rsp,%rax)
movl 0x15d074(%rip), %ebp    # 0x17a1c4
movq %r15, %rdi
callq 0x6420
shll $0x2, %eax
subl %eax, %ebp
movl %ebp, %edi
movl $0x4, %esi
movl $0xe, %edx
xorl %ecx, %ecx
movq %r15, %r8
xorl %r9d, %r9d
callq 0x1915d
movl 0x15d464(%rip), %ecx    # 0x17a5e0
movl 0x15d461(%rip), %r8d    # 0x17a5e4
movl $0x5a, %esi
movq %r15, %rdi
leaq 0x57a3e(%rip), %rdx     # 0x74bd0
movq %r14, %r9
xorl %eax, %eax
callq 0x64f0
movl 0x110bc6(%rip), %esi    # 0x12dd68
addl $-0x9, %esi
movl $0x1, %edi
movl $0x8, %edx
xorl %ecx, %ecx
movq %r15, %r8
xorl %r9d, %r9d
callq 0x1915d
movq 0x15d425(%rip), %rcx    # 0x17a5e8
testq %rcx, %rcx
je 0x1d2e3
movl 0x10(%rsp), %eax
movq %rcx, %r15
decl %eax
jle 0x1d1e0
movq 0x18(%r15), %rcx
testq %rcx, %rcx
jne 0x1d1d0
cmpl $0x28, 0x18(%rsp)
jl 0x1d2e3
movl $0x10, %ebp
movl $0x1, %r12d
xorl %r14d, %r14d
cmpl $0x2, 0x8(%r15)
sete %bl
xorps %xmm0, %xmm0
movups %xmm0, 0x6a(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movq (%r15), %rsi
movl $0x19, %edx
leaq 0x20(%rsp), %r13
movq %r13, %rdi
callq 0x6190
movq %r13, %rdi
callq 0x6420
cmpq $0x19, %rax
jne 0x1d24d
movl $0x2e2e2e, 0x35(%rsp)   # imm = 0x2E2E2E
movb %bl, %r14b
addl $0x3, %r14d
cmpq 0x15d38d(%rip), %r15    # 0x17a5e8
je 0x1d27e
movl $0x20, %edi
movl %ebp, %esi
movl %r14d, %edx
xorl %ecx, %ecx
leaq 0x20(%rsp), %r8
xorl %r9d, %r9d
callq 0x1915d
movl $0x50, %r13d
jmp 0x1d2c9
orl $0x8, %r14d
cmpl $0x0, 0x15d36f(%rip)    # 0x17a5f8
movzwl %r14w, %r14d
movl $0x50, %r13d
jne 0x1d2b0
movl $0x8, %edi
movl %ebp, %esi
movl %r14d, %edx
xorl %ecx, %ecx
leaq 0x5793f(%rip), %r8      # 0x74be7
xorl %r9d, %r9d
callq 0x1915d
movl $0x20, %edi
movl %ebp, %esi
movl %r14d, %edx
xorl %ecx, %ecx
leaq 0x20(%rsp), %r8
xorl %r9d, %r9d
callq 0x1915d
cmpl 0xc(%rsp), %r12d
jge 0x1d2e3
movq 0x10(%r15), %r15
addl $0x8, %ebp
incl %r12d
testq %r15, %r15
jne 0x1d1f6
movq 0x15d306(%rip), %rcx    # 0x17a5f0
testq %rcx, %rcx
leaq 0x160f9c(%rip), %rbx    # 0x17e290
leaq 0x160da5(%rip), %r12    # 0x17e0a0
je 0x1d396
movl 0x10(%rsp), %eax
movq %rcx, %r14
decl %eax
jle 0x1d315
movq 0x18(%r14), %rcx
testq %rcx, %rcx
jne 0x1d305
cmpl $0x28, 0x18(%rsp)
jl 0x1d396
movl $0x10, %ebp
movl $0x1, %r15d
cmpq 0x15d2c2(%rip), %r14    # 0x17a5f0
je 0x1d341
movq (%r14), %r8
movl $0x108, %edi            # imm = 0x108
movl %ebp, %esi
movl $0x7, %edx
jmp 0x1d376
cmpl $0x1, 0x15d2b0(%rip)    # 0x17a5f8
jne 0x1d367
movl $0xf0, %edi
movl %ebp, %esi
movl $0xf, %edx
xorl %ecx, %ecx
leaq 0x57888(%rip), %r8      # 0x74be7
xorl %r9d, %r9d
callq 0x1915d
movq (%r14), %r8
movl $0x108, %edi            # imm = 0x108
movl %ebp, %esi
movl $0xf, %edx
xorl %ecx, %ecx
xorl %r9d, %r9d
callq 0x1915d
cmpl 0xc(%rsp), %r15d
jge 0x1d396
movq 0x10(%r14), %r14
addl $0x8, %ebp
incl %r15d
testq %r14, %r14
jne 0x1d327
callq 0x6efcd
xorl %eax, %eax
movb %al, 0xcb(%rbx)
movb %al, 0xcd(%rbx)
movb %al, 0xc8(%rbx)
movb %al, 0xd0(%rbx)
movb %al, 0x1c(%rbx)
movb %al, 0xf(%rbx)
movb %al, 0x1(%rbx)
leaq 0x20(%rsp), %r15
movl $0x48, %r14d
callq 0x6f32a
testl %eax, %eax
je 0x1d3e2
cmpb $0x0, (%r12)
je 0x1d3e2
movb $0x1, 0x1(%rbx)
movb $0x0, (%r12)
callq 0x1f08a
cmpb $0x0, 0xcb(%rbx)
movl $0x9, %edx
movl $0x9, %ecx
jg 0x1d3fd
movzbl %al, %ecx
cmpb $0x0, 0xcd(%rbx)
cmovgl %edx, %ecx
cmpb $0x0, 0xc8(%rbx)
cmovgl %r14d, %ecx
cmpb $0x0, 0xd0(%rbx)
movl %ecx, %ebp
cmovgl %r13d, %ebp
testb %bpl, %bpl
je 0x1d3c9
movl %ebp, %eax
andb $-0x21, %al
cmpb $0x47, %al
leaq 0x15cd9f(%rip), %r14    # 0x17a1d0
je 0x1d46d
movzbl %al, %eax
cmpl $0x46, %eax
jne 0x1d490
movl $0x0, 0x15d1b3(%rip)    # 0x17a5f8
leaq 0x1972b4(%rip), %rdx    # 0x1b4700
movl (%rdx), %eax
movl $0x1, %ecx
subl %eax, %ecx
movl %ecx, (%rdx)
testl %eax, %eax
je 0x1d4e6
movw $0x2f, 0x15cd68(%rip)   # 0x17a1d0
jmp 0x1d4fa
leaq 0x19728c(%rip), %rax    # 0x1b4700
cmpl $0x0, (%rax)
jne 0x1d509
movl $0x1, %eax
subl 0x110490(%rip), %eax    # 0x12d918
movl %eax, 0x11048a(%rip)    # 0x12d918
jmp 0x1d4fa
movzbl %bpl, %eax
leal -0x48(%rax), %edx
cmpl $0x8, %edx
ja 0x1d567
leaq 0x56d95(%rip), %rsi     # 0x7423c
movslq (%rsi,%rdx,4), %rax
addq %rsi, %rax
jmpq *%rax
cmpl $0x0, 0x15d141(%rip)    # 0x17a5f8
je 0x1d616
movq 0x15d12c(%rip), %rax    # 0x17a5f0
testq %rax, %rax
je 0x1d632
movq 0x18(%rax), %rax
testq %rax, %rax
je 0x1d632
movq %rax, 0x15d10f(%rip)    # 0x17a5f0
jmp 0x1d632
movb $0x0, 0x15cce3(%rip)    # 0x17a1d0
movq %r14, %rdi
movl $0x1, %esi
callq 0x2220a
movq %r14, %rdi
leaq 0x5760d(%rip), %rsi     # 0x74b11
callq 0x1d84c
movq 0x15d0e0(%rip), %rax    # 0x17a5f0
testq %rax, %rax
movsbl %bpl, %edx
movl $0x0, %ecx
cmovnel %edx, %ecx
cmpb $0xd, %dl
cmovnel %edx, %ecx
cmpl $0x1b, %ecx
je 0x1d6c7
cmpl $0xd, %ecx
jne 0x1d030
jmp 0x1d6b4
cmpl $0x0, 0x15d0b5(%rip)    # 0x17a5f8
je 0x1d5ed
movq 0x15d0a0(%rip), %rax    # 0x17a5f0
testq %rax, %rax
je 0x1d509
movq 0x10(%rax), %rax
testq %rax, %rax
je 0x1d509
movq %rax, 0x15d08b(%rip)    # 0x17a5f0
jmp 0x1d509
cmpl $0x9, %eax
jne 0x1d5ab
movl 0x15d086(%rip), %eax    # 0x17a5f8
testl %eax, %eax
jne 0x1d580
cmpq $0x0, 0x15d05a(%rip)    # 0x17a5d8
jne 0x1d596
movb $0x9, %bpl
cmpl $0x1, %eax
jne 0x1d509
cmpq $0x0, 0x15d040(%rip)    # 0x17a5d0
je 0x1d509
movl $0x1, %ecx
subl %eax, %ecx
movl %ecx, 0x15d055(%rip)    # 0x17a5f8
movb $0x9, %bpl
jmp 0x1d509
cmpb $0xd, %bpl
sete %cl
cmpl $0x0, 0x15d03f(%rip)    # 0x17a5f8
sete %dl
movq 0x15d025(%rip), %rax    # 0x17a5e8
testq %rax, %rax
setne %sil
andb %dl, %sil
andb %cl, %sil
cmpb $0x1, %sil
jne 0x1d509
cmpl $0x4, 0x8(%rax)
movq (%rax), %rsi
movq %r14, %rdi
jne 0x1d639
callq 0x6430
jmp 0x1d63e
movq 0x15cff4(%rip), %rax    # 0x17a5e8
testq %rax, %rax
je 0x1d509
movq 0x10(%rax), %rax
testq %rax, %rax
je 0x1d509
movq %rax, 0x15cfd7(%rip)    # 0x17a5e8
jmp 0x1d509
movq 0x15cfcb(%rip), %rax    # 0x17a5e8
testq %rax, %rax
je 0x1d632
movq 0x18(%rax), %rax
testq %rax, %rax
je 0x1d632
movq %rax, 0x15cfb6(%rip)    # 0x17a5e8
movl %ecx, %ebp
jmp 0x1d509
callq 0x6710
movq %r14, %rdi
callq 0x6420
movw $0x2f, (%rax,%r14)
leaq 0x1970ac(%rip), %rax    # 0x1b4700
cmpl $0x1, (%rax)
jne 0x1d668
movq %r14, %rdi
movl $0x1, %esi
callq 0x2220a
jmp 0x1d675
movq %r14, %rdi
movl $0x1, %esi
callq 0x21fdc
movq %r14, %rdi
leaq 0x57492(%rip), %rsi     # 0x74b11
callq 0x1d84c
leaq 0x160a25(%rip), %rax    # 0x17e0b0
movq (%rax), %rdi
movl 0x1106d4(%rip), %esi    # 0x12dd68
leaq 0x160be9(%rip), %rax    # 0x17e284
imull (%rax), %esi
sarl $0x2, %esi
xorl %ebp, %ebp
xorl %edx, %edx
callq 0x4d2d8
callq 0x6efcd
jmp 0x1d509
movq (%rax), %rsi
leaq 0x15cb12(%rip), %rdi    # 0x17a1d0
callq 0x6710
xorl %eax, %eax
jmp 0x1d6d9
leaq 0x197032(%rip), %rax    # 0x1b4700
movl 0x14(%rsp), %ecx
movl %ecx, (%rax)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq