Subversion Repositories SvarDOS

Rev

Rev 421 | Rev 450 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
421 mateuszvis 1
/* This file is part of the SvarCOM project and is published under the terms
2
 * of the MIT license.
3
 *
4
 * Copyright (C) 2021 Mateusz Viste
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a
7
 * copy of this software and associated documentation files (the "Software"),
8
 * to deal in the Software without restriction, including without limitation
9
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10
 * and/or sell copies of the Software, and to permit persons to whom the
11
 * Software is furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be included in
14
 * all copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
 * DEALINGS IN THE SOFTWARE.
23
 */
24
 
405 mateuszvis 25
/*
26
 * echo
27
 */
28
 
29
static int cmd_echo(struct cmd_funcparam *p) {
30
  unsigned short offs = FP_OFF(p->cmdline) + 5;
31
  unsigned short segm = FP_SEG(p->cmdline);
449 mateuszvis 32
  unsigned char far *echostatus = MK_FP(p->rmod->rmodseg, RMOD_OFFSET_ECHOFLAG);
405 mateuszvis 33
 
34
  /* display help only if /? is the only argument */
35
  if ((p->argc == 1) && (imatch(p->argv[0], "/?"))) {
36
    outputnl("Displays messages, or turns command-echoing on or off");
37
    outputnl("");
38
    outputnl("ECHO [ON | OFF]");
39
    outputnl("ECHO [message]");
40
    outputnl("");
41
    outputnl("Type ECHO without parameters to display the current echo setting.");
42
    return(-1);
43
  }
44
 
45
  /* ECHO without any parameter: display current state */
46
  if (p->argc == 0) {
47
    if (*echostatus) {
48
      outputnl("ECHO is on");
49
    } else {
50
      outputnl("ECHO is off");
51
    }
52
    return(-1);
53
  }
54
 
55
  /* ECHO ON */
56
  if ((p->argc == 1) && (imatch(p->argv[0], "on"))) {
57
    *echostatus = 1;
58
    return(-1);
59
  }
60
 
61
  /* ECHO OFF */
62
  if ((p->argc == 1) && (imatch(p->argv[0], "off"))) {
63
    *echostatus = 0;
64
    return(-1);
65
  }
66
 
67
  /* ECHO MSG (start at cmdline+5 since first 5 are "ECHO" + separator) */
68
  _asm {
69
    push ax
70
    push dx
71
    push ds
72
    push si
73
 
74
    mov si, [offs]
75
    cld           /* clear direction flag (DF) so lodsb increments SI */
76
    mov ah, 0x02  /* display char from DL */
77
    mov ds, [segm]
78
    NEXTYBTE:
79
    lodsb         /* load byte at DS:[SI] into AL and inc SI (if DF clear) */
80
    or al, al     /* is AL == 0? then end of string reached */
81
    jz DONE
82
    mov dl, al
83
    int 0x21
84
    jmp NEXTYBTE
85
 
86
    /* output a final CR/LF */
87
    DONE:
88
    mov dl, 0x0D
89
    int 0x21
90
    mov dl, 0x0A
91
    int 0x21
92
 
93
    pop si
94
    pop ds
95
    pop dx
96
    pop ax
97
  }
98
 
99
  return(-1);
100
}