Index: Makefile =================================================================== RCS file: /src/CVS/src/lib/libvgl/Makefile,v retrieving revision 1.2 diff -c -r1.2 Makefile *** Makefile 1997/10/01 20:53:37 1.2 --- Makefile 1999/08/23 11:18:04 *************** *** 1,5 **** LIB= vgl ! SHLIB_MAJOR= 1 SHLIB_MINOR= 0 CFLAGS+=-Wall -I${.CURDIR} SRCS= main.c simple.c bitmap.c text.c mouse.c keyboard.c --- 1,5 ---- LIB= vgl ! SHLIB_MAJOR= 2 SHLIB_MINOR= 0 CFLAGS+=-Wall -I${.CURDIR} SRCS= main.c simple.c bitmap.c text.c mouse.c keyboard.c Index: bitmap.c =================================================================== RCS file: /src/CVS/src/lib/libvgl/bitmap.c,v retrieving revision 1.2 diff -c -r1.2 bitmap.c *** bitmap.c 1999/08/22 03:31:13 1.2 --- bitmap.c 1999/08/28 08:36:09 *************** *** 30,38 **** #include #include #include "vgl.h" ! static byte VGLPlane[4][128]; static byte mask[8] = {0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01}; static int color2bit[16] = {0x00000000, 0x00000001, 0x00000100, 0x00000101, 0x00010000, 0x00010001, 0x00010100, 0x00010101, --- 30,40 ---- #include #include + #include #include "vgl.h" ! #define min(x, y) (((x) < (y)) ? (x) : (y)) ! static byte mask[8] = {0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01}; static int color2bit[16] = {0x00000000, 0x00000001, 0x00000100, 0x00000101, 0x00010000, 0x00010001, 0x00010100, 0x00010101, *************** *** 43,62 **** WriteVerticalLine(VGLBitmap *dst, int x, int y, int width, byte *line) { int i, pos, last, planepos, start_offset, end_offset, offset; unsigned int word = 0; byte *address; switch (dst->Type) { case VIDBUF4: ! address = dst->Bitmap + (dst->Xsize/8 * y) + x/8; start_offset = (x & 0x07); end_offset = (x + width) & 0x07; ! offset = start_offset; pos = 0; planepos = 0; while (pos < width) { word = 0; - last = pos + 8 - offset; while (pos < last && pos < width) word = (word<<1) | color2bit[line[pos++]&0x0f]; VGLPlane[0][planepos] = word; --- 45,72 ---- WriteVerticalLine(VGLBitmap *dst, int x, int y, int width, byte *line) { int i, pos, last, planepos, start_offset, end_offset, offset; + int len; unsigned int word = 0; byte *address; + byte *VGLPlane[4]; switch (dst->Type) { case VIDBUF4: ! case VIDBUF4S: start_offset = (x & 0x07); end_offset = (x + width) & 0x07; ! i = (width + start_offset) / 8; ! if (end_offset) ! i++; ! VGLPlane[0] = VGLBuf; ! VGLPlane[1] = VGLPlane[0] + i; ! VGLPlane[2] = VGLPlane[1] + i; ! VGLPlane[3] = VGLPlane[2] + i; pos = 0; planepos = 0; + last = 8 - start_offset; while (pos < width) { word = 0; while (pos < last && pos < width) word = (word<<1) | color2bit[line[pos++]&0x0f]; VGLPlane[0][planepos] = word; *************** *** 64,70 **** VGLPlane[2][planepos] = word>>16; VGLPlane[3][planepos] = word>>24; planepos++; ! offset = 0; } planepos--; if (end_offset) { --- 74,80 ---- VGLPlane[2][planepos] = word>>16; VGLPlane[3][planepos] = word>>24; planepos++; ! last += 8; } planepos--; if (end_offset) { *************** *** 76,95 **** } if (start_offset || end_offset) width+=8; for (i=0; i<4; i++) { outb(0x3c4, 0x02); outb(0x3c5, 0x01<Bitmap + (dst->Xsize/2 * y) + x/4; for (i=0; i<4; i++) { outb(0x3c4, 0x02); outb(0x3c5, 0x01 << ((x + i)%4)); --- 86,128 ---- } if (start_offset || end_offset) width+=8; + width /= 8; + outb(0x3ce, 0x01); outb(0x3cf, 0x00); /* set/reset enable */ + outb(0x3ce, 0x08); outb(0x3cf, 0xff); /* bit mask */ for (i=0; i<4; i++) { outb(0x3c4, 0x02); outb(0x3c5, 0x01<Type == VIDBUF4) { ! if (end_offset) ! VGLPlane[i][planepos] |= dst->Bitmap[pos+planepos] & mask[end_offset]; ! if (start_offset) ! VGLPlane[i][0] |= dst->Bitmap[pos] & ~mask[start_offset]; ! bcopy(&VGLPlane[i][0], dst->Bitmap + pos, width); ! } else { /* VIDBUF4S */ ! if (end_offset) { ! offset = VGLSetSegment(pos + planepos); ! VGLPlane[i][planepos] |= dst->Bitmap[offset] & mask[end_offset]; ! } ! offset = VGLSetSegment(pos); ! if (start_offset) ! VGLPlane[i][0] |= dst->Bitmap[offset] & ~mask[start_offset]; ! for (last = width; ; ) { ! len = min(VGLAdpInfo.va_window_size - offset, last); ! bcopy(&VGLPlane[i][width - last], dst->Bitmap + offset, len); ! pos += len; ! last -= len; ! if (last <= 0) ! break; ! offset = VGLSetSegment(pos); ! } ! } } break; case VIDBUF8X: ! address = dst->Bitmap + VGLAdpInfo.va_line_width * y + x/4; for (i=0; i<4; i++) { outb(0x3c4, 0x02); outb(0x3c5, 0x01 << ((x + i)%4)); *************** *** 99,107 **** ++address; } break; case VIDBUF8: case MEMBUF: ! address = dst->Bitmap + (dst->Xsize * y) + x; bcopy(line, address, width); break; --- 132,151 ---- ++address; } break; + case VIDBUF8S: + pos = dst->VXsize * y + x; + while (width > 0) { + offset = VGLSetSegment(pos); + i = min(VGLAdpInfo.va_window_size - offset, width); + bcopy(line, dst->Bitmap + offset, i); + line += i; + pos += i; + width -= i; + } + break; case VIDBUF8: case MEMBUF: ! address = dst->Bitmap + dst->VXsize * y + x; bcopy(line, address, width); break; *************** *** 113,152 **** ReadVerticalLine(VGLBitmap *src, int x, int y, int width, byte *line) { int i, bit, pos, count, planepos, start_offset, end_offset, offset; byte *address; switch (src->Type) { case VIDBUF4: ! address = src->Bitmap + (src->Xsize/8 * y) + x/8; start_offset = (x & 0x07); end_offset = (x + width) & 0x07; ! offset = start_offset; ! if (start_offset) ! count = (width - (8 - start_offset)) / 8 + 1; ! else ! count = width / 8; if (end_offset) ! count++; for (i=0; i<4; i++) { outb(0x3ce, 0x04); outb(0x3cf, i); bcopy(address, &VGLPlane[i][0], count); } pos = 0; planepos = 0; while (pos < width) { ! for (bit = (7-offset); bit >= 0 && pos < width; bit--, pos++) { line[pos] = (VGLPlane[0][planepos] & (1<Bitmap + (src->Xsize/2 * y) + x/4; for (i=0; i<4; i++) { outb(0x3ce, 0x04); outb(0x3cf, (x + i)%4); --- 157,223 ---- ReadVerticalLine(VGLBitmap *src, int x, int y, int width, byte *line) { int i, bit, pos, count, planepos, start_offset, end_offset, offset; + int width2, len; byte *address; + byte *VGLPlane[4]; switch (src->Type) { + case VIDBUF4S: + start_offset = (x & 0x07); + end_offset = (x + width) & 0x07; + count = (width + start_offset) / 8; + if (end_offset) + count++; + VGLPlane[0] = VGLBuf; + VGLPlane[1] = VGLPlane[0] + count; + VGLPlane[2] = VGLPlane[1] + count; + VGLPlane[3] = VGLPlane[2] + count; + for (i=0; i<4; i++) { + outb(0x3ce, 0x04); + outb(0x3cf, i); + pos = VGLAdpInfo.va_line_width*y + x/8; + for (width2 = count; width2 > 0; ) { + offset = VGLSetSegment(pos); + len = min(VGLAdpInfo.va_window_size - offset, width2); + bcopy(src->Bitmap + offset, &VGLPlane[i][count - width2], len); + pos += len; + width2 -= len; + } + } + goto read_planar; case VIDBUF4: ! address = src->Bitmap + VGLAdpInfo.va_line_width * y + x/8; start_offset = (x & 0x07); end_offset = (x + width) & 0x07; ! count = (width + start_offset) / 8; if (end_offset) ! count++; ! VGLPlane[0] = VGLBuf; ! VGLPlane[1] = VGLPlane[0] + count; ! VGLPlane[2] = VGLPlane[1] + count; ! VGLPlane[3] = VGLPlane[2] + count; for (i=0; i<4; i++) { outb(0x3ce, 0x04); outb(0x3cf, i); bcopy(address, &VGLPlane[i][0], count); } + read_planar: pos = 0; planepos = 0; + bit = 7 - start_offset; while (pos < width) { ! for (; bit >= 0 && pos < width; bit--, pos++) { line[pos] = (VGLPlane[0][planepos] & (1<Bitmap + VGLAdpInfo.va_line_width * y + x/4; for (i=0; i<4; i++) { outb(0x3ce, 0x04); outb(0x3cf, (x + i)%4); *************** *** 156,164 **** ++address; } break; case VIDBUF8: case MEMBUF: ! address = src->Bitmap + (src->Xsize * y) + x; bcopy(address, line, width); break; default: --- 227,246 ---- ++address; } break; + case VIDBUF8S: + pos = src->VXsize * y + x; + while (width > 0) { + offset = VGLSetSegment(pos); + i = min(VGLAdpInfo.va_window_size - offset, width); + bcopy(src->Bitmap + offset, line, i); + line += i; + pos += i; + width -= i; + } + break; case VIDBUF8: case MEMBUF: ! address = src->Bitmap + src->VXsize * y + x; bcopy(address, line, width); break; default: *************** *** 171,177 **** { int srcline, dstline; ! if (srcx>src->Xsize||srcy>src->Ysize||dstx>dst->Xsize||dsty>dst->Ysize) return -1; if (srcx < 0) { width=width+srcx; dstx-=srcx; srcx=0; --- 253,260 ---- { int srcline, dstline; ! if (srcx>src->VXsize || srcy>src->VYsize ! || dstx>dst->VXsize || dsty>dst->VYsize) return -1; if (srcx < 0) { width=width+srcx; dstx-=srcx; srcx=0; *************** *** 185,214 **** if (dsty < 0) { hight=hight+dsty; srcy-=dsty; dsty=0; } ! if (srcx+width > src->Xsize) ! width=src->Xsize-srcx; ! if (srcy+hight > src->Ysize) ! hight=src->Ysize-srcy; ! if (dstx+width > dst->Xsize) ! width=dst->Xsize-dstx; ! if (dsty+hight > dst->Ysize) ! hight=dst->Ysize-dsty; if (width < 0 || hight < 0) return -1; if (src->Type == MEMBUF) { for (srcline=srcy, dstline=dsty; srclineBitmap+(srcline*src->Xsize)+srcx)); } } else if (dst->Type == MEMBUF) { for (srcline=srcy, dstline=dsty; srclineBitmap+(dstline*dst->Xsize)+dstx)); } } else { ! byte buffer[1024]; for (srcline=srcy, dstline=dsty; srcline src->VXsize) ! width=src->VXsize-srcx; ! if (srcy+hight > src->VYsize) ! hight=src->VYsize-srcy; ! if (dstx+width > dst->VXsize) ! width=dst->VXsize-dstx; ! if (dsty+hight > dst->VYsize) ! hight=dst->VYsize-dsty; if (width < 0 || hight < 0) return -1; if (src->Type == MEMBUF) { for (srcline=srcy, dstline=dsty; srclineBitmap+(srcline*src->VXsize)+srcx)); } } else if (dst->Type == MEMBUF) { for (srcline=srcy, dstline=dsty; srclineBitmap+(dstline*dst->VXsize)+dstx)); } } else { ! byte buffer[2048]; /* XXX */ ! for (srcline=srcy, dstline=dsty; srclineType = type; + object->Xsize = xsize; + object->Ysize = ysize; + object->VXsize = xsize; + object->VYsize = ysize; + object->Xorigin = 0; + object->Yorigin = 0; + object->Bitmap = bits; + return object; + } + + void + VGLBitmapDestroy(VGLBitmap *object) + { + if (object->Bitmap) + free(object->Bitmap); + free(object); + } + + int + VGLBitmapAllocateBits(VGLBitmap *object) + { + object->Bitmap = (byte *)malloc(object->VXsize*object->VYsize); + if (object->Bitmap == NULL) + return -1; + return 0; + } Index: main.c =================================================================== RCS file: /src/CVS/src/lib/libvgl/main.c,v retrieving revision 1.3 diff -c -r1.3 main.c *** main.c 1999/08/22 03:31:13 1.3 --- main.c 1999/08/28 08:35:47 *************** *** 37,50 **** #include #include "vgl.h" VGLBitmap *VGLDisplay; static int VGLMode; static int VGLOldMode; ! static byte *VGLBuf; ! static byte *VGLMem; static int VGLSwitchPending; static int VGLOnDisplay; static int VGLInitDone = 0; void --- 37,57 ---- #include #include "vgl.h" + #define min(x, y) (((x) < (y)) ? (x) : (y)) + #define max(x, y) (((x) > (y)) ? (x) : (y)) + VGLBitmap *VGLDisplay; + video_info_t VGLModeInfo; + video_adapter_info_t VGLAdpInfo; + byte *VGLBuf; static int VGLMode; static int VGLOldMode; ! static size_t VGLBufSize; ! static byte *VGLMem = MAP_FAILED; static int VGLSwitchPending; static int VGLOnDisplay; + static unsigned int VGLCurWindow; static int VGLInitDone = 0; void *************** *** 54,66 **** if (!VGLInitDone) return; ! /* ! while (!VGLOnDisplay) pause(); ! VGLCheckSwitch();; ! */ ! outb(0x3c4, 0x02); ! outb(0x3c5, 0x0f); ! bzero(VGLMem, 64*1024); if (VGLOldMode >= M_VESA_BASE) { /* ugly, but necessary */ ioctl(0, _IO('V', VGLOldMode - M_VESA_BASE), 0); --- 61,77 ---- if (!VGLInitDone) return; ! VGLInitDone = 0; ! ! /* stop vty switching for now */ ! signal(SIGUSR1, SIG_IGN); ! ! /* clear the screen only if we are in the foreground */ ! if (VGLMem != MAP_FAILED) { ! VGLClear(VGLDisplay, 0); ! munmap(VGLMem, VGLAdpInfo.va_window_size); ! } ! if (VGLOldMode >= M_VESA_BASE) { /* ugly, but necessary */ ioctl(0, _IO('V', VGLOldMode - M_VESA_BASE), 0); *************** *** 78,85 **** ioctl(0, KDSETMODE, KD_TEXT); smode.mode = VT_AUTO; ioctl(0, VT_SETMODE, &smode); ! free(VGLBuf); free(VGLDisplay); VGLKeyboardEnd(); } --- 89,99 ---- ioctl(0, KDSETMODE, KD_TEXT); smode.mode = VT_AUTO; ioctl(0, VT_SETMODE, &smode); ! if (VGLBuf) ! free(VGLBuf); ! VGLBuf = NULL; free(VGLDisplay); + VGLDisplay = NULL; VGLKeyboardEnd(); } *************** *** 105,143 **** VGLInit(int mode) { struct vt_mode smode; ! struct winsize winsz; ! int error; signal(SIGUSR1, VGLSwitch); signal(SIGINT, VGLAbort); signal(SIGSEGV, VGLAbort); signal(SIGBUS, VGLAbort); VGLOnDisplay = 1; VGLSwitchPending = 0; ! ioctl(0, CONS_GET, &VGLOldMode); ! VGLMem = (byte*)mmap(0, 0x10000, PROT_READ|PROT_WRITE, MAP_FILE, ! open("/dev/mem", O_RDWR), 0xA0000); ! if (VGLMem <= (byte*)0) ! return 1; ! ! VGLBuf = (byte*)malloc(256*1024); ! if (VGLBuf == NULL) ! return 1; ! VGLDisplay = (VGLBitmap*) malloc(sizeof(VGLBitmap)); ! if (VGLDisplay == NULL) { ! free(VGLBuf); ! return 1; } ! switch (mode) { case SW_BG640x480: case SW_CG640x480: VGLDisplay->Type = VIDBUF4; break; case SW_VGA_CG320: VGLDisplay->Type = VIDBUF8; break; case SW_VGA_MODEX: --- 119,203 ---- VGLInit(int mode) { struct vt_mode smode; ! int adptype; ! ! if (VGLInitDone) ! return -1; signal(SIGUSR1, VGLSwitch); signal(SIGINT, VGLAbort); + signal(SIGTERM, VGLAbort); signal(SIGSEGV, VGLAbort); signal(SIGBUS, VGLAbort); VGLOnDisplay = 1; VGLSwitchPending = 0; ! if (ioctl(0, CONS_GET, &VGLOldMode) || ioctl(0, CONS_CURRENT, &adptype)) ! return -1; ! if (IOCGROUP(mode) == 'V') /* XXX: this is ugly */ ! VGLModeInfo.vi_mode = (mode & 0x0ff) + M_VESA_BASE; ! else ! VGLModeInfo.vi_mode = mode & 0x0ff; ! if (ioctl(0, CONS_MODEINFO, &VGLModeInfo)) /* FBIO_MODEINFO */ ! return -1; ! ! VGLDisplay = (VGLBitmap *)malloc(sizeof(VGLBitmap)); ! if (VGLDisplay == NULL) ! return -2; ! ! if (ioctl(0, KDENABIO, 0)) { ! free(VGLDisplay); ! return -3; ! } ! VGLInitDone = 1; ! #if 0 /* #ifdef V_INFO_MM_OTHER */ ! /* ! * vi_mem_model specifies the memory model of the current video mode ! * in -CURRENT. ! */ ! switch (VGLModeInfo.vi_mem_model) { ! case V_INFO_MM_PLANAR: ! /* we can handle EGA/VGA planner modes only */ ! if (VGLModeInfo.vi_depth != 4 || VGLModeInfo.vi_planes != 4 ! || (adptype != KD_EGA && adptype != KD_VGA)) { ! VGLEnd(); ! return -4; ! } ! VGLDisplay->Type = VIDBUF4; ! break; ! case V_INFO_MM_PACKED: ! /* we can do only 256 color packed modes */ ! if (VGLModeInfo.vi_depth != 8) { ! VGLEnd(); ! return -4; ! } ! VGLDisplay->Type = VIDBUF8; ! break; ! case V_INFO_MM_VGAX: ! VGLDisplay->Type = VIDBUF8X; ! break; ! default: ! VGLEnd(); ! return -4; } ! #else /* V_INFO_MM_OTHER */ switch (mode) { case SW_BG640x480: case SW_CG640x480: + case SW_VESA_800x600: case SW_VESA_1024x768: + case SW_VESA_1280x1024: + if (adptype != KD_EGA && adptype != KD_VGA) { + VGLEnd(); + return -4; + } VGLDisplay->Type = VIDBUF4; break; case SW_VGA_CG320: + case SW_VESA_CG640x400: case SW_VESA_CG640x480: + case SW_VESA_CG800x600: case SW_VESA_CG1024x768: + case SW_VESA_CG1280x1024: VGLDisplay->Type = VIDBUF8; break; case SW_VGA_MODEX: *************** *** 145,198 **** break; default: VGLEnd(); ! return 1; } - if ((error = ioctl(0, KDENABIO, 0))) - return error; - ioctl(0, VT_WAITACTIVE, 0); ioctl(0, KDSETMODE, KD_GRAPHICS); ! if ((error = ioctl(0, mode, 0))) { ! ioctl(0, KDSETMODE, KD_TEXT); ! ioctl(0, KDDISABIO, 0); ! return error; } ! VGLMode = mode; ! outb(0x3c4, 0x02); ! outb(0x3c5, 0x0f); ! bzero(VGLMem, 64*1024); ! if (ioctl(0, TIOCGWINSZ, &winsz)) { ! VGLEnd(); ! return 1; } VGLDisplay->Bitmap = VGLMem; ! VGLDisplay->Xsize = winsz.ws_xpixel; ! VGLDisplay->Ysize = winsz.ws_ypixel; VGLSavePalette(); smode.mode = VT_PROCESS; smode.waitv = 0; smode.relsig = SIGUSR1; smode.acqsig = SIGUSR1; smode.frsig = SIGINT; ! if (ioctl(0, VT_SETMODE, &smode) == -1) { VGLEnd(); ! return 1; } VGLTextSetFontFile((byte*)0); ! VGLInitDone = 1; return 0; } void VGLCheckSwitch() { ! if (VGLSwitchPending) { int i; VGLSwitchPending = 0; --- 205,305 ---- break; default: VGLEnd(); ! return -4; } + #endif /* V_INFO_MM_OTHER */ ioctl(0, VT_WAITACTIVE, 0); ioctl(0, KDSETMODE, KD_GRAPHICS); ! if (ioctl(0, mode, 0)) { ! VGLEnd(); ! return -5; ! } ! if (ioctl(0, CONS_ADPINFO, &VGLAdpInfo)) { /* FBIO_ADPINFO */ ! VGLEnd(); ! return -6; } ! /* ! * Calculate the shadow screen buffer size. In -CURRENT, va_buffer_size ! * always holds the entire frame buffer size, wheather it's in the linear ! * mode or windowed mode. ! * VGLBufSize = VGLAdpInfo.va_buffer_size; ! * In -STABLE, va_buffer_size holds the frame buffer size, only if ! * the linear frame buffer mode is supported. Otherwise the field is zero. ! * We shall calculate the minimal size in this case: ! * VGLAdpInfo.va_line_width*VGLModeInfo.vi_height*VGLModeInfo.vi_planes ! * or ! * VGLAdpInfo.va_window_size*VGLModeInfo.vi_planes; ! * Use whichever is larger. ! */ ! if (VGLAdpInfo.va_buffer_size != 0) ! VGLBufSize = VGLAdpInfo.va_buffer_size; ! else ! VGLBufSize = max(VGLAdpInfo.va_line_width*VGLModeInfo.vi_height, ! VGLAdpInfo.va_window_size)*VGLModeInfo.vi_planes; ! VGLBuf = malloc(VGLBufSize); ! if (VGLBuf == NULL) { ! VGLEnd(); ! return -7; ! } ! fprintf(stderr, "VGLBufSize:0x%x\n", VGLBufSize); ! /* see if we are in the windowed buffer mode or in the linear buffer mode */ ! if (VGLBufSize/VGLModeInfo.vi_planes > VGLAdpInfo.va_window_size) { ! if (VGLDisplay->Type == VIDBUF4) ! VGLDisplay->Type = VIDBUF4S; ! else if (VGLDisplay->Type == VIDBUF8) ! VGLDisplay->Type = VIDBUF8S; } + VGLMode = mode; + VGLCurWindow = 0; + + VGLDisplay->Xsize = VGLModeInfo.vi_width; + VGLDisplay->Ysize = VGLModeInfo.vi_height; + VGLDisplay->VXsize = VGLAdpInfo.va_line_width + *8/(VGLModeInfo.vi_depth/VGLModeInfo.vi_planes); + VGLDisplay->VYsize = VGLBufSize/VGLModeInfo.vi_planes/VGLAdpInfo.va_line_width; + VGLDisplay->Xorigin = 0; + VGLDisplay->Yorigin = 0; + + VGLMem = (byte*)mmap(0, VGLAdpInfo.va_window_size, PROT_READ|PROT_WRITE, + MAP_FILE, 0, 0); + if (VGLMem == MAP_FAILED) { + VGLEnd(); + return -7; + } VGLDisplay->Bitmap = VGLMem; ! VGLSavePalette(); + fprintf(stderr, "va_line_width:%d\n", VGLAdpInfo.va_line_width); + fprintf(stderr, "VGLXsize:%d, Ysize:%d, VXsize:%d, VYsize:%d\n", + VGLDisplay->Xsize, VGLDisplay->Ysize, + VGLDisplay->VXsize, VGLDisplay->VYsize); + smode.mode = VT_PROCESS; smode.waitv = 0; smode.relsig = SIGUSR1; smode.acqsig = SIGUSR1; smode.frsig = SIGINT; ! if (ioctl(0, VT_SETMODE, &smode)) { VGLEnd(); ! return -9; } VGLTextSetFontFile((byte*)0); ! VGLClear(VGLDisplay, 0); return 0; } void VGLCheckSwitch() { ! while (VGLSwitchPending) { ! unsigned int offset; ! unsigned int len; int i; VGLSwitchPending = 0; *************** *** 200,221 **** ioctl(0, KDENABIO, 0); ioctl(0, KDSETMODE, KD_GRAPHICS); ioctl(0, VGLMode, 0); ! outb(0x3c6, 0xff); ! for (i=0; i<4; i++) { ! outb(0x3c4, 0x02); ! outb(0x3c5, 0x01<Bitmap = VGLMem; switch (VGLMode) { case SW_BG640x480: case SW_CG640x480: ! VGLDisplay->Type = VIDBUF4; break; case SW_VGA_CG320: ! VGLDisplay->Type = VIDBUF8; ! break; case SW_VGA_MODEX: VGLDisplay->Type = VIDBUF8X; break; --- 307,365 ---- ioctl(0, KDENABIO, 0); ioctl(0, KDSETMODE, KD_GRAPHICS); ioctl(0, VGLMode, 0); ! VGLCurWindow = 0; ! VGLMem = (byte*)mmap(0, VGLAdpInfo.va_window_size, PROT_READ|PROT_WRITE, ! MAP_FILE, 0, 0); ! /* XXX: what if mmap() has failed! */ ! #if 0 /* #ifdef V_INFO_MM_OTHER */ ! type = VIDBUF8; /* XXX */ ! switch (VGLModeInfo.vi_mem_model) { ! case V_INFO_MM_PLANAR: ! if (VGLModeInfo.vi_depth == 4 && VGLModeInfo.vi_planes == 4) { ! if (VGLBufSize/VGLModeInfo.vi_planes > VGLAdpInfo.va_window_size) ! VGLDisplay->Type = VIDBUF4S; ! else ! VGLDisplay->Type = VIDBUF4; ! } else { ! /* shouldn't be happening */ ! } ! break; ! case V_INFO_MM_PACKED: ! if (VGLModeInfo.vi_depth == 8) { ! if (VGLBufSize/VGLModeInfo.vi_planes > VGLAdpInfo.va_window_size) ! VGLDisplay->Type = VIDBUF8S; ! else ! VGLDisplay->Type = VIDBUF8; ! } else { ! /* shouldn't be happening */ ! } ! break; ! case V_INFO_MM_VGAX: ! VGLDisplay->Type = VIDBUF8X; ! break; ! default: ! /* shouldn't be happening */ ! break; } ! #else /* V_INFO_MM_OTHER */ switch (VGLMode) { case SW_BG640x480: case SW_CG640x480: ! case SW_VESA_800x600: case SW_VESA_1024x768: ! case SW_VESA_1280x1024: ! if (VGLBufSize/VGLModeInfo.vi_planes > VGLAdpInfo.va_window_size) ! VGLDisplay->Type = VIDBUF4S; ! else ! VGLDisplay->Type = VIDBUF4; break; case SW_VGA_CG320: ! case SW_VESA_CG640x400: case SW_VESA_CG640x480: ! case SW_VESA_CG800x600: case SW_VESA_CG1024x768: ! case SW_VESA_CG1280x1024: ! if (VGLBufSize/VGLModeInfo.vi_planes > VGLAdpInfo.va_window_size) ! VGLDisplay->Type = VIDBUF8S; ! else ! VGLDisplay->Type = VIDBUF8; ! break; case SW_VGA_MODEX: VGLDisplay->Type = VIDBUF8X; break; *************** *** 223,243 **** VGLDisplay->Type = VIDBUF8; /* XXX */ break; } } else { ! for (i=0; i<4; i++) { ! outb(0x3ce, 0x04); ! outb(0x3cf, i); ! bcopy(VGLMem, &VGLBuf[i*64*1024], 64*1024); } ioctl(0, VGLOldMode, 0); ioctl(0, KDSETMODE, KD_TEXT); ioctl(0, KDDISABIO, 0); ioctl(0, VT_RELDISP, VT_TRUE); VGLDisplay->Bitmap = VGLBuf; VGLDisplay->Type = MEMBUF; } } ! while (!VGLOnDisplay) pause(); } - --- 367,528 ---- VGLDisplay->Type = VIDBUF8; /* XXX */ break; } + #endif /* V_INFO_MM_OTHER */ + VGLDisplay->Bitmap = VGLMem; + VGLDisplay->Xsize = VGLModeInfo.vi_width; + VGLDisplay->Ysize = VGLModeInfo.vi_height; + VGLSetVScreenSize(VGLDisplay->VXsize, VGLDisplay->VYsize); + VGLPanScreen(VGLDisplay->Xorigin, VGLDisplay->Yorigin); + switch (VGLDisplay->Type) { + case VIDBUF4S: + outb(0x3c6, 0xff); + outb(0x3ce, 0x01); outb(0x3cf, 0x00); /* set/reset enable */ + outb(0x3ce, 0x08); outb(0x3cf, 0xff); /* bit mask */ + for (offset = 0; offset < VGLBufSize/VGLModeInfo.vi_planes; + offset += len) { + VGLSetSegment(offset); + len = min(VGLBufSize/VGLModeInfo.vi_planes - offset, + VGLAdpInfo.va_window_size); + for (i = 0; i < VGLModeInfo.vi_planes; i++) { + outb(0x3c4, 0x02); + outb(0x3c5, 0x01<Type) { ! case VIDBUF4S: ! for (offset = 0; offset < VGLBufSize/VGLModeInfo.vi_planes; ! offset += len) { ! VGLSetSegment(offset); ! len = min(VGLBufSize/VGLModeInfo.vi_planes - offset, ! VGLAdpInfo.va_window_size); ! for (i = 0; i < VGLModeInfo.vi_planes; i++) { ! outb(0x3ce, 0x04); ! outb(0x3cf, i); ! bcopy(VGLMem, &VGLBuf[i*VGLBufSize/VGLModeInfo.vi_planes + offset], ! len); ! } ! } ! break; ! case VIDBUF4: ! case VIDBUF8X: ! /* ! * NOTE: the saved buffer is NOT in the MEMBUF format which ! * the ordinary memory bitmap object is stored in. XXX ! */ ! for (i = 0; i < VGLModeInfo.vi_planes; i++) { ! outb(0x3ce, 0x04); ! outb(0x3cf, i); ! bcopy(VGLMem, &VGLBuf[i*VGLAdpInfo.va_window_size], ! VGLAdpInfo.va_window_size); ! } ! break; ! case VIDBUF8: ! case VIDBUF8S: ! for (offset = 0; offset < VGLBufSize; offset += len) { ! VGLSetSegment(offset); ! len = min(VGLBufSize - offset, VGLAdpInfo.va_window_size); ! bcopy(VGLMem, &VGLBuf[offset], len); ! } ! break; } + VGLMem = MAP_FAILED; + munmap(VGLDisplay->Bitmap, VGLAdpInfo.va_window_size); ioctl(0, VGLOldMode, 0); ioctl(0, KDSETMODE, KD_TEXT); ioctl(0, KDDISABIO, 0); ioctl(0, VT_RELDISP, VT_TRUE); VGLDisplay->Bitmap = VGLBuf; VGLDisplay->Type = MEMBUF; + VGLDisplay->Xsize = VGLDisplay->VXsize; + VGLDisplay->Ysize = VGLDisplay->VYsize; + while (!VGLOnDisplay) pause(); } } ! } ! ! int ! VGLSetSegment(unsigned int offset) ! { ! if (offset/VGLAdpInfo.va_window_size != VGLCurWindow) { ! ioctl(0, CONS_SETWINORG, offset); /* FBIO_SETWINORG */ ! VGLCurWindow = offset/VGLAdpInfo.va_window_size; ! } ! return (offset%VGLAdpInfo.va_window_size); ! } ! ! int ! VGLSetVScreenSize(int VXsize, int VYsize) ! { ! if (VXsize < VGLDisplay->Xsize || VYsize < VGLDisplay->Ysize) ! return -1; ! if (VGLDisplay->Type == MEMBUF) ! return -1; ! #ifdef FBIO_SETLINEWIDTH ! if (ioctl(0, FBIO_SETLINEWIDTH, &VXsize)) ! return -1; ! ioctl(0, CONS_ADPINFO, &VGLAdpInfo); /* FBIO_ADPINFO */ ! VGLDisplay->VXsize = VGLAdpInfo.va_line_width ! *8/(VGLModeInfo.vi_depth/VGLModeInfo.vi_planes); ! VGLDisplay->VYsize = VGLBufSize/VGLModeInfo.vi_planes/VGLAdpInfo.va_line_width; ! if (VYsize < VGLDisplay->VYsize) ! VGLDisplay->VYsize = VYsize; ! ! fprintf(stderr, "new size: VGLXsize:%d, Ysize:%d, VXsize:%d, VYsize:%d\n", ! VGLDisplay->Xsize, VGLDisplay->Ysize, ! VGLDisplay->VXsize, VGLDisplay->VYsize); ! ! return 0; ! #else /* FBIO_SETLINEWIDTH */ ! return -1; ! #endif /* FBIO_SETLINEWIDTH */ ! } ! ! int ! VGLPanScreen(int x, int y) ! { ! video_display_start_t origin; ! ! if (x < 0 || x + VGLDisplay->Xsize > VGLDisplay->VXsize ! || y < 0 || y + VGLDisplay->Ysize > VGLDisplay->VYsize) ! return -1; ! if (VGLDisplay->Type == MEMBUF) ! return 0; ! origin.x = x; ! origin.y = y; ! if (ioctl(0, FBIO_SETDISPSTART, &origin)) ! return -1; ! VGLDisplay->Xorigin = x; ! VGLDisplay->Yorigin = y; ! ! fprintf(stderr, "new origin: (%d, %d)\n", x, y); ! ! return 0; } Index: mouse.c =================================================================== RCS file: /src/CVS/src/lib/libvgl/mouse.c,v retrieving revision 1.1 diff -c -r1.1 mouse.c *** mouse.c 1997/08/17 21:09:35 1.1 --- mouse.c 1999/08/24 12:00:24 *************** *** 35,43 **** #include #include "vgl.h" - /* prototype for internal function */ - int __VGLBitmapCopy(VGLBitmap *src, int srcx, int srcy, VGLBitmap *dst, int dstx, int dsty, int width, int hight); - #define X 0xff static byte StdAndMask[MOUSE_IMG_SIZE*MOUSE_IMG_SIZE] = { X,X,0,0,0,0,0,0,0,0,0,0,0,0,0,0, --- 35,40 ---- *************** *** 77,88 **** }; #undef X static VGLBitmap VGLMouseStdAndMask = ! { MEMBUF, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE, StdAndMask }; static VGLBitmap VGLMouseStdOrMask = ! { MEMBUF, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE, StdOrMask }; static VGLBitmap *VGLMouseAndMask, *VGLMouseOrMask; static byte map[MOUSE_IMG_SIZE*MOUSE_IMG_SIZE]; ! static VGLBitmap VGLMouseSave = { MEMBUF, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE, map}; static int VGLMouseVisible = 0; static int VGLMouseFrozen = 0; static int VGLMouseShown = 0; --- 74,86 ---- }; #undef X static VGLBitmap VGLMouseStdAndMask = ! VGLBITMAP_INITIALIZER(MEMBUF, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE, StdAndMask); static VGLBitmap VGLMouseStdOrMask = ! VGLBITMAP_INITIALIZER(MEMBUF, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE, StdOrMask); static VGLBitmap *VGLMouseAndMask, *VGLMouseOrMask; static byte map[MOUSE_IMG_SIZE*MOUSE_IMG_SIZE]; ! static VGLBitmap VGLMouseSave = ! VGLBITMAP_INITIALIZER(MEMBUF, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE, map); static int VGLMouseVisible = 0; static int VGLMouseFrozen = 0; static int VGLMouseShown = 0; *************** *** 94,100 **** VGLMousePointerShow() { byte buf[MOUSE_IMG_SIZE*MOUSE_IMG_SIZE]; ! VGLBitmap buffer = { MEMBUF, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE, buf }; byte crtcidx, crtcval, gdcidx, gdcval; int pos; --- 92,99 ---- VGLMousePointerShow() { byte buf[MOUSE_IMG_SIZE*MOUSE_IMG_SIZE]; ! VGLBitmap buffer = ! VGLBITMAP_INITIALIZER(MEMBUF, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE, buf); byte crtcidx, crtcval, gdcidx, gdcval; int pos; Index: simple.c =================================================================== RCS file: /src/CVS/src/lib/libvgl/simple.c,v retrieving revision 1.2 diff -c -r1.2 simple.c *** simple.c 1999/08/22 03:31:13 1.2 --- simple.c 1999/08/28 07:43:09 *************** *** 38,82 **** #define ABS(a) (((a)<0) ? -(a) : (a)) #define SGN(a) (((a)<0) ? -1 : 1) - void VGLSetXY(VGLBitmap *object, int x, int y, byte color) { VGLCheckSwitch(); ! if (x>=0 && xXsize && y>=0 && yYsize) { if (!VGLMouseFreeze(x, y, 1, 1, color)) { switch (object->Type) { case MEMBUF: case VIDBUF8: ! object->Bitmap[y*object->Xsize+x]=(color); break; case VIDBUF8X: outb(0x3c4, 0x02); outb(0x3c5, 0x01 << (x&0x3)); ! object->Bitmap[(unsigned)(object->Xsize/2*y)+(x/4)] = (color); break; case VIDBUF4: ! outb(0x3c4, 0x02); outb(0x3c5, 0x01); ! outb(0x3ce, 0x04); outb(0x3cf, 0x00); ! object->Bitmap[(y*object->Xsize/8+x/8)&0xffff] = ! ( object->Bitmap[(y*object->Xsize/8+x/8)&0xffff] & ~(0x80>>(x%8)) ) ! | ((color & 0x01) ? (0x80>>(x%8)) : 0); ! outb(0x3c4, 0x02); outb(0x3c5, 0x02); ! outb(0x3ce, 0x04); outb(0x3cf, 0x01); ! object->Bitmap[(y*object->Xsize/8+x/8)&0xffff] = ! ( object->Bitmap[(y*object->Xsize/8+x/8)&0xffff] & ~(0x80>>(x%8)) ) ! | ((color & 0x02) ? (0x80>>(x%8)) : 0); ! outb(0x3c4, 0x02); outb(0x3c5, 0x04); ! outb(0x3ce, 0x04); outb(0x3cf, 0x02); ! object->Bitmap[(y*object->Xsize/8+x/8)&0xffff] = ! ( object->Bitmap[(y*object->Xsize/8+x/8)&0xffff] & ~(0x80>>(x%8)) ) ! | ((color & 0x04) ? (0x80>>(x%8)) : 0); ! outb(0x3c4, 0x02); outb(0x3c5, 0x08); ! outb(0x3ce, 0x04); outb(0x3cf, 0x03); ! object->Bitmap[(y*object->Xsize/8+x/8)&0xffff] = ! ( object->Bitmap[(y*object->Xsize/8+x/8)&0xffff] & ~(0x80>>(x%8)) ) ! | ((color & 0x08) ? (0x80>>(x%8)) : 0); } } VGLMouseUnFreeze(); --- 38,78 ---- #define ABS(a) (((a)<0) ? -(a) : (a)) #define SGN(a) (((a)<0) ? -1 : 1) + #define min(x, y) (((x) < (y)) ? (x) : (y)) + #define max(x, y) (((x) > (y)) ? (x) : (y)) void VGLSetXY(VGLBitmap *object, int x, int y, byte color) { + int offset; + VGLCheckSwitch(); ! if (x>=0 && xVXsize && y>=0 && yVYsize) { if (!VGLMouseFreeze(x, y, 1, 1, color)) { switch (object->Type) { case MEMBUF: case VIDBUF8: ! object->Bitmap[y*object->VXsize+x]=(color); break; + case VIDBUF8S: + object->Bitmap[VGLSetSegment(y*object->VXsize+x)]=(color); + break; case VIDBUF8X: outb(0x3c4, 0x02); outb(0x3c5, 0x01 << (x&0x3)); ! object->Bitmap[(unsigned)(VGLAdpInfo.va_line_width*y)+(x/4)] = (color); break; + case VIDBUF4S: + offset = VGLSetSegment(y*VGLAdpInfo.va_line_width + x/8); + goto set_planar; case VIDBUF4: ! offset = y*VGLAdpInfo.va_line_width + x/8; ! set_planar: ! outb(0x3c4, 0x02); outb(0x3c5, 0x0f); ! outb(0x3ce, 0x00); outb(0x3cf, color & 0x0f); /* set/reset */ ! outb(0x3ce, 0x01); outb(0x3cf, 0x0f); /* set/reset enable */ ! outb(0x3ce, 0x08); outb(0x3cf, 0x80 >> (x%8)); /* bit mask */ ! object->Bitmap[offset] |= color; } } VGLMouseUnFreeze(); *************** *** 86,104 **** byte VGLGetXY(VGLBitmap *object, int x, int y) { VGLCheckSwitch(); switch (object->Type) { case MEMBUF: case VIDBUF8: ! return object->Bitmap[((y*object->Xsize)+x)]; ! break; case VIDBUF8X: outb(0x3ce, 0x04); outb(0x3cf, x & 0x3); ! return object->Bitmap[(unsigned)(object->Xsize/2*y)+(x/4)]; ! break; case VIDBUF4: ! return (object->Bitmap[((y*object->Xsize/8)+x/8)]&(0x80>>(x%8))) ? 1 : 0; ! break; } return 0; } --- 82,121 ---- byte VGLGetXY(VGLBitmap *object, int x, int y) { + int offset; + int i; + byte color; + byte mask; + VGLCheckSwitch(); + if (x<0 || x>=object->VXsize || y<0 || y>=object->VYsize) + return 0; switch (object->Type) { case MEMBUF: case VIDBUF8: ! return object->Bitmap[((y*object->VXsize)+x)]; ! case VIDBUF8S: ! return object->Bitmap[VGLSetSegment(y*object->VXsize+x)]; case VIDBUF8X: outb(0x3ce, 0x04); outb(0x3cf, x & 0x3); ! return object->Bitmap[(unsigned)(VGLAdpInfo.va_line_width*y)+(x/4)]; ! case VIDBUF4S: ! offset = VGLSetSegment(y*VGLAdpInfo.va_line_width + x/8); ! goto get_planar; case VIDBUF4: ! offset = y*VGLAdpInfo.va_line_width + x/8; ! get_planar: ! #if 1 ! return (object->Bitmap[offset]&(0x80>>(x%8))) ? 1 : 0; /* XXX */ ! #else ! color = 0; ! mask = 0x80 >> (x%8); ! for (i = 0; i < VGLModeInfo.vi_planes; i++) { ! outb(0x3ce, 0x04); outb(0x3cf, i); ! color |= (object->Bitmap[offset] & mask) ? (1 << i) : 0; ! } ! return color; ! #endif } return 0; } *************** *** 234,255 **** void VGLClear(VGLBitmap *object, byte color) { VGLCheckSwitch(); VGLMouseFreeze(0, 0, object->Xsize, object->Ysize, color); switch (object->Type) { case MEMBUF: case VIDBUF8: ! memset(object->Bitmap, color, object->Xsize*object->Ysize); break; case VIDBUF8X: /* XXX works only for Xsize % 4 = 0 */ outb(0x3c4, 0x02); outb(0x3c5, 0x0f); ! memset(object->Bitmap, color, object->Xsize*object->Ysize/4); break; case VIDBUF4: /* XXX works only for Xsize % 8 = 0 */ ! memset(object->Bitmap, color, object->Xsize/8*object->Ysize); break; } VGLMouseUnFreeze(); --- 251,299 ---- void VGLClear(VGLBitmap *object, byte color) { + int offset; + int len; + VGLCheckSwitch(); VGLMouseFreeze(0, 0, object->Xsize, object->Ysize, color); switch (object->Type) { case MEMBUF: case VIDBUF8: ! memset(object->Bitmap, color, object->VXsize*object->VYsize); ! break; ! ! case VIDBUF8S: ! for (offset = 0; offset < object->VXsize*object->VYsize; ) { ! VGLSetSegment(offset); ! len = min(object->VXsize*object->VYsize - offset, ! VGLAdpInfo.va_window_size); ! memset(object->Bitmap, color, len); ! offset += len; ! } break; + case VIDBUF8X: /* XXX works only for Xsize % 4 = 0 */ + outb(0x3c6, 0xff); outb(0x3c4, 0x02); outb(0x3c5, 0x0f); ! memset(object->Bitmap, color, VGLAdpInfo.va_line_width*object->VYsize); break; case VIDBUF4: + case VIDBUF4S: /* XXX works only for Xsize % 8 = 0 */ ! outb(0x3c4, 0x02); outb(0x3c5, 0x0f); ! outb(0x3ce, 0x05); outb(0x3cf, 0x02); /* mode 2 */ ! outb(0x3ce, 0x01); outb(0x3cf, 0x00); /* set/reset enable */ ! outb(0x3ce, 0x08); outb(0x3cf, 0xff); /* bit mask */ ! for (offset = 0; offset < VGLAdpInfo.va_line_width*object->VYsize; ) { ! VGLSetSegment(offset); ! len = min(object->VXsize*object->VYsize - offset, ! VGLAdpInfo.va_window_size); ! memset(object->Bitmap, color, len); ! offset += len; ! } ! outb(0x3ce, 0x05); outb(0x3cf, 0x00); break; } VGLMouseUnFreeze(); Index: text.c =================================================================== RCS file: /src/CVS/src/lib/libvgl/text.c,v retrieving revision 1.2 diff -c -r1.2 text.c *** text.c 1999/08/22 03:31:13 1.2 --- text.c 1999/08/23 11:25:42 *************** *** 29,34 **** --- 29,35 ---- */ #include + #include #include "vgl.h" static VGLText *VGLTextFont = 0; Index: vgl.h =================================================================== RCS file: /src/CVS/src/lib/libvgl/vgl.h,v retrieving revision 1.2 diff -c -r1.2 vgl.h *** vgl.h 1997/10/01 20:53:41 1.2 --- vgl.h 1999/08/24 12:05:35 *************** *** 37,45 **** --- 37,50 ---- typedef struct { byte Type; int Xsize, Ysize; + int VXsize, VYsize; + int Xorigin, Yorigin; byte *Bitmap; } VGLBitmap; + #define VGLBITMAP_INITIALIZER(t, x, y, bits) \ + { (t), (x), (y), 0, 0, 0, 0, (bits) } + /* * Defined Type's */ *************** *** 47,52 **** --- 52,59 ---- #define VIDBUF4 1 #define VIDBUF8 2 #define VIDBUF8X 3 + #define VIDBUF8S 4 + #define VIDBUF4S 5 #define NOBUF 255 typedef struct VGLText { *************** *** 78,84 **** #define VGL_CODEKEYS 2 #define VGL_XLATEKEYS 3 ! extern VGLBitmap *VGLDisplay; /* * Prototypes --- 85,94 ---- #define VGL_CODEKEYS 2 #define VGL_XLATEKEYS 3 ! extern video_adapter_info_t VGLAdpInfo; ! extern video_info_t VGLModeInfo; ! extern VGLBitmap *VGLDisplay; ! extern byte *VGLBuf; /* * Prototypes *************** *** 86,91 **** --- 96,104 ---- /* bitmap.c */ int __VGLBitmapCopy(VGLBitmap *src, int srcx, int srcy, VGLBitmap *dst, int dstx, int dsty, int width, int hight); int VGLBitmapCopy(VGLBitmap *src, int srcx, int srcy, VGLBitmap *dst, int dstx, int dsty, int width, int hight); + VGLBitmap *VGLBitmapCreate(int type, int xsize, int ysize, byte *bits); + void VGLBitmapDestroy(VGLBitmap *object); + int VGLBitmapAllocateBits(VGLBitmap *object); /* keyboard.c */ int VGLKeyboardInit(int mode); void VGLKeyboardEnd(void); *************** *** 94,99 **** --- 107,115 ---- void VGLEnd(void); int VGLInit(int mode); void VGLCheckSwitch(void); + int VGLSetVScreenSize(int VXsize, int VYsize); + int VGLPanScreen(int x, int y); + int VGLSetSegment(unsigned int offset); /* mouse.c */ void VGLMousePointerShow(void); void VGLMousePointerHide(void);