// File: /workspace/github_cpp_makefile_star2_O3/MatthewZMD[P]TetrisDual/window.cc
// Function: Xwindow::Xwindow(int, int)
Xwindow::Xwindow(int width, int height): width{width}, height{height} {

	d = XOpenDisplay(NULL);
	if (d == NULL) {
		cerr << "Cannot open display" << endl;
		exit(1);
	}
	s = DefaultScreen(d);
	w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, width, height, 1,
			BlackPixel(d, s), WhitePixel(d, s));
	XSelectInput(d, w, ExposureMask | KeyPressMask);
	XMapRaised(d, w);

	Pixmap pix = XCreatePixmap(d,w,width,
			height,DefaultDepth(d,DefaultScreen(d)));
	gc = XCreateGC(d, pix, 0,(XGCValues *)0);

	Font thefont = XLoadFont(d, "*-fixed-*-*-*-*-*-*-*-*-*-*-*-*");
	XFlush(d);
	XFlush(d);


	// Set up colours.
	XColor xcolour;
	Colormap cmap;
	char color_vals[11][11] = {"white",  "black", "red",      "green",
		"blue",   "cyan",  "yellow",   "magenta",
		"orange", "brown", "darkgreen"};

	cmap=DefaultColormap(d,DefaultScreen(d));
	for(int i=0; i < 11; ++i) {
		XParseColor(d,cmap,color_vals[i],&xcolour);
		XAllocColor(d,cmap,&xcolour);
		colours[i]=xcolour.pixel;
	}

	XSetForeground(d,gc,colours[Black]);

	// Make window non-resizeable.
	XSizeHints hints;
	hints.flags = (USPosition | PSize | PMinSize | PMaxSize );
	hints.height = hints.base_height = hints.min_height = hints.max_height = height;
	hints.width = hints.base_width = hints.min_width = hints.max_width = width;
	XSetNormalHints(d, w, &hints);

	XSynchronize(d, True);

	XSelectInput(d, w, ExposureMask);
	XFlush(d);
	XEvent event;
	XNextEvent(d, &event); // Hang until the window is ready.
	XSelectInput(d, w, 0);

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1b8, %rsp            # imm = 0x1B8
movl %edx, %r14d
movl %esi, %ebp
movq %rdi, %rbx
movl %esi, 0x78(%rdi)
movl %edx, 0x7c(%rdi)
xorl %edi, %edi
callq 0x53a0
movq %rax, (%rbx)
testq %rax, %rax
je 0x11ade
movslq 0xe0(%rax), %r10
movl %r10d, 0x10(%rbx)
movq 0xe8(%rax), %r11
shlq $0x7, %r10
movq 0x10(%r11,%r10), %rsi
subq $0x8, %rsp
movq %rax, %rdi
movl $0xa, %edx
movl $0xa, %ecx
movl %ebp, %r8d
movl %r14d, %r9d
pushq 0x58(%r11,%r10)
pushq 0x60(%r11,%r10)
pushq $0x1
callq 0x50e0
addq $0x20, %rsp
movq %rax, 0x8(%rbx)
movq (%rbx), %rdi
movl $0x8001, %edx           # imm = 0x8001
movq %rax, %rsi
callq 0x51f0
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
callq 0x5550
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
movq 0xe8(%rdi), %rax
movslq 0xe0(%rdi), %rcx
shlq $0x7, %rcx
movl 0x38(%rax,%rcx), %r8d
movl %ebp, 0xc(%rsp)
movl %ebp, %edx
movl %r14d, %ecx
callq 0x50a0
movq (%rbx), %rdi
movq %rax, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x51b0
movq %rax, 0x18(%rbx)
movq (%rbx), %rdi
leaq 0x224e(%rip), %rsi      # 0x13c04
callq 0x5560
movq (%rbx), %rdi
callq 0x5430
movq (%rbx), %rdi
callq 0x5430
leaq 0x227e(%rip), %rsi      # 0x13c50
leaq 0x70(%rsp), %r15
movl $0xf, %ecx
movq %r15, %rdi
rep  movsq (%rsi), %es:(%rdi)
movb $0x0, 0x78(%r15)
movq (%rbx), %rax
movq 0xe8(%rax), %rcx
movslq 0xe0(%rax), %rax
shlq $0x7, %rax
movq 0x50(%rcx,%rax), %r12
movl $0x4, %ebp
leaq 0x10(%rsp), %r13
movq (%rbx), %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %r13, %rcx
callq 0x5240
movq (%rbx), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x5280
movq 0x10(%rsp), %rax
movq %rax, (%rbx,%rbp,8)
incq %rbp
addq $0xb, %r15
cmpq $0xf, %rbp
jne 0x11a0b
movq (%rbx), %rdi
movq 0x18(%rbx), %rsi
movq 0x28(%rbx), %rdx
callq 0x5130
leaq 0x20(%rsp), %rdx
movq $0x39, (%rdx)
movl %r14d, 0x24(%rdx)
movl %r14d, 0x1c(%rdx)
movl %r14d, 0x44(%rdx)
movl %r14d, 0x14(%rdx)
movl 0xc(%rsp), %eax
movl %eax, 0x20(%rdx)
movl %eax, 0x18(%rdx)
movl %eax, 0x40(%rdx)
movl %eax, 0x10(%rdx)
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
callq 0x5230
movq (%rbx), %rdi
movl $0x1, %esi
callq 0x5110
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
movl $0x8000, %edx           # imm = 0x8000
callq 0x51f0
movq (%rbx), %rdi
callq 0x5430
movq (%rbx), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x53e0
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
xorl %edx, %edx
callq 0x51f0
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xa503(%rip), %rdi      # 0x1bfe8
leaq 0x2104(%rip), %rsi      # 0x13bf0
callq 0x52c0
movq %rax, %rdi
callq 0x5170
movl $0x1, %edi
callq 0x5340
nop