Subversion Repositories SvarDOS

Rev

Rev 450 | Rev 533 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 450 Rev 475
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 Mateusz Viste
4
 * Copyright (C) 2021 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,
10
 * and/or sell copies of the Software, and to permit persons to whom the
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:
11
 * Software is furnished to do so, subject to the following conditions:
12
 *
12
 *
13
 * The above copyright notice and this permission notice shall be included in
13
 * The above copyright notice and this permission notice shall be included in
14
 * all copies or substantial portions of the Software.
14
 * all copies or substantial portions of the Software.
15
 *
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
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,
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
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
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
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
21
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
 * DEALINGS IN THE SOFTWARE.
22
 * DEALINGS IN THE SOFTWARE.
23
 */
23
 */
24
 
24
 
25
/*
25
/*
26
 * echo
26
 * echo
27
 */
27
 */
28
 
28
 
29
static int cmd_echo(struct cmd_funcparam *p) {
29
static int cmd_echo(struct cmd_funcparam *p) {
30
  unsigned short offs = FP_OFF(p->cmdline) + 5;
30
  unsigned short offs = FP_OFF(p->cmdline) + 5;
31
  unsigned short segm = FP_SEG(p->cmdline);
31
  unsigned short segm = FP_SEG(p->cmdline);
32
 
32
 
33
  /* display help only if /? is the only argument */
33
  /* display help only if /? is the only argument */
34
  if ((p->argc == 1) && (imatch(p->argv[0], "/?"))) {
34
  if ((p->argc == 1) && (imatch(p->argv[0], "/?"))) {
35
    outputnl("Displays messages, or turns command-echoing on or off");
35
    outputnl("Displays messages, or turns command-echoing on or off");
36
    outputnl("");
36
    outputnl("");
37
    outputnl("ECHO [ON | OFF]");
37
    outputnl("ECHO [ON | OFF]");
38
    outputnl("ECHO [message]");
38
    outputnl("ECHO [message]");
39
    outputnl("");
39
    outputnl("");
40
    outputnl("Type ECHO without parameters to display the current echo setting.");
40
    outputnl("Type ECHO without parameters to display the current echo setting.");
41
    return(-1);
41
    return(-1);
42
  }
42
  }
43
 
43
 
44
  /* ECHO without any parameter: display current state */
44
  /* ECHO without any parameter: display current state */
45
  if (p->argc == 0) {
45
  if (p->argc == 0) {
46
    if (p->rmod->echoflag) {
46
    if (p->rmod->flags & FLAG_ECHOFLAG) {
47
      outputnl("ECHO is on");
47
      outputnl("ECHO is on");
48
    } else {
48
    } else {
49
      outputnl("ECHO is off");
49
      outputnl("ECHO is off");
50
    }
50
    }
51
    return(-1);
51
    return(-1);
52
  }
52
  }
53
 
53
 
54
  /* ECHO ON */
54
  /* ECHO ON */
55
  if ((p->argc == 1) && (imatch(p->argv[0], "on"))) {
55
  if ((p->argc == 1) && (imatch(p->argv[0], "on"))) {
56
    p->rmod->echoflag = 1;
56
    p->rmod->flags |= FLAG_ECHOFLAG;
57
    return(-1);
57
    return(-1);
58
  }
58
  }
59
 
59
 
60
  /* ECHO OFF */
60
  /* ECHO OFF */
61
  if ((p->argc == 1) && (imatch(p->argv[0], "off"))) {
61
  if ((p->argc == 1) && (imatch(p->argv[0], "off"))) {
62
    p->rmod->echoflag = 0;
62
    p->rmod->flags &= ~FLAG_ECHOFLAG;
63
    return(-1);
63
    return(-1);
64
  }
64
  }
65
 
65
 
66
  /* ECHO MSG (start at cmdline+5 since first 5 are "ECHO" + separator) */
66
  /* ECHO MSG (start at cmdline+5 since first 5 are "ECHO" + separator) */
67
  _asm {
67
  _asm {
68
    push ax
68
    push ax
69
    push dx
69
    push dx
70
    push ds
70
    push ds
71
    push si
71
    push si
72
 
72
 
73
    mov si, [offs]
73
    mov si, [offs]
74
    cld           /* clear direction flag (DF) so lodsb increments SI */
74
    cld           /* clear direction flag (DF) so lodsb increments SI */
75
    mov ah, 0x02  /* display char from DL */
75
    mov ah, 0x02  /* display char from DL */
76
    mov ds, [segm]
76
    mov ds, [segm]
77
    NEXTYBTE:
77
    NEXTYBTE:
78
    lodsb         /* load byte at DS:[SI] into AL and inc SI (if DF clear) */
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 */
79
    or al, al     /* is AL == 0? then end of string reached */
80
    jz DONE
80
    jz DONE
81
    mov dl, al
81
    mov dl, al
82
    int 0x21
82
    int 0x21
83
    jmp NEXTYBTE
83
    jmp NEXTYBTE
84
 
84
 
85
    /* output a final CR/LF */
85
    /* output a final CR/LF */
86
    DONE:
86
    DONE:
87
    mov dl, 0x0D
87
    mov dl, 0x0D
88
    int 0x21
88
    int 0x21
89
    mov dl, 0x0A
89
    mov dl, 0x0A
90
    int 0x21
90
    int 0x21
91
 
91
 
92
    pop si
92
    pop si
93
    pop ds
93
    pop ds
94
    pop dx
94
    pop dx
95
    pop ax
95
    pop ax
96
  }
96
  }
97
 
97
 
98
  return(-1);
98
  return(-1);
99
}
99
}
100
 
100