// File: /workspace/github_cpp_makefile_star2_O2/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 0x5390
movq %rax, (%rbx)
testq %rax, %rax
je 0x10190
movslq 0xe0(%rax), %r10
movl %r10d, 0x10(%rbx)
movq 0xe8(%rax), %r11
shlq $0x7, %r10
movq 0x10(%r11,%r10), %rsi
subq $0x8, %rsp
pushq $0xa
popq %rcx
movq %rax, %rdi
movl %ecx, %edx
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 0x51d0
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
callq 0x5520
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 0x5190
movq %rax, 0x18(%rbx)
movq (%rbx), %rdi
leaq 0x1a7f(%rip), %rsi      # 0x11af4
callq 0x5560
movq (%rbx), %rdi
callq 0x5420
movq (%rbx), %rdi
callq 0x5420
leaq 0x1aaf(%rip), %rsi      # 0x11b40
pushq $0x79
popq %rcx
leaq 0x70(%rsp), %r15
movq %r15, %rdi
rep  movsb (%rsi), %es:(%rdi)
movq (%rbx), %rax
movq 0xe8(%rax), %rcx
movslq 0xe0(%rax), %rax
shlq $0x7, %rax
movq 0x50(%rcx,%rax), %r12
pushq $0x4
popq %rbp
leaq 0x10(%rsp), %r13
movq (%rbx), %rdi
cmpq $0xf, %rbp
je 0x100f7
movq %r12, %rsi
movq %r15, %rdx
movq %r13, %rcx
callq 0x5210
movq (%rbx), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x5250
movq 0x10(%rsp), %rax
movq %rax, (%rbx,%rbp,8)
incq %rbp
addq $0xb, %r15
jmp 0x100c0
movq 0x18(%rbx), %rsi
movq 0x28(%rbx), %rdx
callq 0x5110
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 0x5200
movq (%rbx), %rdi
pushq $0x1
popq %rsi
callq 0x5100
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
movl $0x8000, %edx           # imm = 0x8000
callq 0x51d0
movq (%rbx), %rdi
callq 0x5420
movq (%rbx), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x53d0
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
xorl %edx, %edx
callq 0x51d0
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xbe51(%rip), %rdi      # 0x1bfe8
leaq 0x1942(%rip), %rsi      # 0x11ae0
callq 0x5290
movq %rax, %rdi
callq 0x5160
pushq $0x1
popq %rdi
callq 0x5320
nop