⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vga16.c

📁 libminigui-1.3.0.tar.gz。 miniGUI的库函数源代码!
💻 C
📖 第 1 页 / 共 3 页
字号:
            y += mygc->clipminy - ny;            h -= mygc->clipminy - ny;            ny = mygc->clipminy;        }        if (ny + h - 1 >= mygc->clipmaxy) {            h = mygc->clipmaxy - ny;        }        } else {        if ((nx + w - 1 < 0) || (nx >= mygc->xres))            goto inv_args;        if ((ny + h - 1 < 0) || (ny >= mygc->yres))            goto inv_args;        if (nx < 0) {            x -= nx;            w += nx;            nx = 0;        }         if (nx + w - 1 >= mygc->xres) {            w = mygc->xres- nx;        }        if (ny < 0) {            y -= ny;            h += ny;            ny = 0;        }        if (ny + h - 1 >= mygc->yres) {            h = mygc->yres- ny;        }        }        if ((w <= 0) || (h <= 0))        goto inv_args;    if ((x < 0) || (x + w - 1 >= mygc->xres))        goto inv_args;    if ((y < 0) || (y + h - 1 >= mygc->yres))        goto inv_args;    if (mygc->doclip) {        if ((nx < mygc->clipminx) || (nx + w - 1 >= mygc->clipmaxx))             goto inv_args;        if ((ny < mygc->clipminy) || (ny + h - 1 >= mygc->clipmaxy))             goto inv_args;    } else {        if ((nx < 0) || (nx + w - 1 >= mygc->xres))             goto inv_args;        if ((ny < 0) || (ny + h - 1 >= mygc->yres))             goto inv_args;    }    if (mygc->fb_buff)        copybox_helper1 (mygc, x, y, w, h, nx, ny);    else        copybox_helper2 (mygc, x, y, w, h, nx, ny);inv_args:    UNBLOCK_DRAW_SEM;    return 0;}/*  * Must set destination graphics context */static int crossblit (GAL_GC src, int sx, int sy, int w, int h,        GAL_GC dst, int dx, int dy){#ifdef _LITE_VERSION    GAL_GC gc = dst;#endif    GC_VGA16* dstgc = dst.gc_vga16;    GC_VGA16* srcgc = src.gc_vga16;    if ((w <= 0) || (h <= 0)) return -1;    if (src.gc_vga16 == dst.gc_vga16) {        return copybox (src, sx, sy, w, h, dx, dy);    }        //src clip to screen    if ((sx >= src.gc_vga16->xres) || (sx + w - 1 < 0)) return -1;    if ((sy >= src.gc_vga16->yres) || (sy + h - 1 < 0)) return -1;    if (sx < 0) { dx -= sx; w += sx; sx = 0; }    if (sy < 0) { dy -= sy; h += sy; sy = 0; }        if (sx + w - 1 >= src.gc_vga16->xres) w = src.gc_vga16->xres - sx;    if (sy + h - 1 >= src.gc_vga16->yres) h = src.gc_vga16->yres - sy;            BLOCK_DRAW_SEM;    //dst do clip    if (dst.gc_vga16->doclip) {        if ((dx + w - 1 < dst.gc_vga16->clipminx) || (dx >= dst.gc_vga16->clipmaxx))            goto inv_args;        if ((dy + h - 1 < dst.gc_vga16->clipminy) || (dy >= dst.gc_vga16->clipmaxy))            goto inv_args;        if (dx < dst.gc_vga16->clipminx) {            sx += dst.gc_vga16->clipminx - dx;            w -= dst.gc_vga16->clipminx - dx;            dx = dst.gc_vga16->clipminx;        }         if (dx + w - 1 >= dst.gc_vga16->clipmaxx) {            w = dst.gc_vga16->clipmaxx - dx;        }        if (dy < dst.gc_vga16->clipminy) {            sy += dst.gc_vga16->clipminy - dy;            h -= dst.gc_vga16->clipminy - dy;            dy = dst.gc_vga16->clipminy;        }        if (dy + h - 1 >= dst.gc_vga16->clipmaxy) {            h = dst.gc_vga16->clipmaxy - dy;        }        } else {        if ((dx + w - 1 < 0) || (dx >= dst.gc_vga16->xres))            goto inv_args;        if ((dy + h - 1 < 0) || (dy >= dst.gc_vga16->yres))            goto inv_args;        if (dx < 0) {            sx -= dx;            w += dx;            dx = 0;        }         if (dx + w - 1 >= dst.gc_vga16->xres) {            w = dst.gc_vga16->xres- dx;        }        if (dy < 0) {            sy -= dy;            h += dy;            dy = 0;        }        if (dy + h - 1 >= dst.gc_vga16->yres) {            h = dst.gc_vga16->yres- dy;        }        }        if ((w <= 0) || (h <= 0))        goto inv_args;    if ((sx < 0) || (sx + w - 1 >= src.gc_vga16->xres))        goto inv_args;    if ((sy < 0) || (sy + h - 1 >= src.gc_vga16->yres))        goto inv_args;    if (dst.gc_vga16->doclip) {        if ((dx < dst.gc_vga16->clipminx) || (dx + w - 1 >= dst.gc_vga16->clipmaxx))             goto inv_args;        if ((dy < dst.gc_vga16->clipminy) || (dy + h - 1 >= dst.gc_vga16->clipmaxy))            goto inv_args;    } else {        if ((dx < 0) || (dx + w - 1 >= dst.gc_vga16->xres))             goto inv_args;        if ((dy < 0) || (dy + h - 1 >= dst.gc_vga16->yres))             goto inv_args;    }    if (dstgc->fb_buff) {        gal_uint8 *dst = dstgc->fb_buff + dy * dstgc->pitch + dx;        if (srcgc->fb_buff) {            gal_uint8 *src = srcgc->fb_buff + sy * srcgc->pitch + sx;            while (h--) {                memcpy (dst, src, w);                dst += dstgc->pitch;                src += srcgc->pitch;            }        }        else {            while (h--) {                vga_getscansegment (dst, sx, sy++, w);                dst += dstgc->pitch;            }        }    }    else {        gal_uint8 *src = srcgc->fb_buff + sy * srcgc->pitch + sx;        if (srcgc->fb_buff) {            while (h--) {                vga_drawscansegment (src, dx, dy++, w);                src += srcgc->pitch;            }        }        else {            while (h--) {                vga_getscansegment (srcgc->scanline, sx, sy++, w);                vga_drawscansegment (srcgc->scanline, dx, dy++, w);            }        }    }inv_args:    UNBLOCK_DRAW_SEM;    return 0;}static int drawhline (GAL_GC gc, int x, int y, int w, gal_pixel pixel){    GC_VGA16* mygc = gc.gc_vga16;    BLOCK_DRAW_SEM;    if (vga16_cliphline (mygc, &x, &y, &w)) {        if (mygc->fb_buff) {            gal_uint8 *dst = mygc->fb_buff + y * mygc->pitch + x;            memset (dst, mygc->gr_foreground, w);        }        else {            memset (mygc->scanline, mygc->gr_foreground, w);            vga_drawscansegment (mygc->scanline, x, y, w);        }    }    UNBLOCK_DRAW_SEM;    return 0;}static int drawvline (GAL_GC gc, int x, int y, int h, gal_pixel pixel){    GC_VGA16* mygc = gc.gc_vga16;    if (h <= 0 ) return -1;        BLOCK_DRAW_SEM;    if (vga16_clipvline (mygc, &x, &y, &h)) {        if (mygc->fb_buff) {            gal_uint8 *dst = mygc->fb_buff + y * mygc->pitch + x;            while (h--) {                *dst = mygc->gr_foreground;                dst += mygc->pitch;            }        }        else {            while (h--) {                vga_drawpixel (x, y++);            }        }    }    UNBLOCK_DRAW_SEM;    return 0;}/* *  Pixel operations */static int drawpixel (GAL_GC gc, int x, int y, gal_pixel pixel){    GC_VGA16* mygc = gc.gc_vga16;    BLOCK_DRAW_SEM;    if (vga16_clippoint (mygc, x, y)) {        if (mygc->fb_buff) {            gal_uint8 *dst = mygc->fb_buff + y * mygc->pitch + x;            *dst = mygc->gr_foreground;        }        else            vga_drawpixel (x, y);    }    UNBLOCK_DRAW_SEM;    return 0;}static int getpixel (GAL_GC gc, int x, int y, gal_pixel* pixel){    GC_VGA16* mygc = gc.gc_vga16;    if ((x >= 0) && (x < mygc->xres) && (y >= 0) && (y < mygc->yres)) {        if (mygc->fb_buff) {            gal_uint8 *src = mygc->fb_buff + y * mygc->pitch + x;            *pixel = *src;        }        else            *pixel = vga_getpixel (x, y);    }    return 0;}static void drawline_helper (GC_VGA16* gc, int x1, int y1, int x2, int y2){    int dx = x2 - x1;    int dy = y2 - y1;    int ax = ABS(dx) << 1;    int ay = ABS(dy) << 1;    int sx = (dx >= 0) ? 1 : -1;    int sy = (dy >= 0) ? 1 : -1;    int x = x1;    int y = y1;    gal_uint8* buf = gc->fb_buff + gc->pitch * y + x;    if (ax > ay) {        int d = ay - (ax >> 1);        while (x != x2) {            *buf = gc->gr_foreground;            if (d > 0 || (d == 0 && sx == 1)) {                y += sy;                buf += gc->pitch * sy;                d -= ax;            }            x += sx;            buf += sx;            d += ay;        }    } else {        int d = ax - (ay >> 1);        while (y != y2) {            *buf = gc->gr_foreground;            if (d > 0 || (d == 0 && sy == 1)) {                x += sx;                buf += sx;                d -= ay;            }            y += sy;            buf += gc->pitch * sy;            d += ax;        }    }    *buf = gc->gr_foreground;}static int line (GAL_GC gc, int x1, int y1, int x2, int y2, gal_pixel pixel){    GC_VGA16* mygc = gc.gc_vga16;    BLOCK_DRAW_SEM;    if (vga16_clipline (mygc, &x1, &y1, &x2, &y2)) {        if (mygc->fb_buff)            drawline_helper (mygc, x1, y1, x2, y2);        else            vga_drawline (x1, y1, x2, y2);    }    UNBLOCK_DRAW_SEM;    return 0;}/*  * NOTE: must be normalized rect. */static int rectangle (GAL_GC gc, int l, int t, int r, int b, gal_pixel pixel){    int w = r - l;    int h = b - t;    drawhline (gc, l, t, w, pixel);    drawvline (gc, l, t, h, pixel);    drawhline (gc, l, b, w, pixel);    drawvline (gc, r, t, h, pixel);        return 0;}static int circle (GAL_GC gc, int x, int y, int r, gal_pixel pixel){    return 0;}static void panic (int exitcode){    fprintf (stderr, "MiniGUI Panic. Exit Code: %d.\n", exitcode);    vga_setmode (TEXT);    _exit (exitcode);}#ifdef _LITE_VERSION/* the following varibles defined in svgalib. * For the clients, we should not call vga_init and vga_setmode functions, * so we set these varibles by ourselves. */struct info {    int xdim;    int ydim;    int colors;    int xbytes;    int bytesperpixel;};extern unsigned long int __svgalib_banked_mem_base, __svgalib_banked_mem_size;extern unsigned long int __svgalib_mmio_base, __svgalib_mmio_size;extern unsigned long int __svgalib_linear_mem_base, __svgalib_linear_mem_size;extern unsigned long int __svgalib_mmio_base, __svgalib_mmio_size;extern unsigned char * BANKED_MEM_POINTER, * LINEAR_MEM_POINTER, *MMIO_POINTER;extern unsigned char * B8000_MEM_POINTER;extern struct info __svgalib_cur_info;      /* current video parameters */extern int __svgalib_cur_mode;              /* current video mode       */extern unsigned char *__svgalib_graph_mem;  /* graphics memory frame */extern int __svgalib_modeX;extern int __svgalib_screenon;extern int __svgalib_chipset;extern int __svgalib_mem_fd;#define CI      __svgalib_cur_info#define GM      __svgalib_graph_mem#define CM      __svgalib_cur_mode#define CHIPSET __svgalib_chipset#define SCREENON __svgalib_screenon#define MODEX   __svgalib_modeXstatic BOOL init_vga16_client (void){#if 1    if (ioperm (0x3b4, 0x3df - 0x3b4 + 1, 1) < 0) {#else    if (iopl(3) < 0) {#endif        printf ("VGA16 GAL engine for clients: Can not get I/O permissions.\n");        return FALSE;    }    if ((__svgalib_mem_fd = open ("/dev/mem", O_RDWR)) < 0) {        printf ("VGA16 GAL engine for clients: Can not open /dev/mem.\n");        return FALSE;    }    __svgalib_banked_mem_base = 0xa0000;    __svgalib_banked_mem_size = 0x10000;    BANKED_MEM_POINTER = mmap((caddr_t) 0, __svgalib_banked_mem_size,            PROT_READ | PROT_WRITE, MAP_SHARED,            __svgalib_mem_fd, __svgalib_banked_mem_base);    __svgalib_linear_mem_size = 0;    __svgalib_mmio_size = 0;        B8000_MEM_POINTER = mmap((caddr_t) 0, 32768,            PROT_READ | PROT_WRITE, MAP_SHARED,            __svgalib_mem_fd, (off_t) 0xb8000);    close (__svgalib_mem_fd);    GM = (unsigned char *) BANKED_MEM_POINTER;    if ((long) GM < 0) {        printf ("VGA16 GAL engine for clients: mmap error.\n");        return FALSE;    }    graph_mem = GM;    CI.xdim = 640;    CI.ydim = 480;    CI.colors = 16;    CI.xbytes = 80;    CI.bytesperpixel = 0;    CM = G640x480x16;    MODEX = FALSE;    SCREENON = TRUE;    CHIPSET = VGA;    return TRUE;}static void term_vga16_client (void){    munmap (BANKED_MEM_POINTER, __svgalib_banked_mem_size);    munmap (B8000_MEM_POINTER, 32768);}#endif/************ Initialization and termination of VGA16 GAL engine **************/BOOL InitVGA16 (GFX* gfx){    GC_VGA16* gc;    int i;        if ((gc = malloc (sizeof (GC_VGA16))) == NULL) {        fprintf (stderr, "VGA16 GAL: allocating physical GC error!\n");        return FALSE;    }    gc->xres = 640;    gc->yres = 480;    gc->pitch = 0;    gc->gr_background = 0;    gc->gr_foreground = 15;    gc->fb_buff = NULL;    vga_setmousesupport (0);#ifdef _LITE_VERSION    if (!mgIsServer) {        if (!init_vga16_client ())            return FALSE;    }    else {#endif        vga_init ();        if (vga_setmode (G640x480x16)) {            fprintf (stderr, "VGA16 GAL: can not set correct mode.\n");            return FALSE;        }#ifdef _LITE_VERSION    }#endif    gfx->phygc.gc_vga16 = gc;     gfx->bytes_per_phypixel = 1;    gfx->bits_per_phypixel  = 4;    gfx->width_phygc        = 640;    gfx->height_phygc       = 480;    gfx->colors_phygc       = 16;    gfx->grayscale_screen   = FALSE;        gfx->bytesperpixel      = bytesperpixel;    gfx->bitsperpixel       = bitsperpixel;    gfx->width              = width;    gfx->height             = height;    gfx->colors             = colors;    //now functions    gfx->allocategc         = allocategc;    gfx->freegc             = freegc;    gfx->enableclipping     = enableclipping;    gfx->disableclipping    = disableclipping;    gfx->setclipping        = setclipping;    gfx->getclipping        = getclipping;    gfx->getbgcolor         = getbgcolor;    gfx->setbgcolor         = setbgcolor;    gfx->getfgcolor         = getfgcolor;    gfx->setfgcolor         = setfgcolor;    gfx->mapcolor           = mapcolor;    gfx->unmappixel         = unmappixel;    gfx->getpalette         = getpalette;    gfx->setpalette         = setpalette;    gfx->setcolorfulpalette = setcolorfulpalette;    gfx->boxsize            = boxsize;    gfx->fillbox            = fillbox;    gfx->putbox             = putbox;    gfx->putboxmask         = putboxmask;    gfx->getbox             = getbox;    gfx->scalebox           = scalebox;    gfx->copybox            = copybox;    gfx->crossblit          = crossblit;    gfx->drawhline          = drawhline;    gfx->drawvline          = drawvline;    gfx->drawpixel          = drawpixel;    gfx->getpixel           = getpixel;    gfx->line               = line;    gfx->rectangle          = rectangle;    gfx->panic              = panic;    gfx->circle             = circle;    for (i = 0; i < 17; i++)        SysPixelIndex [i] = mapcolor (gfx->phygc, (GAL_Color*)(SysPixelColor + i));#ifdef _LITE_VERSION    if (mgIsServer)#endif        setcolorfulpalette (gfx->phygc);        setclipping (gfx->phygc, 0, 0, gc->xres - 1, gc->yres - 1);    return TRUE;}void TermVGA16 (GFX* gfx){#ifdef _LITE_VERSION    if (mgIsServer)        vga_setmode (TEXT);    else        term_vga16_client ();#else    vga_setmode (TEXT);#endif}#endif /* _VGA16_GAL */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -