//video.c // 08/13/03 Josh Holtrop ModeInfoBlock video_mode; byte *vid_ptr24; word *vid_ptr16; dword *vid_ptr32; void video_init(ModeInfoBlock *mib) { video_mode = *mib; switch(video_mode.BitsPerPixel) { case 16: vid_ptr16 = (word *) video_mode.PhysBasePtr; break; case 24: vid_ptr24 = (byte *) video_mode.PhysBasePtr; break; case 32: vid_ptr32 = (dword *) video_mode.PhysBasePtr; } UINT tot = ((video_mode.XResolution) * (video_mode.YResolution)); int a; for (a = 0; a < tot; a++) { if (a < (tot / 4)) video_psetp(a, 0x00FF0000); else if (a < (tot / 2)) video_psetp(a, 0x0000FF00); else if (a < ((tot * 3) / 4)) video_psetp(a, 0x000000FF); else video_psetp(a, 0x00FFFFFF); } } void video_horiz(int y, int x1, int x2, dword color) { checkBoundsy(y); checkBoundsx(x1); checkBoundsx(x2); if (x1 > x2) { int tmp = x2; x2 = x1; x1 = tmp; } int pixel = y*video_mode.XResolution+x1; int a; for (a = 0; a <= (x2-x1); a++) { video_psetp(pixel, color); pixel++; } } void video_vert(int x, int y1, int y2, dword color) { checkBoundsx(x); checkBoundsy(y1); checkBoundsy(y2); if (y1 > y2) { int tmp = y2; y2 = y1; y1 = tmp; } int pixel = y1*video_mode.XResolution+x; int a; for (a = 0; a <= (y2-y1); a++) { video_psetp(pixel, color); pixel+=video_mode.XResolution; } } inline void video_pset(int x, int y, dword color) { video_psetp(y*video_mode.XResolution+x, color); } void video_psetp(int pixel, dword color) { switch(video_mode.BitsPerPixel) { case 16: vid_ptr16[pixel] = ((color&0xFF)>>3) | ((((color>>8)&0xFF)>>2)<<6) | ((((color>>16)&0xFF)>>3)<<11); //vid_ptr16[pixel] = ((color&0xFF)>>3) | ((((color>>8)&0xFF)>>3)<<5) | ((((color>>16)&0xFF)>>3)<<10); break; case 24: vid_ptr24[pixel] = (color>>16) & 0xFF; vid_ptr24[pixel+1] = (color>>8) & 0xFF; vid_ptr24[pixel+2] = color & 0xFF; break; case 32: vid_ptr32[pixel] = color; } }