// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rax
leaq 0xb5992(%rip), %rcx     # 0x1b7c2d
movq %rcx, 0x40(%rax)
movq -0x18(%rbp), %rax
movq 0x78(%rax), %rax
movl (%rax), %eax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movzbl 0x3a(%rax), %eax
cmpl $0x30, %eax
jl 0x1022fb
movq -0x18(%rbp), %rax
movzbl 0x3a(%rax), %eax
cmpl $0x33, %eax
jg 0x1022fb
movq -0x18(%rbp), %rax
movl $0x2, 0x98(%rax)
movq -0x18(%rbp), %rax
leaq 0x410(%rip), %rcx       # 0x1026f0
movq %rcx, 0x90(%rax)
movq -0x18(%rbp), %rax
leaq 0xb3190(%rip), %rcx     # 0x1b5482
movq %rcx, 0x40(%rax)
jmp 0x102482
movq -0x18(%rbp), %rax
movzbl 0x38(%rax), %eax
cmpl $0x1, %eax
jne 0x10233c
movq -0x18(%rbp), %rax
movl $0x1, 0x98(%rax)
movq -0x18(%rbp), %rax
leaq 0x74f(%rip), %rcx       # 0x102a70
movq %rcx, 0x90(%rax)
movq -0x18(%rbp), %rax
leaq 0xad68c(%rip), %rcx     # 0x1af9bf
movq %rcx, 0x40(%rax)
jmp 0x102480
movq -0x18(%rbp), %rax
movzbl 0x38(%rax), %eax
cmpl $0x2, %eax
jne 0x10237d
movq -0x18(%rbp), %rax
movl $0x1, 0x98(%rax)
movq -0x18(%rbp), %rax
leaq 0x86e(%rip), %rcx       # 0x102bd0
movq %rcx, 0x90(%rax)
movq -0x18(%rbp), %rax
leaq 0xbf35e(%rip), %rcx     # 0x1c16d2
movq %rcx, 0x40(%rax)
jmp 0x10247e
movq -0x18(%rbp), %rax
movzbl 0x38(%rax), %eax
cmpl $0x4, %eax
jne 0x1023be
movq -0x18(%rbp), %rax
movl $0x1, 0x98(%rax)
movq -0x18(%rbp), %rax
leaq 0x91d(%rip), %rcx       # 0x102cc0
movq %rcx, 0x90(%rax)
movq -0x18(%rbp), %rax
leaq 0xbf329(%rip), %rcx     # 0x1c16de
movq %rcx, 0x40(%rax)
jmp 0x10247c
movq -0x18(%rbp), %rax
movzbl 0x38(%rax), %eax
cmpl $0x8, %eax
jne 0x1023fc
movq -0x18(%rbp), %rax
movl $0x1, 0x98(%rax)
movq -0x18(%rbp), %rax
leaq 0x9bc(%rip), %rcx       # 0x102da0
movq %rcx, 0x90(%rax)
movq -0x18(%rbp), %rax
leaq 0xbf2f9(%rip), %rcx     # 0x1c16ef
movq %rcx, 0x40(%rax)
jmp 0x10247a
movq -0x18(%rbp), %rax
movzbl 0x38(%rax), %eax
cmpl $0x11, %eax
jne 0x10243a
movq -0x18(%rbp), %rax
movl $0x1, 0x98(%rax)
movq -0x18(%rbp), %rax
leaq 0xa3e(%rip), %rcx       # 0x102e60
movq %rcx, 0x90(%rax)
movq -0x18(%rbp), %rax
leaq 0xbf2c5(%rip), %rcx     # 0x1c16f9
movq %rcx, 0x40(%rax)
jmp 0x102478
movq -0x18(%rbp), %rax
movzbl 0x38(%rax), %eax
cmpl $0x31, %eax
jne 0x102476
movq -0x18(%rbp), %rax
movl $0x1, 0x98(%rax)
movq -0x18(%rbp), %rax
leaq 0xb00(%rip), %rcx       # 0x102f60
movq %rcx, 0x90(%rax)
movq -0x18(%rbp), %rax
leaq 0xbf296(%rip), %rcx     # 0x1c1708
movq %rcx, 0x40(%rax)
jmp 0x102478
jmp 0x10247a
jmp 0x10247c
jmp 0x10247e
jmp 0x102480
jmp 0x102482
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rdx
leaq 0xb9c32(%rip), %rsi     # 0x1bc0c7
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
cmpq $0x0, 0x90(%rax)
je 0x1024dc
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movzbl 0x3a(%rax), %edx
movq -0x18(%rbp), %rax
movzbl 0x38(%rax), %ecx
movq -0x20(%rbp), %rax
movl %eax, %r8d
leaq 0xbf254(%rip), %rsi     # 0x1c1720
movb $0x0, %al
callq 0x15b350
movl $0x1, -0x4(%rbp)
jmp 0x102528
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movl (%rax), %ecx
leaq 0xc2cc5(%rip), %rdx     # 0x1c51b2
leaq 0xbf09a(%rip), %rax     # 0x1c158e
cmpl $0x2, %ecx
cmoveq %rax, %rdx
movq -0x18(%rbp), %rax
movzbl 0x3a(%rax), %ecx
movq -0x18(%rbp), %rax
movzbl 0x38(%rax), %r8d
movq -0x20(%rbp), %rax
movl %eax, %r9d
leaq 0xbf23d(%rip), %rsi     # 0x1c1757
movb $0x0, %al
callq 0x15bfb0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)