![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-10-31 15:52 |
47,815 topics / 349,930 posts / today 0 new / 48,290 members |
| DOS开发编程 & 发展交流 (开发室) » 640*480*256 Color Display Program under DOS |
| Printable Version 1,680 / 8 |
| Floor1 dsysps | Posted 2007-09-26 12:14 |
| 初级用户 Posts 34 Credits 98 | |
|
/***************************************************************
File name: DOS256C.CPP Description: 256-color display program under DOS Author: *** Date: 2005/07/12 Description: Last modification date: 2006/08/30 ***************************************************************/ #include "Includes.h" /**************************************************************/ BYTE far *p; // Video memory pointer #define MAXX 640 // Horizontal resolution #define MAXY 480 // Vertical resolution static WORD spage = 0; // Current display page number BYTE vga_mode[64 * 2]; BYTE mode_bak[64 * 2]; /*************************************************************** Function name: SelectPage256(WORD page) Function: Display page switching function Input parameter: page: display page number to switch to Return value: None ***************************************************************/ static void SelectPage256(WORD page) { union REGS r; r.x.ax = 0x4f05; r.x.bx = 0; r.x.dx = page; spage = page; int86(0x10, &r, &r); } /*************************************************************** Function name: OpenCloseDisp(BYTE bClose) Function: Open or close display Input parameter: bClose=1: close display; bClose=0: open display Return value: None ***************************************************************/ void TestVga() { union REGS r; r.x.ax = 0x4f04; r.x.dx = 0x0001; r.x.cx = 0x0001; _ES = FP_SEG(vga_mode); r.x.bx = FP_OFF(vga_mode); int86(0x10, &r, &r); } void OpenCloseDisp(BYTE bClose) { BYTE far *pp; pp = mode_bak; if (bClose == 0) { pp = vga_mode; } union REGS r; r.x.ax = 0x4f04; r.x.dx = 0x0002; _ES = FP_SEG(pp); r.x.bx = FP_OFF(pp); r.x.cx = 0x0001; int86(0x10, &r, &r); } /*************************************************************** Function name: InitColPal(void) Function: Initialize display palette with color values from base\\ColPal.col file Input parameter: None Return value: None ***************************************************************/ void InitColPal(void) { FILE *fp; register r, g, b; if ((fp = fopen("c:\\base\\ColPal.col", "rb")) == NULL) return; for (int i = 0; i < 256; i++) { b = fgetc(fp); /* Get R, G, B components */ g = fgetc(fp); r = fgetc(fp); /* Get R, G, B components */ outportb(0x3c8, i); /* Palette register index */ outportb(0x3c9, r >> 2); /* Pass red component, 6-bit */ outportb(0x3c9, g >> 2); /* Pass blue component, 6-bit */ outportb(0x3c9, b >> 2); /* Pass green component, 6-bit */ fgetc(fp); } fclose(fp); for (i = 0; i < 64 * 2; i++) mode_bak[i] = 0x00; } /************************************************************** Function name: Init256Mode(void)//WORD mode) Function: Display mode initialization Input parameter: mode: display mode to set, fixed to 0X101 here Return value: None ***************************************************************/ void Init256Mode(void) // WORD mode) { p = (BYTE far *)0xa0000000L; union REGS r; r.x.ax = 0x4f02; r.x.bx = 0x101; // mode; //0x101:640*480 0x103:800*600 ...... int86(0x10, &r, &r); InitColPal(); } /*************************************************************** Function name: Exit256Mode(void) Function: Exit display mode and return to default display mode Input parameter: None Return value: None ***************************************************************/ void Exit256Mode(void) { union REGS r; r.x.ax = 0x003; int86(0x10, &r, &r); } /*************************************************************** Function name: SetPixel256(WORD x,WORD y,BYTE c) Function: Set display color of specified pixel point Input parameter: x: X coordinate position y: Y coordinate position c: display color Return value: None ***************************************************************/ void SetPixel256(WORD x, WORD y, BYTE c) { DWORD i; WORD tt; i = (DWORD)y * MAXX + x; tt = (WORD)(i >> 16); if (spage != tt) SelectPage256(tt); *(p + i) = c; } /*************************************************************** Function name: GetPixel256(WORD x,WORD y) Function: Get display color of specified pixel point Input parameter: x: X coordinate position y: Y coordinate position Return value: display color of specified pixel point ***************************************************************/ BYTE GetPixel256(WORD x, WORD y) { DWORD i; WORD tt; i = (DWORD)y * MAXX + x; tt = (WORD)(i >> 16); if (spage != tt) SelectPage256(tt); return (BYTE)*(p + i); } /*************************************************************** Function name: Draw256HL(int sx,int ex,int y,BYTE c) Function: Draw horizontal line at specified position Input parameter: sx: X coordinate start position ex: X coordinate end position y: Y coordinate position c: color of line drawing Return value: None ***************************************************************/ void Draw256HL(int sx, int ex, int y, BYTE c) { WORD tt; DWORD offs = (DWORD)y * MAXX + sx; for (int i = 0; i < ex - sx; i++) { tt = (WORD)(offs >> 16); if (spage != tt) { SelectPage256(tt); } *(p + offs) = c; offs++; } } /*************************************************************** Function name: Draw256VL(int sy,int ey,int x,BYTE c) Function: Draw vertical line at specified position Input parameter: sy: Y coordinate start position ey: Y coordinate start position x: X coordinate position c: color of line drawing Return value: None ***************************************************************/ void Draw256VL(int sy, int ey, int x, BYTE c) { WORD tt; DWORD offs = (long)sy * MAXX + x; for (int i = 0; i < ey - sy; i++) { tt = (WORD)(offs >> 16); if (spage != tt) { SelectPage256(tt); } *(p + offs) = c; offs += MAXX; } } /*************************************************************** Function name: Box256(int sx,int sy,int ex,int ey,BYTE c) Function: Draw rectangle at specified position Input parameter: sx: X coordinate of upper left corner sy: Y coordinate of upper left corner ex: X coordinate of lower right corner ey: Y coordinate of lower right corner c: color of line drawing Return value: None ***************************************************************/ void Box256(int sx, int sy, int ex, int ey, BYTE c) { Draw256HL(sx, ex, sy, c); Draw256HL(sx, ex, ey, c); Draw256VL(sy, ey, sx, c); Draw256VL(sy, ey, ex, c); } /*************************************************************** Function name: BoxFill256(int sx,int sy,int ex,int ey,BYTE c) Function: Draw solid rectangle at specified position Input parameter: sx: X coordinate of upper left corner sy: Y coordinate of upper left corner ex: X coordinate of lower right corner ey: Y coordinate of lower right corner c: fill color Return value: None ***************************************************************/ void BoxFill256(int sx, int sy, int ex, int ey, BYTE c) { for (int j = sy; j <= ey; j++) Draw256HL(sx, ex, j, c); } /*************************************************************** Function name: PlotCircle Function: Input parameter: sy: ey: x: color: Return value: None ***************************************************************/ /*static void PlotCircle(int x, int y, int xc, int yc, BYTE c) { for (int i = 0; i <= x; i++) { SetPixel256(xc - x + i, yc + y, c); SetPixel256(xc + x - i, yc + y, c); SetPixel256(xc - x + i, yc - y, c); SetPixel256(xc + x - i, yc - y, c); } }*/ /*************************************************************** Function name: Circle256(int xc,int yc,int r,BYTE c) Function: Draw circle Input parameter: xc: X coordinate of center yc: Y coordinate of center r: radius c: color of line drawing Return value: None ***************************************************************/ void Circle256(int xc, int yc, int r, BYTE c) { int x, y; static double sind[] = {0.1, 0.2, 0.3, 0.39, 0.48, 0.56, 0.64, 0.72, 0.78, 0.84, 0.89, 0.93, 0.96, 0.99, 1.00}; static double cosd[] = {1, 0.98, 0.95, 0.92, 0.88, 0.83, 0.76, 0.70, 0.62, 0.54, 0.45, 0.36, 0.27, 0.17, 0.07}; for (int j = 0; j < 15; j++) { x = sind[j] * r; y = cosd[j] * r; for (int i = 0; i <= x; i++) { SetPixel256(xc - x + i, yc + y, c); SetPixel256(xc + x - i, yc + y, c); SetPixel256(xc - x + i, yc - y, c); SetPixel256(xc + x - i, yc - y, c); } } } /*************************************************************** Function name: CircleFill256(int xc, int yc, int r, BYTE c) Function: Draw solid circle Input parameter: xc: X coordinate of center yc: Y coordinate of center r: radius (8) c: fill color Return value: None ***************************************************************/ void CircleFill256(int xc, int yc, /*int r, */ BYTE c) { for (int i = 0; i < 8; i++) { Circle256(xc, yc, i, c); } } /*************************************************************** Function name: Get256Blk(int sx,int sy,int ex,int ey,BYTE* pBuf) Function: Save screen display information of specified rectangular area to buffer Input parameter: sy: sy: ex: ey: color: Return value: None ***************************************************************/ /*void Get256Blk(int sx, int sy, int ex, int ey, BYTE* pBuf) { WORD tt; BYTE* ppBuf = pBuf; long off = (long)sy * (long)MAXX + (long)sx; for (int j = sy; j <= ey; j++) { long offs = off + (long)MAXX; off = offs; for (int i = 0; i < ex - sx; i++) { tt = (WORD)(offs >> 16); if (spage != tt) { SelectPage256(tt); } *ppBuf = *(p + offs); offs++; ppBuf++; } } } */ /*************************************************************** Function name: Set256Blk(int sx,int sy,int ex,int ey,BYTE* pBuf) Function: Restore screen display information of specified rectangular area from buffer Input parameter: sx: sy: ex: ey: pBuf: Return value: None ***************************************************************/ /*void Set256Blk(int sx, int sy, int ex, int ey, BYTE* pBuf) { WORD tt = 0; BYTE* ppBuf = pBuf; long off = (long)sy * (long)MAXX + (long)sx; for (int j = sy; j <= ey; j++) { long offs = off + (long)MAXX; off = offs; for (int i = 0; i < ex - sx; i++) { tt = (WORD)(offs >> 16); if (spage != tt) { SelectPage256(tt); } *(p + offs) = *ppBuf; offs++; ppBuf++; } } } */ /*************************************************************** Function name: Save256BlkToXms(int sx,int sy,int ex,int ey,unsigned long pos) Function: Save screen display information of specified rectangular area to extended memory Input parameter: sx: sy: ex: ey: pos: Return value: None ***************************************************************/ void Save256BlkToXms(int sx, int sy, int ex, int ey, unsigned long pos) { WORD tt; long off = (long)sy * (long)MAXX + (long)sx; long x = 0; char buf[640]; for (int j = sy; j <= ey; j++) { long offs = off + (long)MAXX; off = offs; for (int i = 0; i < ex - sx; i++) { tt = (WORD)(offs >> 16); if (spage != tt) { SelectPage256(tt); } buf[i] = *(p + offs); offs++; } x += (ex - sx); xms_write(x + pos - (ex - sx), buf, ex - sx); } } /*************************************************************** Function name: Load256BlkFrXms(int sx,int sy,int ex,int ey,unsigned long pos) Function: Restore screen display information of specified rectangular area from extended memory Input parameter: sx: sy: ex: ey: pos: Return value: None ***************************************************************/ void Load256BlkFrXms(int sx, int sy, int ex, int ey, unsigned long pos) { WORD tt; long off = (long)sy * (long)MAXX + (long)sx; long x = 0; for (int j = sy; j <= ey; j++) { char* pch = (char*)xms_read(x + pos, ex - sx); x += (ex - sx); DWORD offs = off + (long)MAXX; off = offs; for (int i = 0; i < ex - sx; i++) { tt = (WORD)(offs >> 16); if (spage != tt) { SelectPage256(tt); } *(p + offs) = *pch; pch++; offs++; } } } /*************************************************************** Function name: Line256(int x1, int y1, int x2, int y2, BYTE c) Function: Draw line Input parameter: x1: y1: x2: y2: c: Return value: None ***************************************************************/ void Line256(int x1, int y1, int x2, int y2, BYTE c) { int dx = x2 - x1, dy = y2 - y1, sx, sy, che; if (dx < 0) { dx = -dx; /* Draw line from right to left */ sx = -1; } else sx = 1; /* Draw line from left to right */ if (dy < 0) { dy = -dy; /* Draw line from bottom to top */ sy = -1; } else sy = 1; /* Draw line from top to bottom */ if (dx > dy) /* x changes faster than y */ { che = dx >> 1; while (x1 != x2) { SetPixel256(x1, y1, c); x1 += sx; che += dy; if (che > dx) { y1 += sy; che -= dx; } } } else /* y changes faster than x */ { che = dy >> 1; while (y1 != y2) { SetPixel256(x1, y1, c); y1 += sy; che += dx; if (che > dy) { x1 += sx; che -= dy; } } } SetPixel256(x2, y2, c); } /*************************************************************** Function name: ShowBmp256 Function: Display 256-color bitmap file at specified position Input parameter: FileName: x: y: Return value: None ***************************************************************/ /*void ShowBmp256(char* FileName, int x, int y) { char buffer[640]; BYTE page_new = 0; register int i, j, k; DWORD position, opos; DWORD width, length; FILE *fp; if ((fp = fopen(FileName, "rb")) == NULL) return; fseek(fp, 28, SEEK_SET); fread(&i, 2, 1, fp); if (i != 8) // Check if it is a 256-color bitmap { fclose(fp); return; } fseek(fp, 18, SEEK_SET); // Width of bitmap in pixels fread(&width, 4, 1, fp); fread(&length, 4, 1, fp); // Height of bitmap in pixels fseek(fp, 1078, SEEK_SET); // Position of display point k = int((width % 4) ? (4 - width % 4) : 0); // Width correction value opos = (length + y) * 640l + x; for (j = (int)length + y; j > y; j--) { position = opos - 640l; opos = position; fread(buffer, (int)width, 1, fp); for (i = 0; i < width; i++) { position++; // Calculate video memory position of display point page_new = (BYTE)(position >> 16); // Calculate display page if (page_new != spage) // Change page when display page is different { SelectPage256(page_new); } *(p + position) = buffer[i]; // Write to video memory position } fseek(fp, k, SEEK_CUR); // Correct width after each line drawing } fclose(fp); }*/ /*************************************************************** Function name: Show256BmpFrXms(int x,int y,unsigned long pos) Function: Display bitmap from extended memory Input parameter: x: y: pos: Return value: None ***************************************************************/ void Show256BmpFrXms(int x, int y, unsigned long pos) { WORD tt; long off = (long)y * (long)MAXX + (long)x; DWORD *pDw = (DWORD*)xms_read(pos, 8); DWORD width = *pDw; pDw++; DWORD length = *pDw; DWORD xmsPos = 8; long offs = off; for (int j = 0; j < length; j++) { char* pch = (char*)xms_read(xmsPos + pos, width); xmsPos += width; off = offs; for (int i = 0; i < width; i++) { tt = (WORD)(offs >> 16); if (spage != tt) { SelectPage256(tt); } *(p + offs) = *pch; pch++; offs++; } offs = off + (long)MAXX; } } /*End of file**************************************************************/ |
|
| Floor2 BA_WANG_MAO | Posted 2007-09-27 09:04 |
| 初级用户 Posts 13 Credits 147 | |
| Floor3 tangtai | Posted 2007-09-27 13:34 |
| 等待验证用户 Posts 314 Credits 640 | |
|
There is no download link?
|
|
| Floor4 store88 | Posted 2007-09-28 22:51 |
| 中级用户 Posts 125 Credits 416 | |
|
Can this principle achieve 1024*768?
|
|
| Floor5 dsysps | Posted 2007-09-29 14:05 |
| 初级用户 Posts 34 Credits 98 | |
|
Sure, but there are quite a lot of places that need to be changed.
|
|
| Floor6 jxfengzi | Posted 2007-10-17 17:24 |
| 新手上路 Posts 4 Credits 8 | |
|
There is always something wrong with what I wrote. I'll try yours another day.
|
|
| Floor7 wangxy200696 | Posted 2007-10-19 13:55 |
| 初级用户 Posts 22 Credits 52 | |
|
Using VBE? Is there any example of successfully adjusting the dot clock? Preferably in assembly language, and C is also acceptable
|
|
| Floor8 liutong2000 | Posted 2007-12-15 11:03 |
| 新手上路 Posts 2 Credits 4 | |
| Floor9 AlexZhang | Posted 2007-12-16 14:35 |
| 系统支持 Posts 440 Credits 1,028 | |
|
Not bad, add points to support. But... c to be honest I can't understand... _-_-P
|
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |