// File: /workspace/github_cpp_makefile_star2_O1/magmastonealex[P]fbkeyboard/src/Display.cpp
// Function: Display::keyAt(int, int)
char Display::keyAt(int x, int y) {
	if(x < entryWidth) {
		return 0;
	}

	for(int xCheck = 1; xCheck < 5; xCheck++) {
		//determine row of touch.

		int lastRowStart = CHAR_Y_START(entryWidth, scale, xCheck - 1, rowWidth);
		int rowStart = CHAR_Y_START(entryWidth, scale, xCheck, rowWidth);

		if(x > lastRowStart && x < rowStart) {
			//std::cout << "row: " << xCheck << std::endl;
			for(int yCheck = 1; yCheck < 12; yCheck++) {
				int lastCharStart = CHAR_X_START(margin, yCheck-1, stepSizePx, scale);
				int thisCharStart = CHAR_X_START(margin, yCheck, stepSizePx, scale);
				if(y > lastCharStart && y < thisCharStart) {
					//std::cout << "col: " << yCheck << std::endl;
					if(xCheck > 3) {
						std::cout << "col: " << yCheck << std::endl;
						switch(yCheck) {
							case 10:
								toggleSym2();
								return 0;
							case 11:
								toggleSym1();
								return 0;
							default:
								toLower();
								return ' ';
						}
					}
					char touched = (*currentKeyboard)[(xCheck-1)][10-(yCheck-1)];

					if(touched == 0x0F) {
						toggleUpper();
						return 0;
					}
					else if(touched == 0x00) {
						toLower();
					}

					return touched;
				}
			}
		}
	}
	return 0;
}

// Assembly:
cmpl %esi, 0x14(%rdi)
jle 0x2b9c
xorl %eax, %eax
retq
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %r14
leaq 0x68(%rdi), %rax
movq %rax, (%rsp)
leaq 0x89(%rdi), %rax
movq %rax, 0x30(%rsp)
leaq 0xaa(%rdi), %rax
movq %rax, 0x28(%rsp)
leaq 0xcb(%rdi), %rax
movq %rax, 0x20(%rsp)
movl $0x1, %r10d
movl $0xa, %r11d
movl %edx, 0xc(%rsp)
movl %esi, 0x8(%rsp)
movl 0xc(%r14), %ecx
movl 0x1c(%r14), %edi
shll $0x2, %ecx
addl 0x14(%r14), %ecx
movl %r10d, %r8d
subl %edi, %r8d
addl %ecx, %r8d
movb $0x1, %bl
cmpl %esi, %r8d
jge 0x2d8b
imull %r10d, %edi
addl %edi, %ecx
cmpl %esi, %ecx
jle 0x2d8b
movl $0x1, %r13d
xorl %ebp, %ebp
movq %r11, %r15
xorl %ebx, %ebx
movq %r10, 0x10(%rsp)
movq %r11, 0x18(%rsp)
movl 0x8(%r14), %r8d
movl 0xc(%r14), %ecx
leal (,%rcx,8), %r9d
addl 0x20(%r14), %r9d
movl %r9d, %edi
imull %ebp, %edi
subl %ecx, %r8d
addl %r8d, %edi
movb $0x1, %cl
cmpl %edx, %edi
jge 0x2d6a
imull %r13d, %r9d
addl %r9d, %r8d
cmpl %edx, %r8d
jle 0x2d6a
cmpq $0x4, %r10
jne 0x2cfa
movl $0x5, %edx
movq 0x3343(%rip), %r12      # 0x5fc8
movq %r12, %rdi
leaq 0x1400(%rip), %rsi      # 0x408f
callq 0x21c0
movq %r12, %rdi
movl %r13d, %esi
callq 0x2270
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq %r12, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2110
cmpl $0xb, %r13d
je 0x2d23
cmpl $0xa, %r13d
movl 0xc(%rsp), %edx
movl 0x8(%rsp), %esi
movq 0x18(%rsp), %r11
jne 0x2d59
movq 0x20(%rsp), %rax
cmpq %rax, 0x60(%r14)
cmoveq (%rsp), %rax
movq %rax, 0x60(%r14)
xorl %ecx, %ecx
xorl %eax, %eax
jmp 0x2d65
movq 0x60(%r14), %rcx
movzbl (%rcx,%r15), %eax
testl %eax, %eax
je 0x2d4d
cmpl $0xf, %eax
jne 0x2d55
movq 0x30(%rsp), %rax
cmpq %rax, %rcx
cmoveq (%rsp), %rax
movq %rax, 0x60(%r14)
xorl %ecx, %ecx
xorl %eax, %eax
jmp 0x2d6a
movq 0x28(%rsp), %rax
cmpq %rax, 0x60(%r14)
cmoveq (%rsp), %rax
movq %rax, 0x60(%r14)
xorl %ecx, %ecx
xorl %eax, %eax
movl 0xc(%rsp), %edx
movl 0x8(%rsp), %esi
movq 0x10(%rsp), %r10
movq 0x18(%rsp), %r11
jmp 0x2d6a
movq (%rsp), %rcx
movq %rcx, 0x60(%r14)
xorl %ecx, %ecx
jmp 0x2d6a
movq (%rsp), %rax
movq %rax, 0x60(%r14)
movb $0x20, %al
xorl %ecx, %ecx
movq 0x10(%rsp), %r10
testb %cl, %cl
je 0x2d8b
cmpq $0xb, %r13
leaq 0x1(%r13), %rcx
setae %bl
incl %ebp
decq %r15
movq %rcx, %r13
cmpq $0xc, %rcx
jne 0x2c35
testb $0x1, %bl
je 0x2da3
incq %r10
addq $0xb, %r11
cmpq $0x5, %r10
jne 0x2bed
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq