// File: /workspace/github_cpp_makefile_star2_O3/magmastonealex[P]fbkeyboard/src/Display.cpp
// Function: Display::refresh()
void Display::refresh() {
	memset((unsigned char*) keyboardImage->data, 0x70, width*height*3);

	for (int i = 0; i < 3; i++) {
    	for (int z = 0; z < 11; z++) {
    		print_letter((*currentKeyboard)[i][10-z], CHAR_Y_START(entryWidth, scale, i, rowWidth), CHAR_X_START(margin, z, stepSizePx, scale), scale);
    	}
    }

    print_letter(0x01, CHAR_Y_START(entryWidth, scale, 3, rowWidth) , CHAR_X_START(margin, 9, stepSizePx, scale), scale);
    print_letter(0x03, CHAR_Y_START(entryWidth, scale, 3, rowWidth), CHAR_X_START(margin, 10, stepSizePx, scale), scale);


    //event: 4 code 4 value: 42
    RGB color = {0xFF, 0xFF, 0xFF};
	fastRect(0, 0, entryWidth, height, color);
	for(int i=1; i < 11; i++) {
		int lastCharEnd = (CHAR_X_START(margin, i-1, stepSizePx, scale) + (8*scale));
		int thisCharStart = CHAR_X_START(margin, i, stepSizePx, scale);
		xLine(0, (lastCharEnd + thisCharStart) / 2 , color);
	}


	int lastLine = entryWidth;
    for(; lastLine <= width; lastLine+=rowWidth) {
    	yLine(lastLine, 0, color);
    }
    lastLine-=rowWidth*2;

	int lastCharEnd = (CHAR_X_START(margin, 3-1, stepSizePx, scale)+(8*scale));
	int thisCharStart = CHAR_X_START(margin, 3, stepSizePx, scale);

    fastRect(lastLine, (lastCharEnd + thisCharStart) / 2, rowWidth, (stepSizePx + (8*scale))*5, color );

    for(uint8_t i = 0; i < currentText.length() && i < maxlen; i++) {
    	print_letter(currentText.at(i), (entryWidth/2) - ((kbScale*8)/2), height - margin - (kbScale*8) - (i*((kbScale*8) + 4)), kbScale, true);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x30(%rdi), %rax
movq 0x8(%rax), %rdi
movl (%rbx), %eax
imull 0x4(%rbx), %eax
leal (%rax,%rax,2), %eax
movslq %eax, %rdx
movl $0x70, %esi
callq 0x20f0
movl $0xa, %r14d
xorl %r15d, %r15d
movq %r14, %r12
xorl %r13d, %r13d
movq 0x60(%rbx), %rax
movsbl (%rax,%r12), %esi
movl 0x8(%rbx), %ecx
movl 0xc(%rbx), %r8d
leal (,%r8,4), %eax
addl 0x14(%rbx), %eax
movl 0x1c(%rbx), %edx
imull %r15d, %edx
addl %eax, %edx
leal (,%r8,8), %eax
addl 0x20(%rbx), %eax
movl %r13d, %edi
imull %eax, %edi
subl %r8d, %ecx
addl %edi, %ecx
movq %rbx, %rdi
xorl %r9d, %r9d
callq 0x29ce
incq %r13
decq %r12
cmpq $0xb, %r13
jne 0x2d2b
incq %r15
addq $0xb, %r14
cmpq $0x3, %r15
jne 0x2d25
movl 0xc(%rbx), %r8d
leal (,%r8,4), %eax
addl 0x14(%rbx), %eax
movl 0x1c(%rbx), %ecx
leal (%rcx,%rcx,2), %edx
addl %eax, %edx
leal (,%r8,8), %eax
addl 0x20(%rbx), %eax
movl 0x8(%rbx), %ecx
leal (%rax,%rax,8), %eax
subl %r8d, %ecx
addl %eax, %ecx
movq %rbx, %rdi
movl $0x1, %esi
xorl %r9d, %r9d
callq 0x29ce
movl 0xc(%rbx), %r8d
leal (,%r8,4), %eax
addl 0x14(%rbx), %eax
movl 0x1c(%rbx), %ecx
leal (%rcx,%rcx,2), %edx
addl %eax, %edx
leal (,%r8,8), %eax
addl 0x20(%rbx), %eax
movl 0x8(%rbx), %ecx
leal (%rax,%rax,4), %eax
subl %r8d, %ecx
leal (%rcx,%rax,2), %ecx
movq %rbx, %rdi
movl $0x3, %esi
xorl %r9d, %r9d
callq 0x29ce
movl 0x4(%rbx), %r8d
movl 0x14(%rbx), %ecx
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
movl $0xffffff, %r9d         # imm = 0xFFFFFF
callq 0x2a7a
movq 0x30(%rbx), %rax
movq %rax, (%rsp)
movl (%rax), %r12d
movl 0x20(%rbx), %eax
movl 0x8(%rbx), %ecx
movl 0xc(%rbx), %edx
leaq (%r12,%r12,2), %r14
leal (%rdx,%rdx), %esi
shll $0x4, %edx
leal (%rdx,%rax,2), %ebp
subl %esi, %edx
addl %eax, %edx
leal (%rdx,%rcx,2), %r13d
movl $0xa, %r15d
testl %r12d, %r12d
jle 0x2e7b
movl %r13d, %eax
shrl $0x1f, %eax
addl %r13d, %eax
sarl %eax
imull %r12d, %eax
cltq
leaq (%rax,%rax,2), %rdi
movq (%rsp), %rax
addq 0x8(%rax), %rdi
movl $0xff, %esi
movq %r14, %rdx
callq 0x20f0
addl %ebp, %r13d
decl %r15d
jne 0x2e4c
movl 0x14(%rbx), %esi
movslq (%rbx), %rax
movslq 0x1c(%rbx), %rcx
cmpl %eax, %esi
jg 0x2eda
movslq %esi, %rsi
movq 0x30(%rbx), %rdx
movl 0x4(%rdx), %edi
leaq (%rsi,%rsi,2), %r8
addq $0x2, %r8
leaq (%rcx,%rcx,2), %r9
testl %edi, %edi
jle 0x2ecf
movslq (%rdx), %r11
movq 0x8(%rdx), %r10
addq %r8, %r10
leaq (%r11,%r11,2), %r11
movq %rdi, %r14
movw $0xffff, -0x2(%r10)     # imm = 0xFFFF
movb $-0x1, (%r10)
addq %r11, %r10
decq %r14
jne 0x2ebc
addq %rcx, %rsi
addq %r9, %r8
cmpq %rax, %rsi
jle 0x2ea7
subl %ecx, %esi
subl %ecx, %esi
movl 0x8(%rbx), %eax
movl 0xc(%rbx), %edx
leal (,%rdx,8), %edi
addl 0x20(%rbx), %edi
leal (%rdi,%rdi,4), %r8d
subl %edx, %eax
leal (%r8,%rdx,8), %edx
leal (%rdx,%rax,2), %eax
movl %eax, %edx
shrl $0x1f, %edx
addl %eax, %edx
sarl %edx
movq %rbx, %rdi
movl $0xffffff, %r9d         # imm = 0xFFFFFF
callq 0x2a7a
cmpq $0x0, 0x48(%rbx)
je 0x2f7d
xorl %eax, %eax
xorl %ebp, %ebp
movzbl %bpl, %ebp
cmpl %ebp, 0x28(%rbx)
jle 0x2f7d
movq 0x40(%rbx), %rcx
movsbl (%rcx,%rax), %esi
movl 0x4(%rbx), %ecx
movl 0x14(%rbx), %eax
movl %eax, %edx
shrl $0x1f, %edx
addl %eax, %edx
sarl %edx
movl 0x24(%rbx), %r8d
leal (,%r8,8), %eax
leal (,%r8,4), %edi
subl %edi, %edx
movl %eax, %edi
xorl $-0x4, %edi
imull %ebp, %edi
addl 0x8(%rbx), %eax
subl %eax, %ecx
addl %edi, %ecx
movq %rbx, %rdi
movl $0x1, %r9d
callq 0x29ce
incb %bpl
movzbl %bpl, %eax
cmpq %rax, 0x48(%rbx)
ja 0x2f1d
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq