// File: jkingan[P]ladyheather/heathgps.cpp
// Function: set_traim_mode(int, int)
void set_traim_mode(int thresh, int save)
{
int old_thresh;

   if(read_only) return;
   if(luxor) return;

   if(rcvr_type == FURUNO_RCVR) {
      if(thresh <= 0) thresh = 0;
      else            thresh = 1;
      if(pps_enabled) sprintf(out, "GPrrs,%d,%d,%d", thresh,furuno_traim,2);
      else            sprintf(out, "GPrrs,%d,%d,%d", thresh,furuno_traim,0);
      send_furuno_cmd(out);
      send_furuno_cmd("GPrrq");
   }
   else if(rcvr_type == MOTO_RCVR) {
      if(thresh <= 0) {  // 12-channel disable traim
         send_moto_start("Ge");
         send_byte(0);
         send_moto_end();
      }
      else {  // 12-channel enable traim
         send_moto_start("Gf");
         send_word(thresh);
         send_moto_end();

         send_moto_start("Ge");
         send_byte(1);
         send_moto_end();
      }

      // 6/8 channel traim control
      old_thresh = traim_threshold;
      traim_threshold = thresh;
      set_pps(pps_mode, pps_polarity, delay_value, pps1_delay, pps_threshold, save);
      traim_threshold = old_thresh;
set_pps_mode(pps_rate);
   }
   else if(rcvr_type == NVS_RCVR) { 
      send_nvs_start(0xD7);
      send_byte(0x07);
      send_word(thresh);
      send_nvs_end();

      request_pps_info();
   }
   else if(rcvr_type == RFTG_RCVR) {
      if(thresh <= 0) set_rftg_traim(0);
      else            set_rftg_traim(1);
   }
   else if(rcvr_type == ZODIAC_RCVR) {
      if(thresh < 0) thresh = 0;
      set_zod_config(0, 0.0,0.0,0.0, thresh, 6);
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
leaq 0x301315(%rip), %rax    # 0x3961fa
cmpb $0x0, (%rax)
je 0x94eef
jmp 0x95124
leaq 0x209228(%rip), %rax    # 0x29e11e
cmpb $0x0, (%rax)
je 0x94f00
jmp 0x95124
leaq 0x1e2ba9(%rip), %rax    # 0x277ab0
cmpq $0x20000000, (%rax)     # imm = 0x20000000
jne 0x94fa0
cmpl $0x0, -0x4(%rbp)
jg 0x94f23
movl $0x0, -0x4(%rbp)
jmp 0x94f2a
movl $0x1, -0x4(%rbp)
leaq 0x2d7fcf(%rip), %rax    # 0x36cf00
cmpb $0x0, (%rax)
je 0x94f5f
movl -0x4(%rbp), %edx
leaq 0x30753c(%rip), %rax    # 0x39c47c
movl (%rax), %ecx
leaq 0x3064b7(%rip), %rdi    # 0x39b400
leaq 0xef392(%rip), %rsi     # 0x1842e2
movl $0x2, %r8d
movb $0x0, %al
callq 0x9060
jmp 0x94f83
movl -0x4(%rbp), %edx
leaq 0x307513(%rip), %rax    # 0x39c47c
movl (%rax), %ecx
leaq 0x30648e(%rip), %rdi    # 0x39b400
leaq 0xef369(%rip), %rsi     # 0x1842e2
xorl %r8d, %r8d
movb $0x0, %al
callq 0x9060
leaq 0x306476(%rip), %rdi    # 0x39b400
callq 0x83270
leaq 0xef0a2(%rip), %rdi     # 0x184038
callq 0x83270
jmp 0x95124
leaq 0x1e2b09(%rip), %rax    # 0x277ab0
cmpq $0x20, (%rax)
jne 0x95081
cmpl $0x0, -0x4(%rbp)
jg 0x94fd1
leaq 0xef686(%rip), %rdi     # 0x184644
callq 0x86190
xorl %edi, %edi
callq 0x7b210
callq 0x86230
jmp 0x95008
leaq 0xef66f(%rip), %rdi     # 0x184647
callq 0x86190
movl -0x4(%rbp), %eax
movzwl %ax, %edi
callq 0x7b4b0
callq 0x86230
leaq 0xef650(%rip), %rdi     # 0x184644
callq 0x86190
movl $0x1, %edi
callq 0x7b210
callq 0x86230
leaq 0x1e5295(%rip), %rax    # 0x27a2a4
movl (%rax), %eax
movl %eax, -0xc(%rbp)
movl -0x4(%rbp), %ecx
leaq 0x1e5286(%rip), %rax    # 0x27a2a4
movl %ecx, (%rax)
leaq 0x2d7edb(%rip), %rax    # 0x36cf02
movb (%rax), %cl
leaq 0x2d7ec8(%rip), %rax    # 0x36cef8
movl (%rax), %eax
leaq 0x2d7f67(%rip), %rdx    # 0x36cfa0
movsd (%rdx), %xmm0
leaq 0x2d7f74(%rip), %rdx    # 0x36cfb8
movsd (%rdx), %xmm1
leaq 0x2d7ead(%rip), %rdx    # 0x36cefc
movss (%rdx), %xmm2
movl -0x8(%rbp), %edx
movzbl %cl, %edi
movzbl %al, %esi
callq 0x91b20
movl -0xc(%rbp), %ecx
leaq 0x1e5239(%rip), %rax    # 0x27a2a4
movl %ecx, (%rax)
leaq 0x2d7e8f(%rip), %rax    # 0x36cf03
movzbl (%rax), %edi
callq 0x93650
jmp 0x95122
leaq 0x1e2a28(%rip), %rax    # 0x277ab0
cmpq $0x800, (%rax)          # imm = 0x800
jne 0x950bc
movl $0xd7, %edi
callq 0x824f0
movl $0x7, %edi
callq 0x7b210
movl -0x4(%rbp), %eax
movzwl %ax, %edi
callq 0x7b4b0
callq 0x82630
callq 0x91720
jmp 0x95120
leaq 0x1e29ed(%rip), %rax    # 0x277ab0
cmpq $0x400000, (%rax)       # imm = 0x400000
jne 0x950e7
cmpl $0x0, -0x4(%rbp)
jg 0x950db
xorl %edi, %edi
callq 0x95130
jmp 0x950e5
movl $0x1, %edi
callq 0x95130
jmp 0x9511e
leaq 0x1e29c2(%rip), %rax    # 0x277ab0
cmpq $0x100, (%rax)          # imm = 0x100
jne 0x9511c
cmpl $0x0, -0x4(%rbp)
jge 0x95104
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %esi
xorl %edi, %edi
xorps %xmm2, %xmm2
movl $0x6, %edx
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0x8e4f0
jmp 0x9511e
jmp 0x95120
jmp 0x95122
jmp 0x95124
addq $0x10, %rsp
popq %rbp
retq
nopw (%rax,%rax)