// File: /workspace/github_cpp_makefile_star2_O2/jkingan[P]ladyheather/heather.cpp
// Function: dot_char(int, int, unsigned char, unsigned char)
int dot_char(COORD x, COORD y, u08 c, u08 attr)
{
int h,w;
int p;
int xx,yy;
int xl;

   // draw a VFX font character using the line drawing routine
   // (useful if porting Heather to a differnt operating system)
   if(x > SCREEN_WIDTH) x = SCREEN_WIDTH;
   if(y > SCREEN_HEIGHT) y = SCREEN_HEIGHT;

   if(dot_font == 0) dot_font = &h_font_12[0];
   if(use_vc_fonts) {
      p = (4*4) + (0x20*4);    // index of offset to char definition of a valid char
      if(c == DEG_CODE) c = 0xF8;
      else if(c == PLUS_MINUS) c = 0xF1;
   }
   else if(c & 0x80) {
      c = ' '; // char out of range
      p = (4*4) + (c*4);    // index of offset to char definition
   }
   else p = (4*4) + (c*4);    // index of offset to char definition

   h = dot_font[8];      // char height

   p = (dot_font[p+1] * 256) + dot_font[p+0];  // pointer to char definition
   w = dot_font[p];      // char width
   p += 4;               // pointer to char pattern

   if(use_vc_fonts) {  // draw all text using vector characters
      int old_scale;
      old_scale = VCHAR_SCALE;
      VCHAR_SCALE = 1;
      TEXT_WIDTH = (w*vc_font_scale) / 100;
      TEXT_HEIGHT = (h*vc_font_scale) / 100;
      vchar(x,y, 1, attr, c);  // draw a vector character
      if(0 && VCharThickness) w = (TEXT_WIDTH+VCharThickness-1);
      else w = (TEXT_WIDTH+VCharThickness*0);
      VCHAR_SCALE = old_scale;
      return w;
   }

   erase_rectangle(x,y, TEXT_WIDTH,TEXT_HEIGHT);

   for(yy=0; yy<h; yy+=1) {    // for each row in a character
      xl = (-1);               // left-most pixel of a run of dots
      for(xx=0; xx<w; xx+=1) { // for each pixel in a character row
         if(dot_font[p]) {       // character has a visible dot
            if(xl < 0) xl = xx;  // it's the first dot of a run

            if(xx >= (w-1)) {    // this is the last dot in the character row
               if(xl >= 0) {     // we have a run of dots pending, draw it
                  line(x+xl,y+yy, x+xx,y+yy, attr);
               }
            }
         }
         else { // it's a background color dot
            if(xl >= 0) {  // this pixel ends a pending run of visible dots
               line(x+xl,y+yy, x+(xx-1),y+yy, attr);
               xl = (-1);
            }
         }

         ++p;  // next pixel in the char
      }
   }

   return w;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %ecx, %r9d
movl %edx, %r8d
movslq 0x1f4cb2(%rip), %rbx    # 0x202800
cmpl %edi, %ebx
movl %edi, %eax
cmovll %ebx, %eax
movq %rax, -0x38(%rbp)
movl 0x1f4ca5(%rip), %eax    # 0x202804
cmpl %esi, %eax
cmovll %eax, %esi
movq %rsi, -0x40(%rbp)
movq 0x31c379(%rip), %rax    # 0x329ee8
testq %rax, %rax
jne 0xdb82
leaq 0x12ec65(%rip), %rax    # 0x13c7e0
movq %rax, 0x31c366(%rip)    # 0x329ee8
movl 0x1ff9b8(%rip), %ecx    # 0x20d540
testl %ecx, %ecx
je 0xdb9c
movl $0x90, %edx
cmpb $0x1, %r8b
jne 0xdbaf
movb $-0x8, %r8b
jmp 0xdbcb
testb %r8b, %r8b
js 0xdbc3
movzbl %r8b, %edx
leaq 0x10(,%rdx,4), %rdx
jmp 0xdbcb
cmpb $0x1f, %r8b
movzbl %r8b, %esi
movl $0xf1, %r8d
cmovnel %esi, %r8d
jmp 0xdbcb
movl $0x90, %edx
movb $0x20, %r8b
movzbl 0x8(%rax), %r12d
movzwl (%rax,%rdx), %r15d
movzbl (%rax,%r15), %r13d
testl %ecx, %ecx
je 0xdc40
movl 0x1ff958(%rip), %ebx    # 0x20d53c
movl $0x1, 0x1ff94e(%rip)    # 0x20d53c
movl 0x1ff950(%rip), %ecx    # 0x20d544
imull %ecx, %r13d
pushq $0x64
popq %rsi
movl %r13d, %eax
cltd
idivl %esi
movl %eax, 0x1f4c09(%rip)    # 0x202810
imull %ecx, %r12d
movl %r12d, %eax
cltd
idivl %esi
movl %eax, 0x1f4bfd(%rip)    # 0x202814
movzbl %r9b, %ecx
movzbl %r8b, %r8d
pushq $0x1
popq %rdx
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0xdd47
movl 0x1f4bdb(%rip), %eax    # 0x202810
movl %ebx, 0x1ff901(%rip)    # 0x20d53c
jmp 0xdd38
addl $0x4, %r15d
movl 0x1f4bc6(%rip), %edx    # 0x202810
movl 0x1f4bc4(%rip), %ecx    # 0x202814
movq -0x38(%rbp), %r14
movl %edi, -0x48(%rbp)
movl %r14d, %edi
movq -0x40(%rbp), %rsi
movl %r9d, -0x2c(%rbp)
callq 0xd0da
leal -0x1(%r13), %eax
movl %eax, -0x50(%rbp)
leal -0x1(%r14), %eax
movq %rax, -0x68(%rbp)
movslq -0x48(%rbp), %rax
cmpq %rax, %rbx
cmovlq %rbx, %rax
movq %rax, -0x48(%rbp)
movq %r13, -0x58(%rbp)
movl %r13d, %r13d
xorl %ecx, %ecx
movzbl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl %r12d, -0x4c(%rbp)
cmpl %r12d, %ecx
je 0xdd34
movq -0x40(%rbp), %rax
movq %rcx, -0x60(%rbp)
leal (%rcx,%rax), %r12d
xorl %r14d, %r14d
pushq $-0x1
popq %rax
movl %eax, %ebx
cmpl %r14d, %r13d
je 0xdd22
movq 0x31c226(%rip), %rax    # 0x329ee8
addq %r15, %rax
cmpb $0x0, (%r14,%rax)
je 0xdcf8
testl %ebx, %ebx
cmovsl %r14d, %ebx
cmpl -0x50(%rbp), %r14d
jl 0xdd1d
movq -0x38(%rbp), %rax
leal (%rbx,%rax), %edi
movq -0x48(%rbp), %rax
leal (%rax,%r14), %edx
movl %r12d, %esi
movl %r12d, %ecx
movl -0x2c(%rbp), %r8d
callq 0xdedf
jmp 0xdd1d
testl %ebx, %ebx
js 0xdd1d
addl -0x38(%rbp), %ebx
movq -0x68(%rbp), %rax
leal (%rax,%r14), %edx
movl %ebx, %edi
movl %r12d, %esi
movl %r12d, %ecx
movl -0x2c(%rbp), %r8d
callq 0xdedf
pushq $-0x1
popq %rax
movl %eax, %ebx
incq %r14
jmp 0xdcb6
addq %r13, %r15
movq -0x60(%rbp), %rcx
incl %ecx
movl -0x4c(%rbp), %r12d
jmp 0xdc99
movq -0x58(%rbp), %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq