// File: /workspace/github_cpp_makefile_star2_O2/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 0xb9bf
leaq -0x48(%rbp), %rbx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x4520
xorl %r14d, %r14d
leaq -0x68(%rbp), %r15
leaq 0x10c41(%rip), %r12     # 0x16940
movq %rbx, %rdi
callq 0xd028
cwtl
cmpl %eax, %r14d
jge 0x5d33
movq %r15, %rdi
movq %rbx, %rsi
movl %r14d, %edx
callq 0xd04f
movq %r12, %rdi
movq %r15, %rsi
callq 0x6b8a
movq %r15, %rdi
callq 0x4748
incl %r14d
jmp 0x5cff
callq 0x42d0
testq %rax, %rax
je 0x5d60
movq 0x1027c(%rip), %rbx     # 0x15fc0
movq (%rbx), %rcx
testq %rcx, %rcx
je 0x5d75
movl 0x4(%rcx), %eax
incl %eax
movzwl 0x6(%rcx), %edx
incl %edx
cmpw $0x18, %ax
setb %cl
jmp 0x5d7f
movq 0x10261(%rip), %rdi     # 0x15fc8
leaq 0x82a6(%rip), %rsi      # 0xe014
callq 0x4390
jmp 0x5dde
movw $0xffff, %ax            # imm = 0xFFFF
xorl %ecx, %ecx
movw $0xffff, %dx            # imm = 0xFFFF
movw %ax, 0x10bd2(%rip)      # 0x16958
movw %dx, 0x10bcd(%rip)      # 0x1695a
cmpw $0x50, %dx
setb %al
orb %cl, %al
testb $0x1, %al
je 0x5ded
callq 0x4690
movq 0x10222(%rip), %rdi     # 0x15fc8
leaq 0x8286(%rip), %rsi      # 0xe033
callq 0x4390
pushq $0x50
popq %rsi
movq %rax, %rdi
callq 0x4640
pushq $0x78
popq %rsi
movq %rax, %rdi
callq 0x4440
pushq $0x18
popq %rsi
movq %rax, %rdi
callq 0x4640
pushq $0x2e
popq %rsi
movq %rax, %rdi
callq 0x4440
movq %rax, %rdi
callq 0x41f0
xorl %ebx, %ebx
jmp 0x60c1
leaq 0x31d(%rip), %rsi       # 0x6111
pushq $0x1c
popq %rdi
callq 0x4450
callq 0x4240
callq 0x4140
movq (%rbx), %rdi
pushq $0x1
popq %rsi
callq 0x4180
callq 0x46e0
movq (%rbx), %rdi
pushq $0x28
popq %rsi
callq 0x4430
pushq $0x14
popq %rdi
callq 0x4370
callq 0x45a0
xorl %ebx, %ebx
leaq 0x82b9(%rip), %r14      # 0xe0f0
cmpq $0x10, %rbx
je 0x5e51
movsbl (%rbx,%r14), %esi
movswl %bx, %edi
xorl %edx, %edx
callq 0x4260
incq %rbx
jmp 0x5e37
callq 0x4730
movq 0x10173(%rip), %rcx     # 0x15fd0
movl (%rcx), %ecx
cmpl $0x50, %ecx
setge %dl
andb %dl, %al
cmpb $0x1, %al
jne 0x5ee4
andl $0x0, 0x10aea(%rip)     # 0x1695c
movl $0x180, %edi            # imm = 0x180
callq 0x4030
movq %rax, 0x10add(%rip)     # 0x16960
movw $0x10, %r14w
pushq $0x4
popq %r15
leaq 0x826d(%rip), %r12      # 0xe100
cmpq $0x184, %r15            # imm = 0x184
je 0x5f21
movq 0x10ab9(%rip), %rax     # 0x16960
leaq (%rax,%r15), %rcx
leaq (%rax,%r15), %rsi
addq $-0x4, %rsi
leaq -0x2(%rax,%r15), %rdx
movswl %r14w, %ebx
movl %ebx, %edi
callq 0x4190
movswl -0x4(%r15,%r12), %esi
movswl -0x2(%r15,%r12), %edx
movswl (%r15,%r12), %ecx
movl %ebx, %edi
callq 0x4580
incl %r14d
addq $0x6, %r15
jmp 0x5e93
cmpl $0x50, %ecx
jl 0x5f89
movl $0x1, 0x10a65(%rip)     # 0x1695c
xorl %ebx, %ebx
leaq 0x8380(%rip), %r14      # 0xe280
cmpq $0x33, %rbx
je 0x5fe4
movzbl (%rbx,%r14), %esi
leal 0x10(%rbx), %eax
movswl %ax, %edi
xorl %edx, %edx
callq 0x4260
incq %rbx
jmp 0x5f00
movw $0x10, %bx
cmpw $0x43, %bx
je 0x5f3b
movswl %bx, %edi
movl %edi, %esi
xorl %edx, %edx
callq 0x4260
incl %ebx
jmp 0x5f25
movw $0x43, %r14w
xorl %r15d, %r15d
cmpw $0x6, %r15w
je 0x5f80
leal 0x43(%r15), %eax
xorl %r12d, %r12d
movswl %ax, %ebx
cmpw $0x7, %r12w
je 0x5f77
leal (%r14,%r12), %eax
addl $0x49, %r12d
movswl %ax, %edi
movswl %r12w, %esi
movl %ebx, %edx
callq 0x4260
addl $-0x48, %r12d
jmp 0x5f54
incl %r15d
addl $0x7, %r14d
jmp 0x5f43
movw $0x13, %ax
jmp 0x603f
movl $0x2, 0x109c9(%rip)     # 0x1695c
pushq $0x10
popq %r14
xorl %r15d, %r15d
leaq 0x831f(%rip), %r13      # 0xe2c0
cmpq $0x6, %r15
je 0x6031
leaq 0x8315(%rip), %rax      # 0xe2c7
movsbl (%r15,%rax), %eax
movswl %ax, %ebx
xorl %r12d, %r12d
cmpq $0x7, %r12
je 0x5fdb
movsbl (%r12,%r13), %esi
leal (%r14,%r12), %eax
movswl %ax, %edi
movl %ebx, %edx
callq 0x4260
incq %r12
jmp 0x5fbd
incq %r15
addq $0x7, %r14
jmp 0x5fa1
pushq $0x43
popq %r14
xorl %r15d, %r15d
leaq 0x82c1(%rip), %r13      # 0xe2b3
cmpq $0x6, %r15
je 0x603b
leaq 0x82bb(%rip), %rax      # 0xe2ba
movzbl (%r15,%rax), %eax
movzwl %ax, %ebx
xorl %r12d, %r12d
cmpq $0x7, %r12
je 0x6028
movzbl (%r12,%r13), %esi
leal (%r14,%r12), %eax
movswl %ax, %edi
movl %ebx, %edx
callq 0x4260
incq %r12
jmp 0x600a
incq %r15
addq $0x7, %r14
jmp 0x5ff2
movw $0x7, %ax
movw $0x3a, %cx
jmp 0x6043
movw $0x8, %ax
movw $0x6d, %cx
movzwl %cx, %edi
movzwl %ax, %edx
movl %edx, %esi
callq 0x4260
pushq $0x8
popq %rdi
pushq $0x39
popq %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x4380
movq %rax, 0x1090a(%rip)     # 0x16970
pushq $0x17
popq %rdi
pushq $0x39
popq %rcx
movl %edi, %esi
xorl %edx, %edx
callq 0x4380
movq %rax, 0x1090c(%rip)     # 0x16988
pushq $0xf
popq %rdi
pushq $0x39
popq %rsi
pushq $0x8
popq %rdx
xorl %ecx, %ecx
callq 0x4380
movq %rax, 0x108ed(%rip)     # 0x16980
movzwl 0x108be(%rip), %edi     # 0x16958
addl $-0x17, %edi
movzwl 0x108b6(%rip), %esi     # 0x1695a
pushq $0x17
popq %rdx
xorl %ecx, %ecx
callq 0x4380
movq %rax, 0x108c3(%rip)     # 0x16978
callq 0x40c0
movb $0x1, %bl
callq 0x41b0
leaq -0x48(%rbp), %rdi
callq 0x4748
movl %ebx, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x60fd
jmp 0x60fd
jmp 0x60fd
jmp 0x60fd
jmp 0x60fd
jmp 0x60fd
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x4748
jmp 0x6100
jmp 0x60fd
jmp 0x60fd
jmp 0x60fd
jmp 0x60fd
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x4748
movq %rbx, %rdi
callq 0x4650