// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/atari-img.c
// Function: de_run_animatic
static void de_run_animatic(deark *c, de_module_params *mparams)
{
	struct atari_img_decode_data *adata = NULL;
	i64 nframes;
	i64 frame;
	i64 planespan, rowspan, framespan;
	i64 frame_bitmap_pos;
	u32 pal[16];

	de_declare_fmt(c, "Animatic Film");

	adata = de_malloc(c, sizeof(struct atari_img_decode_data));

	nframes = de_getu16be(0);
	de_dbg(c, "number of frames: %d", (int)nframes);
	if(!de_good_image_count(c, nframes)) goto done;

	adata->bpp = 4;
	adata->ncolors = 16;
	adata->pal = pal;
	de_dbg_indent(c, 1);
	fmtutil_read_atari_palette(c, c->infile, 2, adata->pal, 16, adata->ncolors, 0);
	de_dbg_indent(c, -1);

	adata->w = de_getu16be(40);
	adata->h = de_getu16be(42);
	de_dbg_dimensions(c, adata->w, adata->h);
	if(!de_good_image_dimensions(c, adata->w, adata->h)) goto done;

	planespan = 2*((adata->w+15)/16);
	rowspan = planespan*adata->bpp;
	framespan = rowspan*adata->h;

	for(frame=0; frame<nframes; frame++) {
		frame_bitmap_pos = 64 + frame*framespan;
		de_dbg(c, "frame %d bitmap at %d", (int)frame, (int)frame_bitmap_pos);

		adata->unc_pixels = dbuf_open_input_subfile(c->infile, frame_bitmap_pos, framespan);
		adata->img = de_bitmap_create(c, adata->w, adata->h, 3);

		fmtutil_atari_decode_image(c, adata);
		de_bitmap_write_to_file(adata->img, NULL, 0);

		de_bitmap_destroy(adata->img);
		adata->img = NULL;

		dbuf_close(adata->unc_pixels);
		adata->unc_pixels = NULL;
	}

done:
	de_free(c, adata);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %rbx
leaq 0xf0294(%rip), %rsi     # 0x1134b0
callq 0xeb6d6
movl $0x40, %esi
movq %rbx, %rdi
callq 0xe969b
movq %rax, %r14
movq 0x18(%rbx), %rdi
xorl %esi, %esi
callq 0xef169
movq %rax, %r15
leaq 0xf084a(%rip), %rsi     # 0x113a90
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movq %r15, 0x8(%rsp)
movq %r15, %rsi
callq 0xf2509
testl %eax, %eax
je 0x233ce
movq $0x4, (%r14)
movq $0x10, 0x8(%r14)
leaq 0x10(%rsp), %rax
movq %rax, 0x30(%r14)
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%rbx), %rsi
movq 0x8(%r14), %r9
movq 0x30(%r14), %rcx
movl $0x0, (%rsp)
movl $0x2, %edx
movl $0x10, %r8d
movq %rbx, %rdi
callq 0xf8c62
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movq 0x18(%rbx), %rdi
movl $0x28, %esi
callq 0xef169
movq %rax, 0x10(%r14)
movq 0x18(%rbx), %rdi
movl $0x2a, %esi
callq 0xef169
movq %rax, 0x18(%r14)
movq 0x10(%r14), %rsi
movq %rbx, %rdi
movq %rax, %rdx
callq 0xe9b05
movq 0x10(%r14), %rsi
movq 0x18(%r14), %rdx
movq %rbx, %rdi
callq 0xf241d
testl %eax, %eax
je 0x233ce
movq 0x10(%r14), %r12
leaq 0xf(%r12), %rax
addq $0x1e, %r12
testq %rax, %rax
cmovnsq %rax, %r12
cmpq $0x0, 0x8(%rsp)
jle 0x233ce
sarq $0x4, %r12
imulq (%r14), %r12
imulq 0x18(%r14), %r12
addq %r12, %r12
movl $0x40, %r13d
xorl %r15d, %r15d
xorl %ebp, %ebp
movq %rbx, %rdi
leaq 0xf0757(%rip), %rsi     # 0x113aaa
movl %ebp, %edx
movl %r13d, %ecx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0xf1988
movq %rax, 0x20(%r14)
movq 0x10(%r14), %rsi
movq 0x18(%r14), %rdx
movq %rbx, %rdi
movl $0x3, %ecx
callq 0xf2cab
movq %rax, 0x38(%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0xf900c
movq 0x38(%r14), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xf2923
movq 0x38(%r14), %rdi
callq 0xf28d4
movq %r15, 0x38(%r14)
movq 0x20(%r14), %rdi
callq 0xf0b13
movq %r15, 0x20(%r14)
incq %rbp
addq %r12, %r13
cmpq %rbp, 0x8(%rsp)
jne 0x23349
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe9752
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq