Subversion Repositories SvarDOS

Rev

Rev 384 | Rev 389 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 384 Rev 388
Line 29... Line 29...
29
#define cmd_dir_attr_arc 32
29
#define cmd_dir_attr_arc 32
30
 
30
 
31
 
31
 
32
static int cmd_dir(struct cmd_funcparam *p) {
32
static int cmd_dir(struct cmd_funcparam *p) {
33
  const char *filespecptr = "*.*";
33
  const char *filespecptr = "*.*";
34
  unsigned short errcode;
-
 
35
  _Packed struct DTA {
-
 
36
    char reserved[21];
-
 
37
    unsigned char attr;
-
 
38
    unsigned short time;
-
 
39
    unsigned short date;
-
 
40
    unsigned long size;
-
 
41
    char fname[13];
-
 
42
  } *dta = (void *)0x80; /* set DTA to its default location at 80h in PSP */
34
  struct DTA *dta = (void *)0x80; /* set DTA to its default location at 80h in PSP */
43
/*
-
 
44
 * FileInfoRec (DTA) format:
-
 
45
 * offset size desc
-
 
46
 *    +0   21  reserved
-
 
47
 *  +15h    1  file attr (1=RO 2=Hidden 4=System 8=VOL 16=DIR 32=Archive
-
 
48
 *  +16h    2  time: bits 0-4=bi-seconds (0-30), bits 5-10=minutes (0-59), bits 11-15=hour (0-23)
-
 
49
 *  +18h    2  date: bits 0-4=day(0-31), bits 5-8=month (1-12), bits 9-15=years since 1980
-
 
50
 *  +1ah    4  DWORD file size, in bytes
-
 
51
 *  +1eh   13  13-bytes max ASCIIZ filename
-
 
52
 */
-
 
53
 
-
 
54
  errcode = 0;
-
 
55
  _asm {
-
 
56
    push ax
-
 
57
    push cx
-
 
58
    push dx
-
 
59
    /* query DTA location */
-
 
60
    /* mov ah, 0x2f */
-
 
61
    /* int 0x21 */ /* DTA address is in ES:BX now */
-
 
62
    /* mov dta+2, es */
-
 
63
    /* mov dta, bx */
-
 
64
    /* set DTA location */
-
 
65
    mov ah, 0x1a
-
 
66
    mov dx, dta
-
 
67
    int 0x21
-
 
68
    /* FindFirst */
-
 
69
    mov ah, 0x4e
-
 
70
    mov dx, filespecptr   /* filespec */
-
 
71
    mov cx, 0xff         /* file attr to match: when a bit is clear, files with that attr will NOT be found */
-
 
72
    int 0x21
-
 
73
    jnc DONE
-
 
74
    mov errcode, ax
-
 
75
    DONE:
-
 
76
    pop dx
-
 
77
    pop cx
-
 
78
    pop ax
-
 
79
  }
-
 
80
  if (errcode != 0) return(-1);
-
 
81
 
35
 
82
  outputnl(dta->fname);
36
  if (findfirst(dta, filespecptr, cmd_dir_attr_ro | cmd_dir_attr_hid | cmd_dir_attr_sys | cmd_dir_attr_dir | cmd_dir_attr_arc) != 0) return(-1);
83
 
37
 
84
  NEXTFILE:
38
  outputnl(dta->fname);
85
 
39
 
86
  _asm {
-
 
87
    push ax
-
 
88
    push cx
-
 
89
    push dx
-
 
90
    mov ah, 0x4f /* FindNext */
-
 
91
    mov dx, dta
-
 
92
    int 0x21
-
 
93
    jnc DONE
-
 
94
    mov errcode, ax
-
 
95
    DONE:
-
 
96
    pop dx
-
 
97
    pop cx
-
 
98
    pop ax
-
 
99
  }
-
 
100
 
-
 
101
  if (errcode == 0) {
-
 
102
    outputnl(dta->fname);
40
  while (findnext(dta) == 0) outputnl(dta->fname);
103
    goto NEXTFILE;
-
 
104
  }
-
 
105
 
41
 
106
  return(-1);
42
  return(-1);
107
}
43
}