Subversion Repositories SvarDOS

Rev

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

Rev 404 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
 * cls
26
 * cls
3
 */
27
 */
4
 
28
 
5
static int cmd_cls(struct cmd_funcparam *p) {
29
static int cmd_cls(struct cmd_funcparam *p) {
6
  unsigned char screenw, screenh;
30
  unsigned char screenw, screenh;
7
  const char *ansiesc = "\x1B[2J$";
31
  const char *ansiesc = "\x1B[2J$";
8
 
32
 
9
  if (cmd_ishlp(p)) {
33
  if (cmd_ishlp(p)) {
10
    outputnl("Clears the screen");
34
    outputnl("Clears the screen");
11
    outputnl("");
35
    outputnl("");
12
    outputnl("CLS");
36
    outputnl("CLS");
13
    return(-1);
37
    return(-1);
14
  }
38
  }
15
 
39
 
16
  screenw = screen_getwidth();
40
  screenw = screen_getwidth();
17
  screenh = screen_getheight();
41
  screenh = screen_getheight();
18
 
42
 
19
  _asm {
43
  _asm {
20
    /* output an ANSI ESC code for "clear screen" in case the console is
44
    /* output an ANSI ESC code for "clear screen" in case the console is
21
     * some kind of terminal */
45
     * some kind of terminal */
22
    mov ah, 0x09     /* write $-terminated string to stdout */
46
    mov ah, 0x09     /* write $-terminated string to stdout */
23
    mov dx, ansiesc
47
    mov dx, ansiesc
24
    int 0x21
48
    int 0x21
25
 
49
 
26
    /* check what stdout is set to */
50
    /* check what stdout is set to */
27
    mov ax, 0x4400   /* IOCTL query device/flags flags */
51
    mov ax, 0x4400   /* IOCTL query device/flags flags */
28
    mov bx, 1        /* file handle (1 = stdout) */
52
    mov bx, 1        /* file handle (1 = stdout) */
29
    int 0x21         /* CF set on error, otherwise DX set with flags */
53
    int 0x21         /* CF set on error, otherwise DX set with flags */
30
    jc DONE          /* abort on error */
54
    jc DONE          /* abort on error */
31
    /* DX = 10000010
55
    /* DX = 10000010
32
            |   |||
56
            |   |||
33
            |   ||+--- indicates standard output
57
            |   ||+--- indicates standard output
34
            |   |+---- set if NUL device
58
            |   |+---- set if NUL device
35
            |   +----- set if CLOCK device
59
            |   +----- set if CLOCK device
36
            +--------- set if handle is a device (ie. not a file)
60
            +--------- set if handle is a device (ie. not a file)
37
            in other words, DL & 10001110 (8Eh) should result in 10000010 (82h)
61
            in other words, DL & 10001110 (8Eh) should result in 10000010 (82h)
38
            */
62
            */
39
    and dl, 0x8e
63
    and dl, 0x8e
40
    cmp dl, 0x82
64
    cmp dl, 0x82
41
    jne DONE         /* abort on error */
65
    jne DONE         /* abort on error */
42
 
66
 
43
    /* scroll vram out of screen */
67
    /* scroll vram out of screen */
44
    mov ax, 0x0600   /* scroll up entire rectangle */
68
    mov ax, 0x0600   /* scroll up entire rectangle */
45
    mov bh, 0x07     /* fill screen with white-on-black */
69
    mov bh, 0x07     /* fill screen with white-on-black */
46
    xor cx, cx       /* upper left location in CH,CL (0,0) */
70
    xor cx, cx       /* upper left location in CH,CL (0,0) */
47
    /* DX is bottom right location of rectangle (DH=row, DL=column) */
71
    /* DX is bottom right location of rectangle (DH=row, DL=column) */
48
    mov dh, [screenh]
72
    mov dh, [screenh]
49
    dec dh
73
    dec dh
50
    mov dl, [screenw]
74
    mov dl, [screenw]
51
    dec dl
75
    dec dl
52
    int 0x10
76
    int 0x10
53
 
77
 
54
    /* set cursor to top left corner (0,0) of the screen */
78
    /* set cursor to top left corner (0,0) of the screen */
55
    mov ah, 0x02     /* set cursor position */
79
    mov ah, 0x02     /* set cursor position */
56
    xor bh, bh       /* page number */
80
    xor bh, bh       /* page number */
57
    xor dx, dx       /* location in DH,DL */
81
    xor dx, dx       /* location in DH,DL */
58
    int 0x10
82
    int 0x10
59
    DONE:
83
    DONE:
60
  }
84
  }
61
 
85
 
62
  return(-1);
86
  return(-1);
63
}
87
}
64
 
88