// File: /workspace/github_cpp_makefile_star2_O1/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 0x7f15
movl 0xc(%rbx), %eax
addl $-0x28, %eax
cmpl $0xbf, %eax
ja 0x7f15
cmpl $0x44, %ecx
jne 0x7e40
movq $0x1, 0x28(%rbx)
leal -0x44(%rcx), %eax
leal -0x41(%rcx), %edx
testl %eax, %eax
cmovnsl %eax, %edx
movq 0x20(%rbx), %rax
shrb $0x2, %dl
movzbl %dl, %edx
btq %rdx, %rax
setb 0x18(%rbx)
movl %ecx, %eax
subl 0x3c(%rbx), %eax
jl 0x7e6d
cltd
idivl 0x38(%rbx)
cmpl $0x8, %eax
jl 0x7e73
movb $0x0, 0x34(%rbx)
jmp 0x7e7e
movzbl 0x30(%rbx), %edx
btl %eax, %edx
setb 0x34(%rbx)
movl %ecx, %eax
subl 0x50(%rbx), %eax
jl 0x7e8e
cltd
idivl 0x4c(%rbx)
cmpl $0x8, %eax
jl 0x7e94
movb $0x0, 0x48(%rbx)
jmp 0x7e9f
movzbl 0x44(%rbx), %edx
btl %eax, %edx
setb 0x48(%rbx)
cmpb $0x1, 0x5a(%rbx)
jne 0x7ebc
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 0x7ebe
xorl %eax, %eax
movb %al, 0x5b(%rbx)
cmpb $0x1, 0x66(%rbx)
jne 0x7ede
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 0x7ee0
xorl %eax, %eax
movb %al, 0x67(%rbx)
cmpb $0x1, 0x72(%rbx)
jne 0x7f00
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 0x7f02
xorl %eax, %eax
movb %al, 0x73(%rbx)
movq %rbx, %rdi
callq 0x7fc4
movq %rbx, %rdi
callq 0x80fa
movl 0x8(%rbx), %eax
incl %eax
movl %eax, 0x8(%rbx)
cmpl $0xe4, %eax
jne 0x7fc1
cmpb $0x1, 0x33(%rbx)
jne 0x7f58
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 0x7f88
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 0x7f95
movb $0x0, 0x82(%rbx)
movl 0xc(%rbx), %eax
cmpl $0x28, %eax
setge %cl
testb $0xf, %al
setne %dl
orb %cl, %dl
jne 0x7fae
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
nop