// File: jkingan[P]ladyheather/heathui.cpp
// Function: save_cmd_bytes(char*)
void save_cmd_bytes(char *arg)
{
u16 val;
char c;
int i;
u08 saw_digit;

   // save byte string to send to the receiver

   val = 0x00;
   saw_digit = 0;
   for(i=1; i<=(int)strlen(arg); i++) {  // get and save the string of bytes
      c = toupper(arg[i]);
      if((c >= '0') && (c <= '9')) {  // build hex value
         val = (val * 16) + (c-'0');
         saw_digit = 1;
         continue;
      }
      else if((c >= 'A') && (c <= 'F')) {  // build hex value
         val = (val * 16) + (c-'A'+10);
         saw_digit = 1;
         continue;
      }
      else if(saw_digit) {  // end of hex value
         if(arg[0] == '=') {  // add byte to list of bytes to send during receiver init
            if(user_init_len < USER_CMD_LEN) {
               user_init_cmd[user_init_len++] = (u08) val;
            }
         }
         else if(arg[0] == '$') {  // add byte to list of bytes to send every second
            if(user_pps_len < USER_CMD_LEN) {
               user_pps_cmd[user_pps_len++] = (u08) val;
            }
         }

         val = 0x00;     // setup for next hex value
         saw_digit = 0;
      }

      if(c == ',') continue;   // values can be separated by spaces or commas
      else if(c == ' ') continue;
      else break;  // anything else ends the list of hex values
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movw $0x0, -0xa(%rbp)
movb $0x0, -0x11(%rbp)
movl $0x1, -0x10(%rbp)
movl -0x10(%rbp), %eax
movl %eax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
callq 0x9120
movq %rax, %rcx
movl -0x18(%rbp), %eax
cmpl %ecx, %eax
jg 0x638bd
movq -0x8(%rbp), %rax
movslq -0x10(%rbp), %rcx
movsbl (%rax,%rcx), %edi
callq 0x96e0
movb %al, -0xb(%rbp)
movsbl -0xb(%rbp), %eax
cmpl $0x30, %eax
jl 0x637bd
movsbl -0xb(%rbp), %eax
cmpl $0x39, %eax
jg 0x637bd
movzwl -0xa(%rbp), %eax
shll $0x4, %eax
movsbl -0xb(%rbp), %ecx
subl $0x30, %ecx
addl %ecx, %eax
movw %ax, -0xa(%rbp)
movb $0x1, -0x11(%rbp)
jmp 0x638af
movsbl -0xb(%rbp), %eax
cmpl $0x41, %eax
jl 0x637ef
movsbl -0xb(%rbp), %eax
cmpl $0x46, %eax
jg 0x637ef
movzwl -0xa(%rbp), %eax
shll $0x4, %eax
movsbl -0xb(%rbp), %ecx
subl $0x41, %ecx
addl $0xa, %ecx
addl %ecx, %eax
movw %ax, -0xa(%rbp)
movb $0x1, -0x11(%rbp)
jmp 0x638af
cmpb $0x0, -0x11(%rbp)
je 0x63893
movq -0x8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3d, %eax
jne 0x63840
leaq 0x332b08(%rip), %rax    # 0x396314
cmpl $0x101, (%rax)          # imm = 0x101
jge 0x6383e
movw -0xa(%rbp), %ax
movb %al, %dl
leaq 0x332af3(%rip), %rax    # 0x396314
movl (%rax), %eax
movl %eax, %esi
addl $0x1, %esi
leaq 0x332ae5(%rip), %rcx    # 0x396314
movl %esi, (%rcx)
movslq %eax, %rcx
leaq 0x3329d5(%rip), %rax    # 0x396210
movb %dl, (%rax,%rcx)
jmp 0x63889
movq -0x8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x24, %eax
jne 0x63887
leaq 0x332bd1(%rip), %rax    # 0x396424
cmpl $0x101, (%rax)          # imm = 0x101
jge 0x63885
movw -0xa(%rbp), %ax
movb %al, %dl
leaq 0x332bbc(%rip), %rax    # 0x396424
movl (%rax), %eax
movl %eax, %esi
addl $0x1, %esi
leaq 0x332bae(%rip), %rcx    # 0x396424
movl %esi, (%rcx)
movslq %eax, %rcx
leaq 0x332a9e(%rip), %rax    # 0x396320
movb %dl, (%rax,%rcx)
jmp 0x63887
jmp 0x63889
movw $0x0, -0xa(%rbp)
movb $0x0, -0x11(%rbp)
jmp 0x63895
jmp 0x63897
movsbl -0xb(%rbp), %eax
cmpl $0x2c, %eax
jne 0x638a2
jmp 0x638af
movsbl -0xb(%rbp), %eax
cmpl $0x20, %eax
jne 0x638ad
jmp 0x638af
jmp 0x638bd
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x6375d
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)