// File: /workspace/github_c_makefile_star2_O3/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 0x7c9a7(%rip), %rdx     # 0x12c151
movq %rdx, 0x40(%rsi)
movq 0x78(%rsi), %rax
movl (%rax), %ebx
movb 0x3a(%rsi), %al
andb $-0x4, %al
cmpb $0x30, %al
jne 0xaf7d5
leaq 0x7a36a(%rip), %rdx     # 0x129b2e
leaq 0x230(%rip), %rcx       # 0xaf9fb
movl $0x2, %eax
jmp 0xaf85f
movzbl 0x38(%r15), %eax
leal -0x1(%rax), %ecx
cmpl $0x7, %ecx
ja 0xaf802
leaq 0x86247(%rip), %rsi     # 0x135a30
movslq (%rsi,%rcx,4), %rcx
addq %rsi, %rcx
jmpq *%rcx
leaq 0x748d8(%rip), %rdx     # 0x1240d1
leaq 0x43a(%rip), %rcx       # 0xafc3a
jmp 0xaf85f
cmpl $0x11, %eax
je 0xaf84c
cmpl $0x31, %eax
jne 0xaf871
leaq 0x865bd(%rip), %rdx     # 0x135dd0
leaq 0x772(%rip), %rcx       # 0xaff8c
jmp 0xaf85a
leaq 0x86594(%rip), %rdx     # 0x135db7
leaq 0x64a(%rip), %rcx       # 0xafe74
jmp 0xaf85a
leaq 0x86567(%rip), %rdx     # 0x135d9a
leaq 0x4f5(%rip), %rcx       # 0xafd2f
jmp 0xaf85a
leaq 0x86563(%rip), %rdx     # 0x135da6
leaq 0x592(%rip), %rcx       # 0xafddc
jmp 0xaf85a
leaq 0x8656e(%rip), %rdx     # 0x135dc1
leaq 0x693(%rip), %rcx       # 0xafeed
movl $0x1, %eax
movl %eax, 0x98(%r15)
movq %rcx, 0x90(%r15)
movq %rdx, 0x40(%r15)
leaq 0x80d68(%rip), %rsi     # 0x1305e0
xorl %ebp, %ebp
movq %r14, %rdi
xorl %eax, %eax
callq 0xe8617
cmpq $0x0, 0x90(%r15)
je 0xaf8b3
movzbl 0x3a(%r15), %edx
movzbl 0x38(%r15), %ecx
leaq 0x86549(%rip), %rsi     # 0x135de8
movq %r14, %rdi
movl %ebx, %r8d
xorl %eax, %eax
callq 0xe87e4
movl $0x1, %ebp
jmp 0xaf8e7
cmpl $0x2, (%r15)
leaq 0x86398(%rip), %rax     # 0x135c56
leaq 0x8a05d(%rip), %rdx     # 0x139922
cmoveq %rax, %rdx
movzbl 0x3a(%r15), %ecx
movzbl 0x38(%r15), %r8d
leaq 0x86545(%rip), %rsi     # 0x135e1f
movq %r14, %rdi
movl %ebx, %r9d
xorl %eax, %eax
callq 0xe9295
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq