home *** CD-ROM | disk | FTP | other *** search
- /************************** gfx_test.c ***************************/
-
- #include "gfx_test.h"
-
-
- #pragma On(Prototype_override_warnings);
- #pragma On(Int_function_warnings);
- #pragma On(Warn);
- #pragma Off(Optimize_xjmp);
-
- void line_sweep(), _arc(), test_with_views(), triangles(), test_xor(), delay();
- void draw_test(), restore_scrn(), graphics_suite(), move_block(), test_float();
- void draw_triangle(), paint_test(), spin(), test_big_pics(char *), exit();
- int atoi(char *);
-
-
- #define DELETE_FPIC_FILE(tp) _gfx_delete_file(tp)
-
- void main(n_args, argv)
- INT n_args;
- TEXT **argv;
- {
- INT c, cmnd_gfx_mode;
-
- cmnd_gfx_mode = 1;
- if (n_args > 1) {
- c = *argv[1];
- if (inrange('1', c, '7')) then cmnd_gfx_mode = c - '0';
- }
- _gfx.auto_scale = YES;
- _gfx.xlat_scale = 1;
- _gfx.err_number = NO;
- switch(cmnd_gfx_mode) {
- case 4:
- _gfx.card_monitor = _HERC_CARD | _MONO_DISPLAY;
- cmnd_gfx_mode = 2;
- break;
-
- case 5:
- cmnd_gfx_mode = _OR_EGA_MED_RES | 1;
- break;
-
- case 6:
- cmnd_gfx_mode = _OR_EGA_HI_RES | 1;
- break;
-
- case 7:
- _gfx_set_video_resolution(atoi(argv[3]), atoi(argv[4]));
- cmnd_gfx_mode = _FORCE_BIOS_MODE | atoi(argv[2]);
- break;
- }
- if (!_gfx_screen(cmnd_gfx_mode)) {
- _gfx.card_monitor &= ~_EGA_CARD;
- _gfx_screen(cmnd_gfx_mode);
- }
- _gfx_clearscreen();
- test_float();
- test_with_views();
- restore_scrn();
- exit(1);
- }
-
- void restore_scrn()
- {
- _gfx_screen(0);
- /*** !!!!386 exit(1); */
- }
-
- void test_float()
- {
- INT j, view_n;
- double x, y;
- LOCAL INT pattern[] = {0xF0F0, 0xCCCC, 0xFFFF, 0xAAAA};
-
- view_n = _gfx_open_view(0, 0, 319, 199, 0, NO);
- _gfx_scale_float_view(1.1, 1.1, 0.55, 0.55, 1, -1);
- for (j = 0; j < 25; j++) {
- for (x = -0.53; x < 0.53; x += .03)
- _gfx_line(0.0, 0.0, x, 0.53, j|_PAT, 0, pattern[j & 0x3]);
- for (y = 0.53; y > -0.53; y -= .03)
- _gfx_line(0.0, 0.0, 0.53, y, j|_PAT, 0, pattern[j & 0x3]);
- for (x = 0.53; x > -0.53; x -= .03)
- _gfx_line(0.0, 0.0, x, -0.53, j|_PAT, 0, pattern[j & 0x3]);
- for (y = -0.53; y < 0.53; y += .03)
- _gfx_line(0.0, 0.0, -0.53, y, j|_PAT, 0, pattern[j & 0x3]);
- }
- _gfx_close_view(view_n, YES);
- }
-
-
- void test_with_views()
- {
- INT x1, y1, x2, y2;
- INT view_1, view_2, color;
-
-
- graphics_suite();
- _gfx_clearscreen();
- x1=10, y1=10, x2=110, y2=55;
- line_sweep();
- _gfx_create_view_file("GFXVIEW.DAT");
-
- view_1 = _gfx_open_view(x1, y1, x2, y2, 2, YES);
- delay(40);
- _gfx_move_view(180, 20);
- _gfx_scale_int_view(_DFLT, _DFLT, 0, -45, 1, -1);
- line_sweep();
- delay(40);
- _gfx_clearscreen();
- _gfx_move_view(180, 130);
- _gfx_scale_int_view(_DFLT, _DFLT, -110, -72, 1, 1);
- line_sweep();
- delay(40);
- _gfx_clearscreen();
- _gfx_move_view(150, 30);
- _gfx_scale_int_view(_DFLT, _DFLT, 0, 0, 1, 1);
- line_sweep();
- delay(40);
- _gfx_close_view(view_1, 1);
- delay(40);
-
- view_1 = _gfx_open_view(x1, y1, x2, y2, 2, YES);
- view_2 = _gfx_open_view(130, 90, 300, 180, 4, YES);
- delay(40);
- line_sweep();
- _gfx_clear_view(view_2, 8);
- _gfx_switch_view(view_1, 1);
- line_sweep();
- _gfx_clear_view(view_1, 6);
- delay(40);
- _gfx_switch_view(view_2, 1);
- _gfx_clear_view(view_2, 9);
- line_sweep();
- _gfx_switch_view(view_1, 0);
- line_sweep();
- _gfx_switch_view(0, 0);
- _gfx_clear_view(view_1, 14);
- _gfx_clear_view(view_2, 11);
- delay(40);
- _gfx_close_view(view_2, 1);
- _gfx_close_view(view_1, 1);
- delay(40);
-
- color = (_gfx.gfx_mode & HIGH_RES) ? 0 : 4;
- view_1 = _gfx_open_view(10, 10, _STEP, 220, 130, color, YES);
- _gfx_scale_int_view(_DFLT, _DFLT, -60, -55, 1, 1);
- delay(40);
- graphics_suite();
- _gfx_clearscreen();
- delay(40);
- _gfx_screen(0);
- DELETE_FPIC_FILE("GFXVIEW.DAT");
- }
-
- void graphics_suite()
- {
- INT fpic_handle;
-
- _gfx_clearscreen();
- fpic_handle = _gfx_create_fpic("PIC.DAT", 40);
- line_sweep();
- test_xor();
- _gfx_get_fpic(0, 0, 319, 199, 0, fpic_handle);
- delay(40);
- _gfx_clearscreen();
- if (sizeof(TEXT *) == 4) {
- spin();
- _gfx_get_fpic(0, 0, 319, 199, 0, fpic_handle);
- delay(40);
- _gfx_clearscreen();
- }
-
- paint_test();
- _gfx_get_fpic(0, 0, 319, 199, 0, fpic_handle);
- delay(40);
-
- _gfx_clearscreen();
- _arc();
- _gfx_get_fpic(0, 0, 319, 199, 0, fpic_handle);
- delay(40);
- _gfx_clearscreen();
- draw_test();
- _gfx_get_fpic(0, 0, 319, 199, 0, fpic_handle);
- delay(40);
- _gfx_clearscreen();
- triangles();
- _gfx_get_fpic(0, 0, 319, 199, 0, fpic_handle);
- delay(40);
-
-
- _gfx_clearscreen();
- move_block();
- _gfx_get_fpic(0, 0, 319, 199, 0, fpic_handle);
- _gfx_clearscreen();
- _gfx_close_fpic(fpic_handle);
- test_big_pics("PIC.DAT");
- DELETE_FPIC_FILE("PIC.DAT");
- }
-
-
-
- TINY dot_pat[] = {9, 9, 0xC4, 0x62, 0x31, 0x18, 0x8C, 0x46, 0x23, 0x11, 0x88,
- 0x88, 0xC4, 0x62, 0x31, 0x18, 0x8C, 0x46, 0x23, 0x11,
- 0x11, 0x88, 0xC4, 0x62, 0x31, 0x18, 0x8C, 0x46, 0x23,
- 0x23, 0x11, 0x88, 0xC4, 0x62, 0x31, 0x18, 0x8C, 0x46,
- 0x46, 0x23, 0x11, 0x88, 0xC4, 0x62, 0x31, 0x18, 0x8C,
- 0x8C, 0x46, 0x23, 0x11, 0x88, 0xC4, 0x62, 0x31, 0x18,
- 0x18, 0x8C, 0x46, 0x23, 0x11, 0x88, 0xC4, 0x62, 0x31,
- 0x31, 0x18, 0x8C, 0x46, 0x23, 0x11, 0x88, 0xC4, 0x62,
- 0x62, 0x31, 0x18, 0x8C, 0x46, 0x23, 0x11, 0x88, 0xC4
- };
-
- TINY xdot_pat[] = {1, 1, 0x88};
-
- void triangles()
- {
- INT x, y, height, base, color, fill_color, n_reps, i, max_color, last_color;
-
- max_color = 16;
- turn_on_ega();
- for (i = 0; i < 1; i++) {
- x = 160;
- y = 4;
- height = 190;
- base = 310;
- color = i;
- n_reps = 0;
- while (y < 80) {
- if (++color == max_color) then color = 1;
- draw_triangle(x, y, base, height, color);
- height -= 5;
- base -= 20;
- y += 5;
- n_reps++;
- }
- }
- y += 20;
- last_color = color;
- while (n_reps--) {
- if ((fill_color = color+1) >= max_color) then fill_color = 1;
- _gfx_fastfill(x, y, fill_color, color--);
- if (color < 1) then color = max_color-1;
- }
- delay(40);
- _gfx_fastfill(x, y, _PAT|5, last_color, xdot_pat);
- _gfx_fastfill(x, y, _PAT|4, last_color, dot_pat);
- delay(40);
- }
-
-
- void draw_triangle(x, y, base, height, color)
- INT x, y, base, height, color;
- {
- INT y2, new_color;
-
- base >>= 1;
- y2 = height;
- new_color = _gfx_get_color(color);
- _gfx_line(x, y, x-base, y2, new_color, 0);
- _gfx_line(x, y, x+base, y2, new_color, 0);
- _gfx_line(x-base, y2, x+base, y2, new_color, 0);
- }
-
-
- LOCAL INT pattern[] = {0xF0F0, 0xCCCC, 0xFFFF, 0xAAAA};
-
- void line_sweep()
- {
- INT j,x,y;
-
- for (j = 0; j < 25; j++) {
- for (x = 6; x < 320; x += 14)
- _gfx_line(159, 99, x, 2, j|_PAT, 0, pattern[j & 0x3]);
- for (y = 2; y < 200; y += 14)
- _gfx_line(159, 99, 314, y, j|_PAT, 0, pattern[j & 0x3]);
- for (x = 314; x > 0; x -= 14)
- _gfx_line(159, 99, x, 197, j|_PAT, 0, pattern[j & 0x3]);
- Q4: for (y = 197; y > 0; y -= 14)
- _gfx_line(159, 99, 6, y, j|_PAT, 0, pattern[j & 0x3]);
- }
- }
-
- void test_xor()
- {
- INT width, height;
- INT x, y, i, j;
-
- x = 145;
- y = 90;
- width = 30;
- height = 20;
- for (i = 0; i < 40; i++) {
- _gfx_line(x -= 3, y -= 2, _STEP, width, height, 3 | _XOR_PEL, _EMPTY_BOX);
- delay(1);
- _gfx_line(x, y, _STEP, width, height, 3 | _XOR_PEL, _EMPTY_BOX);
- width += 6;
- height += 4;
- }
- _gfx_line(x -= 3, y -= 2, _STEP, width, height, 3 | _XOR_PEL, _EMPTY_BOX);
- width /= 2;
- height /= 2;
- x += width;
- for (j = 0; j < 4; j++) {
- for (i = 0; i < 40; i++) {
- _gfx_line(x, y, _STEP, -width, height, 14 | _XOR_PEL, _DRAW_LINE);
- _gfx_line(x-width, y+height, _STEP, width, height, 14 | _XOR_PEL, _DRAW_LINE);
- _gfx_line(x, y+(height<<1), _STEP, width, -height, 14 | _XOR_PEL, _DRAW_LINE);
- _gfx_line(x+width, y+height, _STEP, -width, -height, 14 | _XOR_PEL, _DRAW_LINE);
- delay(1);
- _gfx_line(x, y, _STEP, -width, height, 14 | _XOR_PEL, _DRAW_LINE);
- _gfx_line(x-width, y+height, _STEP, width, height, 14 | _XOR_PEL, _DRAW_LINE);
- _gfx_line(x, y+(height<<1), _STEP, width, -height, 14 | _XOR_PEL, _DRAW_LINE);
- _gfx_line(x+width, y+height, _STEP, -width, -height, 14 | _XOR_PEL, _DRAW_LINE);
- width -= 3;
- }
- for (i = 0; i < 40; i++) {
- _gfx_line(x, y, _STEP, -width, height, 14 | _XOR_PEL, _DRAW_LINE);
- _gfx_line(x-width, y+height, _STEP, width, height, 14 | _XOR_PEL, _DRAW_LINE);
- _gfx_line(x, y+(height<<1), _STEP, width, -height, 14 | _XOR_PEL, _DRAW_LINE);
- _gfx_line(x+width, y+height, _STEP, -width, -height, 14 | _XOR_PEL, _DRAW_LINE);
- delay(1);
- _gfx_line(x, y, _STEP, -width, height, 14 | _XOR_PEL, _DRAW_LINE);
- _gfx_line(x-width, y+height, _STEP, width, height, 14 | _XOR_PEL, _DRAW_LINE);
- _gfx_line(x, y+(height<<1), _STEP, width, -height, 14 | _XOR_PEL, _DRAW_LINE);
- _gfx_line(x+width, y+height, _STEP, -width, -height, 14 | _XOR_PEL, _DRAW_LINE);
- width += 3;
- }
- }
- _gfx_line(x-width, y, _STEP, width*2, height*2, 3 | _XOR_PEL, _EMPTY_BOX);
- }
-
-
-
- void draw_test()
- {
- INT i, kolor;
-
- _gfx_draw("BM160,70");
- _gfx_draw("S4");
- for (i = 0; i++ < 2; _gfx_draw("S8 BM100,190")) {
- _gfx_draw("C1 U= R= D= L=",60,60,60,60);
- _gfx_draw("BU30 C1 E= F= G= H=",30,30,30,30);
- _gfx_draw("BR30 C1 NU10 NL10 ND10 NR10 NH10 NG10 NE10 NF10");
- }
- _gfx_draw("BM160,100 S4");
- kolor = 1;
- ;
- for (i = 1; i < 14; i++) {
- _gfx_draw("S= BM-30,+0 C= U= R= D= L= U= BM+30,+0", i, kolor, 30, 60, 60, 60, 31);
- }
- }
-
- int x[] = {180, 32, 129};
- int y[] = {130, 32, 146};
-
- void paint_test()
- {
- INT j;
-
- for (j = 0; j < 3; j++) {
- _gfx_clearscreen();
- _gfx_line(28, 28,262, 177, 1, _FILL_BOX);
- _gfx_line(30, 30, 260, 175, 2, _FILL_BOX);
- _gfx_line(40, 160, 240, 165, 1, _FILL_BOX);
- _gfx_line(40, 60, 240, 65, 1, _FILL_BOX);
- _gfx_line(40, 60, 45, 159, 1, _FILL_BOX);
- _gfx_line(235, 64, 240, 157, 1, _FILL_BOX);
- _gfx_line(47, 67, 55, 157, 1, _FILL_BOX);
- _gfx_line(58, 100, 238, 110, 1, _FILL_BOX);
- _gfx_line(230, 110, 235, 145, 1, _FILL_BOX);
- _gfx_line(130, 110, 150, 145, 1, _FILL_BOX);
- _gfx_line(100, 147, 235, 150, 1, _FILL_BOX);
- delay(15);
- _gfx_paint(x[j], y[j], 12, 1);
- delay(15);
- }
- }
-
-
-
- void _arc()
- {
- INT i;
- DBL start, end, delta_angle, frac;
-
- for (frac = 0.1; frac < 4.0; frac += 0.1) {
- start = 0.0;
- delta_angle = .0872638;
- end = 6.283;
- _gfx_ellipse(159,99,50,3, frac);
- for (i = 0; i < 71; i++) {
- _gfx_arc(159,99,50,i&0xF, frac,start, end -= delta_angle);
- }
- }
- for (i = 200; i > 0; i -= 5) {
- _gfx_line(60,15,60+i,15,(i+1)&0xF,0);
- }
- for (i = 170; i > 0; i -= 3) {
- _gfx_line(260,15,260,15+i,(i+1)&0xF,0);
- }
- for (i = 200; i > 0; i -= 5) {
- _gfx_line(60,185,60+i,185,(i+1)&0xF,0);
- }
- for (i = 170; i > 0; i -= 3) {
- _gfx_line(60,15,60,15+i,(i+1)&0xF,0);
- }
- }
-
- /* NOTE THAT THIS FUNCTION WILL ONLY EXECUTE IN
- * PROGRAMS USING LARGE DATA MODEL
- */
-
- extern DBL cos(DBL);
- void spin()
- {
- INT i, j, x, y, radius, index, color, step, angle, pg;
- DBL aspect_ratio, conversion=0.0174527;
- _PIC *pic1[20];
-
- if (sizeof(TEXT *) == 2) then return;
- color = 2;
- index = 0;
- step = 9;
- angle = 0;
- _gfx_set_video_pages(0, 1);
- for (j=0; j < 2; j++) {
- for (i = 0; i < 10; i++) {
- _gfx_line(110,80,210,160,13, _FILL_BOX);
- _gfx_line(120,115,200, 125,0, _FILL_BOX);
- x = 160, y = 120, radius = 30;
- aspect_ratio = 1.1 / (cos((DBL)(angle * conversion)));
- _gfx_ellipse(x, y, radius, color, aspect_ratio);
- _gfx_fastfill(x, y+10, color, color);
- pic1[index] = _gfx_get_pic(128,88,190,150);
- if (pic1[index] == 0) {
- /*printf("MEMORY ALLOCATION FAILURE\n");*/
- goto THE_END;
- }
-
- angle += step;
- index++;
- }
- color = 9;
- step = -9;
- }
- _gfx_set_video_pages(0, 0);
- _gfx_line(110,80,210,160,13, _FILL_BOX);
- _gfx_line(120,115,200, 125,0, _FILL_BOX);
- _gfx_copy_video_pages(0,1);
- pg = 0;
- for (j = 0; j < 4; j++) {
- for (i = 0; i < 20; i++) {
- _gfx_set_video_pages(pg&1, (pg+1)&1);
- pg++;
- _gfx_put_pic(128,88,pic1[i],'P');
- delay(1);
- }
- for (i = 19; --i > 0; ) {
- _gfx_set_video_pages(pg&1, (pg+1)&1);
- pg++;
- _gfx_put_pic(128,88,pic1[i],'P');
- delay(1);
- }
- }
-
- THE_END:
- for (j = 0; j < 20; j++)
- if (pic1[j] != 0) then free((char *)pic1[j]);
- _gfx_set_video_pages(0, 0);
- }
-
-
- void move_block()
- {
- int p1x, p1y, p2x, p2y, p3x, p3y, p4x, p4y, ch;
- int max_x, max_y;
- _PIC *pic1, *pic2, *pic3, *pic4;
-
- _gfx_line(100, 60, 158, 98, 8, 2);
- _gfx_line(100, 102, 158, 140, 6, 2);
- _gfx_line(162, 60, 220, 98, 6, 2);
- _gfx_line(162, 102, 220, 140, 1, 2);
- _gfx_fastfill(101, 61, 9, 8);
- _gfx_fastfill(101, 103, 4, 6);
- _gfx_fastfill(163, 61, 7, 6);
- _gfx_fastfill(163, 103, 12, 1);
- pic1 = _gfx_get_pic(99, 59, 159, 99); p1x = 99; p1y = 59;
- pic2 = _gfx_get_pic(160, 59, 221, 100); p2x = 160; p2y = 59;
- pic3 = _gfx_get_pic(99, 101, 159, 141); p3x = 99; p3y = 101;
- pic4 = _gfx_get_pic(160, 101, 221, 141); p4x = 160; p4y = 101;
- max_x = 320;
- max_y = 200;
- for (ch= 0; ch < 600; ch++) {
- if (p1x < -60) then p1x = max_x+1;
- _gfx_put_pic(p1x, p1y, pic1, 'P');
- p1x--;
- if (p4x > max_x) then p4x = -60;
- _gfx_put_pic(p4x, p4y, pic4, 'P');
- p4x++;
- if (p2y < -40) then p2y = max_y+1;
- _gfx_put_pic(p2x, p2y, pic2, 'P');
- p2y--;
- if (p3y > max_y) then p3y = -40;
- _gfx_put_pic(p3x, p3y, pic3, 'P');
- p3y++;
- }
-
- free((char *)pic1);
- free((char *)pic2);
- free((char *)pic3);
- free((char *)pic4);
- }
-
- void test_big_pics(char *fpic_name)
- {
- INT i, fpic_handle;
-
- fpic_handle = _gfx_open_fpic(fpic_name, 1);
- _gfx_clearscreen();
- _gfx.auto_scale = NO;
- for (i = 1; i < 8; i++) {
- _gfx_put_fpic(0, 0, 'P', i, fpic_handle);
- delay(40);
- }
- _gfx.auto_scale = YES;
- _gfx_close_fpic(fpic_handle);
- }
-
-
- UINT bios_time()
- {
- REG_EX reg;
-
- reg.eax = 0;
- _gfx_call_bios(0x1A, (char *)®, (char *)®);
- return (INT) reg.edx;
- }
-
- void delay(n_ticks)
- INT n_ticks;
- {
- UINT ct;
-
- while (_gfx_call_dos(0xB, 0) & 0xFF) {
- if ((_gfx_call_dos(7, 0) & 0xFF) == '*') then restore_scrn();
- }
- ct = bios_time() + n_ticks;
- while (ct > bios_time());
- }
-