// File: /workspace/github_c_makefile_star2_O3/simh[P]simtools/converters/fsio/os8.c
// Function: os8Dir
static void os8Dir(
  struct mountedFS *mount,
  uint8_t unit,
  char *fname
)
{
  struct OS8data *data = &mount->os8data;
  struct os8FileSpec spec;

  if (os8ParseFilespec(fname, &spec, OS8_M_NONAME) == 0) {
    fprintf(stderr, "dir: syntax error in file spec \"%s\"\n", fname);
    return;
  }

  if (os8UnitValid(data, unit)) {
    unsigned int dirblk = OS8_DSSTART;

    do {
      uint16_t i, entrysz, entries, extra, off = OS8_DH_SIZE;

      if (os8ReadBlock(mount, unit, dirblk, NULL) == 0)
        return;

      entrysz = OS8_DI_SIZE + (-os8SXT(le16toh(data->buf[OS8_DH_EXTRA])));
      entries = os8Neg(le16toh(data->buf[OS8_DH_ENTRIES]));
      extra = os8Neg(le16toh(data->buf[OS8_DH_EXTRA]));

      for (i = 0; i < entries; i++) {
        char temp1[16], temp2[16];

        if (os8Word(le16toh(data->buf[off + OS8_DI_FNAME1])) != 0) {
          if ((spec.flags & OS8_WC_NAME) == 0)
            if ((os8Word(le16toh(data->buf[off + OS8_DI_FNAME1])) != spec.name[0]) ||
                (os8Word(le16toh(data->buf[off + OS8_DI_FNAME2])) != spec.name[1]) ||
                (os8Word(le16toh(data->buf[off + OS8_DI_FNAME3])) != spec.name[2])) {
              off += entrysz;
              continue;
            }

          if ((spec.flags & OS8_WC_EXT) == 0)
            if (os8Word(le16toh(data->buf[off + OS8_DI_EXT])) != spec.ext) {
              off += entrysz;
              continue;
            }

          if (SWISSET('f')) {
            uint16_t length, dateval = 0;
            
            length = os8Neg(le16toh(data->buf[off + extra + OS8_DI_LENGTH]));
            if (extra)
              dateval = os8Word(le16toh(data->buf[off + OS8_DI_DATE]));

            printf("%s  %4hu  %s\n",
                   os8FileName(mount, off, temp1), length,
                   os8Date(dateval, temp2));
          } else printf("%s\n", os8FileName(mount, off, temp1));
          off += entrysz;
        } else off += OS8_ED_SIZE;
      }

      dirblk = os8Word(le16toh(data->buf[OS8_DH_NEXT]));
    } while (dirblk != 0);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdx, %r14
movl %esi, %ebp
movq %rdi, %rbx
leaq 0x1e(%rsp), %rsi
movq %rdx, %rdi
movl $0x2, %edx
callq 0xd82f
testl %eax, %eax
je 0xf344
movq 0x50(%rbx), %rax
testq %rax, %rax
je 0xf335
cmpb %bpl, 0x8(%rax)
jbe 0xf335
movzbl 0x59(%rbx), %eax
movzbl %bpl, %ecx
movl %ecx, 0x14(%rsp)
btl %ecx, %eax
jae 0xf335
movb 0x1e(%rsp), %bpl
movzwl 0x20(%rsp), %r12d
movzwl 0x22(%rsp), %eax
movw %ax, 0x10(%rsp)
movzwl 0x24(%rsp), %eax
movw %ax, 0xc(%rsp)
movl $0x1, %edx
movzwl 0x26(%rsp), %eax
movw %ax, 0x12(%rsp)
movb %bpl, 0xb(%rsp)
movw %r12w, 0xe(%rsp)
movq %rbx, 0x30(%rsp)
movq %rbx, %rdi
movl 0x14(%rsp), %esi
xorl %ecx, %ecx
callq 0xd707
testl %eax, %eax
je 0xf335
movzwl 0x5c(%rbx), %eax
xorl %r15d, %r15d
subw %ax, %r15w
andw $0xfff, %r15w           # imm = 0xFFF
movw $0xfff, %si             # imm = 0xFFF
je 0xf325
movzwl 0x64(%rbx), %edx
movl %edx, %eax
andl $0xfff, %eax            # imm = 0xFFF
movl %edx, %ecx
shll $0x4, %ecx
movswl %cx, %ecx
sarl $0xf, %ecx
andl $0xfffff000, %ecx       # imm = 0xFFFFF000
orl %eax, %ecx
movl $0x5, %r14d
subl %ecx, %r14d
negl %edx
andl $0xfff, %edx            # imm = 0xFFF
movl %edx, 0x18(%rsp)
movl %edx, %eax
addl $0x4, %eax
movq %rax, 0x38(%rsp)
movw $0x5, %ax
movzwl %ax, %r13d
movzwl 0x5c(%rbx,%r13,2), %ecx
andw %si, %cx
je 0xf28d
testb $0x1, %bpl
jne 0xf223
movl %r14d, %eax
cmpw %r12w, %cx
jne 0xf317
movl %r13d, %ecx
movzwl 0x5e(%rbx,%rcx,2), %edx
andl $0xfff, %edx            # imm = 0xFFF
movl %r14d, %eax
cmpw 0x10(%rsp), %dx
jne 0xf317
movzwl 0x60(%rbx,%rcx,2), %ecx
andl $0xfff, %ecx            # imm = 0xFFF
movl %r14d, %eax
cmpw 0xc(%rsp), %cx
jne 0xf317
testb $0x2, %bpl
jne 0xf245
movl %r13d, %eax
movzwl 0x62(%rbx,%rax,2), %ecx
andl $0xfff, %ecx            # imm = 0xFFF
movl %r14d, %eax
cmpw 0x12(%rsp), %cx
jne 0xf317
leaq 0x9d8c(%rip), %rax      # 0x18fd8
testb $0x20, (%rax)
jne 0xf296
movq %rbx, %rdi
movl %r13d, %esi
movl %ebp, %ebx
movl %r14d, %ebp
movl %r12d, %r14d
leaq 0x40(%rsp), %r12
movq %r12, %rdx
callq 0xf715
movq %r12, %rdi
movl %r14d, %r12d
movl %ebp, %r14d
movl %ebx, %ebp
movq 0x30(%rsp), %rbx
callq 0x30e0
movw $0xfff, %si             # imm = 0xFFF
movl %r14d, %eax
jmp 0xf317
movw $0x2, %ax
jmp 0xf317
xorl %ebp, %ebp
movl $0x0, %r12d
cmpw $0x0, 0x18(%rsp)
je 0xf2b6
movl %r13d, %eax
movzwl 0x64(%rbx,%rax,2), %r12d
andl $0xfff, %r12d           # imm = 0xFFF
movq 0x38(%rsp), %rax
addl %r13d, %eax
subw 0x5c(%rbx,%rax,2), %bp
andl $0xfff, %ebp            # imm = 0xFFF
movq %rbx, %rdi
movl %r13d, %esi
leaq 0x40(%rsp), %rdx
callq 0xf715
movzwl %bp, %ebp
movzwl %r12w, %edi
leaq 0x50(%rsp), %r12
movq %r12, %rsi
callq 0xf7ad
leaq 0x3916(%rip), %rdi      # 0x12c0a
leaq 0x40(%rsp), %rsi
movl %ebp, %edx
movq %r12, %rcx
xorl %eax, %eax
callq 0x3160
movl %r14d, %eax
movb 0xb(%rsp), %bpl
movzwl 0xe(%rsp), %r12d
movw $0xfff, %si             # imm = 0xFFF
cwtl
addl %r13d, %eax
decw %r15w
jne 0xf1c8
movzwl 0x60(%rbx), %edx
andl $0xfff, %edx            # imm = 0xFFF
jne 0xf156
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8ca5(%rip), %rax      # 0x17ff0
movq (%rax), %rdi
leaq 0x2a2d(%rip), %rsi      # 0x11d82
movq %r14, %rdx
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x31e0