Subversion Repositories SvarDOS

Rev

Rev 421 | Go to most recent revision | Details | Last modification | View Log | RSS feed

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