// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/storyboard.c
// Function: do_oldfmt_text
static void do_oldfmt_text(deark *c, struct storyboard_ctx *d, i64 pos)
{
	dbuf *unc_data = NULL;
	struct de_char_context *charctx = NULL;

	if(d->mode != 3) goto done;
	d->max_unc_size = 65536;

	unc_data = dbuf_create_membuf(c, 4000, 0);
	dbuf_enable_wbuffer(unc_data);

	if(!decompress_oldfmt(c, d, pos, unc_data)) goto done;
	dbuf_flush(unc_data);

	// Not sure how to figure out the dimensions. The files in the distribution
	// seem to contain this information, but the ones I capture myself contain
	// nonsense. (Maybe mode=3 implies 80x25, so we could just assume that.)
	if(d->rowspan>=80 && d->rowspan<=400 && d->height>=20 && d->height<=100 &&
		(d->rowspan*d->height == unc_data->len))
	{
		d->width_in_chars = d->rowspan/2;
		d->height_in_chars = d->height;
	}
	else {
		d->width_in_chars = 80;
		d->height_in_chars = 25;
	}

	charctx = de_create_charctx(c, 0);
	charctx->screen_image_flag = 1;
	if(d->width_in_chars>80 || d->height_in_chars>25) {
		charctx->no_density = 1;
	}
	de_char_decide_output_format(c, charctx);
	de_copy_std_palette(DE_PALID_PC16, 0, 0, charctx->pal, 16, 0);
	do_oldfmt_text_main(c, d, unc_data, charctx);

done:
	if(charctx) {
		de_free_charctx_screens(c, charctx);
		de_destroy_charctx(c, charctx);
	}
	dbuf_close(unc_data);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x4(%rax), %eax
cmpl $0x3, %eax
je 0x157ed6
jmp 0x158031
movq -0x10(%rbp), %rax
movq $0x10000, 0x38(%rax)    # imm = 0x10000
movq -0x8(%rbp), %rdi
movl $0xfa0, %esi            # imm = 0xFA0
xorl %edx, %edx
callq 0x168020
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
callq 0x167b90
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq 0x1582c0
cmpl $0x0, %eax
jne 0x157f1e
jmp 0x158031
movq -0x20(%rbp), %rdi
callq 0x167c30
movq -0x10(%rbp), %rax
cmpq $0x50, 0x20(%rax)
jl 0x157fa0
movq -0x10(%rbp), %rax
cmpq $0x190, 0x20(%rax)      # imm = 0x190
jg 0x157fa0
movq -0x10(%rbp), %rax
cmpq $0x14, 0x18(%rax)
jl 0x157fa0
movq -0x10(%rbp), %rax
cmpq $0x64, 0x18(%rax)
jg 0x157fa0
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x10(%rbp), %rcx
imulq 0x18(%rcx), %rax
movq -0x20(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jne 0x157fa0
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl $0x2, %ecx
cqto
idivq %rcx
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x30(%rax)
jmp 0x157fb8
movq -0x10(%rbp), %rax
movq $0x50, 0x28(%rax)
movq -0x10(%rbp), %rax
movq $0x19, 0x30(%rax)
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x16d7b0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movb $0x1, 0x2(%rax)
movq -0x10(%rbp), %rax
cmpq $0x50, 0x28(%rax)
jg 0x157fe5
movq -0x10(%rbp), %rax
cmpq $0x19, 0x30(%rax)
jle 0x157fed
movq -0x28(%rbp), %rax
movb $0x1, 0x3(%rax)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x16d9a0
movq -0x28(%rbp), %rcx
addq $0x20, %rcx
movl $0x14, %edi
xorl %r9d, %r9d
xorl %eax, %eax
movl %eax, %edx
movl $0x10, %r8d
movl %r9d, %esi
callq 0x161320
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0x1584f0
cmpq $0x0, -0x28(%rbp)
je 0x158052
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x16d7e0
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x16d910
movq -0x20(%rbp), %rdi
callq 0x1676a0
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)