// File: jkingan[P]ladyheather/heather.cpp
// Function: echo_term(unsigned int, int, int, int)
void echo_term(unsigned port, int i, int hex, int highlight)
{
char s[UNIT_LEN+1];
int color;

   // put a character into the terminal image buffer.  Handle CR and LF chars
   if(port >= NUM_COM_PORTS) return;

   if(pause_monitor) return;

   color = 0x00;
   if((zoom_screen == 'O') || (zoom_screen == 'H')) {
      if(highlight) color = 0x80;
if(hex == 0) i &= 0x7F;
   }

   if(hex) {  // hex terminal display
      sprintf(s, "%02X", i);

      if(zoom_screen == 'O') ;
      else if(zoom_screen == 'H') ;
      else if(i == pkt_end1)   color = 0x80;  // highlight possible packet boundaries
      else if(i == pkt_end2)   color = 0x80;
      else if(i == pkt_start1) color = 0x80;
      else if(i == pkt_start2) color = 0x80;

      term_screen[term_row][term_col+0] = s[0] | color;
      term_screen[term_row][term_col+1] = s[1] | color;
      term_screen[term_row][term_col+2] = ' ';
      term_screen[term_row][term_col+3] = 0;
      term_col += 3;
      term_changed = 1;

      if(SCREEN_WIDTH < (36*3*TEXT_WIDTH)) {  // small screen - 16 vals per line
         if(term_col > (16*3)) {
            term_col = 0;
            scroll_up(port);
         }
      }
      else { // wide screen
         if(term_col == (16*3)) { // two groups of 16 vals per line
            term_screen[term_row][term_col++] = ' ';
            term_screen[term_row][term_col] = 0;
         }

         if(term_col > (16*6+1)) {
            term_col = 0;
            scroll_up(port);
         }
      }
   }
   else if((i & 0x7F) == 0x0D) {  // carriage return
      term_col = 0;
      if(term_crlf) scroll_up(port);
else if(rcvr_type == UCCM_RCVR) scroll_up(port);  // piss
else if(CRLF_RCVR) scroll_up(port);
else if(port == THERMO_PORT) scroll_up(port);
   }
   else if((i & 0x7F) == 0x0A) {  // line feed
      if(term_crlf) term_col = 0;
//else if(rcvr_type == UCCM_RCVR) term_col = 0;  // piss
else if(CRLF_RCVR) term_col = 0;
else if(port == THERMO_PORT) term_col = 0;
else if(port == TRACK_PORT) term_col = 0;
else if(zoom_screen == 'H') term_col = 0;
      scroll_up(port);
   }
   else if(((i & 0x7F) >= ' ') && ((i & 0x7F) < 0x7F)) { // add char to terminal image buffser
      term_screen[term_row][term_col+0] = ((i & 0xFF) | color);
      term_screen[term_row][term_col+1] = 0;
      term_changed = 1;

      if(++term_col >= term_cols) {
         term_col = 0;
         scroll_up(port);
      }
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movl %edx, -0xc(%rbp)
movl %ecx, -0x10(%rbp)
cmpl $0x13, -0x4(%rbp)
jb 0xb1ef
jmp 0xb603
cmpl $0x0, 0x292426(%rip)    # 0x29d61c
je 0xb1fd
jmp 0xb603
movl $0x0, -0x34(%rbp)
movzbl 0x36077d(%rip), %eax    # 0x36b988
cmpl $0x4f, %eax
je 0xb21c
movzbl 0x360771(%rip), %eax    # 0x36b988
cmpl $0x48, %eax
jne 0xb23a
cmpl $0x0, -0x10(%rbp)
je 0xb229
movl $0x80, -0x34(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0xb238
movl -0x8(%rbp), %eax
andl $0x7f, %eax
movl %eax, -0x8(%rbp)
jmp 0xb23a
cmpl $0x0, -0xc(%rbp)
je 0xb442
leaq -0x30(%rbp), %rdi
movl -0x8(%rbp), %edx
leaq 0x182c34(%rip), %rsi    # 0x18de86
movb $0x0, %al
callq 0x9060
movzbl 0x360728(%rip), %eax    # 0x36b988
cmpl $0x4f, %eax
jne 0xb267
jmp 0xb2cd
movzbl 0x36071a(%rip), %eax    # 0x36b988
cmpl $0x48, %eax
jne 0xb275
jmp 0xb2cb
movl -0x8(%rbp), %eax
cmpl 0x26ef9e(%rip), %eax    # 0x27a21c
jne 0xb289
movl $0x80, -0x34(%rbp)
jmp 0xb2c9
movl -0x8(%rbp), %eax
cmpl 0x26ef8e(%rip), %eax    # 0x27a220
jne 0xb29d
movl $0x80, -0x34(%rbp)
jmp 0xb2c7
movl -0x8(%rbp), %eax
cmpl 0x26ef7e(%rip), %eax    # 0x27a224
jne 0xb2b1
movl $0x80, -0x34(%rbp)
jmp 0xb2c5
movl -0x8(%rbp), %eax
cmpl 0x26ef6e(%rip), %eax    # 0x27a228
jne 0xb2c3
movl $0x80, -0x34(%rbp)
jmp 0xb2c5
jmp 0xb2c7
jmp 0xb2c9
jmp 0xb2cb
jmp 0xb2cd
movsbl -0x30(%rbp), %eax
orl -0x34(%rbp), %eax
movb %al, %dl
movslq 0x292333(%rip), %rcx    # 0x29d610
leaq 0x39452c(%rip), %rax    # 0x39f810
imulq $0x85, %rcx, %rcx
addq %rcx, %rax
movl 0x292320(%rip), %ecx    # 0x29d614
addl $0x0, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movsbl -0x2f(%rbp), %eax
orl -0x34(%rbp), %eax
movb %al, %dl
movslq 0x292303(%rip), %rcx    # 0x29d610
leaq 0x3944fc(%rip), %rax    # 0x39f810
imulq $0x85, %rcx, %rcx
addq %rcx, %rax
movl 0x2922f0(%rip), %ecx    # 0x29d614
addl $0x1, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movslq 0x2922dc(%rip), %rcx    # 0x29d610
leaq 0x3944d5(%rip), %rax    # 0x39f810
imulq $0x85, %rcx, %rcx
addq %rcx, %rax
movl 0x2922c9(%rip), %ecx    # 0x29d614
addl $0x2, %ecx
movslq %ecx, %rcx
movb $0x20, (%rax,%rcx)
movslq 0x2922b4(%rip), %rcx    # 0x29d610
leaq 0x3944ad(%rip), %rax    # 0x39f810
imulq $0x85, %rcx, %rcx
addq %rcx, %rax
movl 0x2922a1(%rip), %ecx    # 0x29d614
addl $0x3, %ecx
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
movl 0x292291(%rip), %eax    # 0x29d614
addl $0x3, %eax
movl %eax, 0x292288(%rip)    # 0x29d614
movl $0x1, 0x3965c2(%rip)    # 0x3a1958
movl 0x26c644(%rip), %eax    # 0x2779e0
imull $0x6c, 0x26c64d(%rip), %ecx # 0x2779f0
cmpl %ecx, %eax
jge 0xb3c4
cmpl $0x30, 0x292266(%rip)   # 0x29d614
jle 0xb3c2
movl $0x0, 0x29225a(%rip)    # 0x29d614
movl -0x4(%rbp), %edi
callq 0x2c2e0
jmp 0xb43d
cmpl $0x30, 0x292249(%rip)   # 0x29d614
jne 0xb420
movslq 0x29223c(%rip), %rcx    # 0x29d610
leaq 0x394435(%rip), %rax    # 0x39f810
imulq $0x85, %rcx, %rcx
addq %rcx, %rax
movl 0x292229(%rip), %ecx    # 0x29d614
movl %ecx, %edx
addl $0x1, %edx
movl %edx, 0x29221e(%rip)    # 0x29d614
movslq %ecx, %rcx
movb $0x20, (%rax,%rcx)
movslq 0x29220c(%rip), %rcx    # 0x29d610
leaq 0x394405(%rip), %rax    # 0x39f810
imulq $0x85, %rcx, %rcx
addq %rcx, %rax
movslq 0x2921f8(%rip), %rcx    # 0x29d614
movb $0x0, (%rax,%rcx)
cmpl $0x61, 0x2921ed(%rip)   # 0x29d614
jle 0xb43b
movl $0x0, 0x2921e1(%rip)    # 0x29d614
movl -0x4(%rbp), %edi
callq 0x2c2e0
jmp 0xb43d
jmp 0xb603
movl -0x8(%rbp), %eax
andl $0x7f, %eax
cmpl $0xd, %eax
jne 0xb4b8
movl $0x0, 0x2921bd(%rip)    # 0x29d614
cmpl $0x0, 0x39650a(%rip)    # 0x3a1968
je 0xb46a
movl -0x4(%rbp), %edi
callq 0x2c2e0
jmp 0xb4b3
cmpq $0x8, 0x26c63e(%rip)    # 0x277ab0
jne 0xb47e
movl -0x4(%rbp), %edi
callq 0x2c2e0
jmp 0xb4b1
movabsq $0x151b0f1010, %rax     # imm = 0x151B0F1010
andq 0x26c621(%rip), %rax    # 0x277ab0
cmpq $0x0, %rax
je 0xb49f
movl -0x4(%rbp), %edi
callq 0x2c2e0
jmp 0xb4af
cmpl $0xf, -0x4(%rbp)
jne 0xb4ad
movl -0x4(%rbp), %edi
callq 0x2c2e0
jmp 0xb4af
jmp 0xb4b1
jmp 0xb4b3
jmp 0xb601
movl -0x8(%rbp), %eax
andl $0x7f, %eax
cmpl $0xa, %eax
jne 0xb54e
cmpl $0x0, 0x39649a(%rip)    # 0x3a1968
je 0xb4dc
movl $0x0, 0x29213a(%rip)    # 0x29d614
jmp 0xb541
movabsq $0x151b0f1010, %rax     # imm = 0x151B0F1010
andq 0x26c5c3(%rip), %rax    # 0x277ab0
cmpq $0x0, %rax
je 0xb4ff
movl $0x0, 0x292117(%rip)    # 0x29d614
jmp 0xb53f
cmpl $0xf, -0x4(%rbp)
jne 0xb511
movl $0x0, 0x292105(%rip)    # 0x29d614
jmp 0xb53d
cmpl $0x12, -0x4(%rbp)
jne 0xb523
movl $0x0, 0x2920f3(%rip)    # 0x29d614
jmp 0xb53b
movzbl 0x36045e(%rip), %eax    # 0x36b988
cmpl $0x48, %eax
jne 0xb539
movl $0x0, 0x2920db(%rip)    # 0x29d614
jmp 0xb53b
jmp 0xb53d
jmp 0xb53f
jmp 0xb541
movl -0x4(%rbp), %edi
callq 0x2c2e0
jmp 0xb5ff
movl -0x8(%rbp), %eax
andl $0x7f, %eax
cmpl $0x20, %eax
jl 0xb5fd
movl -0x8(%rbp), %eax
andl $0x7f, %eax
cmpl $0x7f, %eax
jge 0xb5fd
movl -0x8(%rbp), %eax
andl $0xff, %eax
orl -0x34(%rbp), %eax
movb %al, %dl
movslq 0x292090(%rip), %rcx    # 0x29d610
leaq 0x394289(%rip), %rax    # 0x39f810
imulq $0x85, %rcx, %rcx
addq %rcx, %rax
movl 0x29207d(%rip), %ecx    # 0x29d614
addl $0x0, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movslq 0x292069(%rip), %rcx    # 0x29d610
leaq 0x394262(%rip), %rax    # 0x39f810
imulq $0x85, %rcx, %rcx
addq %rcx, %rax
movl 0x292056(%rip), %ecx    # 0x29d614
addl $0x1, %ecx
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
movl $0x1, 0x396386(%rip)    # 0x3a1958
movl 0x29203c(%rip), %eax    # 0x29d614
addl $0x1, %eax
movl %eax, 0x292033(%rip)    # 0x29d614
cmpl 0x39636d(%rip), %eax    # 0x3a1954
jl 0xb5fb
movl $0x0, 0x292021(%rip)    # 0x29d614
movl -0x4(%rbp), %edi
callq 0x2c2e0
jmp 0xb5fd
jmp 0xb5ff
jmp 0xb601
jmp 0xb603
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)