summaryrefslogtreecommitdiff
path: root/rhtvision/classes/dos/vgaregs.c
blob: ed700882b280ad6373c111d56c1cc0db9c84e4cc (plain)
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/* Copyright 2000 (c) by Salvador Eduardo Tropea
   This code is part of the port of Turbo Vision to gcc, please see the rest
 of the file for copying information.
 */
/*
  This module provides the functions declared inline in vgaregs.h.
  They are needed only if you compile without optimizations.
*/
#include <tv/configtv.h>

#define NO_INLINE
typedef unsigned char uchar;
typedef unsigned short ushort;
#include "vgaregs.h"

#ifdef TVCompf_djgpp

#ifdef SAFE_IO
/* C approach, safier than my assembler ;-) */

uchar ReadCRT(uchar index)
{
 outportb(CRTControllerIndex,index);
 return inportb(CRTControllerData);
}

uchar ReadGRA(uchar index)
{
 outportb(GraphicsControllerIndex,index);
 return inportb(GraphicsControllerData);
}

uchar ReadSEQ(uchar index)
{
 outportb(SequencerIndex,index);
 return inportb(SequencerData);
}

void WriteCRT(uchar index, uchar value)
{
 outportb(CRTControllerIndex,index);
 outportb(CRTControllerData,value);
}


void WriteGRA(uchar index, uchar value)
{
 outportb(GraphicsControllerIndex,index);
 outportb(GraphicsControllerData,value);
}

void WriteSEQ(uchar index, uchar value)
{
 outportb(SequencerIndex,index);
 outportb(SequencerData,value);
}

void WaitVRT()
{
 while (inportb(InputStatusRegister1) & 8);
 while (!(inportb(InputStatusRegister1) & 8));
}

#else

uchar ReadCRT(uchar index)
{
 int dummy;
 uchar a RegEAX;
 a=index;
 asm volatile (
"     outb %%al,%%dx          \n"
"     incl %%edx              \n"
"     inb  %%dx,%%al          \n"
      : "=a" (a), "=d" (dummy) : "a" (a), "d" (CRTController));
 return a;
}


uchar ReadGRA(uchar index)
{
 int dummy;
 uchar a RegEAX;
 a=index;
 asm volatile (
"     outb %%al,%%dx          \n"
"     incl %%edx              \n"
"     inb  %%dx,%%al          \n"
      : "=a" (a), "=d" (dummy) : "a" (a), "d" (GraphicsController));
 return a;
}

uchar ReadSEQ(uchar index)
{
 int dummy;
 uchar a RegEAX;
 a=index;
 asm volatile (
"     outb %%al,%%dx          \n"
"     incl %%edx              \n"
"     inb  %%dx,%%al          \n"
     : "=a" (a), "=d" (dummy)  : "a" (a), "d" (Sequencer));
 return a;
}

void WriteCRT(uchar index, uchar value)
{
 int dummy;
 asm volatile (
"     movb %1,%%ah            \n"
"     outw %%ax,%%dx          \n"
     : "=a" (dummy) : "qi" (value), "a" (index), "d" (CRTController));
}

void WriteGRA(uchar index, uchar value)
{
 int dummy;
 asm volatile (
"     movb %1,%%ah          \n"
"     outw %%ax,%%dx        \n"
     : "=a" (dummy) : "qi" (value), "a" (index), "d" (GraphicsController));
}

void WriteSEQ(uchar index, uchar value)
{
 int dummy;
 asm volatile (
"     movb %1,%%ah          \n"
"     outw %%ax,%%dx        \n"
     : "=a" (dummy) : "qi" (value), "a" (index), "d" (Sequencer));
}

void WaitVRT()
{
 asm volatile(
" 1:                         \n"
"     inb   %%dx,%%al        \n"
"     testb $8,%%al          \n"
"     jne 1b                 \n"
"     .align 2,0x90          \n"
" 2:                         \n"
"     inb %%dx,%%al          \n"
"     testb $8,%%al          \n"
"     je 2b                  \n"
      : : "d" (InputStatusRegister1) : "%eax" );
}

#endif

uchar ReadATT(int index)
{
 /* Ensure we will write to the index */
 inportb(ATTdir);
 /* Set the index and disable the screen or we will read nothing */
 outportb(ATTindex,index);
 return inportb(ATTdataR);
}

void ATTEndReads(void)
{
 /* Ensure we will write to the index */
 inportb(ATTdir);
 /* Enable the screen */
 outportb(ATTindex,0x20);
}

void WriteATT(int index, int val)
{
 outportb(ATTindex,index);
 outportb(ATTdataW,val);
}

uchar ReadMOR(void)
{
 return inportb(MORdataR);
}

void WriteMOR(int val)
{
 outportb(MORdataW,val);
}

uchar ReadEDAC(int index)
{
 outportb(EDACindex,index);
 return inportb(EDACdata);
}

void WriteEDAC(int index, int val)
{
 outportb(EDACindex,index);
 outportb(EDACdata,val);
}

void RPF_SetPalRange(unsigned char *_pal_ptr, int color, int cant)
{
 int dummy1,dummy2,dummy3,dummy4;
 asm volatile(
"     outb %%al,%%dx          \n"
"     incl %%edx              \n"
"     cli                     \n"
"     rep                     \n"
"     outsb                   \n"
"     sti                     \n"
: "=a" (dummy1), "=d" (dummy2), "=S" (dummy3), "=c" (dummy4)
: "c" (cant*3), "S" (_pal_ptr), "a" (color), "d" (0x3C8)
);
}

void RPF_GetPalRange(unsigned char *_pal_ptr, int color, int cant)
{
 int dummy1,dummy2,dummy3,dummy4;
 asm volatile (
"     outb %%al,%%dx          \n"
"     addl $2,%%edx           \n"
"     cli                     \n"
"     rep                     \n"
"     insb                    \n"
"     sti                     \n"
: "=a" (dummy1), "=d" (dummy2), "=D" (dummy3), "=c" (dummy4)
: "c" (cant*3), "D" (_pal_ptr), "a" (color), "d" (0x3C7)
);
}
#endif // DJGPP