// File: jkingan[P]ladyheather/heather.cpp
// Function: dump_bmp_file(int, int)
int dump_bmp_file(int invert, int top_line)
{
int x, y, c;

   // main header
   dump_byte('B');   dump_byte('M');                          // magic number
   dump_dword((SCREEN_HEIGHT-top_line)*SCREEN_WIDTH/2L+BM_HEADER_SIZE);  // file size
   dump_dword(0L);              // reserved
   dump_dword(BM_HEADER_SIZE);  // offset of bitmap data in the file

   // info header
   dump_dword(40L);             // info header length
   dump_dword(SCREEN_WIDTH);    // screen size
   dump_dword(SCREEN_HEIGHT-top_line);
   dump_word(1);                // number of planes
   dump_word(4);                // bits per pixel
   dump_dword(0L);              // no compression
   dump_dword(SCREEN_WIDTH*(SCREEN_HEIGHT-top_line)/2L);// picture size in bytes
   dump_dword(0L);              // horizontal resolution
   dump_dword(0L);              // vertical resolution
   dump_dword(16L);             // number of used colors
   dump_dword(16L);             // number of important colors

   // palette
   for(c=0; c<16; c++) {
      x = (c << 2);
      if(invert) {
         if     (c == WHITE)  x = (BLACK << 2);
         else if(c == BLACK)  x = (WHITE << 2);
         else if(c == YELLOW) x = (BMP_YELLOW << 2);
      }
      dump_byte(bmp_pal[x++]);
      dump_byte(bmp_pal[x++]);
      dump_byte(bmp_pal[x++]);
      dump_byte(bmp_pal[x]);
   }

   for(y=SCREEN_HEIGHT-1; y>=top_line; y--) {
      update_pwm();
      for(x=0; x<SCREEN_WIDTH; x+=2) {
         c = (get_pixel(x, y) & 0x0F) << 4;
         c |= (get_pixel(x+1, y) & 0x0F);
         dump_byte(c);
      }
   }

   return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movl $0x42, %edi
callq 0x12520
movl $0x4d, %edi
callq 0x12520
movl 0x2653ec(%rip), %eax    # 0x2779e4
subl -0x8(%rbp), %eax
imull 0x2653de(%rip), %eax    # 0x2779e0
cltq
movl $0x2, %ecx
cqto
idivq %rcx
addq $0x76, %rax
movl %eax, %edi
callq 0x12580
xorl %edi, %edi
callq 0x12580
movl $0x76, %edi
callq 0x12580
movl $0x28, %edi
callq 0x12580
movl 0x2653a6(%rip), %edi    # 0x2779e0
callq 0x12580
movl 0x26539f(%rip), %edi    # 0x2779e4
subl -0x8(%rbp), %edi
callq 0x12580
movl $0x1, %edi
callq 0x12550
movl $0x4, %edi
callq 0x12550
xorl %edi, %edi
callq 0x12580
movl 0x265372(%rip), %eax    # 0x2779e0
movl 0x265370(%rip), %ecx    # 0x2779e4
subl -0x8(%rbp), %ecx
imull %ecx, %eax
cltq
movl $0x2, %ecx
cqto
idivq %rcx
movl %eax, %edi
callq 0x12580
xorl %edi, %edi
callq 0x12580
xorl %edi, %edi
callq 0x12580
movl $0x10, %edi
callq 0x12580
movl $0x10, %edi
callq 0x12580
movl $0x0, -0x14(%rbp)
cmpl $0x10, -0x14(%rbp)
jge 0x1277c
movl -0x14(%rbp), %eax
shll $0x2, %eax
movl %eax, -0xc(%rbp)
cmpl $0x0, -0x4(%rbp)
je 0x12700
cmpl $0xf, -0x14(%rbp)
jne 0x126de
movl $0x0, -0xc(%rbp)
jmp 0x126fe
cmpl $0x0, -0x14(%rbp)
jne 0x126ed
movl $0x3c, -0xc(%rbp)
jmp 0x126fc
cmpl $0xe, -0x14(%rbp)
jne 0x126fa
movl $0x40, -0xc(%rbp)
jmp 0x126fc
jmp 0x126fe
jmp 0x12700
movl -0xc(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0xc(%rbp)
movslq %eax, %rcx
leaq 0x38cb2b(%rip), %rax    # 0x39f240
movzbl (%rax,%rcx), %edi
callq 0x12520
movl -0xc(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0xc(%rbp)
movslq %eax, %rcx
leaq 0x38cb0d(%rip), %rax    # 0x39f240
movzbl (%rax,%rcx), %edi
callq 0x12520
movl -0xc(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0xc(%rbp)
movslq %eax, %rcx
leaq 0x38caef(%rip), %rax    # 0x39f240
movzbl (%rax,%rcx), %edi
callq 0x12520
movslq -0xc(%rbp), %rcx
leaq 0x38cadb(%rip), %rax    # 0x39f240
movzbl (%rax,%rcx), %edi
callq 0x12520
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x126b6
movl 0x265262(%rip), %eax    # 0x2779e4
subl $0x1, %eax
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %eax
cmpl -0x8(%rbp), %eax
jl 0x127fb
callq 0x11ee60
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
cmpl 0x26523b(%rip), %eax    # 0x2779e0
jge 0x127ee
movl -0xc(%rbp), %edi
movl -0x10(%rbp), %esi
callq 0x11e40
movzbl %al, %eax
andl $0xf, %eax
shll $0x4, %eax
movl %eax, -0x14(%rbp)
movl -0xc(%rbp), %edi
addl $0x1, %edi
movl -0x10(%rbp), %esi
callq 0x11e40
movzbl %al, %eax
andl $0xf, %eax
orl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
movzbl %al, %edi
callq 0x12520
movl -0xc(%rbp), %eax
addl $0x2, %eax
movl %eax, -0xc(%rbp)
jmp 0x1279c
jmp 0x127f0
movl -0x10(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x12788
movl $0x1, %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)