// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/atari-dsk.c
// Function: do_atr_disk_image
static void do_atr_disk_image(deark *c, lctx *d, dbuf *f)
{
	i64 sector_pos;
	i64 entrypos;
	i64 sector_size;
	i64 sector_index;
	i64 entry_index;
	i64 entries_per_sector;
	u8 flags;

	if(d->sector_size!=128 && d->sector_size!=256) {
		de_err(c, "Unsupported sector size: %d", (int)d->sector_size);
		return;
	}
	entries_per_sector = d->sector_size / 16;

	for(sector_index=0; sector_index<8; sector_index++) {
		get_sector_offset_and_size(c, d, 361+sector_index, &sector_pos, &sector_size);
		if(sector_pos + sector_size > f->len) break;
		de_dbg(c, "directory sector %d at %d", (int)sector_index, (int)sector_pos);
		de_dbg_indent(c, 1);
		for(entry_index=0; entry_index<entries_per_sector; entry_index++) {
			entrypos = sector_pos + 16*entry_index;

			// Peek at the flags byte, just to avoid printing debugging info
			// about nonexistent files
			flags = dbuf_getbyte(f, entrypos);
			if(flags==0x00) continue;

			de_dbg(c, "directory sector %d entry %d at %d", (int)sector_index,
				(int)entry_index, (int)entrypos);
			de_dbg_indent(c, 1);
			do_directory_entry(c, d, f, entrypos);
			de_dbg_indent(c, -1);
		}
		de_dbg_indent(c, -1);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x80, (%rax)
je 0x25efe
movq -0x10(%rbp), %rax
cmpq $0x100, (%rax)          # imm = 0x100
je 0x25efe
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl %eax, %edx
leaq 0x178d1e(%rip), %rsi    # 0x19ec10
movb $0x0, %al
callq 0x15bfb0
jmp 0x26053
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl $0x10, %ecx
cqto
idivq %rcx
movq %rax, -0x48(%rbp)
movq $0x0, -0x38(%rbp)
cmpq $0x8, -0x38(%rbp)
jge 0x26053
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
addq $0x169, %rdx            # imm = 0x169
leaq -0x20(%rbp), %rcx
leaq -0x30(%rbp), %r8
callq 0x26060
movq -0x20(%rbp), %rax
addq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jle 0x25f5d
jmp 0x26053
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl %eax, %edx
movq -0x20(%rbp), %rax
movl %eax, %ecx
leaq 0x178cb8(%rip), %rsi    # 0x19ec2c
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x48(%rbp), %rax
jge 0x26034
movq -0x20(%rbp), %rax
movq -0x40(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x165060
movb %al, -0x49(%rbp)
movzbl -0x49(%rbp), %eax
cmpl $0x0, %eax
jne 0x25fcd
jmp 0x26023
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl %eax, %edx
movq -0x40(%rbp), %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %eax, %r8d
leaq 0x178c5b(%rip), %rsi    # 0x19ec46
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0x26100
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x25f91
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x25f1b
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)