// File: disjukr[P]Tetris/Console.cc
// Function: Console::Update()
void Console::Update() {
#ifdef _WIN32
    hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
#endif
    int width = screen.GetWidth();
    int height = screen.GetHeight();
    for (int j = 0; j < height; ++j) {
        for (int i = 0; i < width; ++i) {
            Cell* prevCell = prevScreen.GetCell(i, j);
            Cell* cell = screen.GetCell(i, j);
            if (*prevCell == *cell) continue;
#ifdef _WIN32
            DWORD count;
            COORD cursorCoord = {(SHORT) i, (SHORT) j};
            SetConsoleCursorPosition(hStdout, cursorCoord);
#else
            cout << "\x1B[" << to_string(j + 1) << ';'
                << to_string(i + 1) << 'H';
            SetColor(cell -> foreground, cell -> background);
#endif
            cout.put(cell -> value);
#ifdef _WIN32
            FillConsoleOutputAttribute(
                hStdout,
                GetAttributes(cell -> foreground, cell -> background),
                1, cursorCoord, &count);
#else
            UnsetColor();
#endif
            prevCell -> value = cell -> value;
            prevCell -> foreground = cell -> foreground;
            prevCell -> background = cell -> background;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
leaq 0x6cb6(%rip), %rdi      # 0x12188
callq 0xabb0
movl %eax, -0x4(%rbp)
leaq 0x6ca7(%rip), %rdi      # 0x12188
callq 0xabc0
movl %eax, -0x8(%rbp)
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0xb699
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0xb689
movl -0x10(%rbp), %esi
movl -0xc(%rbp), %edx
leaq 0x6c8c(%rip), %rdi      # 0x121a8
callq 0xabe0
movq %rax, -0x18(%rbp)
movl -0x10(%rbp), %esi
movl -0xc(%rbp), %edx
leaq 0x6c56(%rip), %rdi      # 0x12188
callq 0xabe0
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0xb6b0
testb $0x1, %al
jne 0xb54e
jmp 0xb553
jmp 0xb64d
movq 0x6a7e(%rip), %rdi      # 0x11fd8
leaq 0x101d(%rip), %rsi      # 0xc57e
callq 0x3140
movq %rax, -0x88(%rbp)
movl -0xc(%rbp), %esi
incl %esi
leaq -0x40(%rbp), %rdi
movq %rdi, -0x80(%rbp)
callq 0x72f0
movq -0x88(%rbp), %rdi
movq -0x80(%rbp), %rsi
callq 0x3110
movq %rax, -0x78(%rbp)
jmp 0xb595
movq -0x78(%rbp), %rdi
movl $0x3b, %esi
callq 0x3190
movq %rax, -0x90(%rbp)
jmp 0xb5ac
movl -0x10(%rbp), %esi
incl %esi
leaq -0x70(%rbp), %rdi
callq 0x72f0
jmp 0xb5bc
movq -0x90(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x3110
movq %rax, -0x98(%rbp)
jmp 0xb5d5
movq -0x98(%rbp), %rdi
movl $0x48, %esi
callq 0x3190
jmp 0xb5e8
leaq -0x70(%rbp), %rdi
callq 0x30c0
leaq -0x40(%rbp), %rdi
callq 0x30c0
movq -0x20(%rbp), %rax
movl 0x4(%rax), %edi
movq -0x20(%rbp), %rax
movl 0x8(%rax), %esi
callq 0xb250
movq -0x20(%rbp), %rax
movq 0x69c0(%rip), %rdi      # 0x11fd8
movsbl (%rax), %esi
callq 0x3040
callq 0xb3c0
movq -0x20(%rbp), %rax
movb (%rax), %cl
movq -0x18(%rbp), %rax
movb %cl, (%rax)
movq -0x20(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x20(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8(%rax)
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0xb503
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xb67e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x30c0
leaq -0x40(%rbp), %rdi
callq 0x30c0
jmp 0xb6a2
jmp 0xb68b
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0xb4f0
addq $0xa0, %rsp
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x3270
nopl (%rax,%rax)