Subversion Repositories SvarDOS

Rev

Rev 989 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 989 Rev 1823
Line 1... Line 1...
1
/* This file is part of the SvarCOM project and is published under the terms
1
/* This file is part of the SvarCOM project and is published under the terms
2
 * of the MIT license.
2
 * of the MIT license.
3
 *
3
 *
4
 * Copyright (C) 2021-2022 Mateusz Viste
4
 * Copyright (C) 2021-2024 Mateusz Viste
5
 *
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a
6
 * Permission is hereby granted, free of charge, to any person obtaining a
7
 * copy of this software and associated documentation files (the "Software"),
7
 * copy of this software and associated documentation files (the "Software"),
8
 * to deal in the Software without restriction, including without limitation
8
 * to deal in the Software without restriction, including without limitation
9
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
Line 46... Line 46...
46
 
46
 
47
 
47
 
48
/* parse a NULL-terminated string int hour, minutes and seconds, returns 0 on success
48
/* parse a NULL-terminated string int hour, minutes and seconds, returns 0 on success
49
 * valid inputs: 0, 7, 5:5, 23:23, 17:54:45, 9p, 9:05, ...
49
 * valid inputs: 0, 7, 5:5, 23:23, 17:54:45, 9p, 9:05, ...
50
 */
50
 */
51
static int cmd_time_parse(const char *s, signed char *ho, signed char *mi, signed char *se, struct nls_patterns *nls) {
51
static int cmd_time_parse(const char *s, unsigned char *ho, unsigned char *mi, unsigned char *se, struct nls_patterns *nls) {
52
  unsigned short i;
52
  unsigned short i;
53
  const char *ptrs[2] = {NULL, NULL}; /* minutes, seconds */
53
  const char *ptrs[2] = {NULL, NULL}; /* minutes, seconds */
54
  char buff[3];
54
  char buff[3];
55
  char ampm = 0;
55
  char ampm = 0;
56
 
56
 
Line 127... Line 127...
127
  }
127
  }
128
 
128
 
129
  return(0);
129
  return(0);
130
 
130
 
131
  FAIL:
131
  FAIL:
132
  *ho = -1;
132
  *ho = 255;
133
  return(-1);
133
  return(-1);
134
}
134
}
135
 
135
 
136
 
136
 
137
static enum cmd_result cmd_time(struct cmd_funcparam *p) {
137
static enum cmd_result cmd_time(struct cmd_funcparam *p) {
138
  struct nls_patterns *nls = (void *)(p->BUFFER);
138
  struct nls_patterns *nls = (void *)(p->BUFFER);
139
  char *buff = p->BUFFER + sizeof(*nls);
139
  char *buff = p->BUFFER + sizeof(*nls);
140
  unsigned short i;
140
  unsigned short i;
141
  signed char ho = -1, mi = -1, se = -1;
141
  unsigned char ho = 255, mi, se;
142
 
142
 
143
  if (cmd_ishlp(p)) {
143
  if (cmd_ishlp(p)) {
144
    nls_outputnl(22,0); /* "Displays or sets the system time." */
144
    nls_outputnl(22,0); /* "Displays or sets the system time." */
145
    outputnl("");
145
    outputnl("");
146
    nls_outputnl(22,1); /* "TIME [time]" */
146
    nls_outputnl(22,1); /* "TIME [time]" */
Line 156... Line 156...
156
  }
156
  }
157
 
157
 
158
  /* display current time if no args */
158
  /* display current time if no args */
159
  if (p->argc == 0) {
159
  if (p->argc == 0) {
160
    /* get cur time */
160
    /* get cur time */
161
    _asm {
-
 
162
      push ax
-
 
163
      push bx
-
 
164
      push cx
-
 
165
      push dx
161
    dos_get_time(&ho, &mi, &se);
166
 
162
 
167
      mov ah, 0x2c  /* DOS 1+ -- Query DOS Time */
-
 
168
      int 0x21      /* CH=hour CL=minutes DH=seconds DL=1/100sec */
-
 
169
      mov [ho], ch
-
 
170
      mov [mi], cl
-
 
171
      mov [se], dh
-
 
172
 
-
 
173
      pop dx
-
 
174
      pop cx
-
 
175
      pop bx
-
 
176
      pop ax
-
 
177
    }
-
 
178
    buff[0] = ' ';
163
    buff[0] = ' ';
179
    nls_format_time(buff + 1, ho, mi, se, nls);
164
    nls_format_time(buff + 1, ho, mi, se, nls);
180
    nls_output(22,3); /* "Current time is" */
165
    nls_output(22,3); /* "Current time is" */
181
    outputnl(buff);
166
    outputnl(buff);
182
    ho = -1;
167
    ho = 255;
183
  } else { /* parse time if provided */
168
  } else { /* parse time if provided */
184
    if (cmd_time_parse(p->argv[0], &ho, &mi, &se, nls) != 0) {
169
    if (cmd_time_parse(p->argv[0], &ho, &mi, &se, nls) != 0) {
185
      nls_outputnl(22,4); /* "Invalid time" */
170
      nls_outputnl(22,4); /* "Invalid time" */
186
      ho = -1;
171
      ho = 255;
187
    }
172
    }
188
  }
173
  }
189
 
174
 
190
  /* ask for time if not provided or if input was malformed */
175
  /* ask for time if not provided or if input was malformed */
191
  while (ho < 0) {
176
  while (ho == 255) {
192
    nls_output(22,5); /* "Enter new time:" */
177
    nls_output(22,5); /* "Enter new time:" */
193
    output(" ");
178
    output(" ");
194
    /* collect user input into buff */
179
    /* collect user input into buff */
195
    _asm {
180
    _asm {
196
      push ax
181
      push ax
Line 225... Line 210...
225
    if (cmd_time_parse(buff + 2, &ho, &mi, &se, nls) == 0) break;
210
    if (cmd_time_parse(buff + 2, &ho, &mi, &se, nls) == 0) break;
226
    nls_outputnl(22,4); /* "Invalid time" */
211
    nls_outputnl(22,4); /* "Invalid time" */
227
    return(CMD_FAIL);
212
    return(CMD_FAIL);
228
  }
213
  }
229
 
214
 
230
  if (ho >= 0) {
215
  if (ho != 255) {
231
    /* set time */
216
    /* set time */
232
    _asm {
217
    _asm {
233
      push ax
218
      push ax
234
      push bx
219
      push bx
235
      push cx
220
      push cx