// File: /workspace/github_cpp_makefile_star2_O2/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 0x31aac3(%rip), %r8d    # 0x32a168
xorl %ebx, %ebx
testl %r8d, %r8d
jle 0xf6c6
movl 0x31aab9(%rip), %r9d    # 0x32a16c
testl %r9d, %r9d
jle 0xf6c6
movl 0x1f3156(%rip), %edx    # 0x202814
addl %edx, %edx
movl %edi, %eax
subl %edx, %eax
jge 0xf6d7
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 0xf6c6
imull $0xf, %r8d, %r10d
addl %edx, %r10d
cmpl %edi, %r10d
jl 0xf6c6
imull $0x6, %r9d, %edi
addl %edi, %edx
cmpl %esi, %edx
jl 0xf6c6
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 0xf6c6
movl 0x31aa74(%rip), %r12d   # 0x32a190
movl 0x31aa4d(%rip), %r13d   # 0x32a170
callq 0x9f19
cmpl %r13d, %r12d
jne 0xf74d
movl 0x2e7081(%rip), %eax    # 0x2f67b4
orl 0x3160ef(%rip), %eax    # 0x325828
leaq 0x13b710(%rip), %rax    # 0x14ae50
leaq 0x13ae09(%rip), %r12    # 0x14a550
cmovneq %rax, %r12
jmp 0xf754
leaq 0x13bffc(%rip), %r12    # 0x14b750
pushq $0x10
popq %r13
cmpq $0x910, %r13            # imm = 0x910
je 0xf6c6
cmpq $0x0, -0x8(%r12,%r13)
je 0xf77b
cmpl %r15d, -0x10(%r12,%r13)
jne 0xf77b
cmpl %r14d, -0xc(%r12,%r13)
je 0xf781
addq $0x18, %r13
jmp 0xf758
pushq $0x1
popq %rdx
movl %r15d, %edi
movl %r14d, %esi
callq 0xf493
callq 0xaa05
pushq $0x46
popq %rdi
callq 0xae83
movl %r15d, %edi
movl %r14d, %esi
xorl %edx, %edx
callq 0xf493
movl (%r12,%r13), %ebx
jmp 0xf6c6