[f40a309] | 1 | /*
|
---|
| 2 | =============================================================================
|
---|
| 3 | dirfns.c -- miscellaneous directory functions
|
---|
| 4 | Version 4 -- 1987-06-04 -- D.N. Lynx Crowe
|
---|
| 5 | =============================================================================
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #include "stddefs.h"
|
---|
| 9 | #include "biosdefs.h"
|
---|
| 10 |
|
---|
[7258c6a] | 11 | extern int32_t sprintf(int8_t *str, int8_t *fmt, ...);
|
---|
[f40a309] | 12 |
|
---|
[7258c6a] | 13 | static int8_t atrcons[] = "ADVSHR";
|
---|
[f40a309] | 14 |
|
---|
| 15 | /*
|
---|
| 16 | =============================================================================
|
---|
| 17 | atrstr(atr, s) -- convert attributes to character string
|
---|
| 18 | =============================================================================
|
---|
| 19 | */
|
---|
| 20 |
|
---|
[7258c6a] | 21 | int8_t *atrstr(int16_t atr, int8_t s[])
|
---|
[f40a309] | 22 | {
|
---|
[7258c6a] | 23 | register int16_t i, j;
|
---|
[f40a309] | 24 |
|
---|
| 25 | i = 0x20;
|
---|
| 26 |
|
---|
| 27 | for (j = 0; j < 6; j++) {
|
---|
| 28 |
|
---|
| 29 | if (atr & i)
|
---|
| 30 | s[j] = atrcons[j];
|
---|
| 31 | else
|
---|
| 32 | s[j] = '-';
|
---|
| 33 |
|
---|
| 34 | i >>= 1;
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | s[j] = '\0';
|
---|
| 38 | return(s);
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | /* |
---|
| 42 | */
|
---|
[7258c6a] | 43 |
|
---|
[f40a309] | 44 | static int8_t *mnames[] = {
|
---|
| 45 |
|
---|
| 46 | "???",
|
---|
| 47 | "Jan",
|
---|
| 48 | "Feb",
|
---|
| 49 | "Mar",
|
---|
| 50 | "Apr",
|
---|
| 51 | "May",
|
---|
| 52 | "Jun",
|
---|
| 53 | "Jul",
|
---|
| 54 | "Aug",
|
---|
| 55 | "Sep",
|
---|
| 56 | "Oct",
|
---|
| 57 | "Nov",
|
---|
| 58 | "Dec"
|
---|
| 59 | };
|
---|
| 60 |
|
---|
| 61 | /*
|
---|
| 62 | =============================================================================
|
---|
| 63 | mname - convert month number to month name
|
---|
| 64 | =============================================================================
|
---|
| 65 | */
|
---|
[7258c6a] | 66 |
|
---|
[f40a309] | 67 | int8_t *mname(int16_t n)
|
---|
| 68 | {
|
---|
| 69 | return((n < 1 || n > 12) ? mnames[0] : mnames[n]);
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | /* |
---|
| 73 | */
|
---|
| 74 |
|
---|
| 75 | /*
|
---|
| 76 | =============================================================================
|
---|
| 77 | dtunpk(din, tin, s, fmt) -- unpack the date and time from DOS format
|
---|
| 78 | into "yyyy-mm-dd hh:mm", "yyyy mmm dd hh:mm", or "mmm dd yyyy hh:mm"
|
---|
| 79 | format.
|
---|
| 80 | =============================================================================
|
---|
[7258c6a] | 81 | */
|
---|
[f40a309] | 82 |
|
---|
[7258c6a] | 83 | int8_t *dtunpk(int16_t din, int16_t tin, int16_t fmt, int8_t *s)
|
---|
[f40a309] | 84 | {
|
---|
| 85 | register int16_t ftm, fdt;
|
---|
| 86 |
|
---|
| 87 | ftm = ((tin << 8) & 0xFF00) | ((tin >> 8) & 0x00FF);
|
---|
| 88 | fdt = ((din << 8) & 0xFF00) | ((din >> 8) & 0x00FF);
|
---|
| 89 |
|
---|
| 90 | switch (fmt) {
|
---|
| 91 |
|
---|
| 92 | case 0: /* yyyy-mm-dd hh:mm format */
|
---|
| 93 |
|
---|
| 94 | sprintf(s, "%04d-%02d-%02d %02d:%02d",
|
---|
| 95 | 1980 + ((fdt >> 9) & 0x7F),
|
---|
| 96 | (fdt >> 5) & 0xF,
|
---|
| 97 | fdt & 0x1F,
|
---|
| 98 | (ftm >> 11) & 0x1F,
|
---|
| 99 | (ftm >> 5) & 0x3F
|
---|
| 100 | );
|
---|
| 101 |
|
---|
| 102 | s[16] = '\0';
|
---|
| 103 | break;
|
---|
| 104 |
|
---|
| 105 | case 1: /* yyyy mmm dd hh:mm format */
|
---|
| 106 | default:
|
---|
| 107 |
|
---|
| 108 | sprintf(s, "%04d %s %-2d %02d:%02d",
|
---|
| 109 | 1980 + ((fdt >> 9) & 0x7F),
|
---|
| 110 | mname((fdt >> 5) & 0xF),
|
---|
| 111 | fdt & 0x1F,
|
---|
| 112 | (ftm >> 11) & 0x1F,
|
---|
| 113 | (ftm >> 5) & 0x3F
|
---|
| 114 | );
|
---|
| 115 |
|
---|
| 116 | s[17] = '\0';
|
---|
| 117 | break;
|
---|
| 118 |
|
---|
| 119 | /* |
---|
| 120 | */
|
---|
| 121 |
|
---|
| 122 | case 2: /* mmm dd yyyy hh:mm format */
|
---|
| 123 |
|
---|
| 124 | sprintf(s, "%s %2d %04d %02d:%02d",
|
---|
| 125 | mname((fdt >> 5) & 0xF),
|
---|
| 126 | fdt & 0x1F,
|
---|
| 127 | 1980 + ((fdt >> 9) & 0x7F),
|
---|
| 128 | (ftm >> 11) & 0x1F,
|
---|
| 129 | (ftm >> 5) & 0x3F
|
---|
| 130 | );
|
---|
| 131 |
|
---|
| 132 | s[17] = '\0';
|
---|
| 133 | break;
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | return(s);
|
---|
| 137 | }
|
---|