// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/abk.c
// Function: picture_bank_screen_header
static void picture_bank_screen_header(deark *c, lctx *d, struct amosbank *bk, i64 pos)
{
	i64 screen_width, screen_height;
	i64 ncolors;
	i64 nplanes;

	de_dbg(c, "screen header at %"I64_FMT, pos);
	de_dbg_indent(c, 1);

	screen_width = dbuf_getu16be(bk->f, pos+4);
	screen_height = dbuf_getu16be(bk->f, pos+6);
	de_dbg(c, "screen dimensions: %d"DE_CHAR_TIMES"%d", (int)screen_width, (int)screen_height);

	bk->amiga_mode = (UI)dbuf_getu16be(bk->f, pos+20);
	bk->ham_flag = (bk->amiga_mode & 0x0800)!=0;
	// Haven't found any EHB files
	bk->ehb_flag = (bk->amiga_mode & 0x0080)!=0;
	de_dbg(c, "screen mode: 0x%04x", (UI)bk->amiga_mode);
	de_dbg_indent(c, 1);
	de_dbg(c, "HAM: %u", (UI)bk->ham_flag);
	de_dbg_indent(c, -1);

	ncolors = dbuf_getu16be(bk->f, pos+22);
	de_dbg(c, "colors: %u", (UI)ncolors);
	nplanes = dbuf_getu16be(bk->f, pos+24);
	de_dbg(c, "planes: %u", (UI)nplanes);

	if(bk->ham_flag) {
		if(nplanes==6) {
			bk->is_ham6 = 1;
		}
		else {
			bk->errflag = 1;
			bk->need_errmsg = 1;
			goto done;
		}
	}

	bk->pal_pos = pos + 26;

	// Set bk->max_planes, so that do_read_sprite_or_pic_palette doesn't print
	// "[unused]".
	// TODO: We could look ahead at the picture header to figure out how many
	// palette entries are used. Or we could just guess that it's the same as
	// 'nplanes' in the screen header.
	bk->max_planes = 5;
	do_read_sprite_or_pic_palette(c, d, bk);
	bk->max_planes = 0;

done:
	if(bk->need_errmsg) {
		de_err(c, "Unsupported image format");
		bk->need_errmsg = 0;
	}
	de_dbg_indent(c, -1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rdx
leaq 0x181354(%rip), %rsi    # 0x19cefb
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x18(%rbp), %rax
movq 0x50(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x4, %rsi
callq 0x1651d0
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq 0x50(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x6, %rsi
callq 0x1651d0
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl %eax, %edx
movq -0x30(%rbp), %rax
movl %eax, %ecx
leaq 0x18130b(%rip), %rsi    # 0x19cf10
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movq 0x50(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x14, %rsi
callq 0x1651d0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x4b0(%rax)
movq -0x18(%rbp), %rax
movl 0x4b0(%rax), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movzbl %al, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x4b4(%rax)
movq -0x18(%rbp), %rax
movl 0x4b0(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movzbl %al, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x4b5(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x4b0(%rax), %edx
leaq 0x18129c(%rip), %rsi    # 0x19cf2a
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movzbl 0x4b4(%rax), %edx
leaq 0x181285(%rip), %rsi    # 0x19cf3e
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x18(%rbp), %rax
movq 0x50(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x16, %rsi
callq 0x1651d0
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl %eax, %edx
leaq 0x1950ae(%rip), %rsi    # 0x1b0da6
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movq 0x50(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x18, %rsi
callq 0x1651d0
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rax
movl %eax, %edx
leaq 0x18121d(%rip), %rsi    # 0x19cf46
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
cmpb $0x0, 0x4b4(%rax)
je 0x1bd65
cmpq $0x6, -0x40(%rbp)
jne 0x1bd51
movq -0x18(%rbp), %rax
movb $0x1, 0x4b6(%rax)
jmp 0x1bd63
movq -0x18(%rbp), %rax
movb $0x1, 0x30(%rax)
movq -0x18(%rbp), %rax
movb $0x1, 0x31(%rax)
jmp 0x1bda4
jmp 0x1bd65
movq -0x20(%rbp), %rcx
addq $0x1a, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x68(%rax)
movq -0x18(%rbp), %rax
movq $0x5, 0x488(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x1c2e0
movq -0x18(%rbp), %rax
movq $0x0, 0x488(%rax)
movq -0x18(%rbp), %rax
cmpb $0x0, 0x31(%rax)
je 0x1bdc8
movq -0x8(%rbp), %rdi
leaq 0x181198(%rip), %rsi    # 0x19cf51
movb $0x0, %al
callq 0x15bfb0
movq -0x18(%rbp), %rax
movb $0x0, 0x31(%rax)
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)