From: "Gary Smith" Newsgroups: comp.os.msdos.djgpp Subject: Screen / Memory Pointers. HELP !!! Date: Wed, 4 Feb 1998 18:16:13 -0000 Organization: Virgin Net Usenet Service Lines: 175 Message-ID: <6bab3s$el1$1@nclient3-gui.server.virgin.net> NNTP-Posting-Host: 194.168.58.178 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk The program below draws a rotating earth directly to the screen. I want to know how to get the program to draw to a memory bitmap so that I can transfer it to the screen using a BLIT. From the main procedure the variable 'video_buffer' is set to point to the screen memory. video_buffer = (char *)(__djgpp_conventional_base+0xA0000); In proceure 'draw_big_earth', tl is set to point to a location in the screen memory tl = video_buffer+(SCREEN_W-PIC_W)/2; The memory location pointed to by tl is then loaded with a value corresponding to a pixel in a bitmap. *tl++ = *(mtl + ofs); // display pixels to screen //------------------------------------------------------------------ // This program is a modified version of : // // Rotating Earth screen saver by David Lenhart 17 June 1997" // //------------------------------------------------------------------ #include #include #include #include #include "c:/djgpp/include/sys/nearptr.h" #include "allegro.h" #define MAP_W 640 /* disk image dimensions */ #define MAP_H 320 #define MAP_W2 (MAP_W / 2) #define MAP_H2 (MAP_H / 2) #define PIC_W 240 /* large earth dimensions */ #define PIC_H 200 #define PIC_W2 (PIC_W / 2) #define PIC_H2 (PIC_H / 2) #define MIN_DELAY 2 #define INTERRUPT_MSEC 10 int xmap[PIC_H2][PIC_W2]; int ymap[PIC_H2]; int picpos=MAP_W2; BITMAP *earth_map; BITMAP *earth_map1; BITMAP *page1; // This is my memory bitmap <<<<<<<<<<<<<<<<<<<<<< PALETTE earth_pal; char *video_buffer; void calculate_curvature(int *xmap, int *ymap, int w, int h) { int x, y, xx, yy; double q, hradius2, dist, disty, disty2, ang, xloc, yloc, angy; int w2, h2; w2 = w/2; h2 = h/2; for (y=0; y= 0.0 ) { if (fabs(dist) > 0.00001) { ang = PI - atan2( sqrt( q ), dist ); } else { ang = PI2; } xloc = ang / (2.0 * PI) ; xx = ((int)(xloc * MAP_W)) % MAP_W; angy = PI2 + atan2(disty , sqrt(1.0 - disty2)); yloc = angy / PI; yy = ((int)(yloc * MAP_H)) % MAP_H; *(xmap+(y*w2)+x) = xx; if (x == (w2-1)) ymap[y] = yy; } else { *(xmap+(y*w2)+x) = -1; } } } } void draw_big_earth(int picpos) { char *tl, *tr, *bl, *br; char *mtl, *mtr, *mbl, *mbr; int x, y, ofs, *p_xmapy; tl = video_buffer+(SCREEN_W-PIC_W)/2; tr = tl + (PIC_W - 1); bl = tl + SCREEN_W*(PIC_H - 1); br = bl + (PIC_W - 1); for(y=0; yline[ ymap[y] ] + picpos; mtr = mtl + (MAP_W2 - 1); mbl = earth_map->line[ (MAP_H-1) - ymap[y] ] + picpos; mbr = mbl + (MAP_W2 - 1); p_xmapy = &xmap[y][0]; for (x=0; x= MAP_W) { if (picpos < 0) picpos += MAP_W; if (picpos > MAP_W) picpos -= MAP_W; } } main(int argc, char *argv[]) { int n; allegro_init(); install_timer(); install_keyboard(); install_mouse(); i_love_bill = TRUE; video_buffer = (char *)(__djgpp_conventional_base+0xA0000); set_gfx_mode(GFX_VGA,320,200,0,0); earth_map=create_bitmap(MAP_W+MAP_W2,MAP_H); page1=create_bitmap(640,480); earth_map1 = load_bmp("earth.bmp",earth_pal); set_palette(earth_pal); blit(earth_map1, earth_map, 0, 0, 0, 0, MAP_W, MAP_H); blit(earth_map1, earth_map, 0, 0, MAP_W, 0, MAP_W2, MAP_H); destroy_bitmap(earth_map1); calculate_curvature((int *)xmap, (int *)ymap, PIC_W, PIC_H); for (n=0; n<400 ;n++) { animate_earth(-1); } exit(0); }