// File: jkingan[P]ladyheather/heathgps.cpp
// Function: get_ebolt_version()
void get_ebolt_version()
{   // ThunderBolt-E only
u08 rsvd1;
u08 major;
u08 minor;
u08 build;
u08 len;
int i;

   log_packet_id("Packet 0x1C (Tbolt-E version)");

   rev_month = rev_day = rev_hour = 0;
   rev_year = 0;

   subcode = tsip_byte();
   if(subcode == 0x81) {  // firmware version
      rsvd1 = tsip_byte();
      major = tsip_byte();
      minor = tsip_byte();
      build = tsip_byte();
      rev_month = tsip_byte();
      rev_day = tsip_byte();
      rev_year = tsip_word();
      len = tsip_byte();
  
      out[0] = 0;
      for(i=0; i<len; i++) {
         if(i >= MAX_TEXT_COLS) {
            tsip_byte();
            continue;
         }
         out[i] = tsip_byte();
         out[i+1] = 0;
      }
  
      strupr(out);
   }
   else if(subcode == 0x83) {  // hardware version
      ebolt_serno = tsip_dword();
      rev_day = tsip_byte();
      rev_month = tsip_byte();
      rev_year = tsip_word();
      rev_hour = tsip_byte();
      hw_code = tsip_word();
      len = tsip_byte();

      for(i=0; i<UNIT_LEN; i++) unit_name[i] = ' ';
      unit_name[UNIT_LEN] = 0;

      out[0] = 0;
      for(i=0; i<len; i++) {   // get hardware id
         if(i >= MAX_TEXT_COLS) {
            tsip_byte();
            continue;
         }
         out[i] = tsip_byte();  // string can have: ICM, RES SMT, RES360, ACUTIME
         out[i+1] = 0;
         if(i < UNIT_LEN) {
            unit_name[i] = out[i];
         }
      }

      strupr(out);
      if(ACU_GG) ;
      else if(ACU_360) ;       // ACUTIME GG/360 already detected
      else if(ACUTIME) ;  // ACUTIME already detected
      else if(PALISADE) ; // PALISADE already detected
      else if(res_t) ;    // res_t already detected
      else if(saw_icm) ;  // icm already detected
      else { // attempt to identify TSIP receiver type
         if(strstr(out, "ACUTIME")) {
            tsip_type = ACUTIME_TYPE;
            acu_type = '1';
            if(strstr(out, "360")) {  // Acutime 360
               acu_type = '3';
            }
            else if(strstr(out, "GG")) {  // Acutime GG
               acu_type = 'G';
            }

            config_msg_ofs();
            config_rcvr_plots();
         }
         else if(strstr(out, "ICM")) { // !!!!!! ICM RES SMT
            saw_icm = 1;
            saw_gpsdo = 2;
            config_msg_ofs();
            config_rcvr_plots();
         }
         else if(strstr(out, "PALISADE")) {  // PALISADE does not actually output 0x1C-83 messages
            tsip_type = PALISADE_TYPE;
            config_msg_ofs();
            config_rcvr_plots();
         }
         else if(strstr(out, "RESOLUTION")) {
            if(user_set_res_t) ;
            else if(strstr(out, "SMT")) res_t = RES_T_SMT;
            else                        res_t = RES_T;
            config_msg_ofs();
            config_rcvr_plots();
         }
         else if(strstr(out, "RES SMT")) {
            if(!user_set_res_t) res_t = RES_T_RES;
            config_msg_ofs();
            config_rcvr_plots();
         }
         else if(strstr(out, "RES360")) {
            if(!user_set_res_t) res_t = RES_T_360;
            config_msg_ofs();
            config_rcvr_plots();
         }
      }

      if(mini_t == 0) {
         if(strstr(out, "MINI")) {
            mini_t = 1;
            saw_mini = 1;
            config_msg_ofs();
            config_rcvr_plots();
         }
      }

      strncpy(unit_name, out, UNIT_LEN);
      unit_name[UNIT_LEN-1] = 0;
   }
   else {  // unknown
      //!!! process packet contents
   }

   check_tsip_end(1);   
   if(tsip_error) return;

   saw_ebolt();
   tbolt_e |= 0x08;
   saw_version |= 0x02;

   if(1) {  //!!!!!
      if(rev_month > 12) return;
      if(rev_month == 0) return;
      if(rev_day > 31) return;
      if(rev_day == 0) return;
      if(rev_year < 1990) return;
      if(rev_year > 2100) return;
      if(rev_hour > 24) return;
   }

   if(text_mode && first_key) return;
   if(zoom_screen) return;
   if(luxor) return;
   if(just_read) return;

   if(0 && (subcode == 0x83)) {  // !!! disabled since hw_code clashes with sn_prefix
      show_ebolt_info();
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
leaq 0xe95ea(%rip), %rdi     # 0x184cc9
callq 0x7add0
movb $0x0, 0x32f8f5(%rip)    # 0x3cafe0
movb $0x0, 0x32f8eb(%rip)    # 0x3cafdd
movb $0x0, 0x32f8e3(%rip)    # 0x3cafdc
movw $0x0, 0x32f8dc(%rip)    # 0x3cafde
callq 0x7a510
movb %al, %cl
leaq 0x202a2e(%rip), %rax    # 0x29e13e
movb %cl, (%rax)
leaq 0x202a25(%rip), %rax    # 0x29e13e
movzbl (%rax), %eax
cmpl $0x81, %eax
jne 0x9b7e2
callq 0x7a510
movb %al, -0x1(%rbp)
callq 0x7a510
movb %al, -0x2(%rbp)
callq 0x7a510
movb %al, -0x3(%rbp)
callq 0x7a510
movb %al, -0x4(%rbp)
callq 0x7a510
movb %al, 0x32f88a(%rip)     # 0x3cafdc
callq 0x7a510
movb %al, 0x32f880(%rip)     # 0x3cafdd
callq 0x7a560
movw %ax, 0x32f875(%rip)     # 0x3cafde
callq 0x7a510
movb %al, -0x5(%rbp)
leaq 0x2ffc88(%rip), %rax    # 0x39b400
movb $0x0, (%rax)
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
movzbl -0x5(%rbp), %ecx
cmpl %ecx, %eax
jge 0x9b7d1
cmpl $0x200, -0xc(%rbp)      # imm = 0x200
jl 0x9b79d
callq 0x7a510
jmp 0x9b7c6
callq 0x7a510
movb %al, %dl
movslq -0xc(%rbp), %rcx
leaq 0x2ffc51(%rip), %rax    # 0x39b400
movb %dl, (%rax,%rcx)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rcx
leaq 0x2ffc3e(%rip), %rax    # 0x39b400
movb $0x0, (%rax,%rcx)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x9b782
leaq 0x2ffc28(%rip), %rdi    # 0x39b400
callq 0x9890
jmp 0x9bc2e
leaq 0x202955(%rip), %rax    # 0x29e13e
movzbl (%rax), %eax
cmpl $0x83, %eax
jne 0x9bc2a
callq 0x7a680
movl %eax, 0x32f7e2(%rip)    # 0x3cafe4
callq 0x7a510
movb %al, 0x32f7d0(%rip)     # 0x3cafdd
callq 0x7a510
movb %al, 0x32f7c4(%rip)     # 0x3cafdc
callq 0x7a560
movw %ax, 0x32f7ba(%rip)     # 0x3cafde
callq 0x7a510
movb %al, 0x32f7b1(%rip)     # 0x3cafe0
callq 0x7a560
movw %ax, %cx
leaq 0x2d1344(%rip), %rax    # 0x36cb82
movw %cx, (%rax)
callq 0x7a510
movb %al, -0x5(%rbp)
movl $0x0, -0xc(%rbp)
cmpl $0x12, -0xc(%rbp)
jge 0x9b870
movslq -0xc(%rbp), %rcx
leaq 0x2fffbf(%rip), %rax    # 0x39b820
movb $0x20, (%rax,%rcx)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x9b850
leaq 0x2fffa9(%rip), %rax    # 0x39b820
movb $0x0, 0x12(%rax)
leaq 0x2ffb7e(%rip), %rax    # 0x39b400
movb $0x0, (%rax)
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
movzbl -0x5(%rbp), %ecx
cmpl %ecx, %eax
jge 0x9b8ff
cmpl $0x200, -0xc(%rbp)      # imm = 0x200
jl 0x9b8a7
callq 0x7a510
jmp 0x9b8f4
callq 0x7a510
movb %al, %dl
movslq -0xc(%rbp), %rcx
leaq 0x2ffb47(%rip), %rax    # 0x39b400
movb %dl, (%rax,%rcx)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rcx
leaq 0x2ffb34(%rip), %rax    # 0x39b400
movb $0x0, (%rax,%rcx)
cmpl $0x12, -0xc(%rbp)
jge 0x9b8f2
movslq -0xc(%rbp), %rcx
leaq 0x2ffb1f(%rip), %rax    # 0x39b400
movb (%rax,%rcx), %dl
movslq -0xc(%rbp), %rcx
leaq 0x2fff31(%rip), %rax    # 0x39b820
movb %dl, (%rax,%rcx)
jmp 0x9b8f4
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x9b88c
leaq 0x2ffafa(%rip), %rdi    # 0x39b400
callq 0x9890
leaq 0x1dc19e(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0x9b935
leaq 0x1de895(%rip), %rax    # 0x27a1b4
cmpl $0x41, (%rax)
jne 0x9b935
leaq 0x1dc1ad(%rip), %rax    # 0x277ad8
cmpl $0x47, (%rax)
jne 0x9b935
jmp 0x9bbbd
leaq 0x1dc174(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0x9b96b
leaq 0x1de86b(%rip), %rax    # 0x27a1b4
cmpl $0x41, (%rax)
jne 0x9b96b
leaq 0x1dc183(%rip), %rax    # 0x277ad8
cmpl $0x33, (%rax)
je 0x9b966
leaq 0x1dc177(%rip), %rax    # 0x277ad8
cmpl $0x47, (%rax)
jne 0x9b96b
jmp 0x9bbbb
leaq 0x1dc13e(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0x9b989
leaq 0x1de835(%rip), %rax    # 0x27a1b4
cmpl $0x41, (%rax)
jne 0x9b989
jmp 0x9bbb9
leaq 0x1dc120(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0x9b9a7
leaq 0x1de817(%rip), %rax    # 0x27a1b4
cmpl $0x50, (%rax)
jne 0x9b9a7
jmp 0x9bbb7
leaq 0x1dc136(%rip), %rax    # 0x277ae4
cmpb $0x0, (%rax)
je 0x9b9b8
jmp 0x9bbb5
leaq 0x20274e(%rip), %rax    # 0x29e10d
cmpb $0x0, (%rax)
je 0x9b9c9
jmp 0x9bbb3
leaq 0x2ffa30(%rip), %rdi    # 0x39b400
leaq 0xe9310(%rip), %rsi     # 0x184ce7
callq 0x9090
cmpq $0x0, %rax
je 0x9ba5b
leaq 0x1de7cb(%rip), %rax    # 0x27a1b4
movl $0x41, (%rax)
leaq 0x1dc0e2(%rip), %rax    # 0x277ad8
movl $0x31, (%rax)
leaq 0x2ff9fd(%rip), %rdi    # 0x39b400
leaq 0xf5e69(%rip), %rsi     # 0x191873
callq 0x9090
cmpq $0x0, %rax
je 0x9ba24
leaq 0x1dc0bc(%rip), %rax    # 0x277ad8
movl $0x33, (%rax)
jmp 0x9ba4c
leaq 0x2ff9d5(%rip), %rdi    # 0x39b400
leaq 0xf5e1b(%rip), %rsi     # 0x19184d
callq 0x9090
cmpq $0x0, %rax
je 0x9ba4a
leaq 0x1dc094(%rip), %rax    # 0x277ad8
movl $0x47, (%rax)
jmp 0x9ba4c
callq 0x63c20
callq 0x64540
jmp 0x9bbb1
leaq 0x2ff99e(%rip), %rdi    # 0x39b400
leaq 0xe9286(%rip), %rsi     # 0x184cef
callq 0x9090
cmpq $0x0, %rax
je 0x9ba9a
leaq 0x202692(%rip), %rax    # 0x29e10d
movb $0x1, (%rax)
leaq 0x1de793(%rip), %rax    # 0x27a218
movl $0x2, (%rax)
callq 0x63c20
callq 0x64540
jmp 0x9bbaf
leaq 0x2ff95f(%rip), %rdi    # 0x39b400
leaq 0xe924b(%rip), %rsi     # 0x184cf3
callq 0x9090
cmpq $0x0, %rax
je 0x9bacf
leaq 0x1de6fa(%rip), %rax    # 0x27a1b4
movl $0x50, (%rax)
callq 0x63c20
callq 0x64540
jmp 0x9bbad
leaq 0x2ff92a(%rip), %rdi    # 0x39b400
leaq 0xe921f(%rip), %rsi     # 0x184cfc
callq 0x9090
cmpq $0x0, %rax
je 0x9bb33
leaq 0x20261d(%rip), %rax    # 0x29e10c
cmpb $0x0, (%rax)
je 0x9baf6
jmp 0x9bb27
leaq 0x2ff903(%rip), %rdi    # 0x39b400
leaq 0xe9207(%rip), %rsi     # 0x184d0b
callq 0x9090
cmpq $0x0, %rax
je 0x9bb1b
leaq 0x1dbfce(%rip), %rax    # 0x277ae4
movb $0x2, (%rax)
jmp 0x9bb25
leaq 0x1dbfc2(%rip), %rax    # 0x277ae4
movb $0x1, (%rax)
jmp 0x9bb27
callq 0x63c20
callq 0x64540
jmp 0x9bbab
leaq 0x2ff8c6(%rip), %rdi    # 0x39b400
leaq 0xe91c6(%rip), %rsi     # 0x184d07
callq 0x9090
cmpq $0x0, %rax
je 0x9bb6e
leaq 0x2025b9(%rip), %rax    # 0x29e10c
cmpb $0x0, (%rax)
jne 0x9bb62
leaq 0x1dbf85(%rip), %rax    # 0x277ae4
movb $0x3, (%rax)
callq 0x63c20
callq 0x64540
jmp 0x9bba9
leaq 0x2ff88b(%rip), %rdi    # 0x39b400
leaq 0xe9193(%rip), %rsi     # 0x184d0f
callq 0x9090
cmpq $0x0, %rax
je 0x9bba7
leaq 0x20257e(%rip), %rax    # 0x29e10c
cmpb $0x0, (%rax)
jne 0x9bb9d
leaq 0x1dbf4a(%rip), %rax    # 0x277ae4
movb $0x4, (%rax)
callq 0x63c20
callq 0x64540
jmp 0x9bba9
jmp 0x9bbab
jmp 0x9bbad
jmp 0x9bbaf
jmp 0x9bbb1
jmp 0x9bbb3
jmp 0x9bbb5
jmp 0x9bbb7
jmp 0x9bbb9
jmp 0x9bbbb
jmp 0x9bbbd
leaq 0x202554(%rip), %rax    # 0x29e118
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0x9bc05
leaq 0x2ff82d(%rip), %rdi    # 0x39b400
leaq 0xe913c(%rip), %rsi     # 0x184d16
callq 0x9090
cmpq $0x0, %rax
je 0x9bc03
leaq 0x20252c(%rip), %rax    # 0x29e118
movb $0x1, (%rax)
leaq 0x202527(%rip), %rax    # 0x29e11d
movb $0x1, (%rax)
callq 0x63c20
callq 0x64540
jmp 0x9bc05
leaq 0x2ffc14(%rip), %rdi    # 0x39b820
leaq 0x2ff7ed(%rip), %rsi    # 0x39b400
movl $0x12, %edx
callq 0x9170
leaq 0x2ffbfc(%rip), %rax    # 0x39b820
movb $0x0, 0x11(%rax)
jmp 0x9bc2c
jmp 0x9bc2c
jmp 0x9bc2e
movl $0x1, %edi
callq 0x7aee0
leaq 0x202511(%rip), %rax    # 0x29e150
cmpl $0x0, (%rax)
je 0x9bc49
jmp 0x9bd2b
callq 0x81d20
leaq 0x1dbe8b(%rip), %rax    # 0x277ae0
movl (%rax), %ecx
orl $0x8, %ecx
leaq 0x1dbe7f(%rip), %rax    # 0x277ae0
movl %ecx, (%rax)
leaq 0x2d097e(%rip), %rax    # 0x36c5e8
movl (%rax), %ecx
orl $0x2, %ecx
leaq 0x2d0972(%rip), %rax    # 0x36c5e8
movl %ecx, (%rax)
movzbl 0x32f35d(%rip), %eax    # 0x3cafdc
cmpl $0xc, %eax
jle 0x9bc89
jmp 0x9bd2b
movzbl 0x32f34c(%rip), %eax    # 0x3cafdc
cmpl $0x0, %eax
jne 0x9bc9a
jmp 0x9bd2b
movzbl 0x32f33c(%rip), %eax    # 0x3cafdd
cmpl $0x1f, %eax
jle 0x9bcab
jmp 0x9bd2b
movzbl 0x32f32b(%rip), %eax    # 0x3cafdd
cmpl $0x0, %eax
jne 0x9bcb9
jmp 0x9bd2b
movzwl 0x32f31e(%rip), %eax    # 0x3cafde
cmpl $0x7c6, %eax            # imm = 0x7C6
jge 0x9bcc9
jmp 0x9bd2b
movzwl 0x32f30e(%rip), %eax    # 0x3cafde
cmpl $0x834, %eax            # imm = 0x834
jle 0x9bcd9
jmp 0x9bd2b
movzbl 0x32f300(%rip), %eax    # 0x3cafe0
cmpl $0x18, %eax
jle 0x9bce7
jmp 0x9bd2b
leaq 0x1dbcca(%rip), %rax    # 0x2779b8
cmpl $0x0, (%rax)
je 0x9bd01
leaq 0x20243e(%rip), %rax    # 0x29e138
cmpl $0x0, (%rax)
je 0x9bd01
jmp 0x9bd2b
leaq 0x2cfc80(%rip), %rax    # 0x36b988
cmpb $0x0, (%rax)
je 0x9bd0f
jmp 0x9bd2b
leaq 0x202408(%rip), %rax    # 0x29e11e
cmpb $0x0, (%rax)
je 0x9bd1d
jmp 0x9bd2b
leaq 0x2fa4d4(%rip), %rax    # 0x3961f8
cmpb $0x0, (%rax)
je 0x9bd2b
jmp 0x9bd2b
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)