//video.c // 08/13/03 Josh Holtrop 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; } dword 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); } video_rectf(VXR*3/11, 0, VXR*4/11, VYR-1, 0x00000088); //test rectangles, draws "HOS" video_rectf(VXR*7/11, 0, VXR*8/11, VYR-1, 0x00000088); video_rectf(VXR/11, 0, VXR*2/11, VYR*2/5, 0x00000088); video_rectf(VXR/11, VYR*3/5, VXR*2/11, VYR-1, 0x00000088); video_rectf(VXR*5/11, VYR/5, VXR*6/11, VYR*4/5, 0x00000088); video_rectf(VXR*9/11, VYR/5, VXR-1, VYR*2/5, 0x00000088); video_rectf(VXR*8/11, VYR*3/5, VXR*10/11, VYR*4/5, 0x00000088); video_vert(10, 10, 16, 0x00ffff00); //should be yellow 'H' video_horiz(13, 10, 14, 0x00ffff00); video_vert(14, 10, 16, 0x00ffff00); video_horiz(10, 17, 21, 0x00ffff00); video_vert(19, 10, 16, 0x00ffff00); video_horiz(16, 17, 21, 0x00ffff00); int b; for (a = 0; a < 256; a++) { for (b = 0; b < 256; b++) { video_pset(a+5, b+30, (a<<16)|(b<<8)); video_pset(a+270, b+30, (a<<8)|(b)); video_pset(a+535, b+30, (a<<16)|(b)); video_pset(a+5, b+290, (a<<16)|(b<<8)|0x000000ff); video_pset(a+270, b+290, (a<<8)|(b)|0x00ff0000); video_pset(a+535, b+290, (a<<16)|(b)|0x0000ff00); } } } 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; } } void video_rect(int x1, int y1, int x2, int y2, dword color) { checkBoundsx(x1); checkBoundsx(x2); checkBoundsy(y1); checkBoundsy(y2); if (x2 < x1) { int tmp = x2; x2 = x1; x1 = tmp; } if (y2 < y1) { int tmp = y2; y2 = y1; y1 = tmp; } video_horiz(y1, x1, x2, color); video_horiz(y2, x1, x2, color); video_vert(x1, y1, y2, color); video_vert(x2, y1, y2, color); } void video_rectf(int x1, int y1, int x2, int y2, dword color) { checkBoundsx(x1); checkBoundsx(x2); checkBoundsy(y1); checkBoundsy(y2); if (x2 < x1) { int tmp = x2; x2 = x1; x1 = tmp; } if (y2 < y1) { int tmp = y2; y2 = y1; y1 = tmp; } int a; for (a = 0; a <= (y2-y1); a++) video_horiz(y1+a, x1, x2, color); } 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)<<5) | ((((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*3] = color & 0xFF; vid_ptr24[pixel*3+1] = (color>>8) & 0xFF; vid_ptr24[pixel*3+2] = (color>>16) & 0xFF; break; case 32: vid_ptr32[pixel] = color; } }