// File: /workspace/github_c_makefile_star2_O1/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 0xdaa1
testl %eax, %eax
je 0xf65b
movq 0x50(%rbx), %rax
testq %rax, %rax
je 0xf64c
cmpb %bpl, 0x8(%rax)
jbe 0xf64c
movzbl 0x59(%rbx), %eax
movzbl %bpl, %ecx
movl %ecx, 0x10(%rsp)
btl %ecx, %eax
jae 0xf64c
movb 0x1e(%rsp), %bpl
movzwl 0x20(%rsp), %r15d
movzwl 0x22(%rsp), %eax
movw %ax, 0xc(%rsp)
movzwl 0x24(%rsp), %eax
movw %ax, 0x8(%rsp)
movl $0x1, %r12d
movzwl 0x26(%rsp), %eax
movw %ax, 0xe(%rsp)
movb %bpl, 0x7(%rsp)
movw %r15w, 0xa(%rsp)
movq %rbx, 0x30(%rsp)
movq %rbx, %rdi
movl 0x10(%rsp), %esi
movl %r12d, %edx
xorl %ecx, %ecx
callq 0xd979
movw $0xfff, %si             # imm = 0xFFF
testl %eax, %eax
je 0xf63f
movl %eax, 0x14(%rsp)
movzwl 0x5c(%rbx), %eax
xorl %r13d, %r13d
subw %ax, %r13w
andw $0xfff, %r13w           # imm = 0xFFF
je 0xf62f
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, %r12d
movzwl 0x5c(%rbx,%r12,2), %ecx
andw %si, %cx
je 0xf597
testb $0x1, %bpl
jne 0xf52d
movl %r14d, %eax
cmpw %r15w, %cx
jne 0xf621
movl %r12d, %ecx
movzwl 0x5e(%rbx,%rcx,2), %edx
andl $0xfff, %edx            # imm = 0xFFF
movl %r14d, %eax
cmpw 0xc(%rsp), %dx
jne 0xf621
movzwl 0x60(%rbx,%rcx,2), %ecx
andl $0xfff, %ecx            # imm = 0xFFF
movl %r14d, %eax
cmpw 0x8(%rsp), %cx
jne 0xf621
testb $0x2, %bpl
jne 0xf54f
movl %r12d, %eax
movzwl 0x62(%rbx,%rax,2), %ecx
andl $0xfff, %ecx            # imm = 0xFFF
movl %r14d, %eax
cmpw 0xe(%rsp), %cx
jne 0xf621
leaq 0x9a72(%rip), %rax      # 0x18fc8
testb $0x20, (%rax)
jne 0xf5a0
movq %rbx, %rdi
movl %r12d, %esi
movl %ebp, %ebx
movl %r14d, %ebp
movl %r15d, %r14d
leaq 0x40(%rsp), %r15
movq %r15, %rdx
callq 0xfa4d
movq %r15, %rdi
movl %r14d, %r15d
movl %ebp, %r14d
movl %ebx, %ebp
movq 0x30(%rsp), %rbx
callq 0x30e0
movw $0xfff, %si             # imm = 0xFFF
movl %r14d, %eax
jmp 0xf621
movw $0x2, %ax
jmp 0xf621
xorl %ebp, %ebp
movl $0x0, %r15d
cmpw $0x0, 0x18(%rsp)
je 0xf5c0
movl %r12d, %eax
movzwl 0x64(%rbx,%rax,2), %r15d
andl $0xfff, %r15d           # imm = 0xFFF
movq 0x38(%rsp), %rax
addl %r12d, %eax
subw 0x5c(%rbx,%rax,2), %bp
andl $0xfff, %ebp            # imm = 0xFFF
movq %rbx, %rdi
movl %r12d, %esi
leaq 0x40(%rsp), %rdx
callq 0xfa4d
movzwl %bp, %ebp
movzwl %r15w, %edi
leaq 0x50(%rsp), %r15
movq %r15, %rsi
callq 0xfae5
leaq 0x35ec(%rip), %rdi      # 0x12bea
leaq 0x40(%rsp), %rsi
movl %ebp, %edx
movq %r15, %rcx
xorl %eax, %eax
callq 0x3160
movl %r14d, %eax
movb 0x7(%rsp), %bpl
movzwl 0xa(%rsp), %r15d
movw $0xfff, %si             # imm = 0xFFF
cwtl
addl %r12d, %eax
decw %r13w
jne 0xf4d2
movzwl 0x60(%rbx), %r12d
andl $0xfff, %r12d           # imm = 0xFFF
movl 0x14(%rsp), %eax
testl %eax, %eax
je 0xf64c
testl %r12d, %r12d
jne 0xf459
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x898e(%rip), %rax      # 0x17ff0
movq (%rax), %rdi
leaq 0x2716(%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 0x31d0