summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/libdos.cc
blob: b64bb6ee16db150cafa04afd32fa7dc402b3f60d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
 *  File:       libdos.cc
 *  Summary:    Functions for DOS support.
 *              Needed by makefile.dos.
 *  Written by: Darshan Shaligram
 *
 *  Added for Crawl Reference by dshaligram on Wed Nov 22 08:41:20 2006 UTC
 */

// Every .cc must include AppHdr or bad things happen.
#include "AppHdr.h"

#include "cio.h"
#include <termios.h>
#include <conio.h>
#include "options.h"
#include "viewgeom.h"

#if defined(TARGET_OS_DOS)

static bool cursor_is_enabled = true;

void init_libdos()
{
    struct termios charmode;

    tcgetattr (0, &charmode);
    // Ignore Ctrl-C
    charmode.c_lflag &= ~ISIG;
    tcsetattr (0, TCSANOW, &charmode);

    // Turn off blink.
    intensevideo();
}

void clear_message_window()
{
    window(crawl_view.msgp.x, crawl_view.msgp.y,
           get_number_of_cols(), get_number_of_lines());
    clrscr();
    window(1, 1, get_number_of_cols(), get_number_of_lines());
}

static void scroll_message_window()
{
    const int x = wherex(), y = wherey();

    textcolor(LIGHTGREY);
    movetext(crawl_view.msgp.x, crawl_view.msgp.y + 1,
             get_number_of_cols(), get_number_of_lines(),
             crawl_view.msgp.x, crawl_view.msgp.y);
    cgotoxy(1, get_number_of_lines());
    clreol();

    // Cursor also scrolls up so prompts don't look brain-damaged.
    if (y == get_number_of_lines())
        cgotoxy(x, y - 1);
}

void message_out(int *which_line, int colour, const char *s, int firstcol)
{
    if (!firstcol)
        firstcol = Options.delay_message_clear? 2 : 1;

    while (*which_line > crawl_view.msgsz.y - 1)
    {
        scroll_message_window();
        (*which_line)--;
    }

    cgotoxy(firstcol + crawl_view.msgp.x - 1,
           (*which_line) + crawl_view.msgp.y);
    textcolor(colour);

    cprintf("%s", s);
}

void set_cursor_enabled(bool enabled)
{
    cursor_is_enabled = enabled;
    _setcursortype( enabled? _NORMALCURSOR : _NOCURSOR );
}

bool is_cursor_enabled()
{
    return (cursor_is_enabled);
}

// This will force the cursor down to the next line.
void clear_to_end_of_line()
{
    clreol();
}

int get_number_of_lines()
{
    return (25);
}

int get_number_of_cols()
{
    return (80);
}

int getch_ck()
{
    int c = getch();
    if (!c)
    {
        switch (c = getch())
        {
        case 'O':  return CK_END;
        case 'P':  return CK_DOWN;
        case 'I':  return CK_PGUP;
        case 'H':  return CK_UP;
        case 'G':  return CK_HOME;
        case 'K':  return CK_LEFT;
        case 'Q':  return CK_PGDN;
        case 'M':  return CK_RIGHT;
        case 119:  return CK_CTRL_HOME;
        case 141:  return CK_CTRL_UP;
        case 132:  return CK_CTRL_PGUP;
        case 116:  return CK_CTRL_RIGHT;
        case 118:  return CK_CTRL_PGDN;
        case 145:  return CK_CTRL_DOWN;
        case 117:  return CK_CTRL_END;
        case 115:  return CK_CTRL_LEFT;
        case 'S':  return CK_DELETE;
        }
    }
    return c;
}

int m_getch()
{
    return getch();
}

void putwch(unsigned c)
{
    putch(static_cast<char>(c));
}

#endif /* #if defined(TARGET_OS_DOS) */