// File: jkingan[P]ladyheather/heather.cpp
// Function: dump_screen(int, int, char*)
int dump_screen(int invert, int top_line, char *fn)
{
int x, y;
int redraw;
int do_gif;

   strcpy(out, fn);
   if(strstr(out, ".") == 0) {
      #ifdef GIF_FILES
         strcat(out, ".gif");
      #else
         strcat(out, ".bmp");
      #endif
   }

   bmp_file = topen(out, "wb");
   if(bmp_file == 0) return 0;

   strlwr(out);
   if(strstr(out, ".gif") || strstr(out, ".GIF")) do_gif = 1;
   else do_gif = 0;

   redraw = 0;
   if(mouse_plot_valid && (last_mouse_x >= 0)) {
      if(0) {
         x = PLOT_COL+last_mouse_x;
         y = PLOT_ROW+8;
         line(x-1,PLOT_ROW, x-1,y, WHITE);
         line(x+0,PLOT_ROW, x+0,y, WHITE);
         line(x+1,PLOT_ROW, x+1,y, WHITE);
         line(x-3,y+1,  x+3,y+1, WHITE);
         line(x-2,y+2,  x+2,y+2, WHITE);
         line(x-1,y+3,  x+1,y+3, WHITE);
         line(x-0,y+4,  x+0,y+4, WHITE);
      }
      else {
         x = PLOT_COL+last_mouse_x;
         y = last_mouse_y;
         thick_line(x-5,y-5, x+5,y+5, WHITE, 2);
         thick_line(x+5,y-5, x-5,y+5, WHITE, 2);

//       line(x-5,y-5, x+5,y-5, WHITE);
//       line(x-5,y+5, x+5,y+5, WHITE);
//       line(x-5,y-5, x-5,y+5, WHITE);
//       line(x+5,y-5, x+5,y+5, WHITE);
      }
      redraw = 1;
   }

   if(do_screen_dump == 0) {  // keyboard commanded dump
      BEEP(5);                // beep because this can take a while to do
   }

#ifdef USE_X11   // capture the screen image into a buffer
   if(display == 0) return 0;
   if(capture_image) XDestroyImage(capture_image);
   SWAP(SCREEN_WIDTH, SCREEN_HEIGHT);
   capture_image = XGetImage(display,win, 0,0, SCREEN_WIDTH,SCREEN_HEIGHT, AllPlanes,XYPixmap);
   SWAP(SCREEN_WIDTH, SCREEN_HEIGHT);
#endif

   #ifdef GIF_FILES
      if(do_gif) {
         dump_gif_file(invert, top_line, bmp_file);
      }
      else
   #endif
   {
      dump_bmp_file(invert, top_line);
   }

   fclose(bmp_file);
   bmp_file = 0;

#ifdef USE_X11  // free uo the image capture buffer
   if(capture_image) XDestroyImage(capture_image);
   capture_image = 0;
#endif

   if(do_screen_dump == 0) {
      BEEP(6);
   }

   if(redraw) redraw_screen();
   return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl %edi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rsi
leaq 0x388bd3(%rip), %rdi    # 0x39b400
callq 0x9350
leaq 0x388bc7(%rip), %rdi    # 0x39b400
leaq 0x183588(%rip), %rsi    # 0x195dc8
callq 0x9090
cmpq $0x0, %rax
jne 0x1285e
leaq 0x388bae(%rip), %rdi    # 0x39b400
leaq 0x15e384(%rip), %rsi    # 0x170bdd
callq 0x96a0
leaq 0x388b9b(%rip), %rdi    # 0x39b400
leaq 0x15d6ab(%rip), %rsi    # 0x16ff17
callq 0x9b20
movq %rax, 0x38cac8(%rip)    # 0x39f340
cmpq $0x0, 0x38cac0(%rip)    # 0x39f340
jne 0x1288e
movl $0x0, -0x4(%rbp)
jmp 0x12ad3
leaq 0x388b6b(%rip), %rdi    # 0x39b400
callq 0x9850
leaq 0x388b5f(%rip), %rdi    # 0x39b400
leaq 0x15e335(%rip), %rsi    # 0x170bdd
callq 0x9090
cmpq $0x0, %rax
jne 0x128cc
leaq 0x388b46(%rip), %rdi    # 0x39b400
leaq 0x15d659(%rip), %rsi    # 0x16ff1a
callq 0x9090
cmpq $0x0, %rax
je 0x128d5
movl $0x1, -0x28(%rbp)
jmp 0x128dc
movl $0x0, -0x28(%rbp)
movl $0x0, -0x24(%rbp)
cmpb $0x0, 0x267b4e(%rip)    # 0x27a438
je 0x12966
cmpl $0x0, 0x267b7d(%rip)    # 0x27a470
jl 0x12966
movl 0x265165(%rip), %eax    # 0x277a60
addl 0x267b6f(%rip), %eax    # 0x27a470
movl %eax, -0x1c(%rbp)
movl 0x267b6a(%rip), %eax    # 0x27a474
movl %eax, -0x20(%rbp)
movl -0x1c(%rbp), %edi
subl $0x5, %edi
movl -0x20(%rbp), %esi
subl $0x5, %esi
movl -0x1c(%rbp), %edx
addl $0x5, %edx
movl -0x20(%rbp), %ecx
addl $0x5, %ecx
movl $0xf, %r8d
movl $0x2, %r9d
callq 0x11710
movl -0x1c(%rbp), %edi
addl $0x5, %edi
movl -0x20(%rbp), %esi
subl $0x5, %esi
movl -0x1c(%rbp), %edx
subl $0x5, %edx
movl -0x20(%rbp), %ecx
addl $0x5, %ecx
movl $0xf, %r8d
movl $0x2, %r9d
callq 0x11710
movl $0x1, -0x24(%rbp)
movzbl 0x35a80d(%rip), %eax    # 0x36d17a
cmpl $0x0, %eax
jne 0x1297c
movl $0x5, %edi
callq 0x9ec0
cmpq $0x0, 0x1bd71c(%rip)    # 0x1d00a0
jne 0x12992
movl $0x0, -0x4(%rbp)
jmp 0x12ad3
cmpq $0x0, 0x38c796(%rip)    # 0x39f130
je 0x129b0
movq 0x38c78d(%rip), %rax    # 0x39f130
movq 0x60(%rax), %rax
movq 0x38c782(%rip), %rdi    # 0x39f130
callq *%rax
cmpl $0x0, 0x265051(%rip)    # 0x277a08
je 0x129dd
movl 0x265025(%rip), %eax    # 0x2779e4
movl %eax, 0x265047(%rip)    # 0x277a0c
movl 0x265015(%rip), %eax    # 0x2779e0
movl %eax, 0x265013(%rip)    # 0x2779e4
movl 0x265035(%rip), %eax    # 0x277a0c
movl %eax, 0x265003(%rip)    # 0x2779e0
movq 0x1bd6bc(%rip), %rdi    # 0x1d00a0
movq 0x1bd6c5(%rip), %rsi    # 0x1d00b0
movl 0x264fee(%rip), %r8d    # 0x2779e0
movl 0x264feb(%rip), %r9d    # 0x2779e4
xorl %ecx, %ecx
movl %ecx, %edx
movq $-0x1, (%rsp)
movl $0x1, 0x8(%rsp)
callq 0x9040
movq %rax, 0x38c717(%rip)    # 0x39f130
cmpl $0x0, 0x264fe8(%rip)    # 0x277a08
je 0x12a46
movl 0x264fbc(%rip), %eax    # 0x2779e4
movl %eax, 0x264fde(%rip)    # 0x277a0c
movl 0x264fac(%rip), %eax    # 0x2779e0
movl %eax, 0x264faa(%rip)    # 0x2779e4
movl 0x264fcc(%rip), %eax    # 0x277a0c
movl %eax, 0x264f9a(%rip)    # 0x2779e0
cmpl $0x0, -0x28(%rbp)
je 0x12a60
movl -0x8(%rbp), %edi
movl -0xc(%rbp), %esi
movq 0x38c8e7(%rip), %rdx    # 0x39f340
callq 0x168000
jmp 0x12a6b
movl -0x8(%rbp), %edi
movl -0xc(%rbp), %esi
callq 0x125d0
movq 0x38c8ce(%rip), %rdi    # 0x39f340
callq 0x9380
movq $0x0, 0x38c8be(%rip) # 0x39f340
cmpq $0x0, 0x38c6a6(%rip)    # 0x39f130
je 0x12aa0
movq 0x38c69d(%rip), %rax    # 0x39f130
movq 0x60(%rax), %rax
movq 0x38c692(%rip), %rdi    # 0x39f130
callq *%rax
movq $0x0, 0x38c685(%rip) # 0x39f130
movzbl 0x35a6c8(%rip), %eax    # 0x36d17a
cmpl $0x0, %eax
jne 0x12ac1
movl $0x6, %edi
callq 0x9ec0
cmpl $0x0, -0x24(%rbp)
je 0x12acc
callq 0x12ae0
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)