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