// File: /workspace/github_cpp_makefile_star2_O3/lotuskip[P]yuxtapa/client/base.cpp
// Function: Base::init_ncurses()
bool Base::init_ncurses()
{
	short c;
	// First init the animation:
	string full_anim = Config::get_anim();
	for(c = 0; c < num_syms(full_anim); ++c)
		anim_syms.push_back(sym_at(full_anim, c));

	// Then the actual NCurses stuff
	if(!initscr())
	{
		cout << "Failed to init NCurses screen!" << endl;
		return false;
	}

	getmaxyx(stdscr, scr_y, scr_x);
	if(scr_x < MIN_SCREEN_X || scr_y < MIN_SCREEN_Y)
	{
		endwin();
		cout << "Terminal window is too small! Required minimum is "
			<< int(MIN_SCREEN_X) << 'x' << int(MIN_SCREEN_Y) << '.' << endl;
		return false;
	}
	signal(SIGWINCH, update_screen_size);

	start_color();
	raw();
	keypad(stdscr, TRUE);
	noecho();
	timeout(GETCH_TIMEOUT);
	set_escdelay(OUR_ESC_DELAY);
	nonl();

	// init base colours first: (with black background)
	char d;
	char ct[BASE_COLOURS] = { COLOR_BLACK, COLOR_RED, COLOR_GREEN,
		COLOR_YELLOW, COLOR_BLUE, COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE,
		COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_YELLOW, COLOR_BLUE,
		COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE };
	for(c = 0; c < BASE_COLOURS; ++c)
		init_pair(c, ct[c], COLOR_BLACK);

	// figure out colour mode:
	if(can_change_color() && COLORS >= MAX_PREDEF_COLOUR)
	{
		colmode = CM_FULL;
		term_colours = new short[3*(MAX_PREDEF_COLOUR-BASE_COLOURS)];
		for(c = 0; c < MAX_PREDEF_COLOUR-BASE_COLOURS; ++c)
		{
			// store old colours:
			color_content(c+BASE_COLOURS, &term_colours[3*c],
				&term_colours[3*c+1], &term_colours[3*c+2]);
			// and replace with ours:
			init_color(c+BASE_COLOURS, colour[c][0], colour[c][1],
				colour[c][2]); 
		}
		// (see common/col_codes.h)
		for(c = BASE_COLOURS; c < C_BG_HEAL; ++c)
			init_pair(c, c, COLOR_BLACK);
		for(d = 0; d < 6; ++d)
		{
			for(c = 0; c < 7; ++c)
				init_pair(C_GREEN_ON_HEAL+d*7+c, C_BASE_GREEN+c, C_BG_HEAL+d);
		}
		init_pair(C_UNKNOWN, C_WALL_DIM, C_WALL_DIM); 
	}
	else if(COLORS >= MAX_PREDEF_COLOUR) // immutable multi-colour
	{
		colmode = CM_MANY;
		for(c = BASE_COLOURS; c < C_BG_HEAL; ++c)
			init_pair(c, fixed_remap[c-BASE_COLOURS], COLOR_BLACK);
		for(d = 0; d < 6; ++d)
		{
			for(c = 0; c < 7; ++c)
				init_pair(C_GREEN_ON_HEAL+d*7+c, fixed_fgc[c], fixed_bgc[d]);
		}
		init_pair(C_UNKNOWN, 8, 8);
	}
	else // only 8+8 colours
	{
		colmode = CM_FEW;
		// Init the pairs with non-black background
		for(d = 0; d < 6; ++d)
		{
			for(c = 0; c < 7; ++c)
				init_pair(BASE_COLOURS+d*7+c, fgc[c], bgc[d]);
		}
		init_pair(BASE_COLOURS+6*7, BASE_LIGHT_GRAY, BASE_LIGHT_GRAY);
	}
	
	// (ysize, xsize, ypos, xpos)
	windows[STAT_WIN] = newwin(VIEWSIZE - MSG_WIN_Y, MIN_SCREEN_X - VIEWSIZE, 0, 0);
	windows[VIEW_WIN] = newwin(VIEWSIZE, VIEWSIZE, 0, MIN_SCREEN_X - VIEWSIZE);
	windows[MSG_WIN] = newwin(MSG_WIN_Y, MSG_WIN_X, VIEWSIZE - MSG_WIN_Y, 0);
	windows[CHAT_WIN] = newwin(scr_y - VIEWSIZE, scr_x, VIEWSIZE, 0);

	refresh();
	flushinp();
	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
callq 0xdffe
leaq -0x58(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq -0x68(%rbp), %rbx
movq %rbx, %rdi
callq 0x731a
xorl %r14d, %r14d
leaq -0x38(%rbp), %r13
leaq -0x48(%rbp), %r15
leaq 0x1163e(%rip), %r12     # 0x17940
movq %rbx, %rdi
callq 0xf738
cwtl
cmpl %eax, %r14d
jge 0x6343
movq %r15, %rdi
movq %rbx, %rsi
movl %r14d, %edx
callq 0xf765
movq %r12, %rdi
movq %r15, %rsi
callq 0x73b8
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
je 0x633e
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x4390
incl %r14d
jmp 0x6302
callq 0x42b0
testq %rax, %rax
je 0x6370
movq 0x10c6c(%rip), %rbx     # 0x16fc0
movq (%rbx), %rcx
testq %rcx, %rcx
je 0x63a4
movl 0x4(%rcx), %eax
incl %eax
movzwl 0x6(%rcx), %edx
incl %edx
cmpw $0x18, %ax
setb %cl
jmp 0x63ae
movq 0x10c51(%rip), %rbx     # 0x16fc8
leaq 0x9c86(%rip), %rsi      # 0x10004
movl $0x1e, %edx
movq %rbx, %rdi
callq 0x4410
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4360
jmp 0x6447
movw $0xffff, %ax            # imm = 0xFFFF
xorl %ecx, %ecx
movw $0xffff, %dx            # imm = 0xFFFF
movw %ax, 0x115a3(%rip)      # 0x17958
movw %dx, 0x1159e(%rip)      # 0x1795a
cmpw $0x50, %dx
setb %al
orb %cl, %al
testb $0x1, %al
je 0x6461
callq 0x46a0
movq 0x10bef(%rip), %rdi     # 0x16fc8
leaq 0x9c43(%rip), %rsi      # 0x10023
movl $0x32, %edx
callq 0x4410
movq 0x10bd7(%rip), %rdi     # 0x16fc8
movl $0x50, %esi
callq 0x4640
leaq -0x48(%rbp), %rsi
movb $0x78, (%rsi)
movl $0x1, %edx
movq %rax, %rdi
callq 0x4410
movq %rax, %rdi
movl $0x18, %esi
callq 0x4640
leaq -0x48(%rbp), %rsi
movb $0x2e, (%rsi)
movl $0x1, %edx
movq %rax, %rdi
callq 0x4410
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4360
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x4250
xorl %ebx, %ebx
jmp 0x673c
leaq 0x350(%rip), %rsi       # 0x67b8
movl $0x1c, %edi
callq 0x4450
callq 0x4220
callq 0x4130
movq (%rbx), %rdi
movl $0x1, %esi
callq 0x4170
callq 0x46f0
movq (%rbx), %rdi
movl $0x28, %esi
callq 0x4430
movl $0x14, %edi
callq 0x4350
callq 0x4590
xorl %ebx, %ebx
leaq 0x9c2d(%rip), %r14      # 0x100e0
movsbl (%rbx,%r14), %esi
movswl %bx, %edi
xorl %edx, %edx
callq 0x4240
incq %rbx
cmpq $0x10, %rbx
jne 0x64b3
callq 0x4720
movq 0x10af9(%rip), %rcx     # 0x16fd0
movl (%rcx), %ecx
cmpl $0x50, %ecx
setge %dl
andb %dl, %al
cmpb $0x1, %al
jne 0x65c2
movl $0x0, 0x11469(%rip)     # 0x1795c
movl $0x180, %edi            # imm = 0x180
callq 0x4030
movq %rax, 0x1145c(%rip)     # 0x17960
movw $0x10, %r14w
movl $0x4, %r15d
leaq 0x9bda(%rip), %r12      # 0x100f0
movq 0x11443(%rip), %rax     # 0x17960
leaq (%rax,%r15), %rcx
leaq (%rax,%r15), %rsi
addq $-0x4, %rsi
leaq -0x2(%rax,%r15), %rdx
movswl %r14w, %ebx
movl %ebx, %edi
callq 0x4180
movswl -0x4(%r15,%r12), %esi
movswl -0x2(%r15,%r12), %edx
movswl (%r15,%r12), %ecx
movl %ebx, %edi
callq 0x4570
incl %r14d
addq $0x6, %r15
cmpq $0x184, %r15            # imm = 0x184
jne 0x6516
movw $0x10, %bx
movswl %bx, %edi
movl %edi, %esi
xorl %edx, %edx
callq 0x4240
incl %ebx
cmpw $0x43, %bx
jne 0x6565
movw $0x43, %r14w
xorl %r15d, %r15d
leal 0x43(%r15), %eax
xorl %r12d, %r12d
movswl %ax, %ebx
leal (%r14,%r12), %eax
leal 0x49(%r12), %ecx
movswl %ax, %edi
movswl %cx, %esi
movl %ebx, %edx
callq 0x4240
incl %r12d
cmpw $0x7, %r12w
jne 0x658b
incl %r15d
addl $0x7, %r14d
cmpw $0x6, %r15w
jne 0x6581
movw $0x13, %ax
jmp 0x6648
cmpl $0x50, %ecx
jl 0x664e
movl $0x1, 0x11387(%rip)     # 0x1795c
xorl %ebx, %ebx
leaq 0x9c92(%rip), %r14      # 0x10270
movzbl (%rbx,%r14), %esi
leal 0x10(%rbx), %eax
movswl %ax, %edi
xorl %edx, %edx
callq 0x4240
incq %rbx
cmpq $0x33, %rbx
jne 0x65de
movl $0x43, %r14d
xorl %r15d, %r15d
leaq 0x9c9a(%rip), %r13      # 0x102a3
leaq 0x9c9a(%rip), %rax      # 0x102aa
movzbl (%r15,%rax), %eax
movzwl %ax, %ebx
xorl %r12d, %r12d
movzbl (%r12,%r13), %esi
leal (%r14,%r12), %eax
movswl %ax, %edi
movl %ebx, %edx
callq 0x4240
incq %r12
cmpq $0x7, %r12
jne 0x661b
incq %r15
addq $0x7, %r14
cmpq $0x6, %r15
jne 0x6609
movw $0x8, %ax
movw $0x6d, %cx
jmp 0x66ab
movl $0x2, 0x11304(%rip)     # 0x1795c
movl $0x10, %r14d
xorl %r15d, %r15d
leaq 0x9c48(%rip), %r13      # 0x102b0
leaq 0x9c48(%rip), %rax      # 0x102b7
movsbl (%r15,%rax), %eax
movswl %ax, %ebx
xorl %r12d, %r12d
movsbl (%r12,%r13), %esi
leal (%r14,%r12), %eax
movswl %ax, %edi
movl %ebx, %edx
callq 0x4240
incq %r12
cmpq $0x7, %r12
jne 0x667a
incq %r15
addq $0x7, %r14
cmpq $0x6, %r15
jne 0x6668
movw $0x7, %ax
movw $0x3a, %cx
movzwl %cx, %edi
movzwl %ax, %edx
movl %edx, %esi
callq 0x4240
movl $0x8, %edi
movl $0x39, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x4370
movq %rax, 0x1129e(%rip)     # 0x17970
movl $0x17, %edi
movl $0x17, %esi
xorl %edx, %edx
movl $0x39, %ecx
callq 0x4370
movq %rax, 0x11299(%rip)     # 0x17988
movl $0xf, %edi
movl $0x39, %esi
movl $0x8, %edx
xorl %ecx, %ecx
callq 0x4370
movq %rax, 0x11274(%rip)     # 0x17980
movzwl 0x11245(%rip), %edi     # 0x17958
addl $-0x17, %edi
movzwl 0x1123d(%rip), %esi     # 0x1795a
movl $0x17, %edx
xorl %ecx, %ecx
callq 0x4370
movq %rax, 0x11248(%rip)     # 0x17978
callq 0x40b0
movb $0x1, %bl
callq 0x41a0
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x6755
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x4390
movl %ebx, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x6794
jmp 0x6794
jmp 0x6794
jmp 0x6794
jmp 0x6794
jmp 0x6794
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
je 0x6797
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x4390
jmp 0x6797
jmp 0x6794
jmp 0x6794
jmp 0x6794
jmp 0x6794
movq %rax, %rbx
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x67b0
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x4390
movq %rbx, %rdi
callq 0x4660