-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvga256.h
313 lines (277 loc) · 9.78 KB
/
vga256.h
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
#ifndef _VGA256_H
#define _VGA256_H
#include <i86.h>
#include <string.h>
#pragma pack (push, 1)
#define VESA_OK 0
#define VESA_FAIL 1
#define VESA_NOTSUPPORTED 2
#define VESA_INVALIDMODE 3
/* Bit-Definition of the ControllerInfo Capability fields */
#define CAP_8bit_DAC 1
#define CAP_VGACompatible 2
#define CAP_Use_VBE_DAC_Functions 4
/* Bit-Definition of the ModeInfo Attribute fields */
#define ATTR_HardwareMode 1
#define ATTR_TTY_Support 2
#define ATTR_ColorMode 4
#define ATTR_GraphicsMode 8
#define ATTR_No_VGA_Mode 16
#define ATTR_No_SegA000 32
#define ATTR_LFB_Support 64
/* Bit-Definitions of the Window Attributes */
#define WATTR_Relocatable 1
#define WATTR_Readable 2
#define WATTR_Writeable 4
/* Definitions of the MemoryModel Field */
#define MM_TextMode 0
#define MM_CGA_Graphics 1
#define MM_Hercules_Graphics 2
#define MM_Planar 3
#define MM_PackedPixel 4
#define MM_UnChained 5
#define MM_DirectColor 6
#define MM_YUV 7
#ifdef __cplusplus
extern "C" {
#endif
typedef void ( * tagSetDisplayStartType )(short x, short y);
typedef void ( * tagSetBankType )(short bnk);
struct bcd16 {
unsigned char lo;
unsigned char hi;
};
struct DPMI_PTR
{
unsigned short int segment;
unsigned short int selector;
};
struct VBE_VbeInfoBlock
{
char vbeSignature[4];
struct bcd16 vbeVersion;
char * OemStringPtr;
unsigned long Capabilities;
unsigned short * VideoModePtr;
unsigned short TotalMemory;
unsigned short OemSoftwareRev;
char * OemVendorNamePtr;
char * OemProductNamePtr;
char * OemProductRevPtr;
char Reserved[222];
char OemData[256];
};
struct VBE_ModeInfoBlock
{
unsigned short ModeAttributes;
char WinAAttributes;
char WinBAttributes;
unsigned short Granularity;
unsigned short WinSize;
unsigned short WinASegment;
unsigned short WinBSegment;
void * WinFuncPtr;
unsigned short BytesPerScanline;
unsigned short XResolution;
unsigned short YResolution;
char XCharSize;
char YCharSize;
char NumberOfPlanes;
char BitsPerPixel;
char NumberOfBanks;
char MemoryModel;
char BankSize;
char NumberOfImagePages;
char Reserved;
char RedMaskSize;
char RedFieldPosition;
char GreenMaskSize;
char GreenFieldPosition;
char BlueMaskSize;
char BlueFieldPosition;
char RsvdMaskSize;
char RsvdFieldPosition;
char DirectColorModeInfo;
void * PhysBasePtr;
void * OffScreenMemOffset;
unsigned short OffScreenMemSize;
char reserved2[206];
};
#pragma pack (pop)
void VBE_Init (void);
void VBE_Done (void);
void DPMI_AllocDOSMem (short int paras, struct DPMI_PTR *p);
void DPMI_FreeDOSMem (struct DPMI_PTR *p);
void * DPMI_MAP_PHYSICAL (void *p, unsigned long size);
void DPMI_UNMAP_PHYSICAL (void *p);
int VBE_Test (void);
void VBE_Controller_Information (struct VBE_VbeInfoBlock * a);
int VBE_IsModeLinear (short Mode);
extern tagSetBankType VBE_SetBank;
unsigned int VBE_VideoMemory (void);
void VBE_Mode_Information (short Mode, struct VBE_ModeInfoBlock * a);
int VBE_FindMode (int xres, int yres, char bpp);
void VBE_SetMode (short Mode, int linear, int clear);
char * VBE_GetVideoPtr (short mode);
extern tagSetDisplayStartType VBE_SetDisplayStart;
void VBE_SetPixelsPerScanline (short Pixels);
short VBE_MaxBytesPerScanline (void);
void VBE_SetDACWidth (char bits);
int VBE_8BitDAC (void);
/*------------------------------------------------------------------------------------------------------- */
#define VGA256_MODE_640X480X8
#if defined(VGA256_MODE_320X200X8)
#define VGA256_WIDTH (320)
#define VGA256_HEIGHT (200)
#elif defined(VGA256_MODE_640X480X8)
#define VGA256_WIDTH (640)
#define VGA256_HEIGHT (480)
#elif defined(VGA256_MODE_1024X768X8)
#define VGA256_WIDTH (1024)
#define VGA256_HEIGHT (768)
#endif
/*------------------------------------------------------------------------------------------------------- */
#define VGA256PutScreen(pVideo, b) (memcpy(pVideo, b, VGA256_WIDTH * VGA256_HEIGHT))
#define _VGA256ABS(a) ((a < 0) ? -a : a)
#define _VGA256Sgn(a) (a > 0 ? 1 : (a < 0 ? -1 : 0))
/*------------------------------------------------------------------------------------------------------- */
extern const int VGA256SinDeg[];
extern const int VGA256CosDeg[];
extern const unsigned char VGA256Font[];
void VGA256PutPixel(void *pVideo, unsigned int x, unsigned int y, unsigned int color);
unsigned int VGA256GetPixel(void *pVideo, unsigned int x, unsigned int y);
void VGA256LineH(void *pVideo, unsigned int x, unsigned int y, unsigned int width, unsigned int color);
void VGA256LineV(void *pVideo, unsigned int x, unsigned int y, unsigned int height, unsigned int color);
void VGA256DrawBox(void *pVideo, unsigned int x, unsigned int y, unsigned int width, unsigned int height, unsigned int color);
void VGA256FillBox(void *pVideo, unsigned int x, unsigned int y, unsigned int width, unsigned int height, unsigned int color);
void VGA256ClearScreen(void *pVideo, unsigned int color);
void VGA256PutSprite(void *pcDest, void *pcSource, unsigned int piX, unsigned int piY, unsigned int piWidth, unsigned int piHeight);
void VGA256PutImage(void* pVideo, void* pcSource, unsigned int piX, unsigned int piY, unsigned int piWidth, unsigned int piHeight);
void VGA256GetImage(void* pVideo, void* pcSource, unsigned int piX, unsigned int piY, unsigned int piWidth, unsigned int piHeight);
void VGA256WaitVRetrace(void);
void VGA256SetPalette(const void* pal);
void VGA256GetPalette(void* pal);
void VGA256FadeOut(void);
void VGA256FadeIn(char* paleta);
void VGA256FadeTo(char* paleta);
void VGA256Circle(void* pVideo, unsigned x, unsigned int y, unsigned int radio, unsigned int color);
void VGA256Line(void* pVideo, unsigned int a, unsigned int b, unsigned int c, unsigned int d, unsigned char color);
void VGA256ScaleImage(unsigned char* pDest, unsigned char* pSource, unsigned int widthd, unsigned int heightd, unsigned int widths, unsigned int heights);
void VGA256ScaleImage025x(unsigned char* pDest, unsigned char* pSource, unsigned int widths, unsigned int heights);
void VGA256ScaleImage05x(unsigned char* pDest, unsigned char* pSource, unsigned int widths, unsigned int heights);
void VGA256ScaleImage2x(unsigned char* pDest, unsigned char* pSource, unsigned int widths, unsigned int heights);
void VGA256ScaleImage4x(unsigned char* pDest, unsigned char* pSource, unsigned int widths, unsigned int heights);
void VGA256RotateImage(unsigned char* pDest, unsigned char* pSource, unsigned int width, unsigned int height, int angle);
void VGA256FloodFill(void* pVideo, unsigned int x, unsigned int y, unsigned int new_col, unsigned int old_col);
void VGA256OutText(void* pVideo, char* string, unsigned int x, unsigned int y, unsigned int color, unsigned char* font);
void VGA256OutText2x(void* pVideo, char* string, unsigned int x_cursor, unsigned int y_cursor, unsigned int color, unsigned char* font);
void VGA256OutText4x(void* pVideo, char* string, unsigned int x_cursor, unsigned int y_cursor, unsigned int color, unsigned char* font);
int VGA256LoadPCX(char* filename, unsigned char* dest, unsigned char* pal);
int VGA256DecodePCX(unsigned char* dest, unsigned char* buffer);
int VGA256LoadBMP(char* filename, unsigned char* dest, unsigned char* pal);
int VGA256KbHit(void);
int VGA256GetCh(void);
/*------------------------------------------------------------------------------------------------------- */
//void VGA256SetPalette(const void *pal);
#pragma aux VGA256SetPalette =\
"mov ecx, 256*3"\
"xor al, al"\
"mov dx, 3c8h"\
"out dx, al"\
"inc dx"\
"rep outsb"\
parm[ESI]\
modify exact[ESI EDX ECX EAX];
/*------------------------------------------------------------------------------------------------------- */
//void VGA256GetPalette(void* pal);
#pragma aux VGA256GetPalette =\
"mov ecx, 256*3"\
"xor al, al"\
"mov dx, 3c7h"\
"out dx, al"\
"add dx, 2"\
"rep insb"\
parm[EDI]\
modify exact[EDI EDX ECX EAX];
/*------------------------------------------------------------------------------------------------------- */
void _VGA256MemCpy0(void *pDest, void *pSource, size_t iLen);
#pragma aux _VGA256MemCpy0 =\
"cld"\
"push ecx"\
"shr ecx, 2"\
"draw_px_0:"\
"mov eax, [esi]"\
"mov ebx, [edi]"\
"test al, al"\
"jz draw_px_1"\
"mov bl, al"\
"draw_px_1:"\
"test ah, ah"\
"jz draw_px_2"\
"mov bh, ah"\
"draw_px_2:"\
"bswap eax"\
"bswap ebx"\
"test ah, ah"\
"jz draw_px_3"\
"mov bh, ah"\
"draw_px_3:"\
"test al, al"\
"jz draw_px_4"\
"mov bl, al"\
"draw_px_4:"\
"bswap ebx"\
"mov [edi], ebx"\
"add esi, 4"\
"add edi, 4"\
"dec ecx"\
"jnz draw_px_0"\
"pop ecx"\
"and ecx, 3"\
"jz draw_px_7"\
"draw_px_5:"\
"mov al, [esi]"\
"test al, al"\
"jz draw_px_6"\
"mov [edi+0], al"\
"draw_px_6:"\
"inc esi"\
"inc edi"\
"dec ecx"\
"jnz draw_px_5"\
"draw_px_7:"\
parm[EDI][ESI][ECX]\
modify exact[EDI ESI ECX EBX EAX];
/*------------------------------------------------------------------------------------------------------- */
void VGA256MemCpyMMX(char* Dest, char* Src, unsigned int Len);
#pragma aux VGA256MemCpyMMX =\
"mov eax, ecx"\
"sub ecx, edi"\
"sub ecx, eax"\
"and ecx, 7"\
"sub eax, ecx"\
"jle short LEndBytes"\
"emms"\
"rep movsb"\
"mov ecx, eax"\
"and eax, 7"\
"shr ecx, 3"\
"jz LEndBytes"\
"sub edi, esi"\
"l1:"\
"movq mm0, [esi]"\
"movq [edi+esi], mm0"\
"add esi,8"\
"dec ecx"\
"jnz l1"\
"add edi, esi"\
"emms"\
"LEndBytes:"\
"add ecx, eax"\
"rep movsb"\
parm[EDI][ESI][ECX]\
modify[EAX ECX ESI EDI];
#ifdef __cplusplus
}
#endif
#endif