// File: /workspace/github_c_makefile_star2_O1/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 0x196bc3(%rip), %r14    # 0x1b3700
movl (%r14), %eax
movl 0x110222(%rip), %ecx    # 0x12cd68
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 0x1cb6c
movb $0x0, 0x15c667(%rip)    # 0x1791d0
movl %edi, (%r14)
cmpl $0x1, (%r14)
jne 0x1cb85
leaq 0x15c657(%rip), %rdi    # 0x1791d0
movl $0x1, %esi
callq 0x21e2a
jmp 0x1cb96
leaq 0x15c644(%rip), %rdi    # 0x1791d0
movl $0x1, %esi
callq 0x21bc8
sarl $0x3, 0xc(%rsp)
leaq 0x15c62e(%rip), %r15    # 0x1791d0
leaq 0x56e26(%rip), %rsi     # 0x739cf
movq %r15, %rdi
callq 0x1d399
leaq 0x56e1d(%rip), %rdi     # 0x739d5
callq 0x19277
leal 0xf(%rbx), %eax
testl %ebx, %ebx
cmovnsl %ebx, %eax
sarl $0x4, %eax
incl %eax
movl %eax, 0x10(%rsp)
leaq 0x20(%rsp), %r12
movl $0x48, %r13d
leaq 0x1604d0(%rip), %rax    # 0x17d0b0
movq (%rax), %rdi
movl 0x11017f(%rip), %esi    # 0x12cd68
leaq 0x160694(%rip), %rax    # 0x17d284
imull (%rax), %esi
sarl $0x2, %esi
xorl %edx, %edx
callq 0x4abc9
cmpl $0x1, (%r14)
jne 0x1cc34
movups 0x56e0f(%rip), %xmm0    # 0x73a19
movaps %xmm0, 0x40(%rsp)
movups 0x56df3(%rip), %xmm0    # 0x73a09
movaps %xmm0, 0x30(%rsp)
movups 0x56dd7(%rip), %xmm0    # 0x739f9
movaps %xmm0, 0x20(%rsp)
movl $0x2e6d65, 0x50(%rsp)   # imm = 0x2E6D65
jmp 0x1cced
movups 0x56df2(%rip), %xmm0    # 0x73a2d
movaps %xmm0, 0x20(%rsp)
movl 0x10fcd2(%rip), %ebx    # 0x12c918
movq %r12, %rdi
callq 0x6420
addq %rsp, %rax
addq $0x20, %rax
testl %ebx, %ebx
je 0x1ccb9
movabsq $0x6c6e6f2d50524720, %rcx # imm = 0x6C6E6F2D50524720
movq %rcx, (%rax)
movw $0x79, 0x8(%rax)
movq %r12, %rdi
callq 0x6420
movups 0x56dcc(%rip), %xmm0    # 0x73a47
movups %xmm0, 0x20(%rsp,%rax)
movups 0x56dd0(%rip), %xmm0    # 0x73a57
movups %xmm0, 0x30(%rsp,%rax)
movups 0x56dd0(%rip), %xmm0    # 0x73a63
movups %xmm0, 0x3c(%rsp,%rax)
movq %r12, %rdi
callq 0x6420
movabsq $0x656c6966206c6c61, %rcx # imm = 0x656C6966206C6C61
movq %rcx, 0x20(%rsp,%rax)
movl $0x2e7365, 0x27(%rsp,%rax) # imm = 0x2E7365
jmp 0x1cced
movups 0x56da3(%rip), %xmm0    # 0x73a63
movups %xmm0, 0x1c(%rax)
movups 0x56d8c(%rip), %xmm0    # 0x73a57
movups %xmm0, 0x10(%rax)
movups 0x56d71(%rip), %xmm0    # 0x73a47
movups %xmm0, (%rax)
movq %r12, %rdi
callq 0x6420
movups 0x56d96(%rip), %xmm0    # 0x73a7e
movups %xmm0, 0x20(%rsp,%rax)
movl 0x15c4d1(%rip), %ebp    # 0x1791c4
movq %r12, %rdi
callq 0x6420
shll $0x2, %eax
subl %eax, %ebp
movl %ebp, %edi
movl $0x4, %esi
movl $0xe, %edx
xorl %ecx, %ecx
movq %r12, %r8
xorl %r9d, %r9d
callq 0x19108
movl 0x15c8c1(%rip), %ecx    # 0x1795e0
movl 0x15c8be(%rip), %r8d    # 0x1795e4
movl $0x5a, %esi
movq %r12, %rdi
leaq 0x56d59(%rip), %rdx     # 0x73a8e
movq %r15, %r9
xorl %eax, %eax
callq 0x64f0
movl 0x110023(%rip), %esi    # 0x12cd68
addl $-0x9, %esi
movl $0x1, %edi
movl $0x8, %edx
xorl %ecx, %ecx
movq %r12, %r8
xorl %r9d, %r9d
callq 0x19108
movq 0x15c882(%rip), %rcx    # 0x1795e8
testq %rcx, %rcx
je 0x1ce83
movl 0x10(%rsp), %eax
movq %rcx, %r15
decl %eax
jle 0x1cd83
movq 0x18(%r15), %rcx
testq %rcx, %rcx
jne 0x1cd73
cmpl $0x28, 0x18(%rsp)
jl 0x1ce83
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 0x1cdf0
movl $0x2e2e2e, 0x35(%rsp)   # imm = 0x2E2E2E
movb %bl, %r14b
addl $0x3, %r14d
cmpq 0x15c7ea(%rip), %r15    # 0x1795e8
je 0x1ce21
movl $0x20, %edi
movl %ebp, %esi
movl %r14d, %edx
xorl %ecx, %ecx
leaq 0x20(%rsp), %r8
xorl %r9d, %r9d
callq 0x19108
movl $0x48, %r13d
jmp 0x1ce69
cmpl $0x0, 0x15c7d0(%rip)    # 0x1795f8
movl $0x48, %r13d
jne 0x1ce4c
leal 0x8(%r14), %edx
movl $0x8, %edi
movl %ebp, %esi
xorl %ecx, %ecx
leaq 0x56c61(%rip), %r8      # 0x73aa5
xorl %r9d, %r9d
callq 0x19108
orl $0x8, %r14d
movl $0x20, %edi
movl %ebp, %esi
movl %r14d, %edx
xorl %ecx, %ecx
leaq 0x20(%rsp), %r8
xorl %r9d, %r9d
callq 0x19108
cmpl 0xc(%rsp), %r12d
jge 0x1ce83
movq 0x10(%r15), %r15
addl $0x8, %ebp
incl %r12d
testq %r15, %r15
jne 0x1cd99
movq 0x15c766(%rip), %rcx    # 0x1795f0
testq %rcx, %rcx
leaq 0x20(%rsp), %r12
je 0x1cf22
movl 0x10(%rsp), %eax
movq %rcx, %r14
decl %eax
jle 0x1ceac
movq 0x18(%r14), %rcx
testq %rcx, %rcx
jne 0x1ce9c
cmpl $0x28, 0x18(%rsp)
jl 0x1cf22
movl $0x10, %ebp
movl $0x1, %r15d
movw $0x7, %bx
cmpq 0x15c727(%rip), %r14    # 0x1795f0
jne 0x1cef5
movw $0xf, %bx
cmpl $0x1, 0x15c722(%rip)    # 0x1795f8
jne 0x1cef5
movl $0xf0, %edi
movl %ebp, %esi
movl $0xf, %edx
xorl %ecx, %ecx
leaq 0x56bb8(%rip), %r8      # 0x73aa5
xorl %r9d, %r9d
callq 0x19108
movq (%r14), %r8
movzwl %bx, %edx
movl $0x108, %edi            # imm = 0x108
movl %ebp, %esi
xorl %ecx, %ecx
xorl %r9d, %r9d
callq 0x19108
cmpl 0xc(%rsp), %r15d
jge 0x1cf22
movq 0x10(%r14), %r14
addl $0x8, %ebp
incl %r15d
testq %r14, %r14
jne 0x1cebe
callq 0x6d200
xorl %eax, %eax
leaq 0x160360(%rip), %rbx    # 0x17d290
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 0x1967a8(%rip), %r14    # 0x1b3700
leaq 0x160141(%rip), %r15    # 0x17d0a0
callq 0x6d55e
testl %eax, %eax
je 0x1cf76
cmpb $0x0, (%r15)
je 0x1cf76
movb $0x1, 0x1(%rbx)
movb $0x0, (%r15)
callq 0x1ebf5
cmpb $0x0, 0xcb(%rbx)
movl $0x9, %ecx
movl $0x9, %ebp
jg 0x1cf91
movzbl %al, %ebp
cmpb $0x0, 0xcd(%rbx)
cmovgl %ecx, %ebp
cmpb $0x0, 0xc8(%rbx)
cmovgl %r13d, %ebp
cmpb $0x0, 0xd0(%rbx)
movl $0x50, %eax
cmovgl %eax, %ebp
testb %bpl, %bpl
je 0x1cf5f
movl %ebp, %eax
andb $-0x21, %al
cmpb $0x47, %al
leaq 0x15c209(%rip), %r15    # 0x1791d0
je 0x1cff7
movzbl %al, %eax
cmpl $0x46, %eax
jne 0x1d010
movl $0x0, 0x15c61d(%rip)    # 0x1795f8
movl (%r14), %eax
movl $0x1, %ecx
subl %eax, %ecx
movl %ecx, (%r14)
testl %eax, %eax
je 0x1d04f
movw $0x2f, 0x15c1db(%rip)   # 0x1791d0
jmp 0x1d063
cmpl $0x0, (%r14)
jne 0x1d072
movl $0x1, %eax
subl 0x10f910(%rip), %eax    # 0x12c918
movl %eax, 0x10f90a(%rip)    # 0x12c918
jmp 0x1d063
movzbl %bpl, %eax
leal -0x48(%rax), %ecx
cmpl $0x8, %ecx
ja 0x1d0d0
leaq 0x560cd(%rip), %rdx     # 0x730f4
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
cmpl $0x0, 0x15c5c1(%rip)    # 0x1795f8
je 0x1d166
movq 0x15c5ac(%rip), %rax    # 0x1795f0
testq %rax, %rax
je 0x1d072
movq 0x18(%rax), %rax
jmp 0x1d0c2
movb $0x0, 0x15c17a(%rip)    # 0x1791d0
movq %r15, %rdi
movl $0x1, %esi
callq 0x21e2a
movq %r15, %rdi
leaq 0x56962(%rip), %rsi     # 0x739cf
callq 0x1d399
movq 0x15c577(%rip), %rax    # 0x1795f0
testq %rax, %rax
movsbl %bpl, %edx
movl $0x0, %ecx
cmovnel %edx, %ecx
cmpb $0xd, %dl
cmovnel %edx, %ecx
cmpl $0x1b, %ecx
je 0x1d217
cmpl $0xd, %ecx
jne 0x1cbd9
jmp 0x1d204
cmpl $0x0, 0x15c54c(%rip)    # 0x1795f8
je 0x1d150
movq 0x15c537(%rip), %rax    # 0x1795f0
testq %rax, %rax
je 0x1d072
movq 0x10(%rax), %rax
testq %rax, %rax
je 0x1d072
movq %rax, 0x15c522(%rip)    # 0x1795f0
jmp 0x1d072
cmpl $0x9, %eax
jne 0x1d10e
movl 0x15c51d(%rip), %eax    # 0x1795f8
testl %eax, %eax
jne 0x1d0e9
cmpq $0x0, 0x15c4f1(%rip)    # 0x1795d8
jne 0x1d0fc
cmpl $0x1, %eax
jne 0x1d072
cmpq $0x0, 0x15c4da(%rip)    # 0x1795d0
je 0x1d072
movl $0x1, %ecx
subl %eax, %ecx
movl %ecx, 0x15c4ef(%rip)    # 0x1795f8
jmp 0x1d072
cmpb $0xd, %bpl
sete %cl
cmpl $0x0, 0x15c4dc(%rip)    # 0x1795f8
sete %dl
movq 0x15c4c2(%rip), %rax    # 0x1795e8
testq %rax, %rax
setne %sil
andb %dl, %sil
andb %cl, %sil
cmpb $0x1, %sil
jne 0x1d072
cmpl $0x4, 0x8(%rax)
movq (%rax), %rsi
movq %r15, %rdi
jne 0x1d18f
callq 0x6430
jmp 0x1d194
movq 0x15c491(%rip), %rax    # 0x1795e8
testq %rax, %rax
je 0x1d072
movq 0x10(%rax), %rax
jmp 0x1d17a
movq 0x15c47b(%rip), %rax    # 0x1795e8
testq %rax, %rax
je 0x1d072
movq 0x18(%rax), %rax
testq %rax, %rax
je 0x1d072
movq %rax, 0x15c45e(%rip)    # 0x1795e8
jmp 0x1d072
callq 0x6710
movq %r15, %rdi
callq 0x6420
movw $0x2f, (%rax,%r15)
cmpl $0x1, (%r14)
jne 0x1d1b8
movq %r15, %rdi
movl $0x1, %esi
callq 0x21e2a
jmp 0x1d1c5
movq %r15, %rdi
movl $0x1, %esi
callq 0x21bc8
movq %r15, %rdi
leaq 0x56800(%rip), %rsi     # 0x739cf
callq 0x1d399
leaq 0x15fed5(%rip), %rax    # 0x17d0b0
movq (%rax), %rdi
movl 0x10fb84(%rip), %esi    # 0x12cd68
leaq 0x160099(%rip), %rax    # 0x17d284
imull (%rax), %esi
sarl $0x2, %esi
xorl %ebp, %ebp
xorl %edx, %edx
callq 0x4abc9
callq 0x6d200
jmp 0x1d072
movq (%rax), %rsi
leaq 0x15bfc2(%rip), %rdi    # 0x1791d0
callq 0x6710
xorl %eax, %eax
jmp 0x1d223
movl 0x14(%rsp), %eax
movl %eax, (%r14)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq