/* ______ ___ ___ * /\ _ \ /\_ \ /\_ \ * \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___ * \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\ * \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \ * \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/ * \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/ * /\____/ * \_/__/ * * Main test program for the Allegro library. * * By Shawn Hargreaves. * * See readme.txt for copyright information. */ #include #include #include #include #include "allegro.h" int gfx_card = GFX_AUTODETECT; int gfx_w = 640; int gfx_h = 480; int gfx_bpp = 8; int gfx_rate = 0; int mode = DRAW_MODE_SOLID; char mode_string[80]; #define CHECK_TRANS_BLENDER() \ if (bitmap_color_depth(screen) > 8) \ set_trans_blender(0, 0, 0, 0x40); #define TIME_SPEED 2 BITMAP *global_sprite = NULL; RLE_SPRITE *global_rle_sprite = NULL; COMPILED_SPRITE *global_compiled_sprite = NULL; BITMAP *realscreen = NULL; PALETTE mypal; #define NUM_PATTERNS 8 BITMAP *pattern[NUM_PATTERNS]; int cpu_has_capabilities = 0; int type3d = POLYTYPE_FLAT; char gfx_specs[80]; char gfx_specs2[80]; char gfx_specs3[80]; char mouse_specs[80]; char cpu_specs[120]; char buf[160]; int xoff, yoff; long tm = 0; /* counter, incremented once a second */ int _tm = 0; long ct; int profile = FALSE; COLOR_MAP *trans_map = NULL; COLOR_MAP *light_map = NULL; void tm_tick(void) { if (++_tm >= 100) { _tm = 0; tm++; if (realscreen) blit(screen, realscreen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); } } END_OF_FUNCTION(tm_tick) void show_time(long t, BITMAP *bmp, int y) { int s, x1, y1, x2, y2; get_clip_rect(bmp, &x1, &y1, &x2, &y2); s = get_clip_state(bmp); sprintf(buf, "%ld per second", t / TIME_SPEED); set_clip_rect(bmp, 0, 0, SCREEN_W-1, SCREEN_H-1); set_clip_state(bmp, TRUE); textout_centre_ex(bmp, font, buf, SCREEN_W/2, y, palette_color[15], palette_color[0]); set_clip_rect(bmp, x1, y1, x2, y2); set_clip_state(bmp, s); } void message(char *s) { textout_centre_ex(screen, font, s, SCREEN_W/2, 6, palette_color[15], palette_color[0]); if (!profile) textout_centre_ex(screen, font, "Press a key or mouse button", SCREEN_W/2, SCREEN_H-10, palette_color[15], palette_color[0]); } int next(void) { if (keypressed()) { clear_keybuf(); return TRUE; } poll_mouse(); if (mouse_b) { do { poll_mouse(); } while (mouse_b); return TRUE; } return FALSE; } BITMAP *make_sprite(void) { BITMAP *b; solid_mode(); b = create_bitmap(32, 32); clear_to_color(b, bitmap_mask_color(b)); circlefill(b, 16, 16, 8, palette_color[2]); circle(b, 16, 16, 8, palette_color[1]); line(b, 0, 0, 31, 31, palette_color[3]); line(b, 31, 0, 0, 31, palette_color[3]); textout_ex(b, font, "Test", 1, 12, palette_color[15], -1); return b; } int check_tables(void) { if (bitmap_color_depth(screen) > 8) { set_trans_blender(0, 0, 0, 128); } else if ((!rgb_map) || (!trans_map) || (!light_map)) { if (!rgb_map) { rgb_map = malloc(sizeof(RGB_MAP)); create_rgb_table(rgb_map, mypal, NULL); } if (!trans_map) { trans_map = malloc(sizeof(COLOR_MAP)); create_trans_table(trans_map, mypal, 96, 96, 96, NULL); } if (!light_map) { light_map = malloc(sizeof(COLOR_MAP)); create_light_table(light_map, mypal, 0, 0, 0, NULL); } color_map = trans_map; return D_REDRAW; } return D_O_K; } void make_patterns(void) { int c; pattern[0] = create_bitmap(2, 2); clear_to_color(pattern[0], bitmap_mask_color(pattern[0])); putpixel(pattern[0], 0, 0, palette_color[255]); pattern[1] = create_bitmap(2, 2); clear_to_color(pattern[1], bitmap_mask_color(pattern[1])); putpixel(pattern[1], 0, 0, palette_color[255]); putpixel(pattern[1], 1, 1, palette_color[255]); pattern[2] = create_bitmap(4, 4); clear_to_color(pattern[2], bitmap_mask_color(pattern[2])); vline(pattern[2], 0, 0, 4, palette_color[255]); hline(pattern[2], 0, 0, 4, palette_color[255]); pattern[3] = create_bitmap(4, 4); clear_to_color(pattern[3], bitmap_mask_color(pattern[3])); line(pattern[3], 0, 3, 3, 0, palette_color[255]); pattern[4] = create_bitmap(8, 8); clear_to_color(pattern[4], bitmap_mask_color(pattern[4])); for (c=0; c<16; c+=2) circle(pattern[4], 4, 4, c, palette_color[c]); pattern[5] = create_bitmap(8, 8); clear_to_color(pattern[5], bitmap_mask_color(pattern[5])); for (c=0; c<8; c++) hline(pattern[5], 0, c, 8, palette_color[c]); pattern[6] = create_bitmap(8, 8); clear_to_color(pattern[6], bitmap_mask_color(pattern[6])); circle(pattern[6], 0, 4, 3, palette_color[2]); circle(pattern[6], 8, 4, 3, palette_color[2]); circle(pattern[6], 4, 0, 3, palette_color[1]); circle(pattern[6], 4, 8, 3, palette_color[1]); pattern[7] = create_bitmap(64, 8); clear_to_color(pattern[7], bitmap_mask_color(pattern[7])); textout_ex(pattern[7], font, "PATTERN!", 0, 0, palette_color[255], bitmap_mask_color(pattern[7])); } void getpix_demo(void) { int c, ox, oy; scare_mouse(); acquire_screen(); clear_to_color(screen, palette_color[0]); message("getpixel test"); for (c=0; c<16; c++) rectfill(screen, xoff+100+((c&3)<<5), yoff+50+((c>>2)<<5), xoff+120+((c&3)<<5), yoff+70+((c>>2)<<5), palette_color[c]); release_screen(); unscare_mouse(); ox = -1; oy = -1; while (!next()) { rest(20); poll_mouse(); if ((mouse_x != ox) || (mouse_y != oy)) { ox = mouse_x; oy = mouse_y; scare_mouse(); acquire_screen(); c = getpixel(screen, ox-2, oy-2); sprintf(buf, " %X ", c); textout_centre_ex(screen, font, buf, SCREEN_W/2, yoff+24, palette_color[15], palette_color[0]); release_screen(); unscare_mouse(); } } } void putpix_test(int xpos, int ypos) { int c, x, y; for (c=0; c<16; c++) for (x=0; x<16; x+=2) for (y=0; y<16; y+=2) putpixel(screen, xpos+((c&3)<<4)+x, ypos+((c>>2)<<4)+y, palette_color[c]); } void hline_test(int xpos, int ypos) { int c; for (c=0; c<16; c++) hline(screen, xpos+48-c*3, ypos+c*3, xpos+48+c*3, palette_color[c]); } void vline_test(int xpos, int ypos) { int c; for (c=0; c<16; c++) vline(screen, xpos+c*4, ypos+36-c*3, ypos+36+c*3, palette_color[c]); } void line_test(int xpos, int ypos) { int c; for (c=0; c<16; c++) { line(screen, xpos+32, ypos+32, xpos+32+((c-8)<<2), ypos, palette_color[c%15+1]); line(screen, xpos+32, ypos+32, xpos+32-((c-8)<<2), ypos+64, palette_color[c%15+1]); line(screen, xpos+32, ypos+32, xpos, ypos+32-((c-8)<<2), palette_color[c%15+1]); line(screen, xpos+32, ypos+32, xpos+64, ypos+32+((c-8)<<2), palette_color[c%15+1]); } } void rectfill_test(int xpos, int ypos) { int c; for (c=0; c<16; c++) rectfill(screen, xpos+((c&3)*17), ypos+((c>>2)*17), xpos+15+((c&3)*17), ypos+15+((c>>2)*17), palette_color[c]); } void triangle_test(int xpos, int ypos) { int c; for (c=0; c<16; c++) triangle(screen, xpos+22+((c&3)<<4), ypos+15+((c>>2)<<4), xpos+13+((c&3)<<3), ypos+7+((c>>2)<<4), xpos+7+((c&3)<<4), ypos+27+((c>>2)<<3), palette_color[c]); } void circle_test(int xpos, int ypos) { int c; for (c=0; c<16; c++) circle(screen, xpos+32, ypos+32, c*2, palette_color[c%15+1]); } void circlefill_test(int xpos, int ypos) { int c; for (c=15; c>=0; c--) circlefill(screen, xpos+8+((c&3)<<4), ypos+8+((c>>2)<<4), c, palette_color[c%15+1]); } void ellipse_test(int xpos, int ypos) { int c; for (c=15; c>=0; c--) ellipse(screen, xpos+8+((c&3)<<4), ypos+8+((c>>2)<<4), (16-c)*2, (c+1)*2, palette_color[c%15+1]); } void ellipsefill_test(int xpos, int ypos) { int c; for (c=15; c>=0; c--) ellipsefill(screen, xpos+8+((c&3)<<4), ypos+8+((c>>2)<<4), (16-c)*2, (c+1)*2, palette_color[c%15+1]); } void arc_test(int xpos, int ypos) { int c; for (c=0; c<16; c++) arc(screen, xpos+32, ypos+32, itofix(c*12), itofix(64+c*16), c*2, palette_color[c%15+1]); } void textout_test(int xpos, int ypos) { textout_ex(screen, font,"This is a", xpos-8, ypos, palette_color[1], palette_color[0]); textout_ex(screen, font,"test of the", xpos+3, ypos+10, palette_color[1], palette_color[0]); textout_ex(screen, font,"textout", xpos+14, ypos+20, palette_color[1], palette_color[0]); textout_ex(screen, font,"function.", xpos+25, ypos+30, palette_color[1], palette_color[0]); textout_ex(screen, font,"solid background", xpos, ypos+48, palette_color[2], palette_color[0]); textout_ex(screen, font,"solid background", xpos+4, ypos+52, palette_color[4], palette_color[0]); textout_ex(screen, font,"transparent background", xpos, ypos+68, palette_color[2], -1); textout_ex(screen, font,"transparent background", xpos+4, ypos+72, palette_color[4], -1); } void sprite_test(int xpos, int ypos) { int x,y; for (y=0;y<82;y++) for (x=0;x<82;x+=2) putpixel(screen, xpos+x+(y&1), ypos+y, palette_color[8]); for (x=6; x<64; x+=global_sprite->w+6) for (y=6; y<64; y+=global_sprite->w+6) draw_sprite(screen, global_sprite, xpos+x, ypos+y); } void xlu_sprite_test(int xpos, int ypos) { int x,y; solid_mode(); for (y=0;y<82;y++) for (x=0;x<82;x+=2) putpixel(screen, xpos+x+(y&1), ypos+y, palette_color[8]); for (x=6; x<64; x+=global_sprite->w+6) { for (y=6; y<64; y+=global_sprite->w+6) { set_trans_blender(0, 0, 0, x+y*3); draw_trans_sprite(screen, global_sprite, xpos+x, ypos+y); } } } void lit_sprite_test(int xpos, int ypos) { int x,y; solid_mode(); for (y=0;y<82;y++) for (x=0;x<82;x+=2) putpixel(screen, xpos+x+(y&1), ypos+y, palette_color[8]); for (x=6; x<64; x+=global_sprite->w+6) { for (y=6; y<64; y+=global_sprite->w+6) { set_trans_blender(x*4, (x+y)*2, y*4, 0); draw_lit_sprite(screen, global_sprite, xpos+x, ypos+y, ((x*2+y)*5)&0xFF); } } } void rle_xlu_sprite_test(int xpos, int ypos) { int x,y; solid_mode(); for (y=0;y<82;y++) for (x=0;x<82;x+=2) putpixel(screen, xpos+x+(y&1), ypos+y, palette_color[8]); for (x=6; x<64; x+=global_sprite->w+6) { for (y=6; y<64; y+=global_sprite->w+6) { set_trans_blender(0, 0, 0, x+y*3); draw_trans_rle_sprite(screen, global_rle_sprite, xpos+x, ypos+y); } } } void rle_lit_sprite_test(int xpos, int ypos) { int x,y; solid_mode(); for (y=0;y<82;y++) for (x=0;x<82;x+=2) putpixel(screen, xpos+x+(y&1), ypos+y, palette_color[8]); for (x=6; x<64; x+=global_sprite->w+6) { for (y=6; y<64; y+=global_sprite->w+6) { set_trans_blender(x*4, (x+y)*2, y*4, 0); draw_lit_rle_sprite(screen, global_rle_sprite, xpos+x, ypos+y, ((x*2+y)*5)&0xFF); } } } void rle_sprite_test(int xpos, int ypos) { int x,y; for (y=0;y<82;y++) for (x=0;x<82;x+=2) putpixel(screen, xpos+x+(y&1), ypos+y, palette_color[8]); for (x=6; x<64; x+=global_sprite->w+6) for (y=6; y<64; y+=global_sprite->w+6) draw_rle_sprite(screen, global_rle_sprite, xpos+x, ypos+y); } void compiled_sprite_test(int xpos, int ypos) { int x,y; for (y=0;y<82;y++) for (x=0;x<82;x+=2) putpixel(screen, xpos+x+(y&1), ypos+y, palette_color[8]); for (x=6; x<64; x+=global_sprite->w+6) for (y=6; y<64; y+=global_sprite->w+6) draw_compiled_sprite(screen, global_compiled_sprite, xpos+x, ypos+y); } void flipped_sprite_test(int xpos, int ypos) { int x, y; for (y=0;y<88;y++) for (x=0;x<88;x+=2) putpixel(screen, xpos+x+(y&1), ypos+y, palette_color[8]); draw_sprite(screen, global_sprite, xpos+8, ypos+8); draw_sprite_h_flip(screen, global_sprite, xpos+48, ypos+8); draw_sprite_v_flip(screen, global_sprite, xpos+8, ypos+48); draw_sprite_vh_flip(screen, global_sprite, xpos+48, ypos+48); } void putpix_demo(void) { int c = 0; int x, y; tm = 0; _tm = 0; ct = 0; while (!next()) { x = (AL_RAND() & 255) + 32; y = (AL_RAND() & 127) + 40; putpixel(screen, xoff+x, yoff+y, palette_color[c]); if (mode >= DRAW_MODE_COPY_PATTERN) drawing_mode(mode, pattern[AL_RAND()%NUM_PATTERNS], 0, 0); if (++c >= 16) c = 0; if (ct >= 0) { if (tm >= TIME_SPEED) { if (profile) return; show_time(ct, screen, 16); ct = -1; } else ct++; } } ct = -1; } void hline_demo(void) { int c = 0; int x1, x2, y; tm = 0; _tm = 0; ct = 0; while (!next()) { x1 = (AL_RAND() & 255) + 32; x2 = (AL_RAND() & 255) + 32; y = (AL_RAND() & 127) + 40; hline(screen, xoff+x1, yoff+y, xoff+x2, palette_color[c]); if (mode >= DRAW_MODE_COPY_PATTERN) drawing_mode(mode, pattern[AL_RAND()%NUM_PATTERNS], 0, 0); if (++c >= 16) c = 0; if (ct >= 0) { if (tm >= TIME_SPEED) { if (profile) return; show_time(ct, screen, 16); ct = -1; } else ct++; } } ct = -1; } void vline_demo(void) { int c = 0; int x, y1, y2; tm = 0; _tm = 0; ct = 0; while (!next()) { x = (AL_RAND() & 255) + 32; y1 = (AL_RAND() & 127) + 40; y2 = (AL_RAND() & 127) + 40; vline(screen, xoff+x, yoff+y1, yoff+y2, palette_color[c]); if (mode >= DRAW_MODE_COPY_PATTERN) drawing_mode(mode, pattern[AL_RAND()%NUM_PATTERNS], 0, 0); if (++c >= 16) c = 0; if (ct >= 0) { if (tm >= TIME_SPEED) { if (profile) return; show_time(ct, screen, 16); ct = -1; } else ct++; } } ct = -1; } void line_demo(void) { int c = 0; int x1, y1, x2, y2; tm = 0; _tm = 0; ct = 0; while (!next()) { x1 = (AL_RAND() & 255) + 32; x2 = (AL_RAND() & 255) + 32; y1 = (AL_RAND() & 127) + 40; y2 = (AL_RAND() & 127) + 40; line(screen, xoff+x1, yoff+y1, xoff+x2, yoff+y2, palette_color[c]); if (mode >= DRAW_MODE_COPY_PATTERN) drawing_mode(mode, pattern[AL_RAND()%NUM_PATTERNS], 0, 0); if (++c >= 16) c = 0; if (ct >= 0) { if (tm >= TIME_SPEED) { if (profile) return; show_time(ct, screen, 16); ct = -1; } else ct++; } } ct = -1; } void rectfill_demo(void) { int c = 0; int x1, y1, x2, y2; tm = 0; _tm = 0; ct = 0; while (!next()) { x1 = (AL_RAND() & 255) + 32; y1 = (AL_RAND() & 127) + 40; x2 = (AL_RAND() & 255) + 32; y2 = (AL_RAND() & 127) + 40; rectfill(screen, xoff+x1, yoff+y1, xoff+x2, yoff+y2, palette_color[c]); if (mode >= DRAW_MODE_COPY_PATTERN) drawing_mode(mode, pattern[AL_RAND()%NUM_PATTERNS], 0, 0); if (++c >= 16) c = 0; if (ct >= 0) { if (tm >= TIME_SPEED) { if (profile) return; show_time(ct, screen, 16); ct = -1; } else ct++; } } ct = -1; } void triangle_demo(void) { int c = 0; int x1, y1, x2, y2, x3, y3; tm = 0; _tm = 0; ct = 0; while (!next()) { x1 = (AL_RAND() & 255) + 32; x2 = (AL_RAND() & 255) + 32; x3 = (AL_RAND() & 255) + 32; y1 = (AL_RAND() & 127) + 40; y2 = (AL_RAND() & 127) + 40; y3 = (AL_RAND() & 127) + 40; triangle(screen, xoff+x1, yoff+y1, xoff+x2, yoff+y2, xoff+x3, yoff+y3, palette_color[c]); if (mode >= DRAW_MODE_COPY_PATTERN) drawing_mode(mode, pattern[AL_RAND()%NUM_PATTERNS], 0, 0); if (++c >= 16) c = 0; if (ct >= 0) { if (tm >= TIME_SPEED) { if (profile) return; show_time(ct, screen, 16); ct = -1; } else ct++; } } ct = -1; } void triangle3d_demo(void) { V3D v1, v2, v3; int x0 = xoff+32; int y0 = yoff+40; v1.u = 0; v1.v = 0; v2.u = itofix(32); v2.v = 0; v3.u = 0; v3.v = itofix(32); tm = _tm = 0; ct = 0; while (!next()) { v1.x = itofix((AL_RAND() & 255) + x0); v2.x = itofix((AL_RAND() & 255) + x0); v3.x = itofix((AL_RAND() & 255) + x0); v1.y = itofix((AL_RAND() & 127) + y0); v2.y = itofix((AL_RAND() & 127) + y0); v3.y = itofix((AL_RAND() & 127) + y0); v1.z = itofix((AL_RAND() & 127) + 400); v2.z = itofix((AL_RAND() & 127) + 400); v3.z = itofix((AL_RAND() & 127) + 400); if ((type3d == POLYTYPE_ATEX_LIT) || (type3d == POLYTYPE_PTEX_LIT) || (type3d == POLYTYPE_ATEX_MASK_LIT) || (type3d == POLYTYPE_PTEX_MASK_LIT)) { v1.c = AL_RAND() & 255; v2.c = AL_RAND() & 255; v3.c = AL_RAND() & 255; } else { v1.c = palette_color[AL_RAND() & 255]; v2.c = palette_color[AL_RAND() & 255]; v3.c = palette_color[AL_RAND() & 255]; } triangle3d(screen, type3d, pattern[AL_RAND()%NUM_PATTERNS], &v1, &v2, &v3); if (ct >= 0) { if (tm >= TIME_SPEED) { if (profile) return; show_time(ct, screen, 16); ct = -1; } else ct++; } } ct = -1; } void circle_demo(void) { int c = 0; int x, y, r; tm = 0; _tm = 0; ct = 0; while (!next()) { x = (AL_RAND() & 127) + 92; y = (AL_RAND() & 63) + 76; r = (AL_RAND() & 31) + 16; circle(screen, xoff+x, yoff+y, r, palette_color[c]); if (mode >= DRAW_MODE_COPY_PATTERN) drawing_mode(mode, pattern[AL_RAND()%NUM_PATTERNS], 0, 0); if (++c >= 16) c = 0; if (ct >= 0) { if (tm >= TIME_SPEED) { if (profile) return; show_time(ct, screen, 16); ct = -1; } else ct++; } } ct = -1; } void circlefill_demo(void) { int c = 0; int x, y, r; tm = 0; _tm = 0; ct = 0; while (!next()) { x = (AL_RAND() & 127) + 92; y = (AL_RAND() & 63) + 76; r = (AL_RAND() & 31) + 16; circlefill(screen, xoff+x, yoff+y, r, palette_color[c]); if (mode >= DRAW_MODE_COPY_PATTERN) drawing_mode(mode, pattern[AL_RAND()%NUM_PATTERNS], 0, 0); if (++c >= 16) c = 0; if (ct >= 0) { if (tm >= TIME_SPEED) { if (profile) return; show_time(ct, screen, 16); ct = -1; } else ct++; } } ct = -1; } void ellipse_demo(void) { int c = 0; int x, y, rx, ry; tm = 0; _tm = 0; ct = 0; while (!next()) { x = (AL_RAND() & 127) + 92; y = (AL_RAND() & 63) + 76; rx = (AL_RAND() & 31) + 16; ry = (AL_RAND() & 31) + 16; ellipse(screen, xoff+x, yoff+y, rx, ry, palette_color[c]); if (mode >= DRAW_MODE_COPY_PATTERN) drawing_mode(mode, pattern[AL_RAND()%NUM_PATTERNS], 0, 0); if (++c >= 16) c = 0; if (ct >= 0) { if (tm >= TIME_SPEED) { if (profile) return; show_time(ct, screen, 16); ct = -1; } else ct++; } } ct = -1; } void ellipsefill_demo(void) { int c = 0; int x, y, rx, ry; tm = 0; _tm = 0; ct = 0; while (!next()) { x = (AL_RAND() & 127) + 92; y = (AL_RAND() & 63) + 76; rx = (AL_RAND() & 31) + 16; ry = (AL_RAND() & 31) + 16; ellipsefill(screen, xoff+x, yoff+y, rx, ry, palette_color[c]); if (mode >= DRAW_MODE_COPY_PATTERN) drawing_mode(mode, pattern[AL_RAND()%NUM_PATTERNS], 0, 0); if (++c >= 16) c = 0; if (ct >= 0) { if (tm >= TIME_SPEED) { if (profile) return; show_time(ct, screen, 16); ct = -1; } else ct++; } } ct = -1; } void arc_demo(void) { int c = 0; int x, y, r; fixed a1, a2; tm = 0; _tm = 0; ct = 0; while (!next()) { x = (AL_RAND() & 127) + 92; y = (AL_RAND() & 63) + 76; r = (AL_RAND() & 31) + 16; a1 = (AL_RAND() & 0xFF) << 16; a2 = (AL_RAND() & 0xFF) << 16; arc(screen, xoff+x, yoff+y, a1, a2, r, palette_color[c]); if (mode >= DRAW_MODE_COPY_PATTERN) drawing_mode(mode, pattern[AL_RAND()%NUM_PATTERNS], 0, 0); if (++c >= 16) c = 0; if (ct >= 0) { if (tm >= TIME_SPEED) { if (profile) return; show_time(ct, screen, 16); ct = -1; } else ct++; } } ct = -1; } void textout_demo(void) { int c = 0; int x, y; tm = 0; _tm = 0; ct = 0; while (!next()) { x = (AL_RAND() & 127) + 40; y = (AL_RAND() & 127) + 40; textout_ex(screen, font, "textout test", xoff+x, yoff+y, palette_color[c], palette_color[0]); if (++c >= 16) c = 0; if (ct >= 0) { if (tm >= TIME_SPEED) { if (profile) return; show_time(ct, screen, 16); ct = -1; } else ct++; } } ct = -1; } void sprite_demo(void) { int x, y; int xand = (SCREEN_W >= 320) ? 255 : 127; int xadd = (SCREEN_W >= 320) ? 16 : 80; tm = 0; _tm = 0; ct = 0; while (!next()) { x = (AL_RAND() & xand) + xadd; y = (AL_RAND() & 127) + 30; draw_sprite(screen, global_sprite, xoff+x, yoff+y); if (ct >= 0) { if (tm >= TIME_SPEED) { if (profile) return; show_time(ct, screen, 16); ct = -1; } else ct++; } } ct = -1; } void xlu_sprite_demo(void) { int x, y; int xand = (SCREEN_W >= 320) ? 255 : 127; int xadd = (SCREEN_W >= 320) ? 16 : 80; tm = 0; _tm = 0; ct = 0; while (!next()) { x = (AL_RAND() & xand) + xadd; y = (AL_RAND() & 127) + 30; if (bitmap_color_depth(screen) > 8) set_trans_blender(0, 0, 0, AL_RAND()&0x7F); draw_trans_sprite(screen, global_sprite, xoff+x, yoff+y); if (ct >= 0) { if (tm >= TIME_SPEED) { if (profile) return; show_time(ct, screen, 16); ct = -1; } else ct++; } } ct = -1; } void lit_sprite_demo(void) { int c = 1; int x, y; int xand = (SCREEN_W >= 320) ? 255 : 127; int xadd = (SCREEN_W >= 320) ? 16 : 80; tm = 0; _tm = 0; ct = 0; while (!next()) { x = (AL_RAND() & xand) + xadd; y = (AL_RAND() & 127) + 30; if (bitmap_color_depth(screen) > 8) set_trans_blender(AL_RAND()&0xFF, AL_RAND()&0xFF, AL_RAND()&0xFF, 0); draw_lit_sprite(screen, global_sprite, xoff+x, yoff+y, c); c = (c+13) & 0xFF; if (ct >= 0) { if (tm >= TIME_SPEED) { if (profile) return; show_time(ct, screen, 16); ct = -1; } else ct++; } } ct = -1; } void rle_xlu_sprite_demo(void) { int x, y; int xand = (SCREEN_W >= 320) ? 255 : 127; int xadd = (SCREEN_W >= 320) ? 16 : 80; tm = 0; _tm = 0; ct = 0; while (!next()) { x = (AL_RAND() & xand) + xadd; y = (AL_RAND() & 127) + 30; if (bitmap_color_depth(screen) > 8) set_trans_blender(0, 0, 0, AL_RAND()&0x7F); draw_trans_rle_sprite(screen, global_rle_sprite, xoff+x, yoff+y); if (ct >= 0) { if (tm >= TIME_SPEED) { if (profile) return; show_time(ct, screen, 16); ct = -1; } else ct++; } } ct = -1; } void rle_lit_sprite_demo(void) { int c = 1; int x, y; int xand = (SCREEN_W >= 320) ? 255 : 127; int xadd = (SCREEN_W >= 320) ? 16 : 80; tm = 0; _tm = 0; ct = 0; while (!next()) { x = (AL_RAND() & xand) + xadd; y = (AL_RAND() & 127) + 30; if (bitmap_color_depth(screen) > 8) set_trans_blender(AL_RAND()&0xFF, AL_RAND()&0xFF, AL_RAND()&0xFF, 0); draw_lit_rle_sprite(screen, global_rle_sprite, xoff+x, yoff+y, c); c = (c+13) & 0xFF; if (ct >= 0) { if (tm >= TIME_SPEED) { if (profile) return; show_time(ct, screen, 16); ct = -1; } else ct++; } } ct = -1; } void rle_sprite_demo(void) { int x, y; int xand = (SCREEN_W >= 320) ? 255 : 127; int xadd = (SCREEN_W >= 320) ? 16 : 80; tm = 0; _tm = 0; ct = 0; while (!next()) { x = (AL_RAND() & xand) + xadd; y = (AL_RAND() & 127) + 30; draw_rle_sprite(screen, global_rle_sprite, xoff+x, yoff+y); if (ct >= 0) { if (tm >= TIME_SPEED) { if (profile) return; show_time(ct, screen, 16); ct = -1; } else ct++; } } ct = -1; } void compiled_sprite_demo(void) { int x, y; int xand = (SCREEN_W >= 320) ? 255 : 127; int xadd = (SCREEN_W >= 320) ? 16 : 80; tm = 0; _tm = 0; ct = 0; while (!next()) { x = (AL_RAND() & xand) + xadd; y = (AL_RAND() & 127) + 30; draw_compiled_sprite(screen, global_compiled_sprite, xoff+x, yoff+y); if (ct >= 0) { if (tm >= TIME_SPEED) { if (profile) return; show_time(ct, screen, 16); ct = -1; } else ct++; } } ct = -1; } int blit_from_screen = FALSE; int blit_align = FALSE; int blit_mask = FALSE; void blit_demo(void) { int x, y; int sx, sy; BITMAP *b; solid_mode(); b = create_bitmap(64, 32); if (!b) { clear_to_color(screen, palette_color[0]); textout_ex(screen, font, "Out of memory!", 50, 50, palette_color[15], palette_color[0]); destroy_bitmap(b); while (!next()) ; return; } clear_to_color(b, (blit_mask ? bitmap_mask_color(b) : palette_color[0])); circlefill(b, 32, 16, 16, palette_color[4]); circlefill(b, 32, 16, 10, palette_color[2]); circlefill(b, 32, 16, 6, palette_color[1]); line(b, 0, 0, 63, 31, palette_color[3]); line(b, 0, 31, 63, 0, palette_color[3]); rect(b, 8, 4, 56, 28, palette_color[3]); rect(b, 0, 0, 63, 31, palette_color[15]); tm = 0; _tm = 0; ct = 0; sx = ((SCREEN_W-64) / 2) & 0xFFFC; sy = yoff + 32; if (blit_from_screen) blit(b, screen, 0, 0, sx, sy, 64, 32); while (!next()) { x = (AL_RAND() & 127) + 60; y = (AL_RAND() & 63) + 50; if (blit_align) x &= 0xFFFC; if (blit_from_screen) { if (blit_mask) masked_blit(screen, screen, sx, sy, xoff+x, yoff+y+24, 64, 32); else blit(screen, screen, sx, sy, xoff+x, yoff+y+24, 64, 32); } else { if (blit_mask) masked_blit(b, screen, 0, 0, xoff+x, yoff+y, 64, 32); else blit(b, screen, 0, 0, xoff+x, yoff+y, 64, 32); } if (ct >= 0) { if (tm >= TIME_SPEED) { if (profile) return; show_time(ct, screen, 16); ct = -1; } else ct++; } } destroy_bitmap(b); ct = -1; } void misc(void) { BITMAP *p; volatile fixed x, y, z; volatile float fx, fy, fz; clear_to_color(screen, palette_color[0]); textout_ex(screen,font,"Timing some other routines...", xoff+44, 6, palette_color[15], palette_color[0]); p = create_bitmap(320, 200); if (!p) textout_ex(screen,font,"Out of memory!", 16, 50, palette_color[15], palette_color[0]); else { tm = 0; _tm = 0; ct = 0; do { clear_bitmap(p); ct++; if (next()) return; } while (tm < TIME_SPEED); destroy_bitmap(p); sprintf(buf,"clear_bitmap(320x200): %ld per second", ct/TIME_SPEED); textout_ex(screen, font, buf, xoff+16, yoff+15, palette_color[15], palette_color[0]); } x = y = 0; tm = 0; _tm = 0; ct = 0; do { z += fixmul(x,y); x += 1317; y += 7143; ct++; if (next()) return; } while (tm < TIME_SPEED); sprintf(buf, "fixmul(): %ld per second", ct/TIME_SPEED); textout_ex(screen, font, buf, xoff+16, yoff+25, palette_color[15], palette_color[0]); fx = fy = 0; tm = 0; _tm = 0; ct = 0; do { fz += fx * fy; fx += 1317; fy += 7143; ct++; if (next()) return; } while (tm < TIME_SPEED); sprintf(buf, "float *: %ld per second", ct/TIME_SPEED); textout_ex(screen, font, buf, xoff+16, yoff+35, palette_color[15], palette_color[0]); x = y = 0; tm = 0; _tm = 0; ct = 0; do { z += fixdiv(x,y); x += 1317; y += 7143; if (y==0) y++; ct++; if (next()) return; } while (tm < TIME_SPEED); sprintf(buf, "fixdiv(): %ld per second", ct/TIME_SPEED); textout_ex(screen, font, buf, xoff+16, yoff+45, palette_color[15], palette_color[0]); fx = fy = 1; tm = 0; _tm = 0; ct = 0; do { fz += fx / fy; fx += 1317; fy += 7143; if (fy==0) fy++; ct++; if (next()) return; } while (tm < TIME_SPEED); sprintf(buf, "float /: %ld per second", ct/TIME_SPEED); textout_ex(screen, font, buf, xoff+16, yoff+55, palette_color[15], palette_color[0]); x = 1; tm = 0; _tm = 0; ct = 0; do { y += fixsqrt(x); x += 7361; ct++; if (next()) return; } while (tm < TIME_SPEED); sprintf(buf, "fixsqrt(): %ld per second", ct/TIME_SPEED); textout_ex(screen, font, buf, xoff+16, yoff+65, palette_color[15], palette_color[0]); fx = 1; tm = 0; _tm = 0; ct = 0; do { fy += sqrt(fx); fx += 7361; ct++; if (next()) return; } while (tm < TIME_SPEED); sprintf(buf, "libc sqrtf(): %ld per second", ct/TIME_SPEED); textout_ex(screen, font, buf, xoff+16, yoff+75, palette_color[15], palette_color[0]); x = 1; tm = 0; _tm = 0; ct = 0; do { y += fixsin(x); x += 4283; ct++; if (next()) return; } while (tm < TIME_SPEED); sprintf(buf, "fixsin(): %ld per second", ct / TIME_SPEED); textout_ex(screen, font, buf, xoff+16, yoff+85, palette_color[15], palette_color[0]); fx = 1; tm = 0; _tm = 0; ct = 0; do { fy += sin(fx); fx += 4283; ct++; if (next()) return; } while (tm < TIME_SPEED); sprintf(buf, "libc sin(): %ld per second", ct / TIME_SPEED); textout_ex(screen, font, buf, xoff+16, yoff+95, palette_color[15], palette_color[0]); x = 1; tm = 0; _tm = 0; ct = 0; do { y += fixcos(x); x += 4283; ct++; if (next()) return; } while (tm < TIME_SPEED); sprintf(buf, "fixcos(): %ld per second", ct / TIME_SPEED); textout_ex(screen, font, buf, xoff+16, yoff+105, palette_color[15], palette_color[0]); x = 1; tm = 0; _tm = 0; ct = 0; do { y += fixtan(x); x += 8372; ct++; if (next()) return; } while (tm < TIME_SPEED); sprintf(buf, "fixtan(): %ld per second", ct / TIME_SPEED); textout_ex(screen, font, buf, xoff+16, yoff+115, palette_color[15], palette_color[0]); fx = 1; tm = 0; _tm = 0; ct = 0; do { fy += tan(fx); fx += 8372; ct++; if (next()) return; } while (tm < TIME_SPEED); sprintf(buf, "libc tan(): %ld per second", ct / TIME_SPEED); textout_ex(screen, font, buf, xoff+16, yoff+125, palette_color[15], palette_color[0]); x = 1; tm = 0; _tm = 0; ct = 0; do { y += fixasin(x); x += 5621; x &= 0xffff; ct++; if (next()) return; } while (tm < TIME_SPEED); sprintf(buf, "fixasin(): %ld per second", ct / TIME_SPEED); textout_ex(screen, font, buf, xoff+16, yoff+135, palette_color[15], palette_color[0]); x = 1; tm = 0; _tm = 0; ct = 0; do { y += fixacos(x); x += 5621; x &= 0xffff; ct++; if (next()) return; } while (tm < TIME_SPEED); sprintf(buf,"fixacos(): %ld per second", ct / TIME_SPEED); textout_ex(screen, font, buf, xoff+16, yoff+145, palette_color[15], palette_color[0]); x = 1; tm = 0; _tm = 0; ct = 0; do { y += fixatan(x); x += 7358; ct++; if (next()) return; } while (tm < TIME_SPEED); sprintf(buf, "fixatan(): %ld per second", ct / TIME_SPEED); textout_ex(screen, font, buf, xoff+16, yoff+155, palette_color[15], palette_color[0]); fx = 1; tm = 0; _tm = 0; ct = 0; do { fy += atan(fx); fx += 7358; ct++; if (next()) return; } while (tm < TIME_SPEED); sprintf(buf, "libc atan(): %ld per second", ct / TIME_SPEED); textout_ex(screen, font, buf, xoff+16, yoff+165, palette_color[15], palette_color[0]); x = 1, y = 2; tm = 0; _tm = 0; ct = 0; do { z += fixatan2(x, y); x += 5621; y += 7335; ct++; if (next()) return; } while (tm < TIME_SPEED); sprintf(buf, "fixatan2(): %ld per second", ct / TIME_SPEED); textout_ex(screen, font, buf, xoff+16, yoff+175, palette_color[15], palette_color[0]); textout_ex(screen, font, "Press a key or mouse button", xoff+52, SCREEN_H-10, palette_color[15], palette_color[0]); while (!next()) ; } void rainbow(void) { char buf[80]; int x, y; int r, g, b; float h, s, v, c; acquire_screen(); clear_to_color(screen, palette_color[0]); sprintf(buf, "%d bit color...", bitmap_color_depth(screen)); textout_centre_ex(screen, font, buf, SCREEN_W/2, 6, palette_color[15], palette_color[0]); for (h=0; h<360; h+=0.25) { for (c=0; c<1; c+=0.005) { s = 1.0-ABS(1.0-c*2); v = MIN(c*2, 1.0); x = cos(h*3.14159/180.0)*c*128.0; y = sin(h*3.14159/180.0)*c*128.0; hsv_to_rgb(h, s, v, &r, &g, &b); putpixel(screen, SCREEN_W/2+x, SCREEN_H/2+y, makecol(r, g, b)); } } textout_ex(screen, font, "Press a key or mouse button", xoff+52, SCREEN_H-10, palette_color[15], palette_color[0]); release_screen(); while (!next()) ; } static void caps(void) { static char *s[] = { "(scroll)", "(triple buffer)", "(hardware cursor)", "solid hline:", "xor hline:", "solid/masked pattern hline:", "copy pattern hline:", "solid fill:", "xor fill:", "solid/masked pattern fill:", "copy pattern fill:", "solid line:", "xor line:", "solid triangle:", "xor triangle:", "mono text:", "vram->vram blit:", "masked vram->vram blit:", "mem->screen blit:", "masked mem->screen blit:", "system->screen blit:", "masked system->screen blit:", NULL }; int c; acquire_screen(); clear_to_color(screen, palette_color[0]); textout_ex(screen,font,"Hardware accelerated features", xoff+44, 6, palette_color[15], palette_color[0]); for (c=3; s[c]; c++) { textout_ex(screen, font, s[c], SCREEN_W/2+64-text_length(font, s[c]), SCREEN_H/2-184+c*16, palette_color[15], palette_color[0]); textout_ex(screen, font, (gfx_capabilities & (1<= 16) int_c1 = 0; } END_OF_FUNCTION(int1) void int2(void) { if (++int_c2 >= 16) int_c2 = 0; } END_OF_FUNCTION(int2) void int3(void) { if (++int_c3 >= 16) int_c3 = 0; } END_OF_FUNCTION(int3) void interrupt_test(void) { clear_to_color(screen, palette_color[0]); message("Timer interrupt test"); textout_ex(screen,font,"1/4", xoff+108, yoff+78, palette_color[15], palette_color[0]); textout_ex(screen,font,"1", xoff+156, yoff+78, palette_color[15], palette_color[0]); textout_ex(screen,font,"5", xoff+196, yoff+78, palette_color[15], palette_color[0]); LOCK_VARIABLE(int_c1); LOCK_VARIABLE(int_c2); LOCK_VARIABLE(int_c3); LOCK_FUNCTION(int1); LOCK_FUNCTION(int2); LOCK_FUNCTION(int3); install_int(int1, 250); install_int(int2, 1000); install_int(int3, 5000); while (!next()) { rectfill(screen, xoff+110, yoff+90, xoff+130, yoff+110, palette_color[int_c1]); rectfill(screen, xoff+150, yoff+90, xoff+170, yoff+110, palette_color[int_c2]); rectfill(screen, xoff+190, yoff+90, xoff+210, yoff+110, palette_color[int_c3]); } remove_int(int1); remove_int(int2); remove_int(int3); } int fade_color = 63; void fade(void) { RGB rgb; rgb.r = rgb.g = rgb.b = (fade_color < 64) ? fade_color : 127 - fade_color; rgb.filler = 0; _set_color(0, &rgb); fade_color++; if (fade_color >= 128) fade_color = 0; } END_OF_FUNCTION(fade) void rotate_test(void) { fixed c = 0; BITMAP *b; set_clip_rect(screen, 0, 0, VIRTUAL_W-1, VIRTUAL_H-1); clear_to_color(screen, palette_color[0]); message("Bitmap rotation test"); b = create_bitmap(32, 32); draw_sprite(screen, global_sprite, SCREEN_W/2-16-32, SCREEN_H/2-16-32); draw_sprite(screen, global_sprite, SCREEN_W/2-16-64, SCREEN_H/2-16-64); draw_sprite_v_flip(screen, global_sprite, SCREEN_W/2-16-32, SCREEN_H/2-16+32); draw_sprite_v_flip(screen, global_sprite, SCREEN_W/2-16-64, SCREEN_H/2-16+64); draw_sprite_h_flip(screen, global_sprite, SCREEN_W/2-16+32, SCREEN_H/2-16-32); draw_sprite_h_flip(screen, global_sprite, SCREEN_W/2-16+64, SCREEN_H/2-16-64); draw_sprite_vh_flip(screen, global_sprite, SCREEN_W/2-16+32, SCREEN_H/2-16+32); draw_sprite_vh_flip(screen, global_sprite, SCREEN_W/2-16+64, SCREEN_H/2-16+64); tm = 0; _tm = 0; ct = 0; while (!next()) { clear_to_color(b, palette_color[0]); rotate_sprite(b, global_sprite, 0, 0, c); blit(b, screen, 0, 0, SCREEN_W/2-16, SCREEN_H/2-16, b->w, b->h); c += itofix(1) / 16; if (ct >= 0) { if (tm >= TIME_SPEED) { show_time(ct, screen, 16); ct = -1; } else ct++; } } destroy_bitmap(b); } void stretch_test(void) { BITMAP *b; int c; set_clip_rect(screen, 0, 0, VIRTUAL_W-1, VIRTUAL_H-1); clear_to_color(screen, palette_color[0]); message("Bitmap scaling test"); tm = 0; _tm = 0; ct = 0; c = 1; rect(screen, SCREEN_W/2-128, SCREEN_H/2-64, SCREEN_W/2+128, SCREEN_H/2+64, palette_color[15]); set_clip_rect(screen, SCREEN_W/2-127, SCREEN_H/2-63, SCREEN_W/2+127, SCREEN_H/2+63); solid_mode(); b = create_bitmap(32, 32); clear_to_color(b, palette_color[0]); circlefill(b, 16, 16, 8, palette_color[2]); circle(b, 16, 16, 8, palette_color[1]); line(b, 0, 0, 31, 31, palette_color[3]); line(b, 31, 0, 0, 31, palette_color[3]); textout_ex(b, font, "Test", 1, 12, palette_color[15], -1); while (!next()) { stretch_blit(b, screen, 0, 0, 32, 32, SCREEN_W/2-c, SCREEN_H/2-(256-c), c*2, (256-c)*2); if (c >= 255) { c = 1; rectfill(screen, SCREEN_W/2-127, SCREEN_H/2-63, SCREEN_W/2+127, SCREEN_H/2+63, palette_color[0]); } else c++; if (ct >= 0) { if (tm >= TIME_SPEED) { show_time(ct, screen, 16); ct = -1; } else ct++; } } destroy_bitmap(b); } void hscroll_test(void) { int x, y; int done = FALSE; int ox = mouse_x; int oy = mouse_y; set_clip_rect(screen, 0, 0, VIRTUAL_W-1, VIRTUAL_H-1); clear_to_color(screen, palette_color[0]); rect(screen, 0, 0, VIRTUAL_W-1, VIRTUAL_H-1, palette_color[15]); for (x=1; x<16; x++) { vline(screen, VIRTUAL_W*x/16, 1, VIRTUAL_H-2, palette_color[x]); hline(screen, 1, VIRTUAL_H*x/16, VIRTUAL_W-2, palette_color[x]); sprintf(buf, "%x", x); textout_ex(screen, font, buf, 2, VIRTUAL_H*x/16-4, palette_color[15], -1); textout_ex(screen, font, buf, VIRTUAL_W-9, VIRTUAL_H*x/16-4, palette_color[15], -1); textout_ex(screen, font, buf, VIRTUAL_W*x/16-4, 2, palette_color[15], -1); textout_ex(screen, font, buf, VIRTUAL_W*x/16-4, VIRTUAL_H-9, palette_color[15], -1); } sprintf(buf, "Graphics driver: %s", gfx_driver->name); textout_ex(screen, font, buf, 32, 32, palette_color[15], -1); sprintf(buf, "Description: %s", gfx_driver->desc); textout_ex(screen, font, buf, 32, 48, palette_color[15], -1); sprintf(buf, "Specs: %s", gfx_specs); textout_ex(screen, font, buf, 32, 64, palette_color[15], -1); sprintf(buf, "Color depth: %s", gfx_specs2); textout_ex(screen, font, buf, 32, 80, palette_color[15], -1); textout_ex(screen, font, gfx_specs3, 32, 96, palette_color[15], -1); if (gfx_driver->scroll == NULL) textout_ex(screen, font, "Hardware scrolling not supported", 32, 112, palette_color[15], -1); x = y = 0; position_mouse(32, 32); while ((!done) && (!mouse_b)) { poll_mouse(); if ((mouse_x != 32) || (mouse_y != 32)) { x += mouse_x - 32; y += mouse_y - 32; position_mouse(32, 32); } if (keypressed()) { switch (readkey() >> 8) { case KEY_LEFT: x--; break; case KEY_RIGHT: x++; break; case KEY_UP: y--; break; case KEY_DOWN: y++; break; default: done = TRUE; break; } } if (x < 0) x = 0; else if (x > (VIRTUAL_W - SCREEN_W)) x = VIRTUAL_W - SCREEN_W; if (y < 0) y = 0; else if (y > VIRTUAL_H) y = VIRTUAL_H; scroll_screen(x, y); } do { poll_mouse(); } while (mouse_b); position_mouse(ox, oy); clear_keybuf(); scroll_screen(0, 0); } void test_it(char *msg, void (*func)(int, int)) { int x = 0; int y = 0; int c = 0; int pat = AL_RAND()%NUM_PATTERNS; do { acquire_screen(); set_clip_rect(screen, 0, 0, SCREEN_W-1, SCREEN_H-1); clear_to_color(screen, palette_color[0]); message(msg); textout_centre_ex(screen, font, "(arrow keys to slide)", SCREEN_W/2, 28, palette_color[15], palette_color[0]); textout_ex(screen, font, "unclipped:", xoff+48, yoff+50, palette_color[15], palette_color[0]); textout_ex(screen, font, "clipped:", xoff+180, yoff+62, palette_color[15], palette_color[0]); rect(screen, xoff+191, yoff+83, xoff+240, yoff+114, palette_color[15]); set_clip_rect(screen, xoff+192, yoff+84, xoff+239, yoff+113); drawing_mode(mode, pattern[pat], 0, 0); set_clip_state(screen, FALSE); (*func)(xoff+x+60, yoff+y+70); set_clip_state(screen, TRUE); (*func)(xoff+x+180, yoff+y+70); solid_mode(); release_screen(); do { poll_mouse(); if (mouse_b) { do { poll_mouse(); } while (mouse_b); c = KEY_ESC<<8; break; } if (keypressed()) c = readkey(); } while (!c); if ((c>>8) == KEY_LEFT) { if (x > -32) x--; c = 0; } else if ((c>>8) == KEY_RIGHT) { if (x < 32) x++; c = 0; } else if ((c>>8) == KEY_UP) { if (y > -32) y--; c = 0; } else if ((c>>8) == KEY_DOWN) { if (y < 32) y++; c = 0; } } while (!c); } void do_it(char *msg, int clip_flag, void (*func)(void)) { int x1, y1, x2, y2; set_clip_rect(screen, 0, 0, SCREEN_W-1, SCREEN_H-1); clear_to_color(screen, palette_color[0]); message(msg); if (clip_flag) { do { x1 = (AL_RAND() & 255) + 32; x2 = (AL_RAND() & 255) + 32; } while (x2-x1 < 30); do { y1 = (AL_RAND() & 127) + 40; y2 = (AL_RAND() & 127) + 40; } while (y2-y1 < 20); set_clip_rect(screen, xoff+x1, yoff+y1, xoff+x2, yoff+y2); } else set_clip_state(screen, FALSE); drawing_mode(mode, pattern[AL_RAND()%NUM_PATTERNS], 0, 0); (*func)(); solid_mode(); if (!clip_flag) set_clip_state(screen, TRUE); } void circler(BITMAP *b, int x, int y, int c) { circlefill(b, x, y, 4, palette_color[c]); } int floodfill_proc(void) { int ox, oy, nx, ny; int c; scare_mouse(); clear_to_color(screen, palette_color[0]); textout_centre_ex(screen, font, "floodfill test", SCREEN_W/2, 6, palette_color[15], palette_color[0]); textout_centre_ex(screen, font, "Press a mouse button to draw,", SCREEN_W/2, 64, palette_color[15], palette_color[0]); textout_centre_ex(screen, font, "a key 0-9 to floodfill,", SCREEN_W/2, 80, palette_color[15], palette_color[0]); textout_centre_ex(screen, font, "and ESC to finish", SCREEN_W/2, 96, palette_color[15], palette_color[0]); unscare_mouse(); ox = -1; oy = -1; do { poll_mouse(); c = mouse_b; if (c) { nx = mouse_x; ny = mouse_y; if ((ox >= 0) && (oy >= 0)) { scare_mouse(); if (c&1) { line(screen, ox, oy, nx, ny, palette_color[255]); } else { acquire_screen(); do_line(screen, ox, oy, nx, ny, 255, circler); release_screen(); } unscare_mouse(); } ox = nx; oy = ny; } else ox = oy = -1; if (keypressed()) { c = readkey() & 0xff; if ((c >= '0') && (c <= '9')) { scare_mouse(); drawing_mode(mode, pattern[AL_RAND()%NUM_PATTERNS], 0, 0); floodfill(screen, mouse_x, mouse_y, palette_color[c-'0']); solid_mode(); unscare_mouse(); } } } while (c != 27); return D_REDRAW; } void draw_spline(int points[8]) { int i, c1, c2; if (bitmap_color_depth(screen) == 8) { c1 = 255; c2 = 1; } else { c1 = makecol(255, 255, 255); c2 = makecol(0, 255, 255); } spline(screen, points, c1); for (i=0; i<4; i++) rect(screen, points[i*2]-6, points[i*2+1]-6, points[i*2]+5, points[i*2+1]+5, c2); } int spline_proc(void) { int points[8]; int nx, ny, ox, oy; int sel, os; int c; scare_mouse(); acquire_screen(); clear_to_color(screen, palette_color[0]); textout_centre_ex(screen, font, "spline test", SCREEN_W/2, 6, palette_color[15], palette_color[0]); textout_centre_ex(screen, font, "Drag boxes to change guide points,", SCREEN_W/2, 64, palette_color[15], palette_color[0]); textout_centre_ex(screen, font, "and press ESC to finish", SCREEN_W/2, 80, palette_color[15], palette_color[0]); for (c=0; c<4; c++) { points[c*2] = SCREEN_W/2 + c*64 - 96; points[c*2+1] = SCREEN_H/2 + ((c&1) ? 32 : -32); } xor_mode(TRUE); ox = mouse_x; oy = mouse_x; sel = -1; draw_spline(points); release_screen(); unscare_mouse(); for (;;) { poll_mouse(); nx = mouse_x; ny = mouse_y; os = sel; if (mouse_b) { if (sel < 0) { for (sel=3; sel>=0; sel--) { if ((nx >= points[sel*2]-6) && (nx < points[sel*2]+6) && (ny >= points[sel*2+1]-6) && (ny < points[sel*2+1]+6)) break; } } if ((sel >= 0) && ((ox != nx) || (oy != ny) || (os != sel))) { scare_mouse(); acquire_screen(); draw_spline(points); points[sel*2] = nx; points[sel*2+1] = ny; draw_spline(points); release_screen(); unscare_mouse(); } } else sel = -1; if (keypressed()) { c = readkey(); if ((c&0xFF) == 27) break; } ox = nx; oy = ny; } xor_mode(FALSE); return D_REDRAW; } int polygon_proc(void) { #define MAX_POINTS 256 int k = 0; int num_points = 0; int points[MAX_POINTS*2]; CHECK_TRANS_BLENDER(); scare_mouse(); clear_to_color(screen, palette_color[0]); textout_centre_ex(screen, font, "polygon test", SCREEN_W/2, 6, palette_color[15], palette_color[0]); textout_centre_ex(screen, font, "Press left mouse button to add a", SCREEN_W/2, 64, palette_color[15], palette_color[0]); textout_centre_ex(screen, font, "point, right mouse button to draw,", SCREEN_W/2, 80, palette_color[15], palette_color[0]); textout_centre_ex(screen, font, "and ESC to finish", SCREEN_W/2, 96, palette_color[15], palette_color[0]); unscare_mouse(); do { poll_mouse(); } while (mouse_b); do { poll_mouse(); if ((mouse_b & 1) && (num_points < MAX_POINTS)) { points[num_points*2] = mouse_x; points[num_points*2+1] = mouse_y; scare_mouse(); if (num_points > 0) line(screen, points[(num_points-1)*2], points[(num_points-1)*2+1], points[num_points*2], points[num_points*2+1], palette_color[255]); circlefill(screen, points[num_points*2], points[num_points*2+1], 2, palette_color[255]); num_points++; unscare_mouse(); do { poll_mouse(); } while (mouse_b); } if ((mouse_b & 2) && (num_points > 2)) { scare_mouse(); line(screen, points[(num_points-1)*2], points[(num_points-1)*2+1], points[0], points[1], palette_color[255]); drawing_mode(mode, pattern[AL_RAND()%NUM_PATTERNS], 0, 0); polygon(screen, num_points, points, palette_color[1]); solid_mode(); num_points = 0; unscare_mouse(); do { poll_mouse(); } while (mouse_b); } if (keypressed()) k = readkey() & 0xff; } while (k != 27); return D_REDRAW; } int putpixel_proc(void) { CHECK_TRANS_BLENDER(); scare_mouse(); test_it("putpixel test", putpix_test); do_it("timing putpixel", FALSE, putpix_demo); do_it("timing putpixel [clipped]", TRUE, putpix_demo); unscare_mouse(); return D_REDRAW; } int getpixel_proc(void) { getpix_demo(); return D_REDRAW; } int hline_proc(void) { CHECK_TRANS_BLENDER(); scare_mouse(); test_it("hline test", hline_test); do_it("timing hline", FALSE, hline_demo); do_it("timing hline [clipped]", TRUE, hline_demo); unscare_mouse(); return D_REDRAW; } int vline_proc(void) { CHECK_TRANS_BLENDER(); scare_mouse(); test_it("vline test", vline_test); do_it("timing vline", FALSE, vline_demo); do_it("timing vline [clipped]", TRUE, vline_demo); unscare_mouse(); return D_REDRAW; } int line_proc(void) { CHECK_TRANS_BLENDER(); scare_mouse(); test_it("line test", line_test); do_it("timing line", FALSE, line_demo); do_it("timing line [clipped]", TRUE, line_demo); unscare_mouse(); return D_REDRAW; } int rectfill_proc(void) { CHECK_TRANS_BLENDER(); scare_mouse(); test_it("rectfill test", rectfill_test); do_it("timing rectfill", FALSE, rectfill_demo); do_it("timing rectfill [clipped]", TRUE, rectfill_demo); unscare_mouse(); return D_REDRAW; } int triangle_proc(void) { CHECK_TRANS_BLENDER(); scare_mouse(); test_it("triangle test", triangle_test); do_it("timing triangle", FALSE, triangle_demo); do_it("timing triangle [clipped]", TRUE, triangle_demo); unscare_mouse(); return D_REDRAW; } int triangle3d_proc(void) { check_tables(); scare_mouse(); type3d = POLYTYPE_FLAT; do_it("timing triangle 3D [flat]", FALSE, triangle3d_demo); type3d = POLYTYPE_GCOL; do_it("timing triangle 3D [gcol]", FALSE, triangle3d_demo); type3d = POLYTYPE_GRGB; do_it("timing triangle 3D [grgb]", FALSE, triangle3d_demo); type3d = POLYTYPE_ATEX; do_it("timing triangle 3D [atex]", FALSE, triangle3d_demo); type3d = POLYTYPE_PTEX; do_it("timing triangle 3D [ptex]", FALSE, triangle3d_demo); type3d = POLYTYPE_ATEX_MASK; do_it("timing triangle 3D [atex mask]", FALSE, triangle3d_demo); type3d = POLYTYPE_PTEX_MASK; do_it("timing triangle 3D [ptex mask]", FALSE, triangle3d_demo); type3d = POLYTYPE_ATEX_LIT; do_it("timing triangle 3D [atex lit]", FALSE, triangle3d_demo); type3d = POLYTYPE_PTEX_LIT; do_it("timing triangle 3D [ptex lit]", FALSE, triangle3d_demo); type3d = POLYTYPE_ATEX_MASK_LIT; do_it("timing triangle 3D [atex mask lit]", FALSE, triangle3d_demo); type3d = POLYTYPE_PTEX_MASK_LIT; do_it("timing triangle 3D [ptex mask lit]", FALSE, triangle3d_demo); unscare_mouse(); return D_REDRAW; } int circle_proc(void) { CHECK_TRANS_BLENDER(); scare_mouse(); test_it("circle test", circle_test); do_it("timing circle", FALSE, circle_demo); do_it("timing circle [clipped]", TRUE, circle_demo); unscare_mouse(); return D_REDRAW; } int circlefill_proc(void) { CHECK_TRANS_BLENDER(); scare_mouse(); test_it("circlefill test", circlefill_test); do_it("timing circlefill", FALSE, circlefill_demo); do_it("timing circlefill [clipped]", TRUE, circlefill_demo); unscare_mouse(); return D_REDRAW; } int ellipse_proc(void) { CHECK_TRANS_BLENDER(); scare_mouse(); test_it("ellipse test", ellipse_test); do_it("timing ellipse", FALSE, ellipse_demo); do_it("timing ellipse [clipped]", TRUE, ellipse_demo); unscare_mouse(); return D_REDRAW; } int ellipsefill_proc(void) { CHECK_TRANS_BLENDER(); scare_mouse(); test_it("ellipsefill test", ellipsefill_test); do_it("timing ellipsefill", FALSE, ellipsefill_demo); do_it("timing ellipsefill [clipped]", TRUE, ellipsefill_demo); unscare_mouse(); return D_REDRAW; } int arc_proc(void) { CHECK_TRANS_BLENDER(); scare_mouse(); test_it("arc test", arc_test); do_it("timing arc", FALSE, arc_demo); do_it("timing arc [clipped]", TRUE, arc_demo); unscare_mouse(); return D_REDRAW; } int textout_proc(void) { scare_mouse(); test_it("textout test", textout_test); do_it("timing textout", FALSE, textout_demo); do_it("timing textout [clipped]", TRUE, textout_demo); unscare_mouse(); return D_REDRAW; } int blit_proc(void) { int c; scare_mouse(); acquire_screen(); set_clip_rect(screen, 0, 0, SCREEN_W-1, SCREEN_H-1); clear_to_color(screen, palette_color[0]); textout_centre_ex(screen, font, "Testing overlapping blits", SCREEN_W/2, 6, 15, palette_color[0]); for (c=0; c<30; c++) circle(screen, xoff+160, yoff+100, c, palette_color[c]); release_screen(); for (c=0; c<16; c++) { blit(screen, screen, xoff+112, yoff+52, xoff+113, yoff+52, 96, 96); rest(5); } for (c=0; c<32; c++) { blit(screen, screen, xoff+113, yoff+52, xoff+112, yoff+52, 96, 96); rest(5); } for (c=0; c<16; c++) { blit(screen, screen, xoff+112, yoff+52, xoff+113, yoff+52, 96, 96); rest(5); } for (c=0; c<16; c++) { blit(screen, screen, xoff+112, yoff+52, xoff+112, yoff+53, 96, 96); rest(5); } for (c=0; c<32; c++) { blit(screen, screen, xoff+112, yoff+53, xoff+112, yoff+52, 96, 96); rest(5); } for (c=0; c<16; c++) { blit(screen, screen, xoff+112, yoff+52, xoff+112, yoff+53, 96, 96); rest(5); } blit_from_screen = TRUE; do_it("timing blit screen->screen", FALSE, blit_demo); blit_align = TRUE; do_it("timing blit screen->screen (aligned)", FALSE, blit_demo); blit_align = FALSE; blit_from_screen = FALSE; do_it("timing blit memory->screen", FALSE, blit_demo); blit_align = TRUE; do_it("timing blit memory->screen (aligned)", FALSE, blit_demo); blit_align = FALSE; blit_mask = TRUE; if (gfx_capabilities & GFX_HW_VRAM_BLIT_MASKED) { blit_from_screen = TRUE; do_it("timing masked blit screen->screen", FALSE, blit_demo); blit_from_screen = FALSE; } do_it("timing masked blit memory->screen", FALSE, blit_demo); blit_mask = FALSE; do_it("timing blit [clipped]", TRUE, blit_demo); unscare_mouse(); return D_REDRAW; } int sprite_proc(void) { scare_mouse(); test_it("sprite test", sprite_test); do_it("timing draw_sprite", FALSE, sprite_demo); do_it("timing draw_sprite [clipped]", TRUE, sprite_demo); test_it("RLE sprite test", rle_sprite_test); do_it("timing draw_rle_sprite", FALSE, rle_sprite_demo); do_it("timing draw_rle_sprite [clipped]", TRUE, rle_sprite_demo); global_compiled_sprite = get_compiled_sprite(global_sprite, is_planar_bitmap(screen)); test_it("compiled sprite test", compiled_sprite_test); do_it("timing draw_compiled_sprite", FALSE, compiled_sprite_demo); destroy_compiled_sprite(global_compiled_sprite); unscare_mouse(); return D_REDRAW; } int xlu_sprite_proc(void) { check_tables(); scare_mouse(); test_it("translucent sprite test", xlu_sprite_test); do_it("timing draw_trans_sprite", FALSE, xlu_sprite_demo); do_it("timing draw_trans_sprite [clipped]", TRUE, xlu_sprite_demo); test_it("translucent RLE sprite test", rle_xlu_sprite_test); do_it("timing draw_trans_rle_sprite", FALSE, rle_xlu_sprite_demo); do_it("timing draw_trans_rle_sprite [clipped]", TRUE, rle_xlu_sprite_demo); unscare_mouse(); return D_REDRAW; } int lit_sprite_proc(void) { check_tables(); color_map = light_map; scare_mouse(); test_it("tinted sprite test", lit_sprite_test); do_it("timing draw_lit_sprite", FALSE, lit_sprite_demo); do_it("timing draw_lit_sprite [clipped]", TRUE, lit_sprite_demo); test_it("tinted RLE sprite test", rle_lit_sprite_test); do_it("timing draw_lit_rle_sprite", FALSE, rle_lit_sprite_demo); do_it("timing draw_lit_rle_sprite [clipped]", TRUE, rle_lit_sprite_demo); color_map = trans_map; unscare_mouse(); return D_REDRAW; } int rotate_proc(void) { scare_mouse(); test_it("Flipped sprite test", flipped_sprite_test); rotate_test(); unscare_mouse(); return D_REDRAW; } int polygon3d_proc(void) { #define NUM_POINTS 8+6 #define NUM_FACES 6 #define BUFFER_SIZE 128 #define NUM_MODES 15 /* a 3d x,y,z position */ typedef struct POINT { float x, y, z; } POINT; /* four vertices plus a normal make up a quad */ typedef struct QUAD { int v1, v2, v3, v4; int normal; int visible; } QUAD; /* vertices of the cube */ static POINT point[NUM_POINTS] = { /* regular vertices */ { -32, -32, -32 }, { -32, 32, -32 }, { 32, 32, -32 }, { 32, -32, -32 }, { -32, -32, 32 }, { -32, 32, 32 }, { 32, 32, 32 }, { 32, -32, 32 }, /* normals */ { -32, -32, -33 }, { -32, -32, 33 }, { -33, 32, -32 }, { 33, 32, -32 }, { 32, -33, 32 }, { 32, 33, 32 } }; /* output vertex list */ static V3D_f vtx[NUM_POINTS] = { /* x y z u v c */ { 0, 0, 0, 0, 0, 0x30 }, { 0, 0, 0, 0, 32, 0x99 }, { 0, 0, 0, 32, 32, 0x55 }, { 0, 0, 0, 32, 0, 0xDD }, { 0, 0, 0, 32, 0, 0x40 }, { 0, 0, 0, 32, 32, 0xBB }, { 0, 0, 0, 0, 32, 0x77 }, { 0, 0, 0, 0, 0, 0xF0 } }; /* six faces makes up a cube */ QUAD face[NUM_FACES] = { /* v1 v2 v3 v4 nrm v */ { 0, 3, 2, 1, 8, 0 }, { 4, 5, 6, 7, 9, 0 }, { 1, 5, 4, 0, 10, 0 }, { 2, 3, 7, 6, 11, 0 }, { 7, 3, 0, 4, 12, 0 }, { 6, 5, 1, 2, 13, 0 } }; /* descriptions of the render modes */ static char *mode_desc[NUM_MODES] = { "POLYTYPE_FLAT", "POLYTYPE_GCOL", "POLYTYPE_GRGB", "POLYTYPE_ATEX", "POLYTYPE_PTEX", "POLYTYPE_ATEX_MASK", "POLYTYPE_PTEX_MASK", "POLYTYPE_ATEX_LIT", "POLYTYPE_PTEX_LIT", "POLYTYPE_ATEX_MASK_LIT", "POLYTYPE_PTEX_MASK_LIT", "POLYTYPE_ATEX_TRANS", "POLYTYPE_PTEX_TRANS", "POLYTYPE_ATEX_MASK_TRANS", "POLYTYPE_PTEX_MASK_TRANS" }; int c; int key; int mode = POLYTYPE_FLAT; int tile = 1; float xr = -16; float yr = 24; float zr = 0; float dist = 128; float vx, vy, vz; float nx, ny, nz; int redraw_mode = TRUE; MATRIX_f transform, camera; V3D_f *vertex, *normal; BITMAP *buffer, *texture; buffer = create_bitmap(BUFFER_SIZE, BUFFER_SIZE); texture = create_bitmap(32, 32); check_tables(); blit(global_sprite, texture, 0, 0, 0, 0, 32, 32); rect(texture, 0, 0, 31, 31, palette_color[1]); scare_mouse(); acquire_screen(); clear_to_color(screen, palette_color[0]); textout_centre_ex(screen, font, "3d polygon test", SCREEN_W/2, 6, palette_color[15], palette_color[0]); textout_centre_ex(screen, font, "Use the arrow keys to rotate the", SCREEN_W/2, 64, palette_color[15], palette_color[0]); textout_centre_ex(screen, font, "cube, + and - to zoom, space to", SCREEN_W/2, 80, palette_color[15], palette_color[0]); textout_centre_ex(screen, font, "change drawing mode, enter to tile", SCREEN_W/2, 96, palette_color[15], palette_color[0]); textout_centre_ex(screen, font, "the texture, and ESC to finish", SCREEN_W/2, 112, palette_color[15], palette_color[0]); release_screen(); /* set projection parameters */ set_projection_viewport(0, 0, BUFFER_SIZE, BUFFER_SIZE); get_camera_matrix_f(&camera, 0, 0, 0, /* eye position */ 0, 0, 1, /* front vector */ 0, -1, 0, /* up vector */ 32, /* field of view */ 1); /* aspect ratio */ for (;;) { if (redraw_mode) { rectfill(screen, 0, 24, SCREEN_W, 32, palette_color[0]); textout_centre_ex(screen, font, mode_desc[mode], SCREEN_W/2, 24, palette_color[255], palette_color[0]); redraw_mode = FALSE; } clear_to_color(buffer, 8); /* build a transformation matrix */ get_transformation_matrix_f(&transform, 1, xr, yr, zr, 0, 0, dist); /* transform vertices into view space */ for (c=0; c