// File: 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
subq $0x20, %rsp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x6d272
movl $0x1, -0x4(%rbp)
jmp 0x6d648
cmpl $0x13, -0x8(%rbp)
jb 0x6d284
movl $0x2, -0x4(%rbp)
jmp 0x6d648
movq -0x10(%rbp), %rdi
movl $0x2c, %esi
callq 0x9100
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x6d2cc
movq -0x20(%rbp), %rax
movb $0x0, (%rax)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movl $0x1, %edx
callq 0x35ca0
movl %eax, -0x8(%rbp)
cmpl $0x13, -0x8(%rbp)
jb 0x6d2ca
movl $0x3, -0x4(%rbp)
jmp 0x6d648
jmp 0x6d2cc
movl -0x8(%rbp), %eax
movl %eax, %ecx
leaq 0x3001e8(%rip), %rax    # 0x36d4c0
imulq $0x2260, %rcx, %rcx     # imm = 0x2260
addq %rcx, %rax
movl $0x0, (%rax)
movl -0x8(%rbp), %eax
movl %eax, %ecx
leaq 0x3001cc(%rip), %rax    # 0x36d4c0
imulq $0x2260, %rcx, %rcx     # imm = 0x2260
addq %rcx, %rax
movl $0x0, 0x2228(%rax)
movl -0x8(%rbp), %eax
movl %eax, %ecx
leaq 0x3001ac(%rip), %rax    # 0x36d4c0
imulq $0x2260, %rcx, %rcx     # imm = 0x2260
addq %rcx, %rax
movl $0x270f, 0x4(%rax)      # imm = 0x270F
movl -0x8(%rbp), %eax
movl %eax, %ecx
leaq 0x30018f(%rip), %rax    # 0x36d4c0
imulq $0x2260, %rcx, %rcx     # imm = 0x2260
addq %rcx, %rax
movl $0x1, 0x2234(%rax)
movq -0x10(%rbp), %rax
cmpb $0x0, (%rax)
je 0x6d4fd
movl -0x8(%rbp), %eax
leaq 0x300164(%rip), %rdi    # 0x36d4c0
imulq $0x2260, %rax, %rax     # imm = 0x2260
addq %rax, %rdi
addq $0xc, %rdi
movq -0x10(%rbp), %rsi
movl $0x101, %edx            # imm = 0x101
callq 0x9170
movl -0x8(%rbp), %eax
leaq 0x30013e(%rip), %rdi    # 0x36d4c0
imulq $0x2260, %rax, %rax     # imm = 0x2260
addq %rax, %rdi
addq $0xc, %rdi
callq 0x9120
subq $0x1, %rax
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jl 0x6d4fb
movl -0x8(%rbp), %eax
movl %eax, %ecx
leaq 0x30010e(%rip), %rax    # 0x36d4c0
imulq $0x2260, %rcx, %rcx     # imm = 0x2260
addq %rcx, %rax
movslq -0x14(%rbp), %rcx
movsbl 0xc(%rax,%rcx), %eax
cmpl $0xa, %eax
jne 0x6d3ee
movl -0x8(%rbp), %eax
movl %eax, %ecx
leaq 0x3000ea(%rip), %rax    # 0x36d4c0
imulq $0x2260, %rcx, %rcx     # imm = 0x2260
addq %rcx, %rax
movslq -0x14(%rbp), %rcx
movb $0x0, 0xc(%rax,%rcx)
jmp 0x6d4eb
movl -0x8(%rbp), %eax
movl %eax, %ecx
leaq 0x3000c6(%rip), %rax    # 0x36d4c0
imulq $0x2260, %rcx, %rcx     # imm = 0x2260
addq %rcx, %rax
movslq -0x14(%rbp), %rcx
movsbl 0xc(%rax,%rcx), %eax
cmpl $0xd, %eax
jne 0x6d436
movl -0x8(%rbp), %eax
movl %eax, %ecx
leaq 0x3000a2(%rip), %rax    # 0x36d4c0
imulq $0x2260, %rcx, %rcx     # imm = 0x2260
addq %rcx, %rax
movslq -0x14(%rbp), %rcx
movb $0x0, 0xc(%rax,%rcx)
jmp 0x6d4e9
movl -0x8(%rbp), %eax
movl %eax, %ecx
leaq 0x30007e(%rip), %rax    # 0x36d4c0
imulq $0x2260, %rcx, %rcx     # imm = 0x2260
addq %rcx, %rax
movslq -0x14(%rbp), %rcx
movsbl 0xc(%rax,%rcx), %eax
cmpl $0x20, %eax
jne 0x6d47b
movl -0x8(%rbp), %eax
movl %eax, %ecx
leaq 0x30005a(%rip), %rax    # 0x36d4c0
imulq $0x2260, %rcx, %rcx     # imm = 0x2260
addq %rcx, %rax
movslq -0x14(%rbp), %rcx
movb $0x0, 0xc(%rax,%rcx)
jmp 0x6d4e7
movl -0x8(%rbp), %eax
movl %eax, %ecx
leaq 0x300039(%rip), %rax    # 0x36d4c0
imulq $0x2260, %rcx, %rcx     # imm = 0x2260
addq %rcx, %rax
movslq -0x14(%rbp), %rcx
movsbl 0xc(%rax,%rcx), %eax
cmpl $0x9, %eax
jne 0x6d4c0
movl -0x8(%rbp), %eax
movl %eax, %ecx
leaq 0x300015(%rip), %rax    # 0x36d4c0
imulq $0x2260, %rcx, %rcx     # imm = 0x2260
addq %rcx, %rax
movslq -0x14(%rbp), %rcx
movb $0x0, 0xc(%rax,%rcx)
jmp 0x6d4e5
movl -0x8(%rbp), %eax
movl %eax, %ecx
leaq 0x2ffff4(%rip), %rax    # 0x36d4c0
imulq $0x2260, %rcx, %rcx     # imm = 0x2260
addq %rcx, %rax
movslq -0x14(%rbp), %rcx
cmpb $0x0, 0xc(%rax,%rcx)
je 0x6d4e3
jmp 0x6d4fb
jmp 0x6d4e5
jmp 0x6d4e7
jmp 0x6d4e9
jmp 0x6d4eb
jmp 0x6d4ed
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x6d39c
jmp 0x6d546
movl -0x8(%rbp), %eax
movl %eax, %ecx
leaq 0x2fffb7(%rip), %rax    # 0x36d4c0
imulq $0x2260, %rcx, %rcx     # imm = 0x2260
addq %rcx, %rax
cmpb $0x0, 0xc(%rax)
je 0x6d51b
jmp 0x6d544
movl -0x8(%rbp), %eax
leaq 0x2fff9b(%rip), %rdi    # 0x36d4c0
imulq $0x2260, %rax, %rax     # imm = 0x2260
addq %rax, %rdi
addq $0xc, %rdi
leaq 0x102308(%rip), %rsi    # 0x16f842
movl $0x101, %edx            # imm = 0x101
callq 0x9170
jmp 0x6d546
movl -0x8(%rbp), %eax
movl %eax, %ecx
leaq 0x2fff6e(%rip), %rax    # 0x36d4c0
imulq $0x2260, %rcx, %rcx     # imm = 0x2260
addq %rcx, %rax
movsbl 0xc(%rax), %eax
cmpl $0x0, %eax
jne 0x6d571
movl $0x3, -0x4(%rbp)
jmp 0x6d648
movl -0x8(%rbp), %eax
movl %eax, %ecx
leaq 0x2fff43(%rip), %rax    # 0x36d4c0
imulq $0x2260, %rcx, %rcx     # imm = 0x2260
addq %rcx, %rax
movb $0x0, 0x10c(%rax)
movl -0x8(%rbp), %eax
movl %eax, %ecx
leaq 0x2fff26(%rip), %rax    # 0x36d4c0
imulq $0x2260, %rcx, %rcx     # imm = 0x2260
addq %rcx, %rax
cmpl $0x0, 0x2230(%rax)
je 0x6d5fa
movl -0x8(%rbp), %eax
movl %eax, %ecx
leaq 0x2fff07(%rip), %rax    # 0x36d4c0
imulq $0x2260, %rcx, %rcx     # imm = 0x2260
addq %rcx, %rax
movl $0x1, 0x2234(%rax)
movl -0x8(%rbp), %eax
movl %eax, %ecx
leaq 0x2ffee7(%rip), %rax    # 0x36d4c0
imulq $0x2260, %rcx, %rcx     # imm = 0x2260
addq %rcx, %rax
movl $0x0, 0x2228(%rax)
movl -0x8(%rbp), %edi
movl $0xe, %esi
callq 0xc0e0
leaq 0x2ff347(%rip), %rax    # 0x36c948
movsd (%rax), %xmm0
movl -0x8(%rbp), %eax
movl %eax, %ecx
leaq 0x2ffeaf(%rip), %rax    # 0x36d4c0
imulq $0x2260, %rcx, %rcx     # imm = 0x2260
addq %rcx, %rax
subsd 0x2238(%rax), %xmm0
movl -0x8(%rbp), %eax
movl %eax, %ecx
leaq 0x2ffe91(%rip), %rax    # 0x36d4c0
imulq $0x2260, %rcx, %rcx     # imm = 0x2260
addq %rcx, %rax
movsd %xmm0, 0x2248(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)