// File: 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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rcx
movq %rcx, -0x58(%rbp)
movq 0x30(%rcx), %rax
movq 0x8(%rax), %rdi
movl (%rcx), %eax
imull 0x4(%rcx), %eax
imull $0x3, %eax, %eax
movslq %eax, %rdx
movl $0x70, %esi
callq 0x20f0
movl $0x0, -0xc(%rbp)
cmpl $0x3, -0xc(%rbp)
jge 0x31bd
movl $0x0, -0x10(%rbp)
cmpl $0xb, -0x10(%rbp)
jge 0x31ad
movq -0x58(%rbp), %rdi
movq 0x60(%rdi), %rax
movslq -0xc(%rbp), %rcx
imulq $0xb, %rcx, %rcx
addq %rcx, %rax
movl $0xa, %ecx
subl -0x10(%rbp), %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %al
movl 0x14(%rdi), %edx
movl 0xc(%rdi), %ecx
shll $0x2, %ecx
addl %ecx, %edx
movl -0xc(%rbp), %ecx
imull 0x1c(%rdi), %ecx
addl %ecx, %edx
movl 0x8(%rdi), %ecx
movl -0x10(%rbp), %esi
movl 0x20(%rdi), %r8d
movl 0xc(%rdi), %r9d
shll $0x3, %r9d
addl %r9d, %r8d
imull %r8d, %esi
addl %esi, %ecx
subl 0xc(%rdi), %ecx
movl 0xc(%rdi), %r8d
xorl %r9d, %r9d
movsbl %al, %esi
callq 0x2b10
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x313a
jmp 0x31af
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x3129
movq -0x58(%rbp), %rdi
movl 0x14(%rdi), %edx
movl 0x8(%rdi), %ecx
movl 0xc(%rdi), %r8d
movl %r8d, %esi
movl %edx, %eax
leal (%rax,%rsi,4), %edx
movl 0x1c(%rdi), %r9d
movl %r9d, %eax
leal (%rax,%rax,2), %eax
addl %eax, %edx
movl 0x20(%rdi), %r9d
movl %r9d, %eax
leal (%rax,%rsi,8), %esi
movl %esi, %eax
leal (%rax,%rax,8), %eax
addl %eax, %ecx
subl %r8d, %ecx
movl $0x1, %esi
xorl %r9d, %r9d
movl %r9d, -0x5c(%rbp)
callq 0x2b10
movl -0x5c(%rbp), %r9d
movq -0x58(%rbp), %rdi
movl 0x14(%rdi), %edx
movl 0x8(%rdi), %esi
movl 0xc(%rdi), %r8d
movl %r8d, %ecx
movl %edx, %eax
leal (%rax,%rcx,4), %edx
movl 0x1c(%rdi), %r10d
movl %r10d, %eax
leal (%rax,%rax,2), %eax
addl %eax, %edx
movl 0x20(%rdi), %r10d
movl %r10d, %eax
leal (%rax,%rcx,8), %ecx
movl %ecx, %eax
leal (%rax,%rax,4), %eax
movl %eax, %ecx
movl %esi, %eax
leal (%rax,%rcx,2), %ecx
subl %r8d, %ecx
movl $0x3, %esi
callq 0x2b10
movq -0x58(%rbp), %rdi
movb $-0x1, -0x12(%rbp)
movw $0xffff, -0x14(%rbp)    # imm = 0xFFFF
movl 0x4(%rdi), %r8d
movl 0x14(%rdi), %ecx
movb -0x12(%rbp), %al
movb %al, -0x16(%rbp)
movw -0x14(%rbp), %ax
movw %ax, -0x18(%rbp)
movb -0x16(%rbp), %al
movb %al, -0x1a(%rbp)
movw -0x18(%rbp), %ax
movw %ax, -0x1c(%rbp)
movzbl -0x1a(%rbp), %eax
shll $0x10, %eax
movzwl -0x1c(%rbp), %r9d
orl %eax, %r9d
xorl %eax, %eax
xorl %edx, %edx
movl %edx, %esi
callq 0x2c50
movl $0x1, -0x20(%rbp)
cmpl $0xb, -0x20(%rbp)
jge 0x3347
movq -0x58(%rbp), %rdi
movl -0x20(%rbp), %esi
decl %esi
movl 0x20(%rdi), %r9d
movl 0x8(%rdi), %edx
movl 0xc(%rdi), %eax
movl %eax, %ecx
movl %r9d, %r8d
leal (%r8,%rcx,8), %r8d
imull %r8d, %esi
addl %esi, %edx
subl %eax, %edx
movl %edx, %eax
leal (%rax,%rcx,8), %eax
movl %eax, -0x24(%rbp)
movl -0x20(%rbp), %edx
movl 0x20(%rdi), %r9d
movl 0x8(%rdi), %eax
movl 0xc(%rdi), %ecx
movl %ecx, %r8d
movl %r9d, %esi
leal (%rsi,%r8,8), %esi
imull %esi, %edx
addl %edx, %eax
subl %ecx, %eax
movl %eax, -0x28(%rbp)
movl -0x24(%rbp), %edx
movl -0x28(%rbp), %eax
addl %eax, %edx
movl %edx, %eax
shrl $0x1f, %eax
addl %eax, %edx
sarl %edx
movb -0x12(%rbp), %al
movb %al, -0x2a(%rbp)
movw -0x14(%rbp), %ax
movw %ax, -0x2c(%rbp)
movb -0x2a(%rbp), %al
movb %al, -0x2e(%rbp)
movw -0x2c(%rbp), %ax
movw %ax, -0x30(%rbp)
movzbl -0x2e(%rbp), %eax
shll $0x10, %eax
movzwl -0x30(%rbp), %ecx
orl %eax, %ecx
xorl %eax, %eax
xorl %esi, %esi
callq 0x2d50
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x329f
movq -0x58(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x58(%rbp), %rcx
movl -0x34(%rbp), %eax
cmpl (%rcx), %eax
jg 0x33a4
movq -0x58(%rbp), %rdi
movl -0x34(%rbp), %esi
movb -0x12(%rbp), %al
movb %al, -0x36(%rbp)
movw -0x14(%rbp), %ax
movw %ax, -0x38(%rbp)
movb -0x36(%rbp), %al
movb %al, -0x3a(%rbp)
movw -0x38(%rbp), %ax
movw %ax, -0x3c(%rbp)
movzbl -0x3a(%rbp), %eax
shll $0x10, %eax
movzwl -0x3c(%rbp), %ecx
orl %eax, %ecx
xorl %eax, %eax
xorl %edx, %edx
callq 0x2e10
movq -0x58(%rbp), %rax
movl 0x1c(%rax), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0x3351
movq -0x58(%rbp), %rdi
movl 0x1c(%rdi), %ecx
addl %ecx, %ecx
movl -0x34(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x34(%rbp)
movl 0x20(%rdi), %esi
movl 0x8(%rdi), %r8d
movl 0xc(%rdi), %eax
movl %eax, %ecx
movl %esi, %edx
leal (%rdx,%rcx,8), %edx
movl %edx, %esi
movl %r8d, %edx
leal (%rdx,%rsi,2), %edx
subl %eax, %edx
movl %edx, %eax
leal (%rax,%rcx,8), %eax
movl %eax, -0x40(%rbp)
movl 0x20(%rdi), %r8d
movl 0x8(%rdi), %eax
movl 0xc(%rdi), %ecx
movl %ecx, %esi
movl %r8d, %edx
leal (%rdx,%rsi,8), %esi
movl %esi, %edx
leal (%rdx,%rdx,2), %edx
addl %edx, %eax
subl %ecx, %eax
movl %eax, -0x44(%rbp)
movl -0x34(%rbp), %esi
movl -0x40(%rbp), %edx
movl -0x44(%rbp), %eax
addl %eax, %edx
movl %edx, %eax
shrl $0x1f, %eax
addl %eax, %edx
sarl %edx
movl 0xc(%rdi), %eax
movl 0x1c(%rdi), %ecx
movl 0x20(%rdi), %r9d
movl %eax, %r8d
movl %r9d, %eax
leal (%rax,%r8,8), %r8d
movl %r8d, %eax
leal (%rax,%rax,4), %r8d
movb -0x12(%rbp), %al
movb %al, -0x46(%rbp)
movw -0x14(%rbp), %ax
movw %ax, -0x48(%rbp)
movb -0x46(%rbp), %al
movb %al, -0x4a(%rbp)
movw -0x48(%rbp), %ax
movw %ax, -0x4c(%rbp)
movzbl -0x4a(%rbp), %eax
shll $0x10, %eax
movzwl -0x4c(%rbp), %r9d
orl %eax, %r9d
callq 0x2c50
movb $0x0, -0x4d(%rbp)
movq -0x58(%rbp), %rdi
movzbl -0x4d(%rbp), %eax
movq %rax, -0x68(%rbp)
addq $0x40, %rdi
callq 0x22d0
movq -0x68(%rbp), %rcx
movq %rax, %rdx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, -0x5d(%rbp)
jae 0x3490
movq -0x58(%rbp), %rcx
movzbl -0x4d(%rbp), %eax
cmpl 0x28(%rcx), %eax
setl %al
movb %al, -0x5d(%rbp)
movb -0x5d(%rbp), %al
testb $0x1, %al
jne 0x349c
jmp 0x3521
movq -0x58(%rbp), %rdi
addq $0x40, %rdi
movzbl -0x4d(%rbp), %eax
movl %eax, %esi
callq 0x2360
movq -0x58(%rbp), %rdi
movb (%rax), %al
movb %al, -0x69(%rbp)
movl 0x14(%rdi), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x70(%rbp)
movl 0x24(%rdi), %eax
shll $0x3, %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl -0x70(%rbp), %edx
movl %eax, %ecx
movb -0x69(%rbp), %al
subl %ecx, %edx
movl 0x4(%rdi), %ecx
subl 0x8(%rdi), %ecx
movl 0x24(%rdi), %esi
shll $0x3, %esi
subl %esi, %ecx
movzbl -0x4d(%rbp), %esi
movl 0x24(%rdi), %r8d
shll $0x3, %r8d
addl $0x4, %r8d
imull %r8d, %esi
subl %esi, %ecx
movl 0x24(%rdi), %r8d
movl $0x1, %r9d
movsbl %al, %esi
callq 0x2b10
movb -0x4d(%rbp), %al
addb $0x1, %al
movb %al, -0x4d(%rbp)
jmp 0x3459
addq $0x70, %rsp
popq %rbp
retq
nopw (%rax,%rax)