Subversion Repositories SvarDOS

Rev

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

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