// File: magmastonealex[P]fbkeyboard/src/Display.cpp
// Function: Display::Display(int, int, int)
Display::Display(int width, int height, int dpi) : width{width}, height{height}, dpi{dpi} {
	keyboardImage = new ImageRGB();
	keyboardImage->w = width;
	keyboardImage->h = height;
	keyboardImage->data = new RGB[width*height];

	//Initialize background to grey.
	//Doing not-grey would be much slower.
	memset((unsigned char*) keyboardImage->data, 0x70, width*height*3);

	margin = width / 33;
	scale = dpi / 34;

	entryWidth = dpi/3;

	keyboardWidth = width - entryWidth;

	rowWidth = keyboardWidth/4;

	stepSizePx = (height-(2*margin) - (11*8*scale))/10;

	kbScale = scale-2;

	if(kbScale < 0) {
    	kbScale = 1;
    }

    maxlen = (height-(2*margin)) / ((scale*8) + 4);

    currentKeyboard = &LCkeyboard;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x38(%rbp)
movl -0xc(%rbp), %eax
movl %eax, (%rdi)
movl -0x10(%rbp), %eax
movl %eax, 0x4(%rdi)
movl -0x14(%rbp), %eax
movl %eax, 0x10(%rdi)
addq $0x40, %rdi
movq %rdi, -0x40(%rbp)
callq 0x2290
movq -0x38(%rbp), %rax
movups 0x2a5e(%rip), %xmm0     # 0x5014
movups %xmm0, 0x78(%rax)
movups 0x2a43(%rip), %xmm0     # 0x5004
movups %xmm0, 0x68(%rax)
movb $0x0, 0x88(%rax)
movups 0x2a62(%rip), %xmm0     # 0x5035
movups %xmm0, 0x99(%rax)
movups 0x2a44(%rip), %xmm0     # 0x5025
movups %xmm0, 0x89(%rax)
movb $0x0, 0xa9(%rax)
movups 0x2a60(%rip), %xmm0     # 0x5056
movups %xmm0, 0xba(%rax)
movups 0x2a42(%rip), %xmm0     # 0x5046
movups %xmm0, 0xaa(%rax)
movb $0x7c, 0xca(%rax)
movups 0x2a5e(%rip), %xmm0     # 0x5077
movups %xmm0, 0xdb(%rax)
movups 0x2a40(%rip), %xmm0     # 0x5067
movups %xmm0, 0xcb(%rax)
movb $0x0, 0xeb(%rax)
movl $0x10, %edi
callq 0x21c0
movq %rax, -0x30(%rbp)
jmp 0x2645
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
xorps %xmm0, %xmm0
movaps %xmm0, (%rcx)
movq %rcx, 0x30(%rax)
movl -0xc(%rbp), %edx
movq 0x30(%rax), %rcx
movl %edx, (%rcx)
movl -0x10(%rbp), %ecx
movq 0x30(%rax), %rax
movl %ecx, 0x4(%rax)
movl -0xc(%rbp), %eax
movl -0x10(%rbp), %ecx
imull %ecx, %eax
cltq
movl $0x3, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
callq 0x2030
movq %rax, -0x48(%rbp)
jmp 0x2696
movq -0x38(%rbp), %rax
movq -0x48(%rbp), %rdx
movq 0x30(%rax), %rcx
movq %rdx, 0x8(%rcx)
movq 0x30(%rax), %rax
movq 0x8(%rax), %rdi
movl -0xc(%rbp), %eax
imull -0x10(%rbp), %eax
imull $0x3, %eax, %eax
movslq %eax, %rdx
movl $0x70, %esi
callq 0x20f0
movq -0x38(%rbp), %rcx
movl -0xc(%rbp), %eax
movl $0x21, %esi
cltd
idivl %esi
movl %eax, 0x8(%rcx)
movl -0x14(%rbp), %eax
movl $0x22, %esi
cltd
idivl %esi
movl %eax, 0xc(%rcx)
movl -0x14(%rbp), %eax
movl $0x3, %esi
cltd
idivl %esi
movl %eax, 0x14(%rcx)
movl -0xc(%rbp), %eax
subl 0x14(%rcx), %eax
movl %eax, 0x18(%rcx)
movl 0x18(%rcx), %eax
movl $0x4, %esi
cltd
idivl %esi
movl %eax, 0x1c(%rcx)
movl -0x10(%rbp), %eax
movl 0x8(%rcx), %edx
shll %edx
subl %edx, %eax
imull $0x58, 0xc(%rcx), %ecx
subl %ecx, %eax
movl $0xa, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x20(%rax)
movl 0xc(%rax), %ecx
subl $0x2, %ecx
movl %ecx, 0x24(%rax)
cmpl $0x0, 0x24(%rax)
jge 0x275e
movq -0x38(%rbp), %rax
movl $0x1, 0x24(%rax)
jmp 0x275e
movq -0x40(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
callq 0x2120
jmp 0x2792
movq -0x38(%rbp), %rcx
movl -0x10(%rbp), %eax
movl 0x8(%rcx), %edx
shll %edx
subl %edx, %eax
movl 0xc(%rcx), %ecx
shll $0x3, %ecx
addl $0x4, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x28(%rax)
movq %rax, %rcx
addq $0x68, %rcx
movq %rcx, 0x60(%rax)
addq $0x50, %rsp
popq %rbp
retq
movq -0x20(%rbp), %rdi
callq 0x2330
nopl (%rax,%rax)