// File: essarrdee[P]mutantaliens/mutantaliens.cpp
// Function: reconfigure(item*)
bool reconfigure(item* a)
{
	update_device_desciption(a);

	bool unacceptable = true;
	bool cancel = false;
	while(unacceptable)
	{
		std::string s = a->description+" Reconfigure? Space or ("+std::string(1,a->configuration +'a')+
			". Q or ESC to cancel.";
		if(a->configuration != UNCONFIGURED)
		{s += std::string(" (a) remove ")+(a->configuration==ON_TIMER?"timer":"remote control");}
		if(a->configuration != ON_TIMER)
		{s += std::string(" (b) use a timer instead");}
		if(a->configuration != ON_REMOTE)
		{s += std::string(" (c) use a remote control instead");}
		s += ".";
		pretty_print(s);
		/*clear_area(0,0,viewport_width,5);
		mvaddstr(0,0,a->description.c_str());
		mvprintw(1,0,"Reconfigure? Space or (%c) to leave unchanged",a->configuration +'a');
		mvaddstr(2,0,"q or ESC to cancel");
		int i=3;
		if(a->configuration != UNCONFIGURED)
		{
			mvprintw(i,0,"(a) remove %s",a->configuration==ON_TIMER?"timer":"remote control");
			i++;
		}
		if(a->configuration != ON_TIMER)
		{
			mvprintw(i,0,"(b) use a timer instead");
			i++;
		}
		if(a->configuration != ON_REMOTE)
		{
			mvprintw(i,0,"(c) use a remote control instead");
		}*/
		int kp = fgetch();
		draw_scene();
		if(kp == 'q' || kp == 'Q' || kp == KEY_ESC)
		{
			unacceptable = false;
			cancel = true;
		}
		else if(kp == a->configuration + 'a' || kp == ' ')
		{
			unacceptable = false;
		}
		else if(kp == 'a') 
		{
			set_unconfigured(a);
			unacceptable = false;
		}
		else if( kp == 'b')
		{
			draw_scene();
			int t = ask_for_time();
			
			if (t >= 0)
			{
				set_timer(a,t);
				unacceptable = false;
			}
		}
		else if (kp == 'c')
		{
			draw_scene();
			int w = ask_for_wavelength();
			if(w>=0)
			{
				set_remote(a,w);
				unacceptable = false;
			}
		}
	}
	draw_scene();
	return cancel;
}

// Assembly:
subq $0x1a8, %rsp            # imm = 0x1A8
movq %rdi, 0x1a0(%rsp)
movq 0x1a0(%rsp), %rdi
callq 0x13660
movb $0x1, 0x19f(%rsp)
movb $0x0, 0x19e(%rsp)
testb $0x1, 0x19f(%rsp)
je 0x1c9b6
movq 0x1a0(%rsp), %rsi
addq $0x30, %rsi
leaq 0x123e2(%rip), %rdx     # 0x2e7ff
leaq 0x138(%rsp), %rdi
callq 0x20670
movq 0x1a0(%rsp), %rax
movl 0x8c(%rax), %eax
addl $0x61, %eax
movl %eax, 0x2c(%rsp)
leaq 0x117(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x5490
movl 0x2c(%rsp), %eax
movq 0x30(%rsp), %rcx
movsbl %al, %edx
leaq 0x118(%rsp), %rdi
movl $0x1, %esi
callq 0x5210
jmp 0x1c471
leaq 0x158(%rsp), %rdi
leaq 0x138(%rsp), %rsi
leaq 0x118(%rsp), %rdx
callq 0x20350
jmp 0x1c490
leaq 0x12381(%rip), %rdx     # 0x2e818
leaq 0x178(%rsp), %rdi
leaq 0x158(%rsp), %rsi
callq 0x21090
jmp 0x1c4ae
leaq 0x158(%rsp), %rdi
callq 0x54f8
leaq 0x118(%rsp), %rdi
callq 0x54f8
leaq 0x117(%rsp), %rdi
callq 0x5310
leaq 0x138(%rsp), %rdi
callq 0x54f8
movq 0x1a0(%rsp), %rax
cmpl $0x0, 0x8c(%rax)
je 0x1c686
leaq 0xbf(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x5490
movq 0x20(%rsp), %rdx
leaq 0x12319(%rip), %rsi     # 0x2e82e
leaq 0xc0(%rsp), %rdi
callq 0x53d0
jmp 0x1c524
movq 0x1a0(%rsp), %rax
movl 0x8c(%rax), %eax
subl $0x1, %eax
leaq 0x13742(%rip), %rax     # 0x2fc7e
leaq 0x122f8(%rip), %rdx     # 0x2e83b
cmoveq %rax, %rdx
leaq 0xe0(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x21090
jmp 0x1c55e
leaq 0x178(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x5390
jmp 0x1c575
leaq 0xe0(%rsp), %rdi
callq 0x54f8
leaq 0xc0(%rsp), %rdi
callq 0x54f8
leaq 0xbf(%rsp), %rdi
callq 0x5310
jmp 0x1c686
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
jmp 0x1c5fb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
jmp 0x1c5ee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
leaq 0x158(%rsp), %rdi
callq 0x54f8
leaq 0x118(%rsp), %rdi
callq 0x54f8
leaq 0x117(%rsp), %rdi
callq 0x5310
leaq 0x138(%rsp), %rdi
callq 0x54f8
jmp 0x1c9ce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
jmp 0x1c674
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
jmp 0x1c667
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x54f8
leaq 0xc0(%rsp), %rdi
callq 0x54f8
leaq 0xbf(%rsp), %rdi
callq 0x5310
jmp 0x1c9a7
movq 0x1a0(%rsp), %rax
cmpl $0x1, 0x8c(%rax)
je 0x1c744
leaq 0x97(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x5490
movq 0x18(%rsp), %rdx
leaq 0x12191(%rip), %rsi     # 0x2e84a
leaq 0x98(%rsp), %rdi
callq 0x53d0
jmp 0x1c6c8
leaq 0x178(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x5390
jmp 0x1c6df
leaq 0x98(%rsp), %rdi
callq 0x54f8
leaq 0x97(%rsp), %rdi
callq 0x5310
jmp 0x1c744
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
jmp 0x1c732
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
leaq 0x98(%rsp), %rdi
callq 0x54f8
leaq 0x97(%rsp), %rdi
callq 0x5310
jmp 0x1c9a7
movq 0x1a0(%rsp), %rax
cmpl $0x2, 0x8c(%rax)
je 0x1c7ed
leaq 0x6f(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x5490
movq 0x10(%rsp), %rdx
leaq 0x120ef(%rip), %rsi     # 0x2e863
leaq 0x70(%rsp), %rdi
callq 0x53d0
jmp 0x1c780
leaq 0x178(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x5390
jmp 0x1c794
leaq 0x70(%rsp), %rdi
callq 0x54f8
leaq 0x6f(%rsp), %rdi
callq 0x5310
jmp 0x1c7ed
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
jmp 0x1c7de
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x54f8
leaq 0x6f(%rsp), %rdi
callq 0x5310
jmp 0x1c9a7
leaq 0x13037(%rip), %rsi     # 0x2f82b
leaq 0x178(%rsp), %rdi
callq 0x52a0
jmp 0x1c803
leaq 0x48(%rsp), %rdi
leaq 0x178(%rsp), %rsi
callq 0x5180
jmp 0x1c817
leaq 0x48(%rsp), %rdi
callq 0x74d0
jmp 0x1c823
leaq 0x48(%rsp), %rdi
callq 0x54f8
callq 0x21710
movl %eax, 0xc(%rsp)
jmp 0x1c838
movl 0xc(%rsp), %eax
movl %eax, 0x44(%rsp)
xorl %edi, %edi
callq 0x176d0
jmp 0x1c849
cmpl $0x71, 0x44(%rsp)
je 0x1c85e
cmpl $0x51, 0x44(%rsp)
je 0x1c85e
cmpl $0x1b, 0x44(%rsp)
jne 0x1c8af
movb $0x0, 0x19f(%rsp)
movb $0x1, 0x19e(%rsp)
jmp 0x1c995
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
jmp 0x1c9a7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
leaq 0x48(%rsp), %rdi
callq 0x54f8
jmp 0x1c9a7
movl 0x44(%rsp), %eax
movq 0x1a0(%rsp), %rcx
movl 0x8c(%rcx), %ecx
addl $0x61, %ecx
cmpl %ecx, %eax
je 0x1c8cf
cmpl $0x20, 0x44(%rsp)
jne 0x1c8dc
movb $0x0, 0x19f(%rsp)
jmp 0x1c993
cmpl $0x61, 0x44(%rsp)
jne 0x1c8ff
movq 0x1a0(%rsp), %rdi
callq 0x1c200
jmp 0x1c8f2
movb $0x0, 0x19f(%rsp)
jmp 0x1c991
cmpl $0x62, 0x44(%rsp)
jne 0x1c946
xorl %edi, %edi
callq 0x176d0
jmp 0x1c90f
callq 0x1bfa0
movl %eax, 0x8(%rsp)
jmp 0x1c91a
movl 0x8(%rsp), %eax
movl %eax, 0x40(%rsp)
cmpl $0x0, 0x40(%rsp)
jl 0x1c944
movq 0x1a0(%rsp), %rdi
movl 0x40(%rsp), %esi
callq 0x1c2c0
jmp 0x1c93c
movb $0x0, 0x19f(%rsp)
jmp 0x1c98f
cmpl $0x63, 0x44(%rsp)
jne 0x1c98d
xorl %edi, %edi
callq 0x176d0
jmp 0x1c956
callq 0x1c050
movl %eax, 0x4(%rsp)
jmp 0x1c961
movl 0x4(%rsp), %eax
movl %eax, 0x3c(%rsp)
cmpl $0x0, 0x3c(%rsp)
jl 0x1c98b
movq 0x1a0(%rsp), %rdi
movl 0x3c(%rsp), %esi
callq 0x1c340
jmp 0x1c983
movb $0x0, 0x19f(%rsp)
jmp 0x1c98d
jmp 0x1c98f
jmp 0x1c991
jmp 0x1c993
jmp 0x1c995
leaq 0x178(%rsp), %rdi
callq 0x54f8
jmp 0x1c3fc
leaq 0x178(%rsp), %rdi
callq 0x54f8
jmp 0x1c9ce
xorl %edi, %edi
callq 0x176d0
movb 0x19e(%rsp), %al
andb $0x1, %al
addq $0x1a8, %rsp            # imm = 0x1A8
retq
movq 0x108(%rsp), %rdi
callq 0x5480
nopl (%rax,%rax)