-
Notifications
You must be signed in to change notification settings - Fork 2
/
vi_svga.c
285 lines (235 loc) · 5.01 KB
/
vi_svga.c
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
#include "wl_def.h"
#include <vga.h>
#include <vgakeyboard.h>
byte *gfxbuf = NULL;
byte *graphmem = NULL;
void keyboard_handler(myint code, myint press);
void keyboard_handlerx(myint code, myint press);
void DisplayTextSplash(byte *text);
/*
==========================
=
= Quit
=
==========================
*/
void Quit(const char *error)
{
memptr screen = NULL;
if (!error || !*error) {
CA_CacheGrChunk(ORDERSCREEN);
screen = grsegs[ORDERSCREEN];
WriteConfig();
} else if (error) {
CA_CacheGrChunk(ERRORSCREEN);
screen = grsegs[ERRORSCREEN];
}
ShutdownId();
if (screen) {
/* doesn't look too good on console at the moment ...*/
/* DisplayTextSplash(screen); */
}
if (error && *error) {
fprintf(stderr, "Quit: %s\n", error);
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
}
void VL_WaitVBL(myint vbls)
{
myint i;
for (i = 0; i < vbls; i++)
vga_waitretrace();
}
void VW_UpdateScreen()
{
VL_WaitVBL(1);
memcpy(graphmem, gfxbuf, vwidth*vheight);
}
/*
=======================
=
= VL_Startup
=
=======================
*/
void VL_Startup()
{
myint mode;
vga_init(); /* TODO: maybe move into main or such? */
if (MS_CheckParm("x2")) {
mode = G640x400x256;
vwidth = 640;
vheight = 400;
} else {
mode = G320x200x256;
vwidth = 320;
vheight = 200;
}
if (gfxbuf == NULL)
gfxbuf = malloc(vwidth * vheight * 1);
if (vga_hasmode(mode) == 0)
Quit("vga_hasmode failed!");
if (vga_setmode(mode) != 0)
Quit("vga_setmode failed!");
if ((mode != G320x200x256) && (vga_setlinearaddressing() == -1))
Quit("vga_setlinearaddressing failed!");
graphmem = vga_getgraphmem();
keyboard_init();
keyboard_seteventhandler(keyboard_handlerx);
}
/*
=======================
=
= VL_Shutdown
=
=======================
*/
void VL_Shutdown()
{
keyboard_close();
if (gfxbuf != NULL) {
free(gfxbuf);
gfxbuf = NULL;
}
vga_setmode(TEXT);
}
/* ======================================================================== */
/*
=================
=
= VL_SetPalette
=
=================
*/
void VL_SetPalette(const byte *palette)
{
myint i;
VL_WaitVBL(1);
for (i = 0; i < 256; i++)
vga_setpalette(i, palette[i*3+0], palette[i*3+1], palette[i*3+2]);
}
/*
=================
=
= VL_GetPalette
=
=================
*/
void VL_GetPalette(byte *palette)
{
myint i, r, g, b;
for (i = 0; i < 256; i++) {
vga_getpalette(i, &r, &g, &b);
palette[i*3+0] = r;
palette[i*3+1] = g;
palette[i*3+2] = b;
}
}
/*
=============================================================================
GLOBAL VARIABLES
=============================================================================
*/
static myint SVGALibToScancode(myint key)
{
switch(key) {
case SCANCODE_BREAK:
case SCANCODE_BREAK_ALTERNATIVE:
return 0xe1; /* paused */
case SCANCODE_CURSORBLOCKUP:
return sc_UpArrow;
case SCANCODE_CURSORBLOCKDOWN:
return sc_DownArrow;
case SCANCODE_CURSORBLOCKLEFT:
return sc_LeftArrow;
case SCANCODE_CURSORBLOCKRIGHT:
return sc_RightArrow;
case SCANCODE_HOME:
return sc_Home;
case SCANCODE_END:
return sc_End;
case SCANCODE_PAGEUP:
return sc_PgUp;
case SCANCODE_PAGEDOWN:
return sc_PgDn;
case SCANCODE_INSERT:
return sc_Insert;
case SCANCODE_REMOVE:
return sc_Delete;
default: /* rest should be the same hopefully */
return key;
}
}
void keyboard_handlerx(myint code, myint press)
{
keyboard_handler(SVGALibToScancode(code), press);
}
byte IN_MouseButtons()
{
return 0;
}
void IN_GetMouseDelta(myint *dx, myint *dy)
{
}
/*
===================
=
= IN_JoyButtons
=
===================
*/
byte IN_JoyButtons()
{
return 0;
}
///////////////////////////////////////////////////////////////////////////
//
// IN_GetJoyAbs() - Reads the absolute position of the specified joystick
//
///////////////////////////////////////////////////////////////////////////
void IN_GetJoyAbs(word joy,word *xp,word *yp)
{
*xp = 0;
*yp = 0;
}
///////////////////////////////////////////////////////////////////////////
//
// INL_GetJoyDelta() - Returns the relative movement of the specified
// joystick (from +/-127)
//
///////////////////////////////////////////////////////////////////////////
void INL_GetJoyDelta(word joy,myint *dx,myint *dy)
{
*dx = 0;
*dy = 0;
}
///////////////////////////////////////////////////////////////////////////
//
// INL_GetJoyButtons() - Returns the button status of the specified
// joystick
//
///////////////////////////////////////////////////////////////////////////
word INL_GetJoyButtons(word joy)
{
return 0;
}
///////////////////////////////////////////////////////////////////////////
//
// IN_SetupJoy() - Sets up thresholding values and calls INL_SetJoyScale()
// to set up scaling values
//
///////////////////////////////////////////////////////////////////////////
void IN_SetupJoy(word joy,word minx,word maxx,word miny,word maxy)
{
}
void INL_Update()
{
while (keyboard_update()) ; /* get all events */
}
myint main(myint argc, char *argv[])
{
vwidth = 320;
vheight = 200;
return WolfMain(argc, argv);
}