// File: jkingan[P]ladyheather/heather.cpp
// Function: sendout(unsigned int, unsigned char, int)
void sendout(unsigned port, unsigned char val, int eom_flag)
{
unsigned long written;
int flag;
static long x = 0;

   // Ssend data to the receiver.
   // We queue up data until end of message to reduce per-packet overhead.
   // If eom_flag == FLUSH_COM then send buffered chars without adding a new one
   // If eom_flag == 0, add char to buffer (sends buffer if full)
   // If eom_flag != 0, add char to buffer and send buffer

   if((port == RCVR_PORT) && (rcvr_type == NO_RCVR) && (enable_terminal == 0)) { // alternate ready/not ready each check
      return;
   }
if((port == RCVR_PORT) && (rcvr_type == TIDE_RCVR) && (enable_terminal == 0)) {
      return;
}

   if(com[port].com_fd < 0) return;

   if(com[port].process_com == 0) return;
   if(com[port].com_error & XMIT_ERR) return;
   if(just_read && (port == RCVR_PORT)) return;
   if(no_send && (port == RCVR_PORT)) return;
   if(sim_file) return;  // don't send anything out if reading a simulation file

   if(FAKE_ACRON_RCVR && (rcvr_type == ACRON_RCVR) && (port == RCVR_PORT)) {  // simulate echo by sticking char in rcv buffer
      com[port].rcv_buffer[com[port].next_rcv_byte] = val;
      ++com[port].rcv_byte_count;
      return;
   }

   if((zoom_screen == 'O') && (port == monitor_port)) {  // echo data to "terminal" monitor screen
      echo_term(port, (unsigned) val, monitor_hex, 1);
   }

   // we buffer up output chars until buffer full or end of message flag seen
   if(eom_flag == FLUSH_COM) {  // just send buffered chars
      if(x == 0) return;   // nothing to flush
   }
   else com[port].xmit_buffer[x++] = val;  // add char to send buffer

   if((x < (long) XMIT_BUF_SIZE) && (eom_flag == ADD_CHAR)) return;

   update_pwm();   // if doing pwm temperature control

   if(1 || (com[port].com_port != 0) || (com[port].usb_port != 0)) {   // zork COM port in use: send bytes via serial port
      flag = write(com[port].com_fd, com[port].xmit_buffer, x);
if((eom_flag == EOM) || (eom_flag == FLUSH_COM)) {
   fsync(com[port].com_fd);
}
      if(flag == x) written = 1;
      else          written = 0;
   }

   x = 0;

   if((flag == 0) || (written != 1)) {
      if(com_error_exit) {
         error_exit(3, "Serial transmit error");
      }
      else {
         com[port].com_error |= XMIT_ERR;
         ++com_errors;
      }
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movb %sil, %al
movl %edi, -0x4(%rbp)
movb %al, -0x5(%rbp)
movl %edx, -0xc(%rbp)
cmpl $0xa, -0x4(%rbp)
jne 0xd195
cmpq $0x400, 0x26a92b(%rip) # imm = 0x400
jne 0xd195
cmpl $0x0, 0x290f82(%rip)    # 0x29e110
jne 0xd195
jmp 0xd3ea
cmpl $0xa, -0x4(%rbp)
jne 0xd1b6
cmpq $0x800000, 0x26a90a(%rip) # imm = 0x800000
jne 0xd1b6
cmpl $0x0, 0x290f61(%rip)    # 0x29e110
jne 0xd1b6
jmp 0xd3ea
movl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x3602fe(%rip), %rax    # 0x36d4c0
imulq $0x2260, %rcx, %rcx     # imm = 0x2260
addq %rcx, %rax
cmpl $0x0, 0x8(%rax)
jge 0xd1d7
jmp 0xd3ea
movl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x3602dd(%rip), %rax    # 0x36d4c0
imulq $0x2260, %rcx, %rcx     # imm = 0x2260
addq %rcx, %rax
cmpl $0x0, 0x2234(%rax)
jne 0xd1fb
jmp 0xd3ea
movl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x3602b9(%rip), %rax    # 0x36d4c0
imulq $0x2260, %rcx, %rcx     # imm = 0x2260
addq %rcx, %rax
movzbl 0x2251(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0xd225
jmp 0xd3ea
cmpb $0x0, 0x388fcc(%rip)    # 0x3961f8
je 0xd239
cmpl $0xa, -0x4(%rbp)
jne 0xd239
jmp 0xd3ea
cmpb $0x0, 0x388fb9(%rip)    # 0x3961f9
je 0xd24d
cmpl $0xa, -0x4(%rbp)
jne 0xd24d
jmp 0xd3ea
cmpq $0x0, 0x29034b(%rip)    # 0x29d5a0
je 0xd25c
jmp 0xd3ea
movzbl 0x35e725(%rip), %eax    # 0x36b988
cmpl $0x4f, %eax
jne 0xd28a
movl -0x4(%rbp), %eax
cmpl 0x36023f(%rip), %eax    # 0x36d4b0
jne 0xd28a
movl -0x4(%rbp), %edi
movzbl -0x5(%rbp), %esi
movl 0x2903a4(%rip), %edx    # 0x29d624
movl $0x1, %ecx
callq 0xb1d0
cmpl $0x2, -0xc(%rbp)
jne 0xd2a1
cmpq $0x0, 0x391e90(%rip)    # 0x39f128
jne 0xd29f
jmp 0xd3ea
jmp 0xd2d6
movb -0x5(%rbp), %dl
movl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x360210(%rip), %rax    # 0x36d4c0
imulq $0x2260, %rcx, %rcx     # imm = 0x2260
addq %rcx, %rax
movq 0x391e67(%rip), %rcx    # 0x39f128
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x391e59(%rip)    # 0x39f128
movb %dl, 0x220(%rax,%rcx)
cmpq $0x1000, 0x391e47(%rip) # imm = 0x1000
jge 0xd2ee
cmpl $0x0, -0xc(%rbp)
jne 0xd2ee
jmp 0xd3ea
callq 0x11ee60
movl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x3601c1(%rip), %rax    # 0x36d4c0
imulq $0x2260, %rcx, %rcx     # imm = 0x2260
addq %rcx, %rax
movl 0x8(%rax), %edi
movl -0x4(%rbp), %eax
leaq 0x3601aa(%rip), %rsi    # 0x36d4c0
imulq $0x2260, %rax, %rax     # imm = 0x2260
addq %rax, %rsi
addq $0x220, %rsi            # imm = 0x220
movq 0x391dfa(%rip), %rdx    # 0x39f128
callq 0x90f0
movl %eax, -0x1c(%rbp)
cmpl $0x1, -0xc(%rbp)
je 0xd342
cmpl $0x2, -0xc(%rbp)
jne 0xd360
movl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x360172(%rip), %rax    # 0x36d4c0
imulq $0x2260, %rcx, %rcx     # imm = 0x2260
addq %rcx, %rax
movl 0x8(%rax), %edi
callq 0x9310
movslq -0x1c(%rbp), %rax
cmpq 0x391dbd(%rip), %rax    # 0x39f128
jne 0xd377
movq $0x1, -0x18(%rbp)
jmp 0xd37f
movq $0x0, -0x18(%rbp)
movq $0x0, 0x391d9e(%rip) # 0x39f128
cmpl $0x0, -0x1c(%rbp)
je 0xd397
cmpq $0x1, -0x18(%rbp)
je 0xd3ea
cmpb $0x0, 0x26d075(%rip)    # 0x27a413
je 0xd3b3
movl $0x3, %edi
leaq 0x162589(%rip), %rsi    # 0x16f935
callq 0xc050
jmp 0xd3e8
movl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x360101(%rip), %rax    # 0x36d4c0
imulq $0x2260, %rcx, %rcx     # imm = 0x2260
addq %rcx, %rax
movzbl 0x2251(%rax), %ecx
orl $0x2, %ecx
movb %cl, 0x2251(%rax)
movl 0x388e15(%rip), %eax    # 0x3961f4
addl $0x1, %eax
movl %eax, 0x388e0c(%rip)    # 0x3961f4
jmp 0xd3ea
addq $0x20, %rsp
popq %rbp
retq