// File: /workspace/github_cpp_makefile_star2_O2/jkingan[P]ladyheather/heather.cpp
// Function: vidstr(int, int, unsigned char, char*)
void vidstr(COORD row, COORD col, u08 attr, char *s)
{
char *p;
S32 px, py;
char work_str[MAX_TEXT_COLS+1];
char *chp;
char ch;
S32 word_x[UNIT_LEN+1];
S32 n_words;
S32 ux;
char last_uch;
char last_ch;
char uch;
S32 w;
S32 x;

   // this routine recognizes some global variables:
   //   blank_underscore: if set, converts underscore char to blanks
   //   graphics_coords:  if set, row and col are in pixels coordinates
   //                     if clear, they are in character coordinates
   //   no_x_margin:      if set, do not apply the "x" character margin offset
   //   no_y_margin:      if set, do not apply the "y" character margin offset
   //   print_using:      if not null, points to column alignment string
   //                     (note: Heather does not use this functionality, it can be deleted)

   if(graphics_coords) {  // row/col in pixels
      px = col;
      py = row;
   }
   else { // row/col in text positions
      px = col * TEXT_WIDTH;
      py = row * TEXT_HEIGHT;

      if((zoom_screen && (zoom_screen != 'P') && (zoom_screen != 'K')) || (py < (((PLOT_ROW/TEXT_HEIGHT)*TEXT_HEIGHT) - (TEXT_HEIGHT*2)))) {
         if(no_x_margin == 0) px += TEXT_X_MARGIN;   // looks better with margins
         if(no_y_margin == 0) py += TEXT_Y_MARGIN;
      }
   }


   if(print_using == NULL) {  // we are using a monospace font and not aligning columns
      strcpy(work_str, s);

      chp = work_str;
      while(*chp) {
         if(blank_underscore) {
            if(*chp == '_') *chp = ' ';
         }

         if(use_vc_fonts) {
            px += dot_char(px,py, *chp, attr);
         }
         else if(*chp == DEGREES) {
            px += deg_char(py,px, attr);
         }
         else if(*chp == PLUS_MINUS) {
            px += plusminus_char(py,px, attr);
         }
         else {  // dot-by-dot character rendering
            px += dot_char(px,py, *chp, attr);
         }
         ++chp;
      }

      return;
   }

   //
   // At each space->nonspace transition in *s, position cursor at equivalent
   // space->nonspace transition in *print_using
   //
   // This allows table-cell alignment with VFX's proportional font
   //
   // New kludge: the first column is right justified one space before the
   //             second column.
   //

   n_words = 0;
   ux = px;
   last_uch = '\0';

   while(*print_using) {
      uch = *print_using++;

      if(((uch != ' ') && (last_uch == ' ')) || (last_uch == '\0')) {
         word_x[n_words++] = ux;
         if(n_words >= UNIT_LEN) break;
      }

      last_uch = uch;
      if(blank_underscore) {
         if(uch == '_') uch = ' ';  // _ prints as a blank,  but does not cause a space transition
      }

      if(uch == DEGREES) ux += DEG_WIDTH;  //!!! kludge:  hardcoded char width
      else if(uch == PLUS_MINUS) ux += 8;  //!!! kludge:  hardcoded char width
      else ux += 8; // !!!!!! VFX_character_width(vfx_font, uch);
   }

   w = 0;
   x = px;
   last_ch = '\0';

   while(*s) {
      ch = *s++;

      if((ch != ' ') && (last_ch == ' ') && (w < n_words)) {
         x = word_x[w++];
         if(w == 1) {  // right justify the first column
            x = word_x[w];   // x = where the second column starts
            x -= 8; // !!!! VFX_character_width(vfx_font, ' ');  // back up a space
            p = s-1;
            while((*p != ' ') && (*p != '\0')) {  // back up the width of the text
               x -= 8; // !!!!VFX_character_width(vfx_font, *p);
               ++p;
            }
         }
      }

      last_ch = ch;
      if(blank_underscore) {
         if(ch == '_') ch = ' ';
      }

      if(use_vc_fonts) {
         x += dot_char(x,py, ch, attr);
      }
      else if(ch == DEGREES) {
         x += deg_char(py,x, attr);
      }
      else if(ch == PLUS_MINUS) {
         x += plusminus_char(py,x, attr);
      }
      else if(1) { // !!!!! testing dot-by-dot character rendering
         x += dot_char(x,py, ch, attr);
      }
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x218, %rsp            # imm = 0x218
movl %edx, %ebx
movl %esi, %r14d
movl %edi, %esi
cmpb $0x0, 0x1f4574(%rip)    # 0x202868
jne 0xe35e
movl 0x1f4513(%rip), %r8d    # 0x202810
movl %r8d, %r9d
imull %r14d, %r9d
movl 0x1f450a(%rip), %edi    # 0x202814
imull %edi, %esi
movzbl 0x2e8494(%rip), %eax    # 0x2f67a8
testl %eax, %eax
je 0xe322
cmpl $0x50, %eax
je 0xe322
cmpl $0x4b, %eax
jne 0xe33a
movl 0x1f4553(%rip), %r10d   # 0x20287c
movl %r10d, %eax
cltd
idivl %edi
leal (%rdx,%rdi,2), %eax
subl %eax, %r10d
cmpl %r10d, %esi
jge 0xe35b
addl $0x2, %r14d
imull %r14d, %r8d
cmpb $0x0, 0x1f4511(%rip)    # 0x20285a
cmovel %r8d, %r9d
xorl %eax, %eax
cmpb $0x0, 0x1f4505(%rip)    # 0x20285b
cmovel %edi, %eax
addl %eax, %esi
movl %r9d, %r14d
movq 0x1f44fb(%rip), %rdi    # 0x202860
testq %rdi, %rdi
movl %esi, -0x34(%rbp)
je 0xe4eb
movl $0x0, -0x30(%rbp)
movb 0x1f70ab(%rip), %al     # 0x205429
movl %r14d, %r11d
xorl %r8d, %r8d
cmpb $0x0, (%rdi)
je 0xe3fb
leaq 0x1(%rdi), %r10
movq %r10, 0x1f44cc(%rip)    # 0x202860
movb (%rdi), %dl
cmpb $0x20, %dl
setne %dil
cmpb $0x20, %r8b
sete %r9b
testb %r8b, %r8b
je 0xe3af
andb %dil, %r9b
je 0xe3ca
movl -0x30(%rbp), %r8d
movslq %r8d, %rdi
incl %r8d
movl %r8d, -0x30(%rbp)
movl %r11d, -0x240(%rbp,%rdi,4)
cmpl $0x10, %edi
jg 0xe3fb
cmpb $0x5f, %dl
movzbl %dl, %edi
movl %edi, %r8d
pushq $0x20
popq %r9
cmovel %r9d, %r8d
testb %al, %al
cmovel %edi, %r8d
xorl %edi, %edi
cmpb $0x1, %r8b
setne %dil
leal (%r11,%rdi,2), %r11d
addl $0x6, %r11d
movq %r10, %rdi
movl %edx, %r8d
jmp 0xe384
movl -0x23c(%rbp), %eax
leaq 0x1(%rcx), %r13
addl $-0x8, %eax
movl %eax, -0x38(%rbp)
xorl %r12d, %r12d
movzbl %bl, %eax
movl %eax, -0x2c(%rbp)
xorl %r15d, %r15d
movl %r12d, %eax
movb (%rcx), %r12b
testb %r12b, %r12b
je 0xe572
cmpb $0x20, %r12b
setne %dil
cmpb $0x20, %al
sete %al
cmpl -0x30(%rbp), %r15d
setl %dl
andb %al, %dl
andb %dil, %dl
cmpb $0x1, %dl
jne 0xe477
testl %r15d, %r15d
je 0xe459
movslq %r15d, %rax
incl %r15d
movl -0x240(%rbp,%rax,4), %r14d
jmp 0xe477
movl -0x38(%rbp), %r14d
movq %r13, %rax
movl %r12d, %edx
testb $-0x21, %dl
je 0xe473
movb (%rax), %dl
incq %rax
addl $-0x8, %r14d
jmp 0xe463
pushq $0x1
popq %r15
cmpb $0x5f, %r12b
movzbl %r12b, %edx
movl %edx, %eax
pushq $0x20
popq %rdi
cmovel %edi, %eax
cmpb $0x0, 0x1f6f9b(%rip)    # 0x205429
cmovel %edx, %eax
cmpl $0x0, 0x1ff0a8(%rip)    # 0x20d540
movzbl %al, %edx
movq %rcx, %rbx
je 0xe4ad
movl %r14d, %edi
movl -0x2c(%rbp), %ecx
callq 0xdb30
jmp 0xe4d7
cmpb $0x1f, %al
je 0xe4c7
cmpl $0x1, %edx
jne 0xe4a0
movl %esi, %edi
movl %r14d, %esi
movl -0x2c(%rbp), %edx
callq 0xe210
pushq $0x6
jmp 0xe4d6
movl %esi, %edi
movl %r14d, %esi
movl -0x2c(%rbp), %edx
callq 0xdf71
pushq $0x8
popq %rax
movq %rbx, %rcx
incq %rcx
addl %eax, %r14d
incq %r13
movl -0x34(%rbp), %esi
jmp 0xe417
leaq -0x240(%rbp), %r13
movq %r13, %rdi
movq %rcx, %rsi
callq 0x9330
movzbl %bl, %r15d
pushq $0x8
popq %rbx
pushq $0x6
popq %r12
movb (%r13), %al
testb %al, %al
movl -0x34(%rbp), %esi
je 0xe572
cmpb $0x5f, %al
jne 0xe527
cmpb $0x0, 0x1f6f0b(%rip)    # 0x205429
je 0xe527
movb $0x20, (%r13)
movb $0x20, %al
cmpl $0x0, 0x1ff012(%rip)    # 0x20d540
movzbl %al, %edx
je 0xe546
movl %r14d, %edi
movl %r15d, %ecx
callq 0xdb30
addl %eax, %r14d
incq %r13
jmp 0xe508
cmpb $0x1f, %al
je 0xe561
cmpl $0x1, %edx
jne 0xe533
movl %esi, %edi
movl %r14d, %esi
movl %r15d, %edx
callq 0xe210
movl %r12d, %eax
jmp 0xe53e
movl %esi, %edi
movl %r14d, %esi
movl %r15d, %edx
callq 0xdf71
movl %ebx, %eax
jmp 0xe53e
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq