// File: /workspace/github_cpp_makefile_star2_O1/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 0xe07d
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 0x731c
xorl %r14d, %r14d
leaq -0x38(%rbp), %r13
leaq -0x48(%rbp), %r15
leaq 0x115fe(%rip), %r12     # 0x17940
movq %rbx, %rdi
callq 0xf89c
cwtl
cmpl %eax, %r14d
jge 0x6383
movq %r15, %rdi
movq %rbx, %rsi
movl %r14d, %edx
callq 0xf8c6
movq %r12, %rdi
movq %r15, %rsi
callq 0x73b6
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
je 0x637e
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x43a0
incl %r14d
jmp 0x6342
callq 0x42b0
testq %rax, %rax
je 0x645a
movq 0x10c28(%rip), %rbx     # 0x16fc0
movq (%rbx), %rdx
movw $0xffff, %cx            # imm = 0xFFFF
movw $0xffff, %ax            # imm = 0xFFFF
testq %rdx, %rdx
je 0x63ad
movl 0x4(%rdx), %eax
incl %eax
movw %ax, 0x115a4(%rip)      # 0x17958
testq %rdx, %rdx
je 0x63bf
movzwl 0x6(%rdx), %ecx
incl %ecx
movw %cx, 0x11594(%rip)      # 0x1795a
cmpw $0x50, %cx
setb %cl
cmpw $0x18, %ax
setb %al
orb %cl, %al
cmpb $0x1, %al
jne 0x64a3
callq 0x46b0
movq 0x10bde(%rip), %rdi     # 0x16fc8
leaq 0x9c32(%rip), %rsi      # 0x10023
movl $0x32, %edx
callq 0x4420
movq 0x10bc6(%rip), %rdi     # 0x16fc8
movl $0x50, %esi
callq 0x4650
leaq -0x48(%rbp), %rsi
movb $0x78, (%rsi)
movl $0x1, %edx
movq %rax, %rdi
callq 0x4420
movq %rax, %rdi
movl $0x18, %esi
callq 0x4650
leaq -0x48(%rbp), %rsi
movb $0x2e, (%rsi)
movl $0x1, %edx
movq %rax, %rdi
callq 0x4420
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4370
jmp 0x6489
movq 0x10b67(%rip), %rbx     # 0x16fc8
leaq 0x9b9c(%rip), %rsi      # 0x10004
movl $0x1e, %edx
movq %rbx, %rdi
callq 0x4420
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4370
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x4250
xorl %ebx, %ebx
jmp 0x677e
leaq 0x350(%rip), %rsi       # 0x67fa
movl $0x1c, %edi
callq 0x4460
callq 0x4220
callq 0x4130
movq (%rbx), %rdi
movl $0x1, %esi
callq 0x4170
callq 0x4700
movq (%rbx), %rdi
movl $0x28, %esi
callq 0x4440
movl $0x14, %edi
callq 0x4360
callq 0x45a0
xorl %ebx, %ebx
leaq 0x9beb(%rip), %r14      # 0x100e0
movsbl (%rbx,%r14), %esi
movswl %bx, %edi
xorl %edx, %edx
callq 0x4240
incq %rbx
cmpq $0x10, %rbx
jne 0x64f5
callq 0x4730
movq 0x10ab7(%rip), %rcx     # 0x16fd0
movl (%rcx), %ecx
cmpl $0x50, %ecx
setge %dl
andb %dl, %al
cmpb $0x1, %al
jne 0x6604
movl $0x0, 0x11427(%rip)     # 0x1795c
movl $0x180, %edi            # imm = 0x180
callq 0x4030
movq %rax, 0x1141a(%rip)     # 0x17960
movl $0x4, %r14d
movw $0x10, %r15w
leaq 0x9b98(%rip), %r12      # 0x100f0
movq 0x11401(%rip), %rax     # 0x17960
leaq (%rax,%r14), %rcx
leaq (%rax,%r14), %rsi
addq $-0x4, %rsi
leaq -0x2(%rax,%r14), %rdx
movswl %r15w, %ebx
movl %ebx, %edi
callq 0x4180
movswl -0x4(%r14,%r12), %esi
movswl -0x2(%r14,%r12), %edx
movswl (%r14,%r12), %ecx
movl %ebx, %edi
callq 0x4580
addq $0x6, %r14
incl %r15d
cmpq $0x184, %r14            # imm = 0x184
jne 0x6558
movw $0x10, %bx
movswl %bx, %edi
movl %edi, %esi
xorl %edx, %edx
callq 0x4240
incl %ebx
cmpw $0x43, %bx
jne 0x65a7
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 0x65cd
incl %r15d
addl $0x7, %r14d
cmpw $0x6, %r15w
jne 0x65c3
movw $0x13, %ax
jmp 0x668a
cmpl $0x50, %ecx
jl 0x6690
movl $0x1, 0x11345(%rip)     # 0x1795c
xorl %ebx, %ebx
leaq 0x9c50(%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 0x6620
movl $0x43, %r14d
xorl %r15d, %r15d
leaq 0x9c58(%rip), %r13      # 0x102a3
leaq 0x9c58(%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 0x665d
incq %r15
addq $0x7, %r14
cmpq $0x6, %r15
jne 0x664b
movw $0x8, %ax
movw $0x6d, %cx
jmp 0x66ed
movl $0x2, 0x112c2(%rip)     # 0x1795c
movl $0x10, %r14d
xorl %r15d, %r15d
leaq 0x9c06(%rip), %r13      # 0x102b0
leaq 0x9c06(%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 0x66bc
incq %r15
addq $0x7, %r14
cmpq $0x6, %r15
jne 0x66aa
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 0x4380
movq %rax, 0x1125c(%rip)     # 0x17970
movl $0x17, %edi
movl $0x17, %esi
xorl %edx, %edx
movl $0x39, %ecx
callq 0x4380
movq %rax, 0x11257(%rip)     # 0x17988
movl $0xf, %edi
movl $0x39, %esi
movl $0x8, %edx
xorl %ecx, %ecx
callq 0x4380
movq %rax, 0x11232(%rip)     # 0x17980
movzwl 0x11203(%rip), %edi     # 0x17958
addl $-0x17, %edi
movzwl 0x111fb(%rip), %esi     # 0x1795a
movl $0x17, %edx
xorl %ecx, %ecx
callq 0x4380
movq %rax, 0x11206(%rip)     # 0x17978
callq 0x40b0
movb $0x1, %bl
callq 0x41a0
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x6797
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x43a0
movl %ebx, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x67d6
jmp 0x67d6
jmp 0x67d6
jmp 0x67d6
jmp 0x67d6
jmp 0x67d6
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
je 0x67d9
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x43a0
jmp 0x67d9
jmp 0x67d6
jmp 0x67d6
jmp 0x67d6
jmp 0x67d6
movq %rax, %rbx
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x67f2
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x43a0
movq %rbx, %rdi
callq 0x4670