// File: /workspace/github_c_makefile_star2_O1/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 0x7bb68(%rip), %rax     # 0x12be69
movq %rax, 0x40(%rsi)
movq 0x78(%rsi), %rax
movl (%rax), %ebx
movb 0x3a(%rsi), %al
andb $-0x4, %al
cmpb $0x30, %al
jne 0xb032c
leaq 0x795a3(%rip), %rcx     # 0x1298be
leaq 0x234(%rip), %rdx       # 0xb0556
movl $0x2, %eax
jmp 0xb03b6
movzbl 0x38(%r15), %eax
leal -0x1(%rax), %ecx
cmpl $0x7, %ecx
ja 0xb0359
leaq 0x85368(%rip), %rdx     # 0x1356a8
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
leaq 0x73b5f(%rip), %rcx     # 0x123eaf
leaq 0x435(%rip), %rdx       # 0xb078c
jmp 0xb03b6
cmpl $0x11, %eax
je 0xb03a3
cmpl $0x31, %eax
jne 0xb03c8
leaq 0x856de(%rip), %rcx     # 0x135a48
leaq 0x76d(%rip), %rdx       # 0xb0ade
jmp 0xb03b1
leaq 0x856b5(%rip), %rcx     # 0x135a2f
leaq 0x645(%rip), %rdx       # 0xb09c6
jmp 0xb03b1
leaq 0x85688(%rip), %rcx     # 0x135a12
leaq 0x4f0(%rip), %rdx       # 0xb0881
jmp 0xb03b1
leaq 0x85684(%rip), %rcx     # 0x135a1e
leaq 0x58d(%rip), %rdx       # 0xb092e
jmp 0xb03b1
leaq 0x8568f(%rip), %rcx     # 0x135a39
leaq 0x68e(%rip), %rdx       # 0xb0a3f
movl $0x1, %eax
movl %eax, 0x98(%r15)
movq %rdx, 0x90(%r15)
movq %rcx, 0x40(%r15)
movq 0x40(%r15), %rdx
leaq 0x7ff14(%rip), %rsi     # 0x1302e7
xorl %ebp, %ebp
movq %r14, %rdi
xorl %eax, %eax
callq 0xe9226
cmpq $0x0, 0x90(%r15)
je 0xb040e
movzbl 0x3a(%r15), %edx
movzbl 0x38(%r15), %ecx
leaq 0x85666(%rip), %rsi     # 0x135a60
movq %r14, %rdi
movl %ebx, %r8d
xorl %eax, %eax
callq 0xe93cf
movl $0x1, %ebp
jmp 0xb0442
cmpl $0x2, (%r15)
leaq 0x854b5(%rip), %rax     # 0x1358ce
leaq 0x89172(%rip), %rdx     # 0x139592
cmoveq %rax, %rdx
movzbl 0x3a(%r15), %ecx
movzbl 0x38(%r15), %r8d
leaq 0x85662(%rip), %rsi     # 0x135a97
movq %r14, %rdi
movl %ebx, %r9d
xorl %eax, %eax
callq 0xe9df7
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq