// File: 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
subq $0x20, %rsp
movl %edi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
cmpl $0x0, 0x38c4b3(%rip)    # 0x39f348
jg 0x12ea3
movl $0x0, -0x4(%rbp)
jmp 0x130b6
cmpl $0x0, 0x38c4a2(%rip)    # 0x39f34c
jg 0x12eb8
movl $0x0, -0x4(%rbp)
jmp 0x130b6
movl -0x8(%rbp), %eax
movl 0x264b33(%rip), %ecx    # 0x2779f4
shll %ecx
cmpl %ecx, %eax
jge 0x12ed3
movl $0x0, -0x4(%rbp)
jmp 0x130b6
movl -0x8(%rbp), %eax
movl 0x264b18(%rip), %ecx    # 0x2779f4
shll %ecx
imull $0xf, 0x38c463(%rip), %edx # 0x39f348
addl %edx, %ecx
cmpl %ecx, %eax
jle 0x12ef7
movl $0x0, -0x4(%rbp)
jmp 0x130b6
movl -0xc(%rbp), %eax
movl 0x264af4(%rip), %ecx    # 0x2779f4
shll %ecx
cmpl %ecx, %eax
jge 0x12f12
movl $0x0, -0x4(%rbp)
jmp 0x130b6
movl -0xc(%rbp), %eax
movl 0x264ad9(%rip), %ecx    # 0x2779f4
shll %ecx
imull $0x6, 0x38c428(%rip), %edx # 0x39f34c
addl %edx, %ecx
cmpl %ecx, %eax
jle 0x12f36
movl $0x0, -0x4(%rbp)
jmp 0x130b6
movl 0x264ab8(%rip), %ecx    # 0x2779f4
shll %ecx
movl -0x8(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x8(%rbp)
movl 0x38c3fc(%rip), %ecx    # 0x39f348
movl -0x8(%rbp), %eax
cltd
idivl %ecx
movl %eax, -0x8(%rbp)
movl 0x264a99(%rip), %ecx    # 0x2779f4
shll %ecx
movl -0xc(%rbp), %eax
subl %ecx, %eax
movl %eax, -0xc(%rbp)
movl 0x38c3e1(%rip), %ecx    # 0x39f34c
movl -0xc(%rbp), %eax
cltd
idivl %ecx
movl %eax, -0xc(%rbp)
movl 0x38c3f6(%rip), %eax    # 0x39f370
xorl 0x38c3d0(%rip), %eax    # 0x39f350
movl %eax, -0x14(%rbp)
cmpl $0xf, -0x8(%rbp)
jl 0x12f95
movl $0x0, -0x4(%rbp)
jmp 0x130b6
cmpl $0x6, -0xc(%rbp)
jl 0x12fa7
movl $0x0, -0x4(%rbp)
jmp 0x130b6
xorl %edi, %edi
callq 0xa110
cmpl $0x0, -0x14(%rbp)
je 0x12fc8
leaq 0x1ad785(%rip), %rax    # 0x1c0740
movq %rax, -0x20(%rbp)
movl $0x60, -0x10(%rbp)
jmp 0x13002
cmpl $0x0, 0x387a39(%rip)    # 0x39aa08
jne 0x12fda
cmpl $0x0, 0x3589bc(%rip)    # 0x36b994
je 0x12fee
leaq 0x1ace5f(%rip), %rax    # 0x1bfe40
movq %rax, -0x20(%rbp)
movl $0x60, -0x10(%rbp)
jmp 0x13000
leaq 0x1ac54b(%rip), %rax    # 0x1bf540
movq %rax, -0x20(%rbp)
movl $0x60, -0x10(%rbp)
jmp 0x13002
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x130af
movq -0x20(%rbp), %rax
movslq -0x18(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
cmpq $0x0, 0x8(%rax)
jne 0x1302d
jmp 0x1309f
movq -0x20(%rbp), %rax
movslq -0x18(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
cmpl -0xc(%rbp), %eax
jne 0x1309d
movq -0x20(%rbp), %rax
movslq -0x18(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
cmpl -0x8(%rbp), %eax
jne 0x1309d
movl -0xc(%rbp), %edi
movl -0x8(%rbp), %esi
movl $0x1, %edx
callq 0x12b60
callq 0xb0d0
movl $0x46, %edi
callq 0xb8b0
movl -0xc(%rbp), %edi
movl -0x8(%rbp), %esi
xorl %edx, %edx
callq 0x12b60
movq -0x20(%rbp), %rax
movslq -0x18(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0x130b6
jmp 0x1309f
jmp 0x130a1
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x13009
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nop