]> 4ch.mooo.com Git - 16.git/blob - 16/tauron30/C_SRC/TESTS.CPP
added another library ^^
[16.git] / 16 / tauron30 / C_SRC / TESTS.CPP
1 //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
2 //=-                                                                         -=\r
3 //=-                   Tauron VGA Utilities Version 3.0                      -=\r
4 //=-                      Released September 20, 1998                        -=\r
5 //=-                                                                         -=\r
6 //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
7 //=- Copyright (c) 1997, 1998 by Jeff Morgan  =-= This code is FREE provided -=\r
8 //=- All Rights Reserved.                     =-= that you put my name some- -=\r
9 //=-                                          =-= where in your credits.     -=\r
10 //=- DISCLAIMER:                              =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
11 //=- I assume no responsibility whatsoever for any effect that this package, -=\r
12 //=- the information contained therein or the use thereof has on you, your   -=\r
13 //=- sanity, computer, spouse, children, pets or anything else related to    -=\r
14 //=- you or your existance. No warranty is provided nor implied with this    -=\r
15 //=- source code.                                                            -=\r
16 //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
17 #include <stdlib.h>\r
18 #include <stdio.h>\r
19 #include <conio.h>\r
20 #include "tauron.h"\r
21 #define ABS(a)   ((a < 0) ? -a : a)\r
22 #define SGN(a)   ((a < 0) ? -1 : 1)\r
23 \r
24 void Pixel13H(int x, int y, char color)\r
25 {\r
26    int width = Mode.width;\r
27    asm {\r
28    MOV AX,0A000H   //    video memory segment number\r
29    MOV ES,AX       //    place it in es\r
30 \r
31    MOV DX,03C4H\r
32    MOV AL,2\r
33    OUT DX,AL\r
34    INC DX\r
35 \r
36    MOV AL,1\r
37    MOV CX,x\r
38    AND CX,3\r
39    SHL AL,CL\r
40    OUT DX,AL\r
41 \r
42    XOR DI,DI\r
43 \r
44 // Calculate the Offset\r
45    mov ax,width  // width\r
46    mul y         // (Y * width))\r
47    mov bx,x      // (X + (Y * width))\r
48    add ax,bx\r
49 // Done!\r
50 \r
51    ADD DI,AX\r
52    mov ah,color   //    move the Color into ah\r
53    mov es:[di],ah //    move the value to the screen\r
54    }\r
55 }\r
56 \r
57 void pixel(int x, int y, char color)\r
58 {\r
59    int width = Mode.width;\r
60    if (Mode.mode == MODE13H)\r
61       Pixel13H(x,y,color);\r
62    else if (Mode.attrib & TVU_UNCHAINED) {\r
63    asm {\r
64    MOV AX,0A000H   //    video memory segment number\r
65    MOV ES,AX       //    place it in es\r
66 \r
67    MOV DX,03C4H\r
68    MOV AL,2\r
69    OUT DX,AL\r
70    INC DX\r
71 \r
72    MOV AL,1\r
73    MOV CX,x\r
74    AND CX,3\r
75    SHL AL,CL\r
76    OUT DX,AL\r
77 \r
78    XOR DI,DI\r
79 \r
80 // Calculate the Offset\r
81    mov ax,width  // width / 4\r
82    SHR AX,2\r
83    mul y         // (Y * (width / 4))\r
84    mov bx,x      // (X / 4) + (Y * (width / 4))\r
85    shr bx,2\r
86    add ax,bx\r
87 // Done!\r
88 \r
89    ADD DI,AX\r
90    mov ah,color   //    move the Color into ah\r
91    mov es:[di],ah //    move the value to the screen\r
92    }}\r
93    else if (Mode.attrib & TVU_PLANAR)\r
94    {\r
95    asm {\r
96    MOV AX,0A000H   //    video memory segment number\r
97    MOV ES,AX       //    place it in es\r
98 \r
99    MOV BX,x        //    X Value\r
100    MOV CX,BX\r
101    MOV AX,y        //    Y Value\r
102    MOV SI,80\r
103    MUL SI\r
104    SHR BX,3        //    /8\r
105    ADD AX,BX\r
106    MOV DI,AX\r
107 \r
108    AND CL,7\r
109    XOR CL,7\r
110    MOV AH,1\r
111 \r
112    SHL AH,CL\r
113 \r
114    MOV DX,03CEH\r
115    MOV AL,8\r
116    OUT DX,AX\r
117 \r
118    MOV AL,0\r
119    XCHG ES:[DI],AL\r
120 \r
121    MOV DX,03C4H\r
122    MOV AH,color\r
123    MOV AL,2\r
124    OUT DX,AX\r
125 \r
126    MOV BYTE PTR ES:[DI],0FFh\r
127 \r
128    MOV AX,0F02H\r
129    OUT DX,AX\r
130 \r
131    MOV DX,03CEH\r
132    MOV AX,0FF08h\r
133    OUT DX,AX\r
134    }}\r
135 }\r
136 \r
137 // This is Bresenham's Line Drawing Algorithm\r
138 void drawline(int x1, int y1, int x2, int y2, char col)\r
139 {\r
140    int d, x, y, ax, ay, sx, sy, dx, dy;\r
141 \r
142    dx = x2-x1;\r
143    ax = ABS(dx) << 1;\r
144    sx = SGN(dx);\r
145    dy = y2-y1;\r
146    ay = ABS(dy) << 1;\r
147    sy = SGN(dy);\r
148 \r
149    x = x1;\r
150    y = y1;\r
151    if( ax > ay )\r
152    {\r
153       d = ay - (ax >> 1);\r
154       while( x != x2 )\r
155       {\r
156               pixel( x, y, col );\r
157               if( d >= 0 )\r
158               {\r
159                  y += sy;\r
160                  d -= ax;\r
161               }\r
162               x += sx;\r
163               d += ay;\r
164       }\r
165    }\r
166    else\r
167    {\r
168       d = ax - (ay >> 1);\r
169       while( y != y2 )\r
170       {\r
171               pixel( x, y, col );\r
172               if( d >= 0 )\r
173               {\r
174                  x += sx;\r
175                  d -= ay;\r
176               }\r
177               y += sy;\r
178               d += ax;\r
179       }\r
180    }\r
181    return;\r
182 }\r
183 \r
184 void drawrect(int x1, int y1, int x2, int y2, char color)\r
185 {\r
186    drawline(x1,y1,x2,y1,color);\r
187    drawline(x1,y2,x2,y2,color);\r
188    drawline(x1,y1,x1,y2,color);\r
189    drawline(x2,y1,x2,y2+1,color);\r
190 }\r
191 \r
192 void hline(int x1, int x2, int y, char color)\r
193 {\r
194    drawline(x1,y,x2,y,color);\r
195 }\r
196 \r
197 void vline(int y1, int y2, int x, char color)\r
198 {\r
199    drawline(x,y1,x,y2,color);\r
200 }\r
201 \r
202 void fillrect(int x1, int y1, int x2, int y2, char color)\r
203 {\r
204    for (int i = y1; i < y2; i++)\r
205       hline(x1,x2,i,color);\r
206 }\r
207 \r
208 void ModeTest()\r
209 {\r
210    if (Mode.mode == MODE13H)\r
211    {\r
212       Clear13H(0);\r
213    }\r
214    else if (Mode.attrib & TVU_PLANAR)\r
215    {\r
216       PlanarClear(0);\r
217    }\r
218    else if (Mode.attrib & TVU_UNCHAINED)\r
219    {\r
220       UnchainedClear(0);\r
221    }\r
222 \r
223    /* Print mode stats\r
224     *\r
225     */\r
226 \r
227    drawrect(0,0,Mode.width-1,Mode.height-1,15);\r
228    for (int i = 50; i < Mode.height; i += 100)\r
229    {\r
230       hline(0,10,i,15);\r
231       hline(0,25,i+50,15);\r
232    }\r
233 \r
234    for (int i = 40; i < Mode.width; i += 80)\r
235    {\r
236       vline(0,15,i,15);\r
237       vline(0,30,i+40,15);\r
238    }\r
239 \r
240    if (Mode.colors == 2)\r
241    {\r
242       int x,y;\r
243       x = Mode.width - 420;\r
244       y = Mode.height - 220;\r
245       fillrect(x,y,x+200,y+200,0);\r
246       x+=200;\r
247       fillrect(x,y,x+200,y+200,15);\r
248       drawrect(x-200,y,x+200,y+200,15);\r
249    }\r
250    else if (Mode.colors == 16)\r
251    {\r
252       int x,y;\r
253       x = Mode.width - 522;\r
254       y = Mode.height - 135;\r
255       for (int i = 0; i < 8; i++)\r
256       {\r
257          fillrect(x,y,x+64,y+64,i);\r
258          x+=64;\r
259       }\r
260       x = Mode.width - 522;\r
261       y += 64;\r
262       for (int i = 8; i < 16; i++)\r
263       {\r
264          fillrect(x,y,x+64,y+64,i);\r
265          x+=64;\r
266       }\r
267       drawrect(x-512,y-64,x,y+64,15);\r
268    }\r
269    else if (Mode.colors == 256)\r
270    {\r
271       int x,y,k;\r
272       x = Mode.width - 165;\r
273       y = Mode.height - 165;\r
274       k = 0;\r
275       for (int i = 0; i < 16; i++)\r
276       {\r
277          for (int j = 0; j < 16; j++)\r
278          {\r
279             fillrect(x,y,x+10,y+10,k);\r
280             x+=10;\r
281             k++;\r
282          }\r
283          x = Mode.width - 165;\r
284          y += 10;\r
285       }\r
286       drawrect(Mode.width - 165,Mode.height - 165,Mode.width -5,Mode.height - 5,15);\r
287    }\r
288 }\r
289 \r
290 void TextTest()\r
291 {\r
292    TextClear(0x1F);\r
293    gotoxy(1,1);\r
294    if (Mode.mode == MODE00H)\r
295    {\r
296       // ** NOTE ** the gotoxy's here are a hack so that i could use the\r
297       // standard C functions to program this mode.  Normally you would just\r
298       // calculate the proper address and display the text but since DOS still\r
299       // thinks we are in mode 03h (it checks the BIOS), this is necessary.\r
300       gotoxy(1,1);\r
301       printf("ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿\n");\r
302       gotoxy(41,1);\r
303       printf("³Text Mode: 00H        ³\n");\r
304       gotoxy(1,2);\r
305       printf("³Width: 40   Height: 25³\n");\r
306       gotoxy(41,2);\r
307       printf("³Bytes per screen: 2000³\n");\r
308       gotoxy(1,3);\r
309       printf("³Number of pages: 8    ³\n");\r
310       gotoxy(41,3);\r
311       printf("ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ\n");\r
312    }\r
313    else if (Mode.mode == MODE03H)\r
314    {\r
315       printf("ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿\n");\r
316       printf("³Text Mode: 03H        ³\n");\r
317       printf("³Width: 80   Height: 25³\n");\r
318       printf("³Bytes per screen: 4000³\n");\r
319       printf("³Number of pages: 8    ³\n");\r
320       printf("ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ\n");\r
321    }\r
322    else if (Mode.mode == MODE_J)\r
323    {\r
324       printf("ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿\n");\r
325       printf("³Text Mode K           ³\n");\r
326       printf("³Width: 80   Height: 43³\n");\r
327       printf("³Bytes per screen: 3440³\n");\r
328       printf("³Number of pages: 8    ³\n");\r
329       printf("ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ\n");\r
330    }\r
331    else if (Mode.mode == MODE_K)\r
332    {\r
333       printf("ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿\n");\r
334       printf("³Text Mode K           ³\n");\r
335       printf("³Width: 80   Height: 50³\n");\r
336       printf("³Bytes per screen: 4000³\n");\r
337       printf("³Number of pages: 8    ³\n");\r
338       printf("ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ\n");\r
339    }\r
340    else if (Mode.mode == MODE_L)\r
341    {\r
342       // ** NOTE ** the gotoxy's here are a hack so that i could use the\r
343       // standard C functions to program this mode.  Normally you would just\r
344       // calculate the proper address and display the text but since DOS still\r
345       // thinks we are in mode 03h (it checks the BIOS), this is necessary.\r
346       printf("ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿\n");\r
347       gotoxy(41,1);\r
348       printf("³Text Mode L           ³\n");\r
349       gotoxy(1,2);\r
350       printf("³Width: 40   Height: 43³\n");\r
351       gotoxy(41,2);\r
352       printf("³Bytes per screen: 3440³\n");\r
353       gotoxy(1,3);\r
354       printf("³Number of pages: 8    ³\n");\r
355       gotoxy(41,3);\r
356       printf("ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ\n");\r
357    }\r
358    else if (Mode.mode == MODE_M)\r
359    {\r
360       // ** NOTE ** the gotoxy's here are a hack so that i could use the\r
361       // standard C functions to program this mode.  Normally you would just\r
362       // calculate the proper address and display the text but since DOS still\r
363       // thinks we are in mode 03h (it checks the BIOS), this is necessary.\r
364       printf("ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿\n");\r
365       gotoxy(41,1);\r
366       printf("³Text Mode K           ³\n");\r
367       printf("³Width: 40   Height: 50³\n");\r
368       gotoxy(1,2);\r
369       gotoxy(41,2);\r
370       printf("³Bytes per screen: 4000³\n");\r
371       gotoxy(1,3);\r
372       printf("³Number of pages: 8    ³\n");\r
373       gotoxy(41,3);\r
374       printf("ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ\n");\r
375    }\r
376 }\r