// File: mikeakohn[P]cloudtari/build/../src/TelevisionHttp.cxx
// Function: TelevisionHttp::send_index_html()
int TelevisionHttp::send_index_html()
{
  std::string header;
  const char *page =
    "<html>\n<body onload='init();' bgcolor='#000000'>\n"
    "<script type='text/javascript'>\n"
    "var queue = '';\n"
    "function init()\n"
    "{\n"
      "setTimeout(refresh_image, 2000);\n"
      "window.addEventListener('keydown', function(event)\n"
      "{\n"
        "if (event.defaultPrevented) { return; }\n"
        "switch(event.keyCode)\n"
        "{\n"
          "case 40: queue += 's'; break;\n"
          "case 38: queue += 'w'; break;\n"
          "case 37: queue += 'a'; break;\n"
          "case 39: queue += 'd'; break;\n"
          "case 32: queue += 'f'; break;\n"
          "case 13: queue += 'e'; break;\n"
          "case 67: queue += 'c'; break;\n"
          "default: break;\n"
        "}\n"
      "});\n"
      "window.addEventListener('keyup', function(event)\n"
      "{\n"
        "if (event.defaultPrevented) { return; }\n"
        "switch(event.keyCode)\n"
        "{\n"
          "case 40: queue += 'S'; break;\n"
          "case 38: queue += 'W'; break;\n"
          "case 37: queue += 'A'; break;\n"
          "case 39: queue += 'D'; break;\n"
          "case 32: queue += 'F'; break;\n"
          "case 13: queue += 'E'; break;\n"
          "case 67: queue += 'C'; break;\n"
          "default: break;\n"
        "}\n"
      "});\n"
    "}\n"
    "function refresh_image()\n"
    "{\n"
    //"console.log('refresh_image()');\n"
    "var atari = document.getElementById('atari');\n"
    "if (atari.complete)\n"
    "{\n"
    "atari.src = 'image.gif?' + queue + '#' + new Date().getTime();\n"
    "queue = '';\n"
    "}\n"
    "setTimeout(refresh_image, 33);\n"
    "}\n"
    "</script>\n"
    "<table width=100%% height=100%%>"
    "<tr><td width=100%% height=100%% align='center'>"
    "<img src='image.gif' id='atari'></td></tr>"
    "</body>\n</html>\n\n";

  header =
    "HTTP/1.1 200 OK\n"
    "Cache-Control: no-cache, must-revalidate\n"
    "Pragma: no-cache\n"
    "Content-Type: text/html\n"
    "Content-Length: " + std::to_string(strlen(page)) + "\n\n";

  net_send((uint8_t *)header.c_str(), header.size());
  net_send((uint8_t *)page, strlen(page));

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xa8(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x4340
leaq 0x3823(%rip), %rax      # 0xfcdd
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x4130
movq %rax, %rsi
leaq -0x90(%rbp), %rdi
callq 0xce90
jmp 0xc4d8
leaq 0x3caf(%rip), %rsi      # 0x1018e
leaq -0x70(%rbp), %rdi
leaq -0x90(%rbp), %rdx
callq 0xce40
jmp 0xc4f1
leaq 0x3c93(%rip), %rdx      # 0x1018b
leaq -0x50(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0xcdf0
jmp 0xc507
leaq -0x28(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
leaq -0x50(%rbp), %rsi
movq %rsi, -0xc8(%rbp)
callq 0x4300
movq -0xc8(%rbp), %rdi
callq 0x41b0
leaq -0x70(%rbp), %rdi
callq 0x41b0
leaq -0x90(%rbp), %rdi
callq 0x41b0
movq -0xa8(%rbp), %rax
movq -0xc0(%rbp), %rdi
addq $0x20, %rax
movq %rax, -0xb8(%rbp)
callq 0x4120
movq -0xc0(%rbp), %rdi
movq %rax, -0xb0(%rbp)
callq 0x41c0
movq -0xb8(%rbp), %rdi
movq -0xb0(%rbp), %rsi
movl %eax, %edx
callq 0x9ba0
jmp 0xc58b
movq -0xa8(%rbp), %rax
addq $0x20, %rax
movq %rax, -0xd8(%rbp)
movq -0x30(%rbp), %rdi
movq %rdi, -0xd0(%rbp)
callq 0x4130
movq -0xd8(%rbp), %rdi
movq -0xd0(%rbp), %rsi
movl %eax, %edx
callq 0x9ba0
jmp 0xc5c4
leaq -0x28(%rbp), %rdi
callq 0x41b0
xorl %eax, %eax
addq $0xe0, %rsp
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0xc627
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0xc61b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x41b0
leaq -0x90(%rbp), %rdi
callq 0x41b0
leaq -0x28(%rbp), %rdi
callq 0x41b0
movq -0x98(%rbp), %rdi
callq 0x43d0
nopl (%rax)