// File: /workspace/github_cpp_makefile_star2_O3/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 0x330422(%rip), %r8d    # 0x340168
xorl %ebx, %ebx
testl %r8d, %r8d
jle 0xfd67
movl 0x330418(%rip), %r9d    # 0x34016c
testl %r9d, %r9d
jle 0xfd67
movl 0x208ab5(%rip), %edx    # 0x218814
addl %edx, %edx
movl %edi, %eax
subl %edx, %eax
jge 0xfd78
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 0xfd67
leal (%r8,%r8,4), %r10d
leal (%r10,%r10,2), %r10d
addl %edx, %r10d
cmpl %edi, %r10d
jl 0xfd67
leal (%r9,%r9,2), %edi
leal (%rdx,%rdi,2), %edx
cmpl %esi, %edx
jl 0xfd67
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 0xfd67
movl 0x3303ce(%rip), %r12d   # 0x340190
movl 0x3303a7(%rip), %r13d   # 0x340170
cmpb $0x0, 0x2fe4f8(%rip)    # 0x30e2c8
je 0xfdec
cmpb $0x0, 0x20b445(%rip)    # 0x21b21e
je 0xfdec
leaq 0xf98d3(%rip), %rdi     # 0x1096b5
movl $0x1, %esi
callq 0x9ccb
cmpl %r13d, %r12d
jne 0xfe11
movl 0x2fc9bd(%rip), %eax    # 0x30c7b4
orl 0x32ba2b(%rip), %eax    # 0x33b828
leaq 0x15104c(%rip), %rax    # 0x160e50
leaq 0x150745(%rip), %r12    # 0x160550
cmovneq %rax, %r12
jmp 0xfe18
leaq 0x151938(%rip), %r12    # 0x161750
movl $0x10, %r13d
cmpq $0x0, -0x8(%r12,%r13)
je 0xfe34
cmpl %r15d, -0x10(%r12,%r13)
jne 0xfe34
cmpl %r14d, -0xc(%r12,%r13)
je 0xfe46
addq $0x18, %r13
cmpq $0x910, %r13            # imm = 0x910
jne 0xfe1e
jmp 0xfd67
movl %r15d, %edi
movl %r14d, %esi
movl $0x1, %edx
callq 0xfb0c
callq 0xab54
movl $0x11170, %edi          # imm = 0x11170
callq 0x9540
movl %r15d, %edi
movl %r14d, %esi
xorl %edx, %edx
callq 0xfb0c
movl (%r12,%r13), %ebx
jmp 0xfd67