// File: /workspace/github_cpp_makefile_star2_O3/mikeakohn[P]cloudtari/build/../src/TIA.cxx
// Function: TIA::clock()
void TIA::clock()
{
  // The main playfield area starts after 68 clocks.
  if (pos_x >= 68 && pos_y >= 40 && pos_y < 232)
  {
    // The point to the first bit to be displayed from PF0, PF1, PF2.
    if (pos_x == 68) { playfield.reset(); }

    playfield.compute_pixel(pos_x);
    player_0.compute_pixel(pos_x);
    player_1.compute_pixel(pos_x);
    missile_0.compute_pixel(pos_x);
    missile_1.compute_pixel(pos_x);
    ball.compute_pixel(pos_x);

    draw_pixel();
    compute_collisions();
  }

  pos_x++;

  if (pos_x == 68 + 160)
  {
    if (player_0.need_update) { build_player_0(); }
    if (player_1.need_update) { build_player_1(); }

    if (!hsync_latch) { write_regs[WSYNC] = 0; }

#if 0
    if (pos_y >= 40 && pos_y <= 232)
    {
      television->refresh();
    }
#endif

    if (pos_y < 40 && (pos_y & 0xf) == 0) { check_events = true; }

    pos_x = 0;
    pos_y++;

    // This really shouldn't be needed.. but..
    if (pos_y > 262) { pos_y = 0; }
  }
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
movl 0x8(%rdi), %ecx
cmpl $0x44, %ecx
jl 0x810a
movl 0xc(%rbx), %eax
addl $-0x28, %eax
cmpl $0xbf, %eax
ja 0x810a
cmpl $0x44, %ecx
jne 0x803a
movq $0x1, 0x28(%rbx)
leal -0x44(%rcx), %eax
movq 0x20(%rbx), %rdx
shrb $0x2, %al
movzbl %al, %eax
btq %rax, %rdx
setb 0x18(%rbx)
movl %ecx, %eax
subl 0x3c(%rbx), %eax
jl 0x805f
cltd
idivl 0x38(%rbx)
cmpl $0x8, %eax
jl 0x8065
movb $0x0, 0x34(%rbx)
jmp 0x8070
movzbl 0x30(%rbx), %edx
btl %eax, %edx
setb 0x34(%rbx)
movl %ecx, %eax
subl 0x50(%rbx), %eax
jl 0x8080
cltd
idivl 0x4c(%rbx)
cmpl $0x8, %eax
jl 0x8086
movb $0x0, 0x48(%rbx)
jmp 0x8091
movzbl 0x44(%rbx), %edx
btl %eax, %edx
setb 0x48(%rbx)
cmpb $0x1, 0x5a(%rbx)
jne 0x80ae
movl 0x5c(%rbx), %eax
cmpl %ecx, %eax
setle %dl
movzbl 0x58(%rbx), %esi
addl %eax, %esi
cmpl %ecx, %esi
setg %al
andb %dl, %al
jmp 0x80b0
xorl %eax, %eax
movb %al, 0x5b(%rbx)
cmpb $0x1, 0x66(%rbx)
jne 0x80d0
movl 0x68(%rbx), %eax
cmpl %ecx, %eax
setle %dl
movzbl 0x64(%rbx), %esi
addl %eax, %esi
cmpl %ecx, %esi
setg %al
andb %dl, %al
jmp 0x80d2
xorl %eax, %eax
movb %al, 0x67(%rbx)
cmpb $0x1, 0x72(%rbx)
jne 0x80f2
movl 0x74(%rbx), %eax
cmpl %ecx, %eax
setle %dl
movzbl 0x70(%rbx), %esi
addl %eax, %esi
cmpl %ecx, %esi
setg %al
andb %dl, %al
jmp 0x80f4
xorl %eax, %eax
movb %al, 0x73(%rbx)
movq %rbx, %rdi
callq 0x81b6
movq %rbx, %rdi
callq 0x82ec
movl 0x8(%rbx), %ecx
incl %ecx
movl %ecx, 0x8(%rbx)
cmpl $0xe4, %ecx
jne 0x81b4
cmpb $0x1, 0x33(%rbx)
jne 0x814b
leaq 0x9b(%rbx), %rax
testb $0x8, 0x8b(%rbx)
movzbl 0x9b(%rbx), %ecx
leaq 0xd0(%rbx,%rcx), %rcx
cmovneq %rax, %rcx
movb (%rcx), %al
movb %al, 0x30(%rbx)
movb $0x0, 0x33(%rbx)
cmpb $0x1, 0x47(%rbx)
jne 0x817b
leaq 0x9c(%rbx), %rax
testb $0x8, 0x8c(%rbx)
movzbl 0x9c(%rbx), %ecx
leaq 0xd0(%rbx,%rcx), %rcx
cmovneq %rax, %rcx
movb (%rcx), %al
movb %al, 0x44(%rbx)
movb $0x0, 0x47(%rbx)
cmpb $0x0, 0x10(%rbx)
jne 0x8188
movb $0x0, 0x82(%rbx)
movl 0xc(%rbx), %eax
cmpl $0x28, %eax
setge %cl
testb $0xf, %al
setne %dl
orb %cl, %dl
jne 0x81a1
movb $0x1, 0x1e4(%rbx)
xorl %ecx, %ecx
movl %ecx, 0x8(%rbx)
leal 0x1(%rax), %edx
cmpl $0x106, %eax            # imm = 0x106
cmovgel %ecx, %edx
movl %edx, 0xc(%rbx)
popq %rbx
retq