// File: /workspace/github_cpp_makefile_star2_O2/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
pushq $0x70
popq %rsi
callq 0x20e0
pushq $0xa
popq %r14
xorl %r15d, %r15d
cmpq $0x3, %r15
je 0x2b19
movq %r14, %r12
xorl %r13d, %r13d
cmpq $0xb, %r13
je 0x2b10
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 0x2794
incq %r13
decq %r12
jmp 0x2abd
incq %r15
addq $0xb, %r14
jmp 0x2ab1
movl 0xc(%rbx), %r8d
leal (,%r8,4), %eax
addl 0x14(%rbx), %eax
imull $0x3, 0x1c(%rbx), %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
pushq $0x1
popq %rbp
movq %rbx, %rdi
movl %ebp, %esi
xorl %r9d, %r9d
callq 0x2794
movl 0xc(%rbx), %r8d
leal (,%r8,4), %eax
addl 0x14(%rbx), %eax
imull $0x3, 0x1c(%rbx), %edx
addl %eax, %edx
leal (,%r8,8), %eax
addl 0x20(%rbx), %eax
movl 0x8(%rbx), %ecx
imull $0xa, %eax, %eax
subl %r8d, %ecx
addl %eax, %ecx
pushq $0x3
popq %rsi
movq %rbx, %rdi
xorl %r9d, %r9d
callq 0x2794
movl 0x4(%rbx), %r8d
movl 0x14(%rbx), %ecx
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
movl $0xffffff, %r9d         # imm = 0xFFFFFF
callq 0x2842
pushq $0x2
popq %r12
cmpl $0x15, %ebp
je 0x2be4
movl 0x8(%rbx), %eax
movl 0xc(%rbx), %ecx
leal (,%rcx,8), %edx
addl 0x20(%rbx), %edx
imull %ebp, %edx
subl %ecx, %eax
leal (%rdx,%rcx,8), %ecx
leal (%rcx,%rax,2), %eax
cltd
idivl %r12d
movq %rbx, %rdi
xorl %esi, %esi
movl %eax, %edx
movl $0xffffff, %ecx         # imm = 0xFFFFFF
callq 0x28b2
addl $0x2, %ebp
jmp 0x2baa
movl 0x14(%rbx), %ebp
cmpl (%rbx), %ebp
jg 0x2c01
movq %rbx, %rdi
movl %ebp, %esi
xorl %edx, %edx
movl $0xffffff, %ecx         # imm = 0xFFFFFF
callq 0x28fc
addl 0x1c(%rbx), %ebp
jmp 0x2be7
movl 0x1c(%rbx), %ecx
subl %ecx, %ebp
subl %ecx, %ebp
movl 0x8(%rbx), %eax
movl 0xc(%rbx), %edx
leal (,%rdx,8), %esi
addl 0x20(%rbx), %esi
leal (%rsi,%rsi,4), %r8d
subl %edx, %eax
leal (%r8,%rdx,8), %edx
leal (%rdx,%rax,2), %eax
cltd
idivl %r12d
movq %rbx, %rdi
movl %ebp, %esi
movl %eax, %edx
movl $0xffffff, %r9d         # imm = 0xFFFFFF
callq 0x2842
leaq 0x40(%rbx), %r14
xorl %eax, %eax
pushq $0x1
popq %rbp
movzbl %al, %r15d
cmpq %r15, 0x48(%rbx)
jbe 0x2ca5
cmpl %r15d, 0x28(%rbx)
jle 0x2ca5
movq %r14, %rdi
movq %r15, %rsi
callq 0x2280
movsbl (%rax), %esi
movl 0x4(%rbx), %ecx
movl 0x14(%rbx), %eax
cltd
idivl %r12d
movl 0x24(%rbx), %r8d
leal (,%r8,8), %edx
leal (,%r8,4), %edi
subl %edi, %eax
movl %edx, %edi
xorl $-0x4, %edi
imull %r15d, %edi
addl 0x8(%rbx), %edx
subl %edx, %ecx
addl %edi, %ecx
movq %rbx, %rdi
movl %eax, %edx
movl %ebp, %r9d
callq 0x2794
leal 0x1(%r15), %eax
jmp 0x2c44
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq