// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/pcpaint.c
// Function: do_set_up_decoder
static int do_set_up_decoder(deark *c, lctx *d)
{
	i64 edesc;

	d->imgtype_name = "?";
	edesc = d->pal_info_to_use->edesc; // For brevity

	if(d->video_mode>='0' && d->video_mode<='3') {
		d->screen_mode_type = SCREENMODETYPE_TEXT;
		d->decoder_fn = decode_text;
		d->imgtype_name = "character";
	}
	else if(d->plane_info==0x01) {
		// Expected video mode(s): 0x43, 0x45, 0x48, 0x4f, 0x50, 0x55
		// CGA or EGA or VGA or Hercules 2-color
		d->screen_mode_type = SCREENMODETYPE_BITMAP;
		d->decoder_fn = decode_bilevel;
		d->imgtype_name = "bilevel";
	}
	else if(d->plane_info==0x02) {
		// Expected video mode(s): 0x41
		d->screen_mode_type = SCREENMODETYPE_BITMAP;
		d->decoder_fn = decode_cga4;
		d->imgtype_name = "4-color CGA";
	}
	else if(d->plane_info==0x04) {
		d->screen_mode_type = SCREENMODETYPE_BITMAP;
		d->decoder_fn = decode_egavga16;
		d->imgtype_name = "16-color EGA/VGA";
	}
	else if(d->plane_info==0x08) {
		// Expected video mode(s): 0x4c
		d->screen_mode_type = SCREENMODETYPE_BITMAP;
		d->decoder_fn = decode_vga256;
		d->imgtype_name = "256-color";
	}
	else if(d->plane_info==0x11) { // e.g. vmode='F'
		d->screen_mode_type = SCREENMODETYPE_BITMAP;
		d->decoder_fn = decode_4color_planar;
		d->imgtype_name = "4-color planar";
	}
	else if(d->plane_info==0x31) {
		d->screen_mode_type = SCREENMODETYPE_BITMAP;
		d->decoder_fn = decode_egavga16_planar;
		d->imgtype_name = "16-color planar EGA/VGA";
	}

	de_dbg(c, "image type: %s", d->imgtype_name);

	if(d->decoder_fn) {
		de_dbg2(c, "image details: evideo=0x%02x, bitsinf=0x%02x, edesc=%u",
			d->video_mode, d->plane_info, (UI)edesc);
		return 1;
	}

	de_err(c, "This type of PCPaint %s is not supported (evideo=0x%02x, bitsinf=0x%02x, edesc=%u)",
		(d->file_fmt==FMT_CLP) ? "CLP" : "PIC",
		d->video_mode, d->plane_info, (UI)edesc);

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %r15
movq %rdi, %r14
leaq 0x761da(%rip), %rdx     # 0x11eee1
movq %rdx, 0x40(%rsi)
movq 0x78(%rsi), %rax
movl (%rax), %ebx
movb 0x3a(%rsi), %al
andb $-0x4, %al
cmpb $0x30, %al
jne 0xa8d30
leaq 0x73bbd(%rip), %rdx     # 0x11c8de
leaq 0x226(%rip), %rsi       # 0xa8f4e
pushq $0x2
popq %rax
jmp 0xa8dba
pushq $0x1
popq %rcx
movzbl 0x38(%r15), %eax
leal -0x1(%rax), %esi
cmpl $0x7, %esi
ja 0xa8d60
leaq 0x7fa09(%rip), %rdi     # 0x128750
movslq (%rdi,%rsi,4), %rsi
addq %rdi, %rsi
jmpq *%rsi
leaq 0x6e178(%rip), %rdx     # 0x116ecf
leaq 0x40a(%rip), %rsi       # 0xa9168
jmp 0xa8dba
cmpl $0x11, %eax
je 0xa8daa
cmpl $0x31, %eax
jne 0xa8dcc
leaq 0x7fd7f(%rip), %rdx     # 0x128af0
leaq 0x704(%rip), %rsi       # 0xa947c
jmp 0xa8db8
leaq 0x7fd56(%rip), %rdx     # 0x128ad7
leaq 0x5f1(%rip), %rsi       # 0xa9379
jmp 0xa8db8
leaq 0x7fd29(%rip), %rdx     # 0x128aba
leaq 0x4b5(%rip), %rsi       # 0xa924d
jmp 0xa8db8
leaq 0x7fd25(%rip), %rdx     # 0x128ac6
leaq 0x543(%rip), %rsi       # 0xa92eb
jmp 0xa8db8
leaq 0x7fd30(%rip), %rdx     # 0x128ae1
leaq 0x631(%rip), %rsi       # 0xa93e9
movl %ecx, %eax
movl %eax, 0x98(%r15)
movq %rsi, 0x90(%r15)
movq %rdx, 0x40(%r15)
leaq 0x7a56c(%rip), %rsi     # 0x12333f
xorl %ebp, %ebp
movq %r14, %rdi
xorl %eax, %eax
callq 0xde896
cmpq $0x0, 0x90(%r15)
je 0xa8e0c
movzbl 0x3a(%r15), %edx
movzbl 0x38(%r15), %ecx
leaq 0x7fd0e(%rip), %rsi     # 0x128b08
movq %r14, %rdi
movl %ebx, %r8d
xorl %eax, %eax
callq 0xde9f1
pushq $0x1
popq %rbp
jmp 0xa8e40
cmpl $0x2, (%r15)
leaq 0x7fb5f(%rip), %rax     # 0x128976
leaq 0x83804(%rip), %rdx     # 0x12c622
cmoveq %rax, %rdx
movzbl 0x3a(%r15), %ecx
movzbl 0x38(%r15), %r8d
leaq 0x7fd0c(%rip), %rsi     # 0x128b3f
movq %r14, %rdi
movl %ebx, %r9d
xorl %eax, %eax
callq 0xdf2a5
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq