// File: jkingan[P]ladyheather/heathgps.cpp
// Function: set_trimble_protocol(int, int, int, int, int, int)
int set_trimble_protocol(int baud,int data_bits,int parity,int stop_bits, int in_prot,int out_prot)
{
   if(read_only) return 2;
   if(rcvr_type != TSIP_RCVR) return 2;

   // in_prot, out_prot:  2=TSIP  4=NMEA
   in_prot = out_prot = 2;  // !!!! always use TSIP

   if     (baud == 4800)   baud = 6;
   else if(baud == 9600)   baud = 7;
   else if(baud == 19200)  baud = 8;
   else if(baud == 38400)  baud = 9;
   else if(baud == 57600)  baud = 10;
   else if(baud == 115200) baud = 11;
   else return 1;

   data_bits = 3;   // !!!! we always use 8 bits

   if     (parity == ODD_PAR)  parity = 1;
   else if(parity == EVEN_PAR) parity = 2;
   else                        parity = 0;

   if(stop_bits == 2) stop_bits = 1;
   else               stop_bits = 0;

   send_tsip_start(0xBC);
   send_byte(0xFF);       // current com port (0=main com)
   send_byte(baud);       // 9600 baud
   send_byte(baud);       // 9600 baud
   send_byte(3);          // 8-bit
   send_byte(parity);     // no parity
   send_byte(stop_bits);  // 1 stop bit
   send_byte(0);          // rsvd (flow control)
   send_byte(in_prot);    // 2=tsip 4=nmea
   send_byte(out_prot);   // 
   send_byte(0);          // rsvd
   send_tsip_end();

   return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movl %edi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movl %r8d, -0x18(%rbp)
movl %r9d, -0x1c(%rbp)
leaq 0x304f97(%rip), %rax    # 0x3961fa
cmpb $0x0, (%rax)
je 0x91274
movl $0x2, -0x4(%rbp)
jmp 0x913db
leaq 0x1e6835(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
je 0x9128d
movl $0x2, -0x4(%rbp)
jmp 0x913db
movl $0x2, -0x1c(%rbp)
movl $0x2, -0x18(%rbp)
cmpl $0x12c0, -0x8(%rbp)     # imm = 0x12C0
jne 0x912ad
movl $0x6, -0x8(%rbp)
jmp 0x9131d
cmpl $0x2580, -0x8(%rbp)     # imm = 0x2580
jne 0x912bf
movl $0x7, -0x8(%rbp)
jmp 0x9131b
cmpl $0x4b00, -0x8(%rbp)     # imm = 0x4B00
jne 0x912d1
movl $0x8, -0x8(%rbp)
jmp 0x91319
cmpl $0x9600, -0x8(%rbp)     # imm = 0x9600
jne 0x912e3
movl $0x9, -0x8(%rbp)
jmp 0x91317
cmpl $0xe100, -0x8(%rbp)     # imm = 0xE100
jne 0x912f5
movl $0xa, -0x8(%rbp)
jmp 0x91315
cmpl $0x1c200, -0x8(%rbp)    # imm = 0x1C200
jne 0x91307
movl $0xb, -0x8(%rbp)
jmp 0x91313
movl $0x1, -0x4(%rbp)
jmp 0x913db
jmp 0x91315
jmp 0x91317
jmp 0x91319
jmp 0x9131b
jmp 0x9131d
movl $0x3, -0xc(%rbp)
cmpl $0x1, -0x10(%rbp)
jne 0x91333
movl $0x1, -0x10(%rbp)
jmp 0x9134b
cmpl $0x2, -0x10(%rbp)
jne 0x91342
movl $0x2, -0x10(%rbp)
jmp 0x91349
movl $0x0, -0x10(%rbp)
jmp 0x9134b
cmpl $0x2, -0x14(%rbp)
jne 0x9135a
movl $0x1, -0x14(%rbp)
jmp 0x91361
movl $0x0, -0x14(%rbp)
movl $0xbc, %edi
callq 0x824f0
movl $0xff, %edi
callq 0x7b210
movl -0x8(%rbp), %eax
movzbl %al, %edi
callq 0x7b210
movl -0x8(%rbp), %eax
movzbl %al, %edi
callq 0x7b210
movl $0x3, %edi
callq 0x7b210
movl -0x10(%rbp), %eax
movzbl %al, %edi
callq 0x7b210
movl -0x14(%rbp), %eax
movzbl %al, %edi
callq 0x7b210
xorl %edi, %edi
callq 0x7b210
movl -0x18(%rbp), %eax
movzbl %al, %edi
callq 0x7b210
movl -0x1c(%rbp), %eax
movzbl %al, %edi
callq 0x7b210
xorl %edi, %edi
callq 0x7b210
callq 0x82590
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)