-
Notifications
You must be signed in to change notification settings - Fork 2
/
GFXMODE.C
executable file
·164 lines (156 loc) · 3.64 KB
/
GFXMODE.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
#include <bios.h>
#include <dos.h>
#include "gfx.h"
unsigned char display_page, render_page;
unsigned char far *page_addr[2];
unsigned char far *renderbuff;
static int orgmode;
static int leftedge[200], rightedge[200];
static int maxscan = 199;
static int minscan = 0;
void (*fillhspan)(int xl, int xr, int y);
void (*fillvspan)(int x, int yt, int yb);
void (*clear)(void);
void (*flip)(void);
void (*render)(int page);
void (*color)(int red, int grn, int blu);
void (*hspan)(int xl, int xr, int y);
void (*vspan)(int x, int yt, int yb);
void (*pixel)(int x, int y);
void (*aapixel)(int x, int y, int alpha);
void (*aahspan)(int xl, int xr, int y);
void (*aavspan)(int x, int yt, int yb);
int gfxmode8(int mono);
int gfxmode4(int mono);
int gfxmode2(int mono);
void gfxrender(int page);
void bitblt(int xl, int yt, int width, int height, int xoffset, int yoffset, unsigned char far *src, int pitch);
int gfxmode(int modeflags)
{
union REGS regs;
/*
* Get current mode
*/
regs.x.ax = 0x0F00;
int86(0x10, ®s, ®s);
orgmode = regs.h.al;
/*
* Initiaze buffers.
*/
display_page = 0;
render_page = 0;
render = gfxrender;
/*
* Initialize edge fill arrays.
*/
for (minscan = 0; minscan < 200; minscan++)
{
leftedge[minscan] = 320;
rightedge[minscan] = -1;
}
/*
* Map best mode.
*/
if (modeflags & MODE_8BPP)
{
if (gfxmode8(modeflags))
return 8;
modeflags |= MODE_4BPP;
}
if (modeflags & MODE_4BPP)
{
if (gfxmode4(modeflags))
return 4;
modeflags |= MODE_2BPP;
}
if (modeflags & MODE_2BPP)
{
if (gfxmode2(modeflags))
return 2;
}
return 0;
}
void restoremode(void)
{
union REGS regs;
regs.x.ax = orgmode;
int86(0x10, ®s, ®s);
}
/*
* Set render page.
*/
static void gfxrender(int page)
{
union REGS regs;
render_page = (page & 1) ^ display_page;
renderbuff = page_addr[render_page];
}
/*
* Fill mode.
*/
static void hfill(int xl, int xr, int y)
{
if (y >= 0 && y <= 199)
{
if (y < minscan) minscan = y;
if (y > maxscan) maxscan = y;
if (leftedge[y] > xl) leftedge[y] = xl;
if (rightedge[y] < xr) rightedge[y] = xr;
}
}
static void vfill(int x, int yt, int yb)
{
int i;
if (yt < 0) yt = 0;
if (yb > 199) yb = 199;
for (i = yt; i <= yb; i++)
{
if (i < minscan) minscan = i;
if (i > maxscan) maxscan = i;
if (leftedge[i] > x) leftedge[i] = x;
if (rightedge[i] < x) rightedge[i] = x;
}
}
void beginfill(void)
{
/*
* Override span filling routines.
*/
fillhspan = hspan;
fillvspan = vspan;
hspan = hfill;
vspan = vfill;
minscan = 200;
maxscan = -1;
}
void endfill(void)
{
int i;
/*
* Fill edge array.
*/
for (i = minscan; i <= maxscan; i++)
{
if (leftedge[i] < 0) leftedge[i] = 0;
if (rightedge[i] > 319) rightedge[i] = 319;
if (leftedge[i] <= rightedge[i])
fillhspan(leftedge[i], rightedge[i], i);
leftedge[i] = 320;
rightedge[i] = -1;
}
/*
* Reset span filling routines.
*/
hspan = fillhspan;
vspan = fillvspan;
}
void text(int x, int y, char *string)
{
while (*string)
{
bitblt(x, y, 8, 8, ((unsigned char)*string) * 64, 0, (unsigned char far *)0xFFA6000EL, 1);
string++;
x += 8;
}
}