Subversion Repositories SvarDOS

Rev

Rev 475 | Rev 534 | 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
 
533 mateuszvis 29
static enum cmd_result cmd_echo(struct cmd_funcparam *p) {
405 mateuszvis 30
  unsigned short offs = FP_OFF(p->cmdline) + 5;
31
  unsigned short segm = FP_SEG(p->cmdline);
32
 
33
  /* display help only if /? is the only argument */
34
  if ((p->argc == 1) && (imatch(p->argv[0], "/?"))) {
35
    outputnl("Displays messages, or turns command-echoing on or off");
36
    outputnl("");
37
    outputnl("ECHO [ON | OFF]");
38
    outputnl("ECHO [message]");
39
    outputnl("");
40
    outputnl("Type ECHO without parameters to display the current echo setting.");
533 mateuszvis 41
    return(CMD_OK);
405 mateuszvis 42
  }
43
 
44
  /* ECHO without any parameter: display current state */
45
  if (p->argc == 0) {
475 mateuszvis 46
    if (p->rmod->flags & FLAG_ECHOFLAG) {
405 mateuszvis 47
      outputnl("ECHO is on");
48
    } else {
49
      outputnl("ECHO is off");
50
    }
533 mateuszvis 51
    return(CMD_OK);
405 mateuszvis 52
  }
53
 
54
  /* ECHO ON */
55
  if ((p->argc == 1) && (imatch(p->argv[0], "on"))) {
475 mateuszvis 56
    p->rmod->flags |= FLAG_ECHOFLAG;
533 mateuszvis 57
    return(CMD_OK);
405 mateuszvis 58
  }
59
 
60
  /* ECHO OFF */
61
  if ((p->argc == 1) && (imatch(p->argv[0], "off"))) {
475 mateuszvis 62
    p->rmod->flags &= ~FLAG_ECHOFLAG;
533 mateuszvis 63
    return(CMD_OK);
405 mateuszvis 64
  }
65
 
66
  /* ECHO MSG (start at cmdline+5 since first 5 are "ECHO" + separator) */
67
  _asm {
68
    push ax
69
    push dx
70
    push ds
71
    push si
72
 
73
    mov si, [offs]
74
    cld           /* clear direction flag (DF) so lodsb increments SI */
75
    mov ah, 0x02  /* display char from DL */
76
    mov ds, [segm]
77
    NEXTYBTE:
78
    lodsb         /* load byte at DS:[SI] into AL and inc SI (if DF clear) */
79
    or al, al     /* is AL == 0? then end of string reached */
80
    jz DONE
81
    mov dl, al
82
    int 0x21
83
    jmp NEXTYBTE
84
 
85
    /* output a final CR/LF */
86
    DONE:
87
    mov dl, 0x0D
88
    int 0x21
89
    mov dl, 0x0A
90
    int 0x21
91
 
92
    pop si
93
    pop ds
94
    pop dx
95
    pop ax
96
  }
97
 
533 mateuszvis 98
  return(CMD_OK);
405 mateuszvis 99
}