// File: /workspace/github_cpp_makefile_star2_O1/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 %edi, %r13d
movslq 0x20a819(%rip), %rbx    # 0x218800
cmpl %edi, %ebx
movl %edi, %eax
cmovll %ebx, %eax
movq %rax, -0x38(%rbp)
movl 0x20a80c(%rip), %eax    # 0x218804
cmpl %esi, %eax
cmovll %eax, %esi
movq %rsi, -0x40(%rbp)
cmpq $0x0, 0x331edf(%rip)    # 0x33fee8
jne 0xe019
leaq 0x1447ce(%rip), %rax    # 0x1527e0
movq %rax, 0x331ecf(%rip)    # 0x33fee8
movl 0x215521(%rip), %eax    # 0x223540
testl %eax, %eax
je 0xe031
movl $0x90, %edi
cmpb $0x1, %dl
jne 0xe042
movb $-0x8, %dl
jmp 0xe059
testb %dl, %dl
js 0xe052
movzbl %dl, %esi
leaq 0x10(,%rsi,4), %rdi
jmp 0xe059
cmpb $0x1f, %dl
movzbl %dl, %esi
movl $0xf1, %edx
cmovnel %esi, %edx
jmp 0xe059
movl $0x90, %edi
movb $0x20, %dl
movq 0x331e88(%rip), %rsi    # 0x33fee8
movzbl 0x8(%rsi), %r14d
movzwl (%rsi,%rdi), %r15d
movzbl (%rsi,%r15), %r12d
testl %eax, %eax
je 0xe0fa
movl 0x2154bf(%rip), %ebx    # 0x22353c
movl $0x1, 0x2154b5(%rip)    # 0x22353c
movl 0x2154b7(%rip), %eax    # 0x223544
imull %eax, %r12d
movslq %r12d, %rsi
imulq $0x51eb851f, %rsi, %rdi # imm = 0x51EB851F
movq %rdi, %rsi
shrq $0x3f, %rsi
sarq $0x25, %rdi
addl %esi, %edi
movl %edi, 0x20a762(%rip)    # 0x218810
imull %eax, %r14d
movslq %r14d, %rax
imulq $0x51eb851f, %rax, %rax # imm = 0x51EB851F
movq %rax, %rsi
shrq $0x3f, %rsi
sarq $0x25, %rax
addl %esi, %eax
movl %eax, 0x20a745(%rip)    # 0x218814
movzbl %cl, %ecx
movzbl %dl, %r8d
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
movl $0x1, %edx
callq 0xe211
movl 0x20a721(%rip), %r12d   # 0x218810
movl %ebx, 0x215447(%rip)    # 0x22353c
jmp 0xe1ff
movl %ecx, -0x2c(%rbp)
movl 0x20a70d(%rip), %edx    # 0x218810
movl 0x20a70b(%rip), %ecx    # 0x218814
movq $0x0, -0x48(%rbp)
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
xorl %r8d, %r8d
callq 0xf30c
testl %r14d, %r14d
je 0xe1ff
addl $0x4, %r15d
leal -0x1(%r12), %eax
movl %eax, -0x50(%rbp)
movq %r12, -0x58(%rbp)
movl %r12d, %r12d
movslq %r13d, %rax
cmpq %rax, %rbx
cmovlq %rbx, %rax
movq %rax, -0x68(%rbp)
decq %rax
movq %rax, -0x60(%rbp)
movzbl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl %r14d, -0x4c(%rbp)
cmpl $0x0, -0x58(%rbp)
je 0xe1e1
movq -0x40(%rbp), %rax
movq -0x48(%rbp), %rcx
leal (%rcx,%rax), %r13d
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
xorl %r14d, %r14d
movq 0x331d6a(%rip), %rax    # 0x33fee8
addq %r15, %rax
cmpb $0x0, (%r14,%rax)
je 0xe1b4
testl %ebx, %ebx
cmovsl %r14d, %ebx
cmpl -0x50(%rbp), %r14d
jl 0xe1d9
movq -0x38(%rbp), %rax
leal (%rbx,%rax), %edi
movq -0x68(%rbp), %rax
leal (%rax,%r14), %edx
movl %r13d, %esi
movl %r13d, %ecx
movl -0x2c(%rbp), %r8d
callq 0xe3c3
jmp 0xe1d9
testl %ebx, %ebx
js 0xe1d9
addl -0x38(%rbp), %ebx
movq -0x60(%rbp), %rax
leal (%rax,%r14), %edx
movl %ebx, %edi
movl %r13d, %esi
movl %r13d, %ecx
movl -0x2c(%rbp), %r8d
callq 0xe3c3
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
incq %r14
cmpl %r14d, %r12d
jne 0xe177
movq -0x48(%rbp), %rax
incl %eax
addq %r12, %r15
movl -0x4c(%rbp), %r14d
movq %rax, -0x48(%rbp)
cmpl %r14d, %eax
jne 0xe15d
movq -0x58(%rbp), %r12
movl %r12d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq