Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
42 pj 1
/* Project:     OSLib
2
 * Description: The OS Construction Kit
3
 * Date:                1.6.2000
4
 * Idea by:             Luca Abeni & Gerardo Lamastra
5
 *
6
 * OSLib is an SO project aimed at developing a common, easy-to-use
7
 * low-level infrastructure for developing OS kernels and Embedded
8
 * Applications; it partially derives from the HARTIK project but it
9
 * currently is independently developed.
10
 *
11
 * OSLib is distributed under GPL License, and some of its code has
12
 * been derived from the Linux kernel source; also some important
13
 * ideas come from studying the DJGPP go32 extender.
14
 *
15
 * We acknowledge the Linux Community, Free Software Foundation,
16
 * D.J. Delorie and all the other developers who believe in the
17
 * freedom of software and ideas.
18
 *
19
 * For legalese, check out the included GPL license.
20
 */
21
 
22
/*      Console output functions - part 2       */
23
 
24
#include <ll/i386/hw-data.h>
25
#include <ll/i386/hw-instr.h>
26
#include <ll/i386/cons.h>
27
/* #include <xsys.h>*/
28
#include <ll/i386/string.h>
29
#include <ll/i386/stdlib.h>
30
#include <ll/i386/stdio.h>
31
#include <ll/stdarg.h>
32
 
33
FILE(Cons2);
34
 
35
#define PAGE_SIZE               2048
36
#define PAGE_MAX                8
37
 
38
/* CGA compatible registers */
39
 
40
#define CGA_INDEX_REG   0x3D4
41
#define CGA_DATA_REG    0x3D5
42
 
43
#define VIDEO_ADDRESS_MSB       0x0C
44
#define VIDEO_ADDRESS_LSB       0x0D
45
 
46
 
47
extern int active_page;
48
extern int visual_page;
49
static int curs_x[PAGE_MAX];
50
static int curs_y[PAGE_MAX];
51
extern BYTE bios_x, bios_y, bios_attr;
52
 
53
void set_visual_page(int page)
54
{
55
    unsigned short page_offset;
56
 
57
    page_offset = page * PAGE_SIZE;
58
    visual_page = page;
59
    outp(CGA_INDEX_REG, VIDEO_ADDRESS_LSB);
60
    outp(CGA_DATA_REG, page_offset & 0xFF);
61
    outp(CGA_INDEX_REG, VIDEO_ADDRESS_MSB);
62
    outp(CGA_DATA_REG, (page_offset >> 8) & 0xFF);
63
}
64
 
65
void set_active_page(int page)
66
{
67
    curs_x[active_page] = bios_x;
68
    curs_y[active_page] = bios_y;
69
    bios_x = curs_x[page];
70
    bios_y = curs_y[page];
71
    active_page = page;
72
}
73
 
74
int get_visual_page(void)
75
{
76
    return(visual_page);
77
}
78
 
79
int get_active_page(void)
80
{
81
    return(active_page);
82
}
83
 
84
void _clear(char c,char attr,int x1,int y1,int x2,int y2)
85
{
86
    register int i,j;
87
    WORD w = attr;
88
 
89
    w <<= 8; w |= c;
90
    for (i = x1; i <= x2; i++)
91
        for (j = y1; j <= y2; j++)
92
            lmempokew((LIN_ADDR)(0xB8000 + 2*i+160*j + 2*active_page*PAGE_SIZE),w);
93
    place(x1,y1);
94
    bios_y = y1;
95
    bios_x = x1;
96
}
97
 
98
void clear()
99
{
100
    _clear(' ',bios_attr,0,0,79,24);
101
}
102
 
103
void puts_xy(int x,int y,char attr,char *s)
104
{
105
    LIN_ADDR v = (LIN_ADDR)(0xB8000 + (80*y+x)*2 + active_page*(2*PAGE_SIZE));
106
    while (*s != 0) {
107
        /* REMEMBER! This is a macro! v++ is out to prevent side-effects */
108
        lmempokeb(v,*s); s++; v++;
109
        lmempokeb(v,attr); v++;
110
    }
111
}
112
 
113
void putc_xy(int x,int y,char attr,char c)
114
{
115
    LIN_ADDR v = (LIN_ADDR)(0xB8000 + (80*y+x)*2 + active_page*(2*PAGE_SIZE));
116
    /* REMEMBER! This is a macro! v++ is out to prevent side-effects */
117
    lmempokeb(v,c); v++;
118
    lmempokeb(v,attr);
119
}
120
 
121
char getc_xy(int x,int y,char *attr,char *c)
122
{
123
    LIN_ADDR v = (LIN_ADDR)(0xB8000 + (80*y+x)*2 + active_page*(2*PAGE_SIZE));
124
    char r;
125
    r = lmempeekb(v); v++;
126
    if (c != NULL) *c = r;
127
    r = lmempeekb(v);
128
    if (attr != NULL) *attr = r;
129
    return(r);
130
}