// File: /workspace/github_cpp_makefile_star2_O2/jkingan[P]ladyheather/heathui.cpp
// Function: config_input_device(unsigned int, char*)
int config_input_device(unsigned port, char *arg)
{
int i;
char *comma;

   // __linux__  __MACH__  __FreeBSD__   ... WINDOWS can't do this

   // setup to use a com device using a com device name.
   // Returns 0 if successful,  non-zero if error.
   // Serial port baud rate info can follow the device number/name - separated by a comma

   #ifdef WINDOWS
      return 4;     // Windows does not support named input devices
   #endif

   if(arg == 0) return 1;
   if(port >= NUM_COM_PORTS) return 2;

   comma = strchr(arg, ',');
   if(comma) {     // baud rate info follows the '='
      *comma = 0;
//    port = (unsigned) set_serial_params(port, arg, 0);
      port = (unsigned) set_serial_params(port, arg, 1);
      if(port >= NUM_COM_PORTS) return 3;
   }

   com[port].com_port = 0;
   com[port].user_disabled_com = 0;
   com[port].usb_port = USE_IDEV_NAME;
   com[port].process_com = 1;

   if(arg[0]) {  // device name given
      strncpy(com[port].com_dev, &arg[0], sizeof(com[port].com_dev));

      for(i=strlen(com[port].com_dev)-1; i>=0; i++) {  // trim trailing scuzz
         if     (com[port].com_dev[i] == 0x0A) com[port].com_dev[i] = 0;
         else if(com[port].com_dev[i] == 0x0D) com[port].com_dev[i] = 0;
         else if(com[port].com_dev[i] == ' ')  com[port].com_dev[i] = 0;
         else if(com[port].com_dev[i] == '\t') com[port].com_dev[i] = 0;
         else if(com[port].com_dev[i]) break;
      }
   }
   else if(com[port].com_dev[0]) {   // use previously set device name
   }
   else {  // use default device name
      strncpy(com[port].com_dev, "/dev/heather", sizeof(com[port].com_dev));
   }

   if(com[port].com_dev[0] == 0) return 3;
   com[port].com_dev[sizeof(com[port].com_dev)-1] = 0;

   if(com[port].com_running) {
      com[port].process_com = 1;
      com[port].user_disabled_com = 0;
      init_com(port, 14);
   }

   com[port].last_com_time = this_msec - com[port].com_timeout;

   return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
testq %rsi, %rsi
je 0x49120
movl %edi, %r14d
cmpl $0x12, %edi
jbe 0x49134
pushq $0x2
jmp 0x49122
pushq $0x1
popq %rbx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rsi, %r15
pushq $0x2c
popq %rsi
movq %r15, %rdi
callq 0x9100
pushq $0x3
popq %rbx
testq %rax, %rax
je 0x49163
movb $0x0, (%rax)
pushq $0x1
popq %rdx
movl %r14d, %edi
movq %r15, %rsi
callq 0x246b8
movl %eax, %r14d
cmpl $0x12, %eax
ja 0x49123
movl %r14d, %eax
movq %rax, -0x30(%rbp)
imulq $0x2260, %rax, %r14     # imm = 0x2260
leaq 0x2af168(%rip), %rcx    # 0x2f82e0
movabsq $0x270f00000000, %rax   # imm = 0x270F00000000
leaq (%rcx,%r14), %r12
addq $0xc, %r12
movq %rax, -0xc(%r12)
andl $0x0, 0x221c(%r12)
leaq (%rcx,%r14), %r13
movl $0x1, 0x2228(%r12)
cmpb $0x0, (%r15)
je 0x49202
movl $0x101, %edx            # imm = 0x101
movq %r12, %rdi
movq %r15, %rsi
movq %rcx, %r15
callq 0x9170
movq %r12, %rdi
callq 0x9120
decl %eax
addq %rax, %r14
leaq (%r15,%r14), %rcx
addq $0xc, %rcx
movabsq $0x100002600, %rdx      # imm = 0x100002600
testl %eax, %eax
js 0x4921d
movzbl (%rcx), %esi
cmpq $0x20, %rsi
ja 0x4921d
btq %rsi, %rdx
jae 0x491fb
movb $0x0, (%rcx)
incq %rcx
jmp 0x491e0
testq %rsi, %rsi
je 0x491f6
jmp 0x4921d
cmpb $0x0, (%r12)
jne 0x4921d
leaq 0xaa895(%rip), %rsi     # 0xf3aa5
movl $0x101, %edx            # imm = 0x101
movq %r12, %rdi
callq 0x9170
cmpb $0x0, 0xc(%r13)
je 0x49123
movb $0x0, 0x10c(%r13)
cmpl $0x0, 0x2230(%r13)
je 0x49259
movl $0x1, 0x2234(%r13)
andl $0x0, 0x2228(%r13)
pushq $0xe
popq %rsi
movq -0x30(%rbp), %rdi
callq 0xb30a
leaq 0x2ae508(%rip), %rax    # 0x2f7768
movsd (%rax), %xmm0
subsd 0x2238(%r13), %xmm0
movsd %xmm0, 0x2248(%r13)
xorl %ebx, %ebx
jmp 0x49123