// File: /workspace/github_cpp_makefile_star2_O1/jkingan[P]ladyheather/heather.cpp
// Function: touch_key(int, int)
int touch_key(int x,int y)
{
int num_keys;
int shift;
int i;
struct KEY_CAP *table;

   // Convert a mouse click on the touch screen keyboard to a simulated
   // keystroke.  Return the simulated keystoke value or 0 if blank/no key
   // was pressed.

   if(key_width <= 0) return 0;
   if(key_height <= 0) return 0;
   if(x < TOUCH_MARGIN) return 0;
   if(x > (TOUCH_MARGIN + (key_width*KBD_COLS))) return 0;
   if(y < TOUCH_MARGIN) return 0;
   if(y > (TOUCH_MARGIN + (key_height*KBD_ROWS))) return 0;

   x -= TOUCH_MARGIN;
   x /= key_width;
   y -= TOUCH_MARGIN;
   y /= key_height;

   shift = (shifted ^ caps_lock);

   if(x >= KBD_COLS) return 0;
   if(y >= KBD_ROWS) return 0;


   click_sound(0);  // keyboard typing key clicks

   if(shift) {  // upper case/shiftet keys
      table = &uc_table[0];
      num_keys = sizeof(uc_table) / sizeof(struct KEY_CAP);
   }
   else if(rpn_mode || last_zoom_calc) {
      table = &calc_lc_table[0];
      num_keys = sizeof(calc_lc_table) / sizeof(struct KEY_CAP);
   }
   else {
      table = &normal_lc_table[0];
      num_keys = sizeof(normal_lc_table) / sizeof(struct KEY_CAP);
   }

   for(i=0; i<num_keys; i++) {  // search the key table and look up keystroke value
      if(table[i].label == 0) ;
      else if((table[i].row == y) && (table[i].col == x)) {
         show_key(y,x, 1);        // flash the touched key
         refresh_page();
         Sleep(KBD_FLASH_TIME);
         show_key(y,x, 0);

         return table[i].val;
      }
   }

   return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl 0x33039f(%rip), %r8d    # 0x340168
xorl %ebx, %ebx
testl %r8d, %r8d
jle 0xfdea
movl 0x330395(%rip), %r9d    # 0x34016c
testl %r9d, %r9d
jle 0xfdea
movl 0x208a32(%rip), %edx    # 0x218814
addl %edx, %edx
movl %edi, %eax
subl %edx, %eax
jge 0xfdfb
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %esi, %ecx
subl %edx, %ecx
jl 0xfdea
leal (%r8,%r8,4), %r10d
leal (%r10,%r10,2), %r10d
addl %edx, %r10d
cmpl %edi, %r10d
jl 0xfdea
leal (%r9,%r9,2), %edi
leal (%rdx,%rdi,2), %edx
cmpl %esi, %edx
jl 0xfdea
cltd
idivl %r8d
movl %eax, %r14d
movl %ecx, %eax
cltd
idivl %r9d
movl %eax, %r15d
cmpl $0xf, %r14d
setge %al
cmpl $0x6, %r15d
setge %cl
orb %al, %cl
jne 0xfdea
movl 0x33034b(%rip), %r12d   # 0x340190
movl 0x330324(%rip), %r13d   # 0x340170
cmpb $0x0, 0x2fe475(%rip)    # 0x30e2c8
je 0xfe6f
cmpb $0x0, 0x20b3c2(%rip)    # 0x21b21e
je 0xfe6f
leaq 0xf9840(%rip), %rdi     # 0x1096a5
movl $0x1, %esi
callq 0x9cd3
cmpl %r13d, %r12d
jne 0xfe94
movl 0x2fc93a(%rip), %eax    # 0x30c7b4
orl 0x32b9a8(%rip), %eax    # 0x33b828
leaq 0x150fc9(%rip), %rax    # 0x160e50
leaq 0x1506c2(%rip), %r12    # 0x160550
cmovneq %rax, %r12
jmp 0xfe9b
leaq 0x1518b5(%rip), %r12    # 0x161750
movl $0x10, %r13d
cmpq $0x0, -0x8(%r12,%r13)
je 0xfeb7
cmpl %r15d, -0x10(%r12,%r13)
jne 0xfeb7
cmpl %r14d, -0xc(%r12,%r13)
je 0xfec9
addq $0x18, %r13
cmpq $0x910, %r13            # imm = 0x910
jne 0xfea1
jmp 0xfdea
movl %r15d, %edi
movl %r14d, %esi
movl $0x1, %edx
callq 0xfb8f
callq 0xab5f
movl $0x11170, %edi          # imm = 0x11170
callq 0x9540
movl %r15d, %edi
movl %r14d, %esi
xorl %edx, %edx
callq 0xfb8f
movl (%r12,%r13), %ebx
jmp 0xfdea